From c66edf5df34c7d03026c9fb7cb651eec7d4539bc Mon Sep 17 00:00:00 2001 From: lnsun <57457122+lnsun@users.noreply.github.com> Date: Tue, 16 Jun 2020 18:26:33 -0400 Subject: [PATCH 1/3] add param to hasFieldInvariantAnnotation --- .../InitializationAnnotatedTypeFactory.java | 11 +++++++---- .../initialization/InitializationTransfer.java | 2 +- .../nullness/NullnessAnnotatedTypeFactory.java | 3 ++- 3 files changed, 10 insertions(+), 6 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 891b4d9c091..657cfec18bb 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,11 @@ 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 * @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 @@ -394,7 +397,7 @@ public void postAsMemberOf( * @see #computeFieldAccessType * @see #getAnnotatedTypeLhs(Tree) */ - private boolean computingAnnotatedTypeMirrorOfLHS = false; + protected boolean computingAnnotatedTypeMirrorOfLHS = false; @Override public AnnotatedTypeMirror getAnnotatedTypeLhs(Tree lhsTree) { 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 8a2bc660ec4..b539d07bb12 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 136e384c522..b1f91db5088 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); From 7efaacb186ce676732392da27ad0e8d7051bcd1c Mon Sep 17 00:00:00 2001 From: lnsun <57457122+lnsun@users.noreply.github.com> Date: Mon, 22 Jun 2020 11:04:12 -0400 Subject: [PATCH 2/3] revert a change --- .../initialization/InitializationAnnotatedTypeFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 657cfec18bb..7158f4530ab 100644 --- a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java +++ b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java @@ -397,7 +397,7 @@ public void postAsMemberOf( * @see #computeFieldAccessType * @see #getAnnotatedTypeLhs(Tree) */ - protected boolean computingAnnotatedTypeMirrorOfLHS = false; + private boolean computingAnnotatedTypeMirrorOfLHS = false; @Override public AnnotatedTypeMirror getAnnotatedTypeLhs(Tree lhsTree) { From 75966f65e58a99e14c8f683bf2cab63f230736a8 Mon Sep 17 00:00:00 2001 From: lnsun <57457122+lnsun@users.noreply.github.com> Date: Wed, 24 Jun 2020 17:57:19 -0400 Subject: [PATCH 3/3] javadoc --- .../initialization/InitializationAnnotatedTypeFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 7158f4530ab..76fcda52282 100644 --- a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java +++ b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java @@ -197,7 +197,8 @@ 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 + * @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(