|
17 | 17 | package com.google.errorprone.bugpatterns;
|
18 | 18 |
|
19 | 19 | import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
|
20 |
| -import static com.google.errorprone.util.ASTHelpers.getSymbol; |
21 | 20 | import static com.google.errorprone.util.ASTHelpers.getType;
|
22 |
| -import static com.google.errorprone.util.ASTHelpers.isStatic; |
23 | 21 |
|
24 | 22 | import com.google.errorprone.BugPattern;
|
25 |
| -import com.google.errorprone.ErrorProneFlags; |
26 | 23 | import com.google.errorprone.VisitorState;
|
27 | 24 | import com.sun.source.tree.ExpressionTree;
|
28 |
| -import com.sun.tools.javac.code.Flags; |
29 |
| -import com.sun.tools.javac.code.Symbol; |
30 |
| -import com.sun.tools.javac.code.Symbol.VarSymbol; |
31 | 25 | import com.sun.tools.javac.code.Type;
|
32 | 26 | import javax.inject.Inject;
|
33 | 27 |
|
|
40 | 34 | altNames = {"NumericEquality"},
|
41 | 35 | severity = ERROR)
|
42 | 36 | public final class BoxedPrimitiveEquality extends AbstractReferenceEquality {
|
43 |
| - private final boolean exemptStaticConstants; |
44 |
| - |
45 | 37 | @Inject
|
46 |
| - BoxedPrimitiveEquality(ErrorProneFlags flags) { |
47 |
| - this.exemptStaticConstants = |
48 |
| - flags.getBoolean("BoxedPrimitiveEquality:ExemptStaticConstants").orElse(false); |
49 |
| - } |
| 38 | + BoxedPrimitiveEquality() {} |
50 | 39 |
|
51 | 40 | @Override
|
52 | 41 | protected boolean matchArgument(ExpressionTree tree, VisitorState state) {
|
53 | 42 | var type = getType(tree);
|
54 |
| - if (type == null || !isRelevantType(type, state)) { |
55 |
| - return false; |
56 |
| - } |
57 |
| - |
58 |
| - // Using a static final field as a sentinel is OK |
59 |
| - // TODO(cushon): revisit this assumption carried over from NumericEquality |
60 |
| - return !(exemptStaticConstants && isStaticConstant(getSymbol(tree))); |
| 43 | + return type != null && isRelevantType(type, state); |
61 | 44 | }
|
62 | 45 |
|
63 | 46 | private boolean isRelevantType(Type type, VisitorState state) {
|
64 | 47 | return !type.isPrimitive() && state.getTypes().unboxedType(type).isPrimitive();
|
65 | 48 | }
|
66 |
| - |
67 |
| - private static boolean isStaticConstant(Symbol sym) { |
68 |
| - return sym instanceof VarSymbol && isFinal(sym) && isStatic(sym); |
69 |
| - } |
70 |
| - |
71 |
| - public static boolean isFinal(Symbol s) { |
72 |
| - return (s.flags() & Flags.FINAL) == Flags.FINAL; |
73 |
| - } |
74 | 49 | }
|
0 commit comments