From e7ddf2f7ee77c07a7094d8d00618ec6021afc5ae Mon Sep 17 00:00:00 2001 From: lnsun <57457122+lnsun@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:41:05 -0400 Subject: [PATCH] add param VariableElement to hasFieldInvariantAnnotation --- .../InitializationAnnotatedTypeFactory.java | 10 +++++++--- .../checker/initialization/InitializationTransfer.java | 2 +- .../checker/nullness/NullnessAnnotatedTypeFactory.java | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java index 891b4d9c0915..76fcda52282e 100644 --- a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java +++ b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java @@ -174,7 +174,7 @@ public Set> getInvalidConstructorReturnTypeAnnotatio * Returns whether or not {@code field} has the invariant annotation. * *

This method is a convenience method for {@link - * #hasFieldInvariantAnnotation(AnnotatedTypeMirror)}. + * #hasFieldInvariantAnnotation(AnnotatedTypeMirror, VariableElement)}. * *

If the {@code field} is a type variable, this method returns true if any possible * instantiation of the type parameter could have the invariant annotation. See {@link @@ -185,7 +185,8 @@ public Set> getInvalidConstructorReturnTypeAnnotatio */ protected final boolean hasFieldInvariantAnnotation(VariableTree field) { AnnotatedTypeMirror type = getAnnotatedType(field); - return hasFieldInvariantAnnotation(type); + VariableElement fieldElement = TreeUtils.elementFromDeclaration(field); + return hasFieldInvariantAnnotation(type, fieldElement); } /** @@ -196,9 +197,12 @@ protected final boolean hasFieldInvariantAnnotation(VariableTree field) { * NullnessAnnotatedTypeFactory#hasFieldInvariantAnnotation(VariableTree)} for an example. * * @param type of field that might have invariant annotation + * @param fieldElement the field element, which can be used to check annotations on the + * declaration * @return whether or not the type has the invariant annotation */ - protected abstract boolean hasFieldInvariantAnnotation(AnnotatedTypeMirror type); + protected abstract boolean hasFieldInvariantAnnotation( + AnnotatedTypeMirror type, VariableElement fieldElement); /** * Creates a {@link UnderInitialization} annotation with the given type as its type frame diff --git a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationTransfer.java b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationTransfer.java index 8a2bc660ec4f..b539d07bb12f 100644 --- a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationTransfer.java +++ b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationTransfer.java @@ -138,7 +138,7 @@ protected void markInvariantFieldsAsInitialized( continue; } AnnotatedTypeMirror fieldType = atypeFactory.getAnnotatedType(field); - if (atypeFactory.hasFieldInvariantAnnotation(fieldType)) { + if (atypeFactory.hasFieldInvariantAnnotation(fieldType, field)) { result.add(field); } } diff --git a/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java b/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java index 136e384c5220..b1f91db5088c 100644 --- a/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java +++ b/checker/src/main/java/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java @@ -550,7 +550,8 @@ public AnnotationMirror getFieldInvariantAnnotation() { * @return whether or not type has the invariant annotation */ @Override - protected boolean hasFieldInvariantAnnotation(AnnotatedTypeMirror type) { + protected boolean hasFieldInvariantAnnotation( + AnnotatedTypeMirror type, VariableElement fieldElement) { AnnotationMirror invariant = getFieldInvariantAnnotation(); Set lowerBounds = AnnotatedTypes.findEffectiveLowerBoundAnnotations(qualHierarchy, type);