@@ -45,80 +45,80 @@ public PICOVariableAnnotator(InferenceAnnotatedTypeFactory typeFactory, Annotate
4545 super (typeFactory , realTypeFactory , realChecker , slotManager , constraintManager );
4646 }
4747
48- @ Override
49- protected void handleClassDeclaration (AnnotatedDeclaredType classType , ClassTree classTree ) {
50- super .handleClassDeclaration (classType , classTree );
51- int interfaceIndex = 1 ;
52- for (Tree implementsTree : classTree .getImplementsClause ()) {
53- final AnnotatedTypeMirror implementsType = inferenceTypeFactory .getAnnotatedTypeFromTypeTree (implementsTree );
54- AnnotatedTypeMirror supertype = classType .directSuperTypes ().get (interfaceIndex );
55- assert supertype .getUnderlyingType () == implementsType .getUnderlyingType ();
56- visit (supertype , implementsTree );
57- interfaceIndex ++;
58- }
59- }
60-
61- @ Override
62- protected void handleClassDeclarationBound (AnnotatedDeclaredType classType ) {
63- TypeElement classElement = (TypeElement ) classType .getUnderlyingType ().asElement ();
64- if (classDeclAnnos .containsKey (classElement )) {
65- classType .addAnnotation (slotManager .getAnnotation (classDeclAnnos .get (classElement )));
66- classType .addAnnotation (READONLY );
67- return ;
68- }
69- AnnotatedDeclaredType bound = inferenceTypeFactory .fromElement (classElement );
70-
71- VariableSlot boundSlot ;
72-
73- // Insert @Immutable VarAnnot directly to enum bound
74- // if (PICOTypeUtil.isEnumOrEnumConstant(bound)) {
75- // boundSlot = slotManager.createConstantSlot(IMMUTABLE);
76- // classType.addAnnotation(slotManager.getAnnotation(boundSlot));
77- // classDeclAnnos.put(classElement, boundSlot);
48+ // @Override
49+ // protected void handleClassDeclaration(AnnotatedDeclaredType classType, ClassTree classTree) {
50+ // super.handleClassDeclaration(classType, classTree);
51+ // int interfaceIndex = 1;
52+ // for(Tree implementsTree : classTree.getImplementsClause()) {
53+ // final AnnotatedTypeMirror implementsType = inferenceTypeFactory.getAnnotatedTypeFromTypeTree(implementsTree);
54+ // AnnotatedTypeMirror supertype = classType.directSupertypes().get(interfaceIndex);
55+ // assert supertype.getUnderlyingType() == implementsType.getUnderlyingType();
56+ // visit(supertype, implementsTree);
57+ // interfaceIndex++;
58+ // }
59+ // }
60+
61+ // @Override
62+ // protected void handleClassDeclarationBound(AnnotatedDeclaredType classType) {
63+ // TypeElement classElement = (TypeElement) classType.getUnderlyingType().asElement();
64+ // if (classDeclAnnos.containsKey(classElement)) {
65+ // classType.addAnnotation(slotManager.getAnnotation(classDeclAnnos.get(classElement)));
66+ // classType.addAnnotation(READONLY);
7867// return;
7968// }
80-
81- Tree classTree = inferenceTypeFactory .declarationFromElement (classElement );
82- if (classTree != null ) {
83- // Have source tree
84- if (bound .isAnnotatedInHierarchy (READONLY )) {
85- // Have bound annotation -> convert to equivalent ConstantSlot
86- boundSlot = slotManager .createConstantSlot (bound .getAnnotationInHierarchy (READONLY ));
87- } else {
88- // No existing annotation -> create new VariableSlot
89- boundSlot = createVariable (treeToLocation (classTree ));
90- }
91- } else {
92- // No source tree: bytecode classes
93- if (bound .isAnnotatedInHierarchy (READONLY )) {
94- // Have bound annotation in stub file
95- boundSlot = slotManager .createConstantSlot (bound .getAnnotationInHierarchy (READONLY ));
96- } else {
97- // No stub file
98- if (PICOTypeUtil .isImplicitlyImmutableType (classType )) {
99- // Implicitly immutable
100- boundSlot = slotManager .createConstantSlot (IMMUTABLE );
101- } else {
102- // None of the above applies: use conservative @Mutable
103- boundSlot = slotManager .createConstantSlot (MUTABLE );
104- }
105- }
106- }
107- classType .addAnnotation (slotManager .getAnnotation (boundSlot ));
108- classDeclAnnos .put (classElement , boundSlot );
109- }
69+ // AnnotatedDeclaredType bound = inferenceTypeFactory.fromElement(classElement);
70+ //
71+ // VariableSlot boundSlot;
72+ //
73+ // // Insert @Immutable VarAnnot directly to enum bound
74+ //// if (PICOTypeUtil.isEnumOrEnumConstant(bound)) {
75+ //// boundSlot = slotManager.createConstantSlot(IMMUTABLE);
76+ //// classType.addAnnotation(slotManager.getAnnotation(boundSlot));
77+ //// classDeclAnnos.put(classElement, boundSlot);
78+ //// return;
79+ //// }
80+ //
81+ // Tree classTree = inferenceTypeFactory.declarationFromElement(classElement);
82+ // if (classTree != null) {
83+ // // Have source tree
84+ // if (bound.isAnnotatedInHierarchy(READONLY)) {
85+ // // Have bound annotation -> convert to equivalent ConstantSlot
86+ // boundSlot = slotManager.createConstantSlot(bound.getAnnotationInHierarchy(READONLY));
87+ // } else {
88+ // // No existing annotation -> create new VariableSlot
89+ // boundSlot = createVariable(treeToLocation(classTree));
90+ // }
91+ // } else {
92+ // // No source tree: bytecode classes
93+ // if (bound.isAnnotatedInHierarchy(READONLY)) {
94+ // // Have bound annotation in stub file
95+ // boundSlot = slotManager.createConstantSlot(bound.getAnnotationInHierarchy(READONLY));
96+ // } else {
97+ // // No stub file
98+ // if (PICOTypeUtil.isImplicitlyImmutableType(classType)) {
99+ // // Implicitly immutable
100+ // boundSlot = slotManager.createConstantSlot(IMMUTABLE);
101+ // } else {
102+ // // None of the above applies: use conservative @Mutable
103+ // boundSlot = slotManager.createConstantSlot(MUTABLE);
104+ // }
105+ // }
106+ // }
107+ // classType.addAnnotation(slotManager.getAnnotation(boundSlot));
108+ // classDeclAnnos.put(classElement, boundSlot);
109+ // }
110110
111111 @ Override
112112 protected VariableSlot getOrCreateDeclBound (AnnotatedDeclaredType type ) {
113113 TypeElement classDecl = (TypeElement ) type .getUnderlyingType ().asElement ();
114114
115- VariableSlot declSlot = classDeclAnnos . get (classDecl );
115+ AnnotationMirror declSlot = getClassDeclVarAnnot (classDecl );
116116 if (declSlot == null ) {
117117 // if a explicit annotation presents on the class DECL, use that directly
118118 if (type .isDeclaration () && type .isAnnotatedInHierarchy (READONLY ) && !type .hasAnnotation (READONLY )) {
119119 VariableSlot constantSlot = (VariableSlot ) slotManager .getSlot (type .getAnnotationInHierarchy (READONLY ));
120120// TypeElement classDecl = (TypeElement) type.getUnderlyingType().asElement();
121- classDeclAnnos . put ( classDecl , constantSlot );
121+ super . getOrCreateDeclBound ( type );
122122// // avoid duplicate annos
123123// type.removeAnnotationInHierarchy(READONLY);
124124 return constantSlot ;
@@ -134,21 +134,21 @@ protected VariableSlot getOrCreateDeclBound(AnnotatedDeclaredType type) {
134134 return (VariableSlot ) slotManager .getSlot (type .getAnnotation (VarAnnot .class ));
135135 }
136136 }
137- return super .getOrCreateDeclBound (type );
137+ return ( VariableSlot ) super .getOrCreateDeclBound (type );
138138 }
139139
140- @ Override
141- protected void handleExplicitExtends (Tree extendsTree ) {
142- // PICO cannot use base extends handling: not simply subtype relationship because of RDM
143- // Constraints already generated in processClassTree
144- }
140+ // @Override
141+ // protected void handleExplicitExtends(Tree extendsTree) {
142+ // // PICO cannot use base extends handling: not simply subtype relationship because of RDM
143+ // // Constraints already generated in processClassTree
144+ // }
145145
146146 @ Override
147147 public void storeElementType (Element element , AnnotatedTypeMirror atm ) {
148148 // this method is override the behavior of super.handleClassDeclaration before storing
149149 // find a better way
150150
151- Slot slot = slotManager .getVariableSlot (atm );
151+ Slot slot = slotManager .getSlot (atm );
152152 // do not use potential slot generated on the class decl annotation
153153 // PICO always have a annotation on the class bound, so Existential should always exist
154154 // TODO make VariableAnnotator::getOrCreateDeclBound protected and override that instead of this method
@@ -167,22 +167,22 @@ public void storeElementType(Element element, AnnotatedTypeMirror atm) {
167167 }
168168
169169 // Don't generate subtype constraint between use type and bound type
170- @ Override
171- protected void handleInstantiationConstraint (AnnotatedTypeMirror .AnnotatedDeclaredType adt , VariableSlot instantiationSlot , Tree tree ) {
172- return ;
173- }
174-
175- @ Override
176- protected VariableSlot addPrimaryVariable (AnnotatedTypeMirror atm , Tree tree ) {
177- // if (PICOTypeUtil.isEnumOrEnumConstant(atm)) {
178- // // Don't add new VarAnnot to type use of enum type
179- // PICOTypeUtil.applyConstant(atm, IMMUTABLE);
170+ // @Override
171+ // protected void handleInstantiationConstraint(AnnotatedTypeMirror.AnnotatedDeclaredType adt, VariableSlot instantiationSlot, Tree tree) {
172+ // return;
173+ // }
174+
175+ // @Override
176+ // protected VariableSlot addPrimaryVariable(AnnotatedTypeMirror atm, Tree tree) {
177+ //// if (PICOTypeUtil.isEnumOrEnumConstant(atm)) {
178+ //// // Don't add new VarAnnot to type use of enum type
179+ //// PICOTypeUtil.applyConstant(atm, IMMUTABLE);
180+ //// }
181+ // if (atm instanceof AnnotatedTypeMirror.AnnotatedNullType) {
182+ // PICOTypeUtil.applyConstant(atm, BOTTOM);
180183// }
181- if (atm instanceof AnnotatedTypeMirror .AnnotatedNullType ) {
182- PICOTypeUtil .applyConstant (atm , BOTTOM );
183- }
184- return super .addPrimaryVariable (atm , tree );
185- }
184+ // return super.addPrimaryVariable(atm, tree);
185+ // }
186186
187187 // Generates inequality constraint between every strict VariableSlot and @Bottom so that @Bottom is not inserted
188188 // back to source code, but can be within the internal state because of dataflow refinement
@@ -285,7 +285,7 @@ public Void visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType
285285
286286 @ Override
287287 public void handleBinaryTree (AnnotatedTypeMirror atm , BinaryTree binaryTree ) {
288- if (atm .isAnnotatedInHierarchy (varAnnot )) {
288+ if (atm .isAnnotatedInHierarchy (inferenceTypeFactory . getVarAnnot () )) {
289289 // Happens for binary trees whose atm is implicitly immutable and already handled by
290290 // PICOInferencePropagationTreeAnnotator
291291 return ;
@@ -294,15 +294,12 @@ public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) {
294294 }
295295
296296 public AnnotationMirror getClassDeclAnno (Element ele ) {
297- if (classDeclAnnos .get (ele ) != null ) {
298- return slotManager .getAnnotation (classDeclAnnos .get (ele ));
299- }
300- return null ;
297+ return getClassDeclVarAnnot ((TypeElement ) ele ); // todo: solved
301298 }
302299
303300
304301 @ Override
305- protected void addDeclarationConstraints (VariableSlot declSlot , VariableSlot instanceSlot ) {
302+ protected void addDeclarationConstraints (Slot declSlot , Slot instanceSlot ) {
306303 // RDM-related constraints cannot use subtype.
307304 // Necessary constraints added in visitor instead.
308305 }
0 commit comments