Class CompileTimeConstantChecker
java.lang.Object
com.google.errorprone.bugpatterns.BugChecker
com.google.errorprone.bugpatterns.CompileTimeConstantChecker
- All Implemented Interfaces:
BugChecker.AssignmentTreeMatcher
,BugChecker.LambdaExpressionTreeMatcher
,BugChecker.MemberReferenceTreeMatcher
,BugChecker.MethodInvocationTreeMatcher
,BugChecker.MethodTreeMatcher
,BugChecker.NewClassTreeMatcher
,BugChecker.VariableTreeMatcher
,Suppressible
,Serializable
public class CompileTimeConstantChecker extends BugChecker implements BugChecker.LambdaExpressionTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.MethodTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.AssignmentTreeMatcher
Detects invocations of methods with a parameter annotated
@CompileTimeConstant
such that
the corresponding actual parameter is not a compile-time constant expression, and initialisation
of fields declared @CompileTimeConstant final
such that the actual value is not a
compile-time constant expression.
This type annotation checker enforces that for all method and constructor invocations, for all
formal parameters of the invoked method/constructor that are annotated with the CompileTimeConstant
type annotation, the corresponding actual
parameter is an expression that satisfies one of the following conditions:
- The expression is one for which the Java compiler can determine a constant value at compile time, or
- the expression consists of the literal
null
, or - the expression consists of a single identifier, where the identifier is a formal method
parameter or class field that is declared
final
and has theCompileTimeConstant
annotation.
This type annotation checker also enforces that for all field declarations annotated with the
CompileTimeConstant
type annotation, the field is also
declared final
and the corresponding initialised value satifsies one of the following
conditions:
- The expression is one for which the Java compiler can determine a constant value at compile time, or
- the expression consists of the literal
null
, or - the expression consists of a single identifier, where the identifier is a formal method
parameter or class field that is declared
final
and has theCompileTimeConstant
annotation.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.errorprone.bugpatterns.BugChecker
BugChecker.AnnotatedTypeTreeMatcher, BugChecker.AnnotationTreeMatcher, BugChecker.ArrayAccessTreeMatcher, BugChecker.ArrayTypeTreeMatcher, BugChecker.AssertTreeMatcher, BugChecker.AssignmentTreeMatcher, BugChecker.BinaryTreeMatcher, BugChecker.BlockTreeMatcher, BugChecker.BreakTreeMatcher, BugChecker.CaseTreeMatcher, BugChecker.CatchTreeMatcher, BugChecker.ClassTreeMatcher, BugChecker.CompilationUnitTreeMatcher, BugChecker.CompoundAssignmentTreeMatcher, BugChecker.ConditionalExpressionTreeMatcher, BugChecker.ContinueTreeMatcher, BugChecker.DoWhileLoopTreeMatcher, BugChecker.EmptyStatementTreeMatcher, BugChecker.EnhancedForLoopTreeMatcher, BugChecker.ExpressionStatementTreeMatcher, BugChecker.ForLoopTreeMatcher, BugChecker.IdentifierTreeMatcher, BugChecker.IfTreeMatcher, BugChecker.ImportTreeMatcher, BugChecker.InstanceOfTreeMatcher, BugChecker.IntersectionTypeTreeMatcher, BugChecker.LabeledStatementTreeMatcher, BugChecker.LambdaExpressionTreeMatcher, BugChecker.LiteralTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.MemberSelectTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.MethodTreeMatcher, BugChecker.ModifiersTreeMatcher, BugChecker.NewArrayTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.ParameterizedTypeTreeMatcher, BugChecker.ParenthesizedTreeMatcher, BugChecker.PrimitiveTypeTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.SuppressibleTreePathScanner<A,B>, BugChecker.SwitchTreeMatcher, BugChecker.SynchronizedTreeMatcher, BugChecker.ThrowTreeMatcher, BugChecker.TryTreeMatcher, BugChecker.TypeCastTreeMatcher, BugChecker.TypeParameterTreeMatcher, BugChecker.UnaryTreeMatcher, BugChecker.UnionTypeTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.WhileLoopTreeMatcher, BugChecker.WildcardTreeMatcher
-
Constructor Summary
Constructors Constructor Description CompileTimeConstantChecker()
-
Method Summary
Modifier and Type Method Description Description
matchAssignment(com.sun.source.tree.AssignmentTree node, VisitorState state)
Description
matchLambdaExpression(com.sun.source.tree.LambdaExpressionTree node, VisitorState state)
Description
matchMemberReference(com.sun.source.tree.MemberReferenceTree node, VisitorState state)
Description
matchMethod(com.sun.source.tree.MethodTree node, VisitorState state)
Description
matchMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)
Description
matchNewClass(com.sun.source.tree.NewClassTree tree, VisitorState state)
Description
matchVariable(com.sun.source.tree.VariableTree node, VisitorState state)
Methods inherited from class com.google.errorprone.bugpatterns.BugChecker
allNames, buildDescription, buildDescription, buildDescription, canonicalName, customSuppressionAnnotations, defaultSeverity, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, disableable, equals, hashCode, isSuppressed, isSuppressed, isSuppressed, isSuppressed, linkUrl, message, supportsSuppressWarnings, suppressedByAnyOf, suppressedRegions
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.google.errorprone.matchers.Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
Constructor Details
-
CompileTimeConstantChecker
public CompileTimeConstantChecker()
-
-
Method Details
-
matchNewClass
- Specified by:
matchNewClass
in interfaceBugChecker.NewClassTreeMatcher
-
matchMethodInvocation
public Description matchMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)- Specified by:
matchMethodInvocation
in interfaceBugChecker.MethodInvocationTreeMatcher
-
matchMethod
- Specified by:
matchMethod
in interfaceBugChecker.MethodTreeMatcher
-
matchMemberReference
public Description matchMemberReference(com.sun.source.tree.MemberReferenceTree node, VisitorState state)- Specified by:
matchMemberReference
in interfaceBugChecker.MemberReferenceTreeMatcher
-
matchLambdaExpression
public Description matchLambdaExpression(com.sun.source.tree.LambdaExpressionTree node, VisitorState state)- Specified by:
matchLambdaExpression
in interfaceBugChecker.LambdaExpressionTreeMatcher
-
matchVariable
- Specified by:
matchVariable
in interfaceBugChecker.VariableTreeMatcher
-
matchAssignment
- Specified by:
matchAssignment
in interfaceBugChecker.AssignmentTreeMatcher
-