-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation of commonAssignmentCheck and correct overrides #6347
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
import javax.lang.model.element.ExecutableElement; | ||
import javax.lang.model.element.VariableElement; | ||
import org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey; | ||
import org.checkerframework.checker.formatter.qual.FormatMethod; | ||
import org.checkerframework.common.aliasing.qual.LeakedToResult; | ||
import org.checkerframework.common.aliasing.qual.NonLeaked; | ||
import org.checkerframework.common.aliasing.qual.Unique; | ||
|
@@ -172,15 +171,16 @@ protected boolean commonAssignmentCheck( | |
} | ||
|
||
@Override | ||
@FormatMethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this removed? |
||
protected boolean commonAssignmentCheck( | ||
AnnotatedTypeMirror varType, | ||
AnnotatedTypeMirror valueType, | ||
Tree valueTree, | ||
ExpressionTree valueTree, | ||
@CompilerMessageKey String errorKey, | ||
Object... extraArgs) { | ||
boolean result = | ||
super.commonAssignmentCheck(varType, valueType, valueTree, errorKey, extraArgs); | ||
|
||
if (shouldSkipUses(valueTree)) { | ||
return true; | ||
} | ||
boolean result = super.commonAssignmentCheck(varType, valueTree, errorKey, extraArgs); | ||
|
||
// If we are visiting a pseudo-assignment, visitorLeafKind is either | ||
// Tree.Kind.NEW_CLASS or Tree.Kind.METHOD_INVOCATION. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2923,6 +2923,12 @@ protected AnnotationMirrorSet getThrowUpperBoundAnnotations() { | |
* Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and | ||
* emits an error message (through the compiler's messaging interface) if it is not valid. | ||
* | ||
* <p>Because this method is not called for all pseudo-assignments, subclasses should only | ||
* override this class if {@code varTree} is needed. Otherwise, {@link | ||
* #commonAssignmentCheck(AnnotatedTypeMirror, ExpressionTree, String, Object...)} or {@link | ||
* #commonAssignmentCheck(AnnotatedTypeMirror, AnnotatedTypeMirror, Tree, String, Object...)} | ||
* should be overridden instead. | ||
* | ||
* @param varTree the AST node for the lvalue (usually a variable) | ||
* @param valueExpTree the AST node for the rvalue (the new value) | ||
* @param errorKey the error message key to use if the check fails | ||
|
@@ -2957,8 +2963,15 @@ protected boolean commonAssignmentCheck( | |
} | ||
|
||
/** | ||
* Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and | ||
* emits an error message (through the compiler's messaging interface) if it is not valid. | ||
* Checks the validity of an assignment (or pseudo-assignment) from {@code valueExpTree} to a | ||
* variable with type {@code varType} and emits an error message (through the compiler's messaging | ||
* interface) if it is not valid. | ||
* | ||
* <p>Because this method is not called for all pseudo-assignments, subclasses should only | ||
* override this, if the tree of the value expression is required; otherwise, override {@link | ||
* #commonAssignmentCheck(AnnotatedTypeMirror, AnnotatedTypeMirror, Tree, String, Object...)}. If | ||
* this method is overridden, then the first then should call {@link | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify this? |
||
* #shouldSkipUses(ExpressionTree)} and return if that method returns true. | ||
* | ||
* @param varType the annotated type for the lvalue (usually a variable) | ||
* @param valueExpTree the AST node for the rvalue (the new value) | ||
|
@@ -2972,18 +2985,6 @@ protected boolean commonAssignmentCheck( | |
@CompilerMessageKey String errorKey, | ||
Object... extraArgs) { | ||
if (shouldSkipUses(valueExpTree)) { | ||
if (showchecks) { | ||
System.out.printf( | ||
"%s %s (at %s): actual tree = %s %s%n expected: %s %s%n", | ||
this.getClass().getSimpleName(), | ||
"skipping test whether actual is a subtype of expected" | ||
+ " because shouldSkipUses() returned true", | ||
fileAndLineNumber(valueExpTree), | ||
valueExpTree.getKind(), | ||
valueExpTree, | ||
varType.getKind(), | ||
varType.toString()); | ||
} | ||
return true; | ||
} | ||
if (valueExpTree.getKind() == Tree.Kind.MEMBER_REFERENCE | ||
|
@@ -3039,24 +3040,29 @@ protected boolean commonAssignmentCheck( | |
} | ||
|
||
/** | ||
* Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and | ||
* emits an error message (through the compiler's messaging interface) if it is not valid. | ||
* Checks the validity of an assignment (or pseudo-assignment) from {@code valueType} to {@code | ||
* variableType} and emits an error message (through the compiler's messaging interface) if it is | ||
* not valid. | ||
* | ||
* <p>Subclasses should override this method if in all cases unless the tree for the {@code | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammar issue here. |
||
* varType} or {@code valueType} are needed. | ||
* | ||
* @param varType the annotated type of the variable | ||
* @param valueType the annotated type of the value | ||
* @param valueExpTree the location to use when reporting the error message | ||
* @param errorLocation the location to use when reporting the error message; this is NOT the tree | ||
* for {@code valueType} in all cases | ||
* @param errorKey the error message key to use if the check fails | ||
* @param extraArgs arguments to the error message key, before "found" and "expected" types | ||
* @return true if the check succeeds, false if an error message was issued | ||
*/ | ||
protected boolean commonAssignmentCheck( | ||
AnnotatedTypeMirror varType, | ||
AnnotatedTypeMirror valueType, | ||
Tree valueExpTree, | ||
Tree errorLocation, | ||
@CompilerMessageKey String errorKey, | ||
Object... extraArgs) { | ||
|
||
commonAssignmentCheckStartDiagnostic(varType, valueType, valueExpTree); | ||
commonAssignmentCheckStartDiagnostic(varType, valueType, errorLocation); | ||
|
||
AnnotatedTypeMirror widenedValueType = atypeFactory.getWidenedType(valueType, varType); | ||
boolean result = typeHierarchy.isSubtype(widenedValueType, varType); | ||
|
@@ -3066,7 +3072,7 @@ protected boolean commonAssignmentCheck( | |
for (Class<? extends Annotation> mono : atypeFactory.getSupportedMonotonicTypeQualifiers()) { | ||
if (valueType.hasPrimaryAnnotation(mono) && varType.hasPrimaryAnnotation(mono)) { | ||
checker.reportError( | ||
valueExpTree, | ||
errorLocation, | ||
"monotonic", | ||
mono.getSimpleName(), | ||
mono.getSimpleName(), | ||
|
@@ -3081,12 +3087,12 @@ protected boolean commonAssignmentCheck( | |
String valueTypeString = pair.found; | ||
String varTypeString = pair.required; | ||
checker.reportError( | ||
valueExpTree, | ||
errorLocation, | ||
errorKey, | ||
ArraysPlume.concatenate(extraArgs, valueTypeString, varTypeString)); | ||
} | ||
|
||
commonAssignmentCheckEndDiagnostic(result, null, varType, valueType, valueExpTree); | ||
commonAssignmentCheckEndDiagnostic(result, null, varType, valueType, errorLocation); | ||
|
||
return result; | ||
} | ||
|
@@ -4838,7 +4844,21 @@ protected final boolean shouldSkipUses(ExpressionTree exprTree) { | |
return true; | ||
} | ||
Element elm = TreeUtils.elementFromTree(exprTree); | ||
return checker.shouldSkipUses(elm); | ||
boolean shouldSkipUses = checker.shouldSkipUses(elm); | ||
if (showchecks) { | ||
TypeMirror exprTypeMirror = TreeUtils.typeOf(exprTree); | ||
System.out.printf( | ||
"%s %s (at %s): actual tree = %s %s%n expected: %s %s%n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this labeled "expected"? That doesn't seem to fit with |
||
this.getClass().getSimpleName(), | ||
"skipping test whether actual is a subtype of expected" | ||
+ " because shouldSkipUses() returned true", | ||
fileAndLineNumber(exprTree), | ||
exprTree.getKind(), | ||
exprTree, | ||
exprTypeMirror.getKind(), | ||
exprTypeMirror.toString()); | ||
} | ||
return shouldSkipUses; | ||
} | ||
|
||
// ********************************************************************** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed?