From 87254630b9deee6df7adb50acffee23c8ac54dd4 Mon Sep 17 00:00:00 2001 From: zcai Date: Wed, 23 Mar 2022 23:46:45 -0400 Subject: [PATCH 1/2] convert real type declaration bounds to VarAnnots in inference getTypeDeclarationBounds --- .../InferenceAnnotatedTypeFactory.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/checkers/inference/InferenceAnnotatedTypeFactory.java b/src/checkers/inference/InferenceAnnotatedTypeFactory.java index a25df78d..4bcbfea9 100644 --- a/src/checkers/inference/InferenceAnnotatedTypeFactory.java +++ b/src/checkers/inference/InferenceAnnotatedTypeFactory.java @@ -28,6 +28,7 @@ import org.checkerframework.framework.util.defaults.QualifierDefaults; import org.checkerframework.framework.util.dependenttypes.DependentTypesHelper; import org.checkerframework.javacutil.AnnotationBuilder; +import org.checkerframework.javacutil.AnnotationUtils; import org.checkerframework.javacutil.BugInCF; import org.checkerframework.javacutil.ElementUtils; import org.checkerframework.javacutil.Pair; @@ -570,10 +571,14 @@ protected InferenceViewpointAdapter createViewpointAdapter() { */ @Override public Set getTypeDeclarationBounds(TypeMirror type) { - final TypeElement elt = (TypeElement) getProcessingEnv().getTypeUtils().asElement(type); - AnnotationMirror vAnno = variableAnnotator.getClassDeclVarAnnot(elt); - if (vAnno != null) { - return Collections.singleton(vAnno); + final Element elt = getProcessingEnv().getTypeUtils().asElement(type); + AnnotationMirror vAnno; + + if (elt instanceof TypeElement) { + vAnno = variableAnnotator.getClassDeclVarAnnot((TypeElement) elt); + if (vAnno != null) { + return Collections.singleton(vAnno); + } } // This is to handle the special case of anonymous classes when the super class (or interface) @@ -590,7 +595,13 @@ public Set getTypeDeclarationBounds(TypeMirror type) { } // If the declaration bound of the underlying type is not cached, use default - return (Set) getDefaultTypeDeclarationBounds(); + Set realBounds = realTypeFactory.getTypeDeclarationBounds(type); + Set boundsVarAnnos = AnnotationUtils.createAnnotationSet(); + for (AnnotationMirror realBound : realBounds) { + Slot slot = slotManager.getSlot(realBound); + boundsVarAnnos.add(slotManager.getAnnotation(slot)); + } + return boundsVarAnnos; } /** From 87f938fd39f95155f134ccba76a0e58cdd76895c Mon Sep 17 00:00:00 2001 From: zcai Date: Thu, 7 Jul 2022 02:17:01 -0400 Subject: [PATCH 2/2] remove condition for non-TypeElement --- .../inference/InferenceAnnotatedTypeFactory.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/checkers/inference/InferenceAnnotatedTypeFactory.java b/src/checkers/inference/InferenceAnnotatedTypeFactory.java index 8eda35e2..067a3f53 100644 --- a/src/checkers/inference/InferenceAnnotatedTypeFactory.java +++ b/src/checkers/inference/InferenceAnnotatedTypeFactory.java @@ -572,14 +572,10 @@ protected InferenceViewpointAdapter createViewpointAdapter() { */ @Override public Set getTypeDeclarationBounds(TypeMirror type) { - final Element elt = getProcessingEnv().getTypeUtils().asElement(type); - AnnotationMirror vAnno; - - if (elt instanceof TypeElement) { - vAnno = variableAnnotator.getClassDeclVarAnnot((TypeElement) elt); - if (vAnno != null) { - return Collections.singleton(vAnno); - } + final TypeElement elt = (TypeElement) getProcessingEnv().getTypeUtils().asElement(type); + AnnotationMirror vAnno = variableAnnotator.getClassDeclVarAnnot(elt); + if (vAnno != null) { + return Collections.singleton(vAnno); } // This is to handle the special case of anonymous classes when the super class (or interface)