1 package org.robolectric.internal.bytecode;
2 
3 import java.util.Objects;
4 import org.robolectric.annotation.Implements;
5 import org.robolectric.annotation.Implements.DefaultShadowPicker;
6 import org.robolectric.shadow.api.ShadowPicker;
7 
8 @SuppressWarnings("NewApi")
9 public class ShadowInfo {
10 
11   public final String shadowedClassName;
12   public final String shadowClassName;
13   public final boolean callThroughByDefault;
14   public final boolean looseSignatures;
15   private final int minSdk;
16   private final int maxSdk;
17   private final Class<? extends ShadowPicker<?>> shadowPickerClass;
18 
ShadowInfo( String shadowedClassName, String shadowClassName, boolean callThroughByDefault, boolean looseSignatures, int minSdk, int maxSdk, Class<? extends ShadowPicker<?>> shadowPickerClass)19   ShadowInfo(
20       String shadowedClassName,
21       String shadowClassName,
22       boolean callThroughByDefault,
23       boolean looseSignatures,
24       int minSdk,
25       int maxSdk,
26       Class<? extends ShadowPicker<?>> shadowPickerClass) {
27     this.shadowedClassName = shadowedClassName;
28     this.shadowClassName = shadowClassName;
29     this.callThroughByDefault = callThroughByDefault;
30     this.looseSignatures = looseSignatures;
31     this.minSdk = minSdk;
32     this.maxSdk = maxSdk;
33     this.shadowPickerClass =
34         DefaultShadowPicker.class.equals(shadowPickerClass)
35             ? null
36             : shadowPickerClass;
37   }
38 
ShadowInfo(String shadowedClassName, String shadowClassName, Implements annotation)39   ShadowInfo(String shadowedClassName, String shadowClassName, Implements annotation) {
40     this(shadowedClassName,
41         shadowClassName,
42         annotation.callThroughByDefault(),
43         annotation.looseSignatures(),
44         annotation.minSdk(),
45         annotation.maxSdk(),
46         annotation.shadowPicker());
47   }
48 
supportsSdk(int sdkInt)49   public boolean supportsSdk(int sdkInt) {
50     return minSdk <= sdkInt && (maxSdk == -1 || maxSdk >= sdkInt);
51   }
52 
isShadowOf(Class<?> clazz)53   public boolean isShadowOf(Class<?> clazz) {
54     return shadowedClassName.equals(clazz.getName());
55   }
56 
hasShadowPicker()57   public boolean hasShadowPicker() {
58     return shadowPickerClass != null && !DefaultShadowPicker.class.equals(shadowPickerClass);
59   }
60 
getShadowPickerClass()61   public Class<? extends ShadowPicker<?>> getShadowPickerClass() {
62     return shadowPickerClass;
63   }
64 
65   @Override
equals(Object o)66   public boolean equals(Object o) {
67     if (this == o) {
68       return true;
69     }
70     if (!(o instanceof ShadowInfo)) {
71       return false;
72     }
73     ShadowInfo that = (ShadowInfo) o;
74     return callThroughByDefault == that.callThroughByDefault
75         && looseSignatures == that.looseSignatures
76         && minSdk == that.minSdk
77         && maxSdk == that.maxSdk
78         && Objects.equals(shadowedClassName, that.shadowedClassName)
79         && Objects.equals(shadowClassName, that.shadowClassName)
80         && Objects.equals(shadowPickerClass, that.shadowPickerClass);
81   }
82 
83   @Override
hashCode()84   public int hashCode() {
85     return Objects.hash(
86         shadowedClassName,
87         shadowClassName,
88         callThroughByDefault,
89         looseSignatures,
90         minSdk,
91         maxSdk,
92         shadowPickerClass);
93   }
94 }
95