22
22
23
23
import com .google .common .io .Resources ;
24
24
import com .google .errorprone .BugPattern ;
25
- import com .google .errorprone .ErrorProneFlags ;
26
25
import com .google .errorprone .VisitorState ;
27
26
import com .google .errorprone .matchers .Description ;
28
27
import com .google .errorprone .matchers .Matcher ;
29
28
import com .google .protobuf .ExtensionRegistry ;
30
29
import com .sun .source .tree .ExpressionTree ;
31
30
import java .io .IOException ;
32
31
import java .io .UncheckedIOException ;
33
- import javax .inject .Inject ;
34
32
35
33
/**
36
34
* Checks for uses of classes, fields, or methods that are not compatible with legacy Android
37
35
* devices. As of Android N, that includes all of JDK8 (which is only supported on Nougat) except
38
36
* type and repeated annotations, which are compiled in a backwards compatible way.
39
37
*/
40
38
@ BugPattern (
41
- name = "AndroidJdkLibsChecker" ,
42
39
altNames = "AndroidApiChecker" ,
43
40
summary = "Use of class, field, or method that is not compatible with legacy Android devices" ,
44
41
severity = ERROR )
45
42
// TODO(b/32513850): Allow Android N+ APIs, e.g., by computing API diff using android.jar
46
43
public class AndroidJdkLibsChecker extends ApiDiffChecker {
47
44
48
- private static ApiDiff loadApiDiff (boolean allowJava8 ) {
45
+ private static ApiDiff loadApiDiff () {
49
46
try {
50
47
byte [] diffData =
51
48
Resources .toByteArray (
52
- Resources .getResource (
53
- AndroidJdkLibsChecker .class ,
54
- allowJava8 ? "android_java8.binarypb" : "android.binarypb" ));
49
+ Resources .getResource (AndroidJdkLibsChecker .class , "android_java8.binarypb" ));
55
50
ApiDiffProto .Diff diff =
56
51
ApiDiffProto .Diff .newBuilder ()
57
52
.mergeFrom (diffData , ExtensionRegistry .getEmptyRegistry ())
@@ -62,20 +57,8 @@ private static ApiDiff loadApiDiff(boolean allowJava8) {
62
57
}
63
58
}
64
59
65
- private final boolean allowJava8 ;
66
-
67
- @ Inject
68
- AndroidJdkLibsChecker (ErrorProneFlags flags ) {
69
- this (flags .getBoolean ("Android:Java8Libs" ).orElse (false ));
70
- }
71
-
72
- public AndroidJdkLibsChecker () {
73
- this (false );
74
- }
75
-
76
- private AndroidJdkLibsChecker (boolean allowJava8 ) {
77
- super (loadApiDiff (allowJava8 ));
78
- this .allowJava8 = allowJava8 ;
60
+ private AndroidJdkLibsChecker () {
61
+ super (loadApiDiff ());
79
62
}
80
63
81
64
private static final Matcher <ExpressionTree > FOREACH_ON_COLLECTION =
@@ -90,7 +73,7 @@ protected Description check(ExpressionTree tree, VisitorState state) {
90
73
if (description .equals (NO_MATCH )) {
91
74
return NO_MATCH ;
92
75
}
93
- if (allowJava8 && FOREACH_ON_COLLECTION .matches (tree , state )) {
76
+ if (FOREACH_ON_COLLECTION .matches (tree , state )) {
94
77
return NO_MATCH ;
95
78
}
96
79
return description ;
0 commit comments