From 43622f3853524ea5daedac0a6af8758ca6cee0e6 Mon Sep 17 00:00:00 2001 From: Baorui Zhou Date: Thu, 11 Apr 2019 17:32:04 -0400 Subject: [PATCH 1/2] properly replace pre-existing annotations with VarAnnot --- src/checkers/inference/VariableAnnotator.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/checkers/inference/VariableAnnotator.java b/src/checkers/inference/VariableAnnotator.java index 693086513..8f4d549dc 100644 --- a/src/checkers/inference/VariableAnnotator.java +++ b/src/checkers/inference/VariableAnnotator.java @@ -500,6 +500,10 @@ private VariableSlot addPrimaryVariable(AnnotatedTypeMirror atm, final Tree tree if (variable.getLocation() == null) { variable.setLocation(treeToLocation(tree)); } + if (variable instanceof ConstantSlot) { + atm.removeAnnotation(((ConstantSlot) variable).getValue()); + } + atm.addAnnotation(slotManager.getAnnotation(variable)); } else { AnnotationLocation location = treeToLocation(tree); variable = replaceOrCreateEquivalentVarAnno(atm, tree, location); @@ -509,9 +513,6 @@ private VariableSlot addPrimaryVariable(AnnotatedTypeMirror atm, final Tree tree treeToVarAnnoPair.put(tree, varATMPair); } - - atm.replaceAnnotation(slotManager.getAnnotation(variable)); - return variable; } @@ -566,8 +567,10 @@ private VariableSlot replaceOrCreateEquivalentVarAnno(AnnotatedTypeMirror atm, T } else { varSlot = createVariable(location); } - - atm.replaceAnnotation(slotManager.getAnnotation(varSlot)); + if (realQualifier != null) { + atm.removeAnnotation(realQualifier); + } + atm.addAnnotation(slotManager.getAnnotation(varSlot)); return varSlot; } From 18c069f54ec1cc0d10a540331818009b0e697c31 Mon Sep 17 00:00:00 2001 From: Baorui Zhou Date: Thu, 18 Apr 2019 17:53:36 -0400 Subject: [PATCH 2/2] avoid adding multiple VarAnnots --- src/checkers/inference/VariableAnnotator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checkers/inference/VariableAnnotator.java b/src/checkers/inference/VariableAnnotator.java index 8f4d549dc..99bfee5c3 100644 --- a/src/checkers/inference/VariableAnnotator.java +++ b/src/checkers/inference/VariableAnnotator.java @@ -503,7 +503,7 @@ private VariableSlot addPrimaryVariable(AnnotatedTypeMirror atm, final Tree tree if (variable instanceof ConstantSlot) { atm.removeAnnotation(((ConstantSlot) variable).getValue()); } - atm.addAnnotation(slotManager.getAnnotation(variable)); + atm.replaceAnnotation(slotManager.getAnnotation(variable)); } else { AnnotationLocation location = treeToLocation(tree); variable = replaceOrCreateEquivalentVarAnno(atm, tree, location); @@ -570,7 +570,7 @@ private VariableSlot replaceOrCreateEquivalentVarAnno(AnnotatedTypeMirror atm, T if (realQualifier != null) { atm.removeAnnotation(realQualifier); } - atm.addAnnotation(slotManager.getAnnotation(varSlot)); + atm.replaceAnnotation(slotManager.getAnnotation(varSlot)); return varSlot; }