Class OptionalVisitor
java.lang.Object
com.sun.source.util.TreeScanner<R,P>
com.sun.source.util.TreePathScanner<R,P>
org.checkerframework.framework.source.SourceVisitor<Void,Void>
org.checkerframework.common.basetype.BaseTypeVisitor<BaseAnnotatedTypeFactory>
org.checkerframework.checker.optional.OptionalVisitor
The OptionalVisitor enforces the Optional Checker rules. These rules are described in the Checker
Framework Manual.
- See the Checker Framework Manual:
- Optional Checker
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.OverrideChecker
-
Field Summary
Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
atypeFactory, checker, DETERMINISTIC, methodTree, positions, PURE, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeValidator, unusedWhenElement
Fields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected BaseTypeValidator
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.visitConditionalExpression
(com.sun.source.tree.ConditionalExpressionTree node, 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.visitMethodInvocation
(com.sun.source.tree.MethodInvocationTree node, Void p) Performs a method invocation check.visitVariable
(com.sun.source.tree.VariableTree node, Void p) Rule #6 (partial).Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkConstructorResult, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactory, createTypeFactoryPublic, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypes
Methods inherited from class org.checkerframework.framework.source.SourceVisitor
visit
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitArrayAccess, visitArrayType, visitAssert, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitContinue, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitGuardedPattern, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitParenthesizedPattern, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSwitchExpression, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard, visitYield
-
Constructor Details
-
OptionalVisitor
Create an OptionalVisitor.
-
-
Method Details
-
createTypeValidator
- Overrides:
createTypeValidator
in classBaseTypeVisitor<BaseAnnotatedTypeFactory>
-
visitConditionalExpression
Description copied from class:BaseTypeVisitor
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. However, let's add another failsafe guard and do the checks.- Specified by:
visitConditionalExpression
in interfacecom.sun.source.tree.TreeVisitor<Void,
Void> - Overrides:
visitConditionalExpression
in classBaseTypeVisitor<BaseAnnotatedTypeFactory>
-
handleTernaryIsPresentGet
public void handleTernaryIsPresentGet(com.sun.source.tree.ConditionalExpressionTree node) Part of rule #3.Pattern match for:
VAR.isPresent() ? VAR.get().METHOD() : VALUE
Prefer:
VAR.map(METHOD).orElse(VALUE);
-
visitIf
-
handleConditionalStatementIsPresentGet
public void handleConditionalStatementIsPresentGet(com.sun.source.tree.IfTree node) Part of rule #3.Pattern match for:
if (VAR.isPresent()) { METHOD(VAR.get()); }
Prefer:
VAR.ifPresent(METHOD);
-
visitMethodInvocation
Description copied from class:BaseTypeVisitor
Performs a method invocation check.An invocation of a method, m, on the receiver, r is valid only if:
- passed arguments are subtypes of corresponding m parameters
- r is a subtype of m receiver type
- if m is generic, passed type arguments are subtypes of m type variables
- Specified by:
visitMethodInvocation
in interfacecom.sun.source.tree.TreeVisitor<Void,
Void> - Overrides:
visitMethodInvocation
in classBaseTypeVisitor<BaseAnnotatedTypeFactory>
-
handleCreationElimination
public void handleCreationElimination(com.sun.source.tree.MethodInvocationTree node) Rule #4.Pattern match for:
CREATION().ELIMINATION()
Prefer:
VAR.ifPresent(METHOD);
-
visitVariable
Rule #6 (partial).Don't use Optional in fields and method parameters.
- Specified by:
visitVariable
in interfacecom.sun.source.tree.TreeVisitor<Void,
Void> - Overrides:
visitVariable
in classBaseTypeVisitor<BaseAnnotatedTypeFactory>
-
skipBlocks
public 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. Otherwise, return the same tree.- Parameters:
tree
- a statement tree- Returns:
- the single enclosed statement, if it exists; otherwise, the same tree
-