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

changeset 121
609fb59657b4
parent 113
eff38cc97183
child 155
4d2d8b6459e1
equal deleted inserted replaced
120:ddd110646d21 121:609fb59657b4
130 */ 130 */
131 public Symbol clone(Symbol newOwner) { 131 public Symbol clone(Symbol newOwner) {
132 throw new AssertionError(); 132 throw new AssertionError();
133 } 133 }
134 134
135 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
136 return v.visitSymbol(this, p);
137 }
138
135 /** The Java source which this symbol represents. 139 /** The Java source which this symbol represents.
136 * A description of this symbol; overrides Object. 140 * A description of this symbol; overrides Object.
137 */ 141 */
138 public String toString() { 142 public String toString() {
139 return name.toString(); 143 return name.toString();
475 public void complete() throws CompletionFailure { other.complete(); } 479 public void complete() throws CompletionFailure { other.complete(); }
476 480
477 public <R, P> R accept(ElementVisitor<R, P> v, P p) { 481 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
478 return other.accept(v, p); 482 return other.accept(v, p);
479 } 483 }
484
485 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
486 return v.visitSymbol(other, p);
487 }
480 } 488 }
481 489
482 /** A class for type symbols. Type variables are represented by instances 490 /** A class for type symbols. Type variables are represented by instances
483 * of this class, classes and packages by instances of subclasses. 491 * of this class, classes and packages by instances of subclasses.
484 */ 492 */
568 public <R, P> R accept(ElementVisitor<R, P> v, P p) { 576 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
569 assert type.tag == TYPEVAR; // else override will be invoked 577 assert type.tag == TYPEVAR; // else override will be invoked
570 return v.visitTypeParameter(this, p); 578 return v.visitTypeParameter(this, p);
571 } 579 }
572 580
581 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
582 return v.visitTypeSymbol(this, p);
583 }
584
573 public List<Type> getBounds() { 585 public List<Type> getBounds() {
574 TypeVar t = (TypeVar)type; 586 TypeVar t = (TypeVar)type;
575 Type bound = t.getUpperBound(); 587 Type bound = t.getUpperBound();
576 if (!bound.isCompound()) 588 if (!bound.isCompound())
577 return List.of(bound); 589 return List.of(bound);
651 } 663 }
652 664
653 public <R, P> R accept(ElementVisitor<R, P> v, P p) { 665 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
654 return v.visitPackage(this, p); 666 return v.visitPackage(this, p);
655 } 667 }
668
669 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
670 return v.visitPackageSymbol(this, p);
671 }
656 } 672 }
657 673
658 /** A class for class symbols 674 /** A class for class symbols
659 */ 675 */
660 public static class ClassSymbol extends TypeSymbol implements TypeElement { 676 public static class ClassSymbol extends TypeSymbol implements TypeElement {
840 return JavacElements.getAnnotation(this, annoType); 856 return JavacElements.getAnnotation(this, annoType);
841 } 857 }
842 858
843 public <R, P> R accept(ElementVisitor<R, P> v, P p) { 859 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
844 return v.visitType(this, p); 860 return v.visitType(this, p);
861 }
862
863 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
864 return v.visitClassSymbol(this, p);
845 } 865 }
846 } 866 }
847 867
848 868
849 /** A class for variable symbols 869 /** A class for variable symbols
967 987
968 public void setData(Object data) { 988 public void setData(Object data) {
969 assert !(data instanceof Env<?>) : this; 989 assert !(data instanceof Env<?>) : this;
970 this.data = data; 990 this.data = data;
971 } 991 }
992
993 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
994 return v.visitVarSymbol(this, p);
995 }
972 } 996 }
973 997
974 /** A class for method symbols. 998 /** A class for method symbols.
975 */ 999 */
976 public static class MethodSymbol extends Symbol implements ExecutableElement { 1000 public static class MethodSymbol extends Symbol implements ExecutableElement {
1230 1254
1231 public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1255 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1232 return v.visitExecutable(this, p); 1256 return v.visitExecutable(this, p);
1233 } 1257 }
1234 1258
1259 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1260 return v.visitMethodSymbol(this, p);
1261 }
1262
1235 public Type getReturnType() { 1263 public Type getReturnType() {
1236 return asType().getReturnType(); 1264 return asType().getReturnType();
1237 } 1265 }
1238 1266
1239 public List<Type> getThrownTypes() { 1267 public List<Type> getThrownTypes() {
1248 public int opcode; 1276 public int opcode;
1249 1277
1250 public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) { 1278 public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
1251 super(PUBLIC | STATIC, name, type, owner); 1279 super(PUBLIC | STATIC, name, type, owner);
1252 this.opcode = opcode; 1280 this.opcode = opcode;
1281 }
1282
1283 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1284 return v.visitOperatorSymbol(this, p);
1253 } 1285 }
1254 } 1286 }
1255 1287
1256 /** Symbol completer interface. 1288 /** Symbol completer interface.
1257 */ 1289 */
1306 super.initCause(cause); 1338 super.initCause(cause);
1307 return this; 1339 return this;
1308 } 1340 }
1309 1341
1310 } 1342 }
1343
1344 /**
1345 * A visitor for symbols. A visitor is used to implement operations
1346 * (or relations) on symbols. Most common operations on types are
1347 * binary relations and this interface is designed for binary
1348 * relations, that is, operations on the form
1349 * Symbol&nbsp;&times;&nbsp;P&nbsp;&rarr;&nbsp;R.
1350 * <!-- In plain text: Type x P -> R -->
1351 *
1352 * @param <R> the return type of the operation implemented by this
1353 * visitor; use Void if no return type is needed.
1354 * @param <P> the type of the second argument (the first being the
1355 * symbol itself) of the operation implemented by this visitor; use
1356 * Void if a second argument is not needed.
1357 */
1358 public interface Visitor<R,P> {
1359 R visitClassSymbol(ClassSymbol s, P arg);
1360 R visitMethodSymbol(MethodSymbol s, P arg);
1361 R visitPackageSymbol(PackageSymbol s, P arg);
1362 R visitOperatorSymbol(OperatorSymbol s, P arg);
1363 R visitVarSymbol(VarSymbol s, P arg);
1364 R visitTypeSymbol(TypeSymbol s, P arg);
1365 R visitSymbol(Symbol s, P arg);
1366 }
1311 } 1367 }

mercurial