public class OptionalVisitor extends BaseTypeVisitor<BaseAnnotatedTypeFactory>
BaseTypeVisitor.OverrideChecker
atypeFactory, checker, contractsUtils, positions, TARGET, targetValueElement, typeValidator, visitorState
elements, root, trees, treesWithSuppressWarnings, types
Constructor and Description |
---|
OptionalVisitor(BaseTypeChecker checker)
Create an OptionalVisitor.
|
Modifier and Type | Method and Description |
---|---|
protected BaseTypeValidator |
createTypeValidator() |
void |
handleConditionalStatementIsPresentGet(com.sun.source.tree.IfTree node)
Part of rule #3.
|
void |
handleCreationElimination(com.sun.source.tree.MethodInvocationTree node)
Rule #4.
|
void |
handleTernaryIsPresentGet(com.sun.source.tree.ConditionalExpressionTree node)
Part of rule #3.
|
static com.sun.source.tree.StatementTree |
skipBlocks(com.sun.source.tree.StatementTree tree)
If the given tree is a block tree with a single element, return the enclosed non-block
statement.
|
java.lang.Void |
visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node,
java.lang.Void p)
If the computation of the type of the ConditionalExpressionTree in
org.checkerframework.framework.type.TypeFromTree.TypeFromExpression.visitConditionalExpression(ConditionalExpressionTree,
AnnotatedTypeFactory) is correct, the following checks are redundant.
|
java.lang.Void |
visitIf(com.sun.source.tree.IfTree node,
java.lang.Void p) |
java.lang.Void |
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node,
java.lang.Void p)
Performs a method invocation check.
|
java.lang.Void |
visitVariable(com.sun.source.tree.VariableTree node,
java.lang.Void p)
Rule #6 (partial).
|
checkAccess, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkConstructorResult, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExtendsImplements, checkFieldInvariantDeclarations, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactory, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isTypeCastSafe, isValidUse, isValidUse, isValidUse, processClassTree, reportPurityErrors, scan, setRoot, shouldSkipUses, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotation, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewArray, visitNewClass, visitReturn, visitThrow, visitTypeCast, visitTypeParameter, visitUnary
visit
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard
public OptionalVisitor(BaseTypeChecker checker)
protected BaseTypeValidator createTypeValidator()
createTypeValidator
in class BaseTypeVisitor<BaseAnnotatedTypeFactory>
public java.lang.Void visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node, java.lang.Void p)
BaseTypeVisitor
visitConditionalExpression
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitConditionalExpression
in class BaseTypeVisitor<BaseAnnotatedTypeFactory>
public void handleTernaryIsPresentGet(com.sun.source.tree.ConditionalExpressionTree node)
Pattern match for: VAR.isPresent() ? VAR.get().METHOD() : VALUE
Prefer: VAR.map(METHOD).orElse(VALUE);
public java.lang.Void visitIf(com.sun.source.tree.IfTree node, java.lang.Void p)
visitIf
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitIf
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public void handleConditionalStatementIsPresentGet(com.sun.source.tree.IfTree node)
Pattern match for: if (VAR.isPresent()) { METHOD(VAR.get()); }
Prefer: VAR.ifPresent(METHOD);
public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node, java.lang.Void p)
BaseTypeVisitor
An invocation of a method, m, on the receiver, r is valid only if:
visitMethodInvocation
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitMethodInvocation
in class BaseTypeVisitor<BaseAnnotatedTypeFactory>
public void handleCreationElimination(com.sun.source.tree.MethodInvocationTree node)
Pattern match for: CREATION().ELIMINATION()
Prefer: VAR.ifPresent(METHOD);
public java.lang.Void visitVariable(com.sun.source.tree.VariableTree node, java.lang.Void p)
Don't use Optional in fields and method parameters.
visitVariable
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitVariable
in class BaseTypeVisitor<BaseAnnotatedTypeFactory>
public static com.sun.source.tree.StatementTree skipBlocks(com.sun.source.tree.StatementTree tree)
tree
- a statement tree