src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java

changeset 2168
119747cd9f25
parent 2150
ae4f5cb78ebd
child 2525
2eb010b6cb22
equal deleted inserted replaced
2167:d2fa3f7e964e 2168:119747cd9f25
368 } 368 }
369 369
370 sym.appendUniqueTypeAttributes(typeAnnotations); 370 sym.appendUniqueTypeAttributes(typeAnnotations);
371 371
372 if (sym.getKind() == ElementKind.PARAMETER || 372 if (sym.getKind() == ElementKind.PARAMETER ||
373 sym.getKind() == ElementKind.LOCAL_VARIABLE || 373 sym.getKind() == ElementKind.LOCAL_VARIABLE ||
374 sym.getKind() == ElementKind.RESOURCE_VARIABLE || 374 sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
375 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { 375 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
376 // Make sure all type annotations from the symbol are also 376 // Make sure all type annotations from the symbol are also
377 // on the owner. 377 // on the owner.
378 sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes()); 378 sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes());
379 } 379 }
380 } 380 }
1219 public void visitTypeParameter(JCTypeParameter tree) { 1219 public void visitTypeParameter(JCTypeParameter tree) {
1220 findPosition(tree, peek2(), tree.annotations); 1220 findPosition(tree, peek2(), tree.annotations);
1221 super.visitTypeParameter(tree); 1221 super.visitTypeParameter(tree);
1222 } 1222 }
1223 1223
1224 private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
1225 Symbol sym = tree.def.sym;
1226 TypeAnnotationPosition pos = new TypeAnnotationPosition();
1227 ListBuffer<Attribute.TypeCompound> newattrs =
1228 new ListBuffer<Attribute.TypeCompound>();
1229
1230 for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
1231 newattrs.append(new Attribute.TypeCompound(old.type, old.values,
1232 pos));
1233 }
1234
1235 pos.type = TargetType.NEW;
1236 pos.pos = tree.pos;
1237 sym.owner.appendUniqueTypeAttributes(newattrs.toList());
1238 }
1239
1224 @Override 1240 @Override
1225 public void visitNewClass(JCNewClass tree) { 1241 public void visitNewClass(JCNewClass tree) {
1226 if (tree.def != null && 1242 if (tree.def != null &&
1227 !tree.def.mods.annotations.isEmpty()) { 1243 !tree.def.mods.annotations.isEmpty()) {
1228 JCClassDecl classdecl = tree.def; 1244 JCClassDecl classdecl = tree.def;
1237 // In contrast to CLASS elsewhere, typarams cannot occur here. 1253 // In contrast to CLASS elsewhere, typarams cannot occur here.
1238 Assert.error("Could not determine position of tree " + tree); 1254 Assert.error("Could not determine position of tree " + tree);
1239 } 1255 }
1240 Type before = classdecl.sym.type; 1256 Type before = classdecl.sym.type;
1241 separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos); 1257 separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
1242 1258 copyNewClassAnnotationsToOwner(tree);
1243 // classdecl.sym.type now contains an annotated type, which 1259 // classdecl.sym.type now contains an annotated type, which
1244 // is not what we want there. 1260 // is not what we want there.
1245 // TODO: should we put this type somewhere in the superclass/interface? 1261 // TODO: should we put this type somewhere in the superclass/interface?
1246 classdecl.sym.type = before; 1262 classdecl.sym.type = before;
1247 } 1263 }

mercurial