equal
deleted
inserted
replaced
80 * separate declaration from type annotations and insert the type |
80 * separate declaration from type annotations and insert the type |
81 * annotations to their types; |
81 * annotations to their types; |
82 * and determine the TypeAnnotationPositions for all type annotations. |
82 * and determine the TypeAnnotationPositions for all type annotations. |
83 */ |
83 */ |
84 public class TypeAnnotations { |
84 public class TypeAnnotations { |
85 protected static final Context.Key<TypeAnnotations> typeAnnosKey = |
85 protected static final Context.Key<TypeAnnotations> typeAnnosKey = new Context.Key<>(); |
86 new Context.Key<TypeAnnotations>(); |
|
87 |
86 |
88 public static TypeAnnotations instance(Context context) { |
87 public static TypeAnnotations instance(Context context) { |
89 TypeAnnotations instance = context.get(typeAnnosKey); |
88 TypeAnnotations instance = context.get(typeAnnosKey); |
90 if (instance == null) |
89 if (instance == null) |
91 instance = new TypeAnnotations(context); |
90 instance = new TypeAnnotations(context); |
153 */ |
152 */ |
154 public void organizeTypeAnnotationsBodies(JCClassDecl tree) { |
153 public void organizeTypeAnnotationsBodies(JCClassDecl tree) { |
155 new TypeAnnotationPositions(false).scan(tree); |
154 new TypeAnnotationPositions(false).scan(tree); |
156 } |
155 } |
157 |
156 |
158 public enum AnnotationType { DECLARATION, TYPE, BOTH }; |
157 public enum AnnotationType { DECLARATION, TYPE, BOTH } |
159 |
158 |
160 /** |
159 /** |
161 * Determine whether an annotation is a declaration annotation, |
160 * Determine whether an annotation is a declaration annotation, |
162 * a type annotation, or both. |
161 * a type annotation, or both. |
163 */ |
162 */ |
284 * annotations and marks them as if they were part of the type. |
283 * annotations and marks them as if they were part of the type. |
285 */ |
284 */ |
286 private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym, |
285 private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym, |
287 TypeAnnotationPosition pos) { |
286 TypeAnnotationPosition pos) { |
288 List<Attribute.Compound> annotations = sym.getRawAttributes(); |
287 List<Attribute.Compound> annotations = sym.getRawAttributes(); |
289 ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<Attribute.Compound>(); |
288 ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<>(); |
290 ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<Attribute.TypeCompound>(); |
289 ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<>(); |
291 ListBuffer<Attribute.TypeCompound> onlyTypeAnnos = new ListBuffer<Attribute.TypeCompound>(); |
290 ListBuffer<Attribute.TypeCompound> onlyTypeAnnos = new ListBuffer<>(); |
292 |
291 |
293 for (Attribute.Compound a : annotations) { |
292 for (Attribute.Compound a : annotations) { |
294 switch (annotationType(a, sym)) { |
293 switch (annotationType(a, sym)) { |
295 case DECLARATION: |
294 case DECLARATION: |
296 declAnnos.append(a); |
295 declAnnos.append(a); |
349 // note that the typeAnnotations will also be added to the owner below. |
348 // note that the typeAnnotations will also be added to the owner below. |
350 } else { |
349 } else { |
351 MethodType methType = sym.owner.type.asMethodType(); |
350 MethodType methType = sym.owner.type.asMethodType(); |
352 List<VarSymbol> params = ((MethodSymbol)sym.owner).params; |
351 List<VarSymbol> params = ((MethodSymbol)sym.owner).params; |
353 List<Type> oldArgs = methType.argtypes; |
352 List<Type> oldArgs = methType.argtypes; |
354 ListBuffer<Type> newArgs = new ListBuffer<Type>(); |
353 ListBuffer<Type> newArgs = new ListBuffer<>(); |
355 while (params.nonEmpty()) { |
354 while (params.nonEmpty()) { |
356 if (params.head == sym) { |
355 if (params.head == sym) { |
357 newArgs.add(type); |
356 newArgs.add(type); |
358 } else { |
357 } else { |
359 newArgs.add(oldArgs.head); |
358 newArgs.add(oldArgs.head); |
1222 } |
1221 } |
1223 |
1222 |
1224 private void copyNewClassAnnotationsToOwner(JCNewClass tree) { |
1223 private void copyNewClassAnnotationsToOwner(JCNewClass tree) { |
1225 Symbol sym = tree.def.sym; |
1224 Symbol sym = tree.def.sym; |
1226 TypeAnnotationPosition pos = new TypeAnnotationPosition(); |
1225 TypeAnnotationPosition pos = new TypeAnnotationPosition(); |
1227 ListBuffer<Attribute.TypeCompound> newattrs = |
1226 ListBuffer<Attribute.TypeCompound> newattrs = new ListBuffer<>(); |
1228 new ListBuffer<Attribute.TypeCompound>(); |
|
1229 |
1227 |
1230 for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) { |
1228 for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) { |
1231 newattrs.append(new Attribute.TypeCompound(old.type, old.values, |
1229 newattrs.append(new Attribute.TypeCompound(old.type, old.values, |
1232 pos)); |
1230 pos)); |
1233 } |
1231 } |