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:

  1. The expression is one for which the Java compiler can determine a constant value at compile time, or
  2. the expression consists of the literal null, or
  3. the expression consists of a single identifier, where the identifier is a formal method parameter or class field that is declared final and has the CompileTimeConstant 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:

  1. The expression is one for which the Java compiler can determine a constant value at compile time, or
  2. the expression consists of the literal null, or
  3. the expression consists of a single identifier, where the identifier is a formal method parameter or class field that is declared final and has the CompileTimeConstant annotation.
See Also:
CompileTimeConstantExpressionMatcher, Serialized Form