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

changeset 1570
f91144b7da75
parent 1521
71f35e4b93a5
child 1541
4cc73ec94686
equal deleted inserted replaced
1569:475eb15dfdad 1570:f91144b7da75
1 /* 1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
82 /** An accessor method for the attributes of this symbol. 82 /** An accessor method for the attributes of this symbol.
83 * Attributes of class symbols should be accessed through the accessor 83 * Attributes of class symbols should be accessed through the accessor
84 * method to make sure that the class symbol is loaded. 84 * method to make sure that the class symbol is loaded.
85 */ 85 */
86 public List<Attribute.Compound> getRawAttributes() { 86 public List<Attribute.Compound> getRawAttributes() {
87 return annotations.getAttributes(); 87 return annotations.getDeclarationAttributes();
88 }
89
90 /** An accessor method for the type attributes of this symbol.
91 * Attributes of class symbols should be accessed through the accessor
92 * method to make sure that the class symbol is loaded.
93 */
94 public List<Attribute.TypeCompound> getRawTypeAttributes() {
95 return annotations.getTypeAttributes();
88 } 96 }
89 97
90 /** Fetch a particular annotation from a symbol. */ 98 /** Fetch a particular annotation from a symbol. */
91 public Attribute.Compound attribute(Symbol anno) { 99 public Attribute.Compound attribute(Symbol anno) {
92 for (Attribute.Compound a : getRawAttributes()) { 100 for (Attribute.Compound a : getRawAttributes()) {
448 456
449 /** 457 /**
450 * This is the implementation for {@code 458 * This is the implementation for {@code
451 * javax.lang.model.element.Element.getAnnotationMirrors()}. 459 * javax.lang.model.element.Element.getAnnotationMirrors()}.
452 */ 460 */
453 public final List<Attribute.Compound> getAnnotationMirrors() { 461 public final List<? extends AnnotationMirror> getAnnotationMirrors() {
454 return getRawAttributes(); 462 return getRawAttributes();
463 }
464
465 /**
466 * TODO: Should there be a {@code
467 * javax.lang.model.element.Element.getTypeAnnotationMirrors()}.
468 */
469 public final List<Attribute.TypeCompound> getTypeAnnotationMirrors() {
470 return getRawTypeAttributes();
455 } 471 }
456 472
457 /** 473 /**
458 * @deprecated this method should never be used by javac internally. 474 * @deprecated this method should never be used by javac internally.
459 */ 475 */
460 @Deprecated 476 @Deprecated
461 public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) { 477 public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
462 return JavacElements.getAnnotation(this, annoType); 478 return JavacElements.getAnnotation(this, annoType);
479 }
480
481 // This method is part of the javax.lang.model API, do not use this in javac code.
482 public <A extends java.lang.annotation.Annotation> A[] getAnnotations(Class<A> annoType) {
483 return JavacElements.getAnnotations(this, annoType);
463 } 484 }
464 485
465 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList 486 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
466 public java.util.List<Symbol> getEnclosedElements() { 487 public java.util.List<Symbol> getEnclosedElements() {
467 return List.nil(); 488 return List.nil();
788 public List<Attribute.Compound> getRawAttributes() { 809 public List<Attribute.Compound> getRawAttributes() {
789 if (completer != null) complete(); 810 if (completer != null) complete();
790 return super.getRawAttributes(); 811 return super.getRawAttributes();
791 } 812 }
792 813
814 @Override
815 public List<Attribute.TypeCompound> getRawTypeAttributes() {
816 if (completer != null) complete();
817 return super.getRawTypeAttributes();
818 }
819
793 public Type erasure(Types types) { 820 public Type erasure(Types types) {
794 if (erasure_field == null) 821 if (erasure_field == null)
795 erasure_field = new ClassType(types.erasure(type.getEnclosingType()), 822 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
796 List.<Type>nil(), this); 823 List.<Type>nil(), this);
797 return erasure_field; 824 return erasure_field;
1226 // JLS 8.4.6.1 1253 // JLS 8.4.6.1
1227 switch ((int)(flags_field & Flags.AccessFlags)) { 1254 switch ((int)(flags_field & Flags.AccessFlags)) {
1228 case Flags.PRIVATE: 1255 case Flags.PRIVATE:
1229 return false; 1256 return false;
1230 case Flags.PUBLIC: 1257 case Flags.PUBLIC:
1231 return true; 1258 return !this.owner.isInterface() ||
1259 (flags_field & STATIC) == 0;
1232 case Flags.PROTECTED: 1260 case Flags.PROTECTED:
1233 return (origin.flags() & INTERFACE) == 0; 1261 return (origin.flags() & INTERFACE) == 0;
1234 case 0: 1262 case 0:
1235 // for package private: can only override in the same 1263 // for package private: can only override in the same
1236 // package 1264 // package
1237 return 1265 return
1238 this.packge() == origin.packge() && 1266 this.packge() == origin.packge() &&
1239 (origin.flags() & INTERFACE) == 0; 1267 (origin.flags() & INTERFACE) == 0;
1240 default: 1268 default:
1241 return false; 1269 return false;
1270 }
1271 }
1272
1273 @Override
1274 public boolean isInheritedIn(Symbol clazz, Types types) {
1275 switch ((int)(flags_field & Flags.AccessFlags)) {
1276 case PUBLIC:
1277 return !this.owner.isInterface() ||
1278 clazz == owner ||
1279 (flags_field & STATIC) == 0;
1280 default:
1281 return super.isInheritedIn(clazz, types);
1242 } 1282 }
1243 } 1283 }
1244 1284
1245 /** The implementation of this (abstract) symbol in class origin; 1285 /** The implementation of this (abstract) symbol in class origin;
1246 * null if none exists. Synthetic methods are not considered 1286 * null if none exists. Synthetic methods are not considered
1367 1407
1368 public Attribute getDefaultValue() { 1408 public Attribute getDefaultValue() {
1369 return defaultValue; 1409 return defaultValue;
1370 } 1410 }
1371 1411
1372 public List<VarSymbol> getParameters() { 1412 public List<VarSymbol> getParameters() {
1373 return params(); 1413 return params();
1374 } 1414 }
1375 1415
1376 public boolean isVarArgs() { 1416 public boolean isVarArgs() {
1377 return (flags() & VARARGS) != 0; 1417 return (flags() & VARARGS) != 0;

mercurial