-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
…tations Which contain array fields, but make defensive copies to ensure the class is immutable. RELNOTES: N/A ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178042508
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import static com.google.errorprone.BugPattern.Category.JDK; | ||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; | ||
import static com.google.errorprone.matchers.Description.NO_MATCH; | ||
import static com.google.errorprone.util.ASTHelpers.getGeneratedBy; | ||
import static com.google.errorprone.util.ASTHelpers.getSymbol; | ||
import static com.google.errorprone.util.ASTHelpers.getType; | ||
|
||
|
@@ -39,6 +40,7 @@ | |
import com.sun.source.tree.ClassTree; | ||
import com.sun.source.tree.Tree; | ||
import com.sun.tools.javac.code.Symbol.ClassSymbol; | ||
import java.util.Collections; | ||
import java.util.Optional; | ||
|
||
/** @author cushon@google.com (Liam Miller-Cushon) */ | ||
|
@@ -57,6 +59,11 @@ public class ImmutableAnnotationChecker extends BugChecker implements ClassTreeM | |
"annotations are immutable by default; annotating them with" | ||
+ " @com.google.errorprone.annotations.Immutable is unnecessary"; | ||
|
||
private static final ImmutableSet<String> PROCESSOR_BLACKLIST = | ||
ImmutableSet.of( | ||
"com.google.auto.value.processor.AutoAnnotationProcessor" | ||
); | ||
|
||
private final WellKnownMutability wellKnownMutability; | ||
|
||
@Deprecated // Used reflectively, but you should pass in ErrorProneFlags to get custom mutability | ||
|
@@ -76,6 +83,9 @@ public Description matchClass(ClassTree tree, VisitorState state) { | |
|| !WellKnownMutability.isAnnotation(state, symbol.type)) { | ||
return NO_MATCH; | ||
} | ||
if (!Collections.disjoint(getGeneratedBy(symbol, state), PROCESSOR_BLACKLIST)) { | ||
return NO_MATCH; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cushon
Author
Collaborator
|
||
|
||
if (ASTHelpers.hasAnnotation(symbol, Immutable.class, state)) { | ||
AnnotationTree annotation = | ||
|
Unless the processor exposes defensive copies of any arbitrary mutable public property, isn't this too optimistic?
(An alternative would be for Google Auto value to annotate the array fields it generates with
@SuppressWarnings("Immutable")
. That's what I did for Immutables in immutables/immutables@80d0633.)