Fri, 12 Apr 2013 12:05:04 +0200
7015104: use new subtype of TypeSymbol for type parameters
Reviewed-by: jjg, mcimadamore
1 /*
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.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.code;
28 import java.util.Set;
29 import java.util.concurrent.Callable;
31 import javax.lang.model.element.*;
32 import javax.tools.JavaFileObject;
34 import com.sun.tools.javac.code.Type.*;
35 import com.sun.tools.javac.comp.Attr;
36 import com.sun.tools.javac.comp.AttrContext;
37 import com.sun.tools.javac.comp.Env;
38 import com.sun.tools.javac.jvm.*;
39 import com.sun.tools.javac.model.*;
40 import com.sun.tools.javac.tree.JCTree;
41 import com.sun.tools.javac.util.*;
42 import com.sun.tools.javac.util.Name;
43 import static com.sun.tools.javac.code.Flags.*;
44 import static com.sun.tools.javac.code.Kinds.*;
45 import static com.sun.tools.javac.code.TypeTag.CLASS;
46 import static com.sun.tools.javac.code.TypeTag.FORALL;
47 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
49 /** Root class for Java symbols. It contains subclasses
50 * for specific sorts of symbols, such as variables, methods and operators,
51 * types, packages. Each subclass is represented as a static inner class
52 * inside Symbol.
53 *
54 * <p><b>This is NOT part of any supported API.
55 * If you write code that depends on this, you do so at your own risk.
56 * This code and its internal interfaces are subject to change or
57 * deletion without notice.</b>
58 */
59 public abstract class Symbol implements Element {
60 // public Throwable debug = new Throwable();
62 /** The kind of this symbol.
63 * @see Kinds
64 */
65 public int kind;
67 /** The flags of this symbol.
68 */
69 public long flags_field;
71 /** An accessor method for the flags of this symbol.
72 * Flags of class symbols should be accessed through the accessor
73 * method to make sure that the class symbol is loaded.
74 */
75 public long flags() { return flags_field; }
77 /** The attributes of this symbol are contained in this
78 * Annotations. The Annotations instance is NOT immutable.
79 */
80 public final Annotations annotations = new Annotations(this);
82 /** An accessor method for the attributes of this symbol.
83 * Attributes of class symbols should be accessed through the accessor
84 * method to make sure that the class symbol is loaded.
85 */
86 public List<Attribute.Compound> getRawAttributes() {
87 return annotations.getDeclarationAttributes();
88 }
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();
96 }
98 /** Fetch a particular annotation from a symbol. */
99 public Attribute.Compound attribute(Symbol anno) {
100 for (Attribute.Compound a : getRawAttributes()) {
101 if (a.type.tsym == anno) return a;
102 }
103 return null;
104 }
106 /** The name of this symbol in Utf8 representation.
107 */
108 public Name name;
110 /** The type of this symbol.
111 */
112 public Type type;
114 /** The owner of this symbol.
115 */
116 public Symbol owner;
118 /** The completer of this symbol.
119 */
120 public Completer completer;
122 /** A cache for the type erasure of this symbol.
123 */
124 public Type erasure_field;
126 /** Construct a symbol with given kind, flags, name, type and owner.
127 */
128 public Symbol(int kind, long flags, Name name, Type type, Symbol owner) {
129 this.kind = kind;
130 this.flags_field = flags;
131 this.type = type;
132 this.owner = owner;
133 this.completer = null;
134 this.erasure_field = null;
135 this.name = name;
136 }
138 /** Clone this symbol with new owner.
139 * Legal only for fields and methods.
140 */
141 public Symbol clone(Symbol newOwner) {
142 throw new AssertionError();
143 }
145 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
146 return v.visitSymbol(this, p);
147 }
149 /** The Java source which this symbol represents.
150 * A description of this symbol; overrides Object.
151 */
152 public String toString() {
153 return name.toString();
154 }
156 /** A Java source description of the location of this symbol; used for
157 * error reporting.
158 *
159 * @return null if the symbol is a package or a toplevel class defined in
160 * the default package; otherwise, the owner symbol is returned
161 */
162 public Symbol location() {
163 if (owner.name == null || (owner.name.isEmpty() &&
164 (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) {
165 return null;
166 }
167 return owner;
168 }
170 public Symbol location(Type site, Types types) {
171 if (owner.name == null || owner.name.isEmpty()) {
172 return location();
173 }
174 if (owner.type.hasTag(CLASS)) {
175 Type ownertype = types.asOuterSuper(site, owner);
176 if (ownertype != null) return ownertype.tsym;
177 }
178 return owner;
179 }
181 public Symbol baseSymbol() {
182 return this;
183 }
185 /** The symbol's erased type.
186 */
187 public Type erasure(Types types) {
188 if (erasure_field == null)
189 erasure_field = types.erasure(type);
190 return erasure_field;
191 }
193 /** The external type of a symbol. This is the symbol's erased type
194 * except for constructors of inner classes which get the enclosing
195 * instance class added as first argument.
196 */
197 public Type externalType(Types types) {
198 Type t = erasure(types);
199 if (name == name.table.names.init && owner.hasOuterInstance()) {
200 Type outerThisType = types.erasure(owner.type.getEnclosingType());
201 return new MethodType(t.getParameterTypes().prepend(outerThisType),
202 t.getReturnType(),
203 t.getThrownTypes(),
204 t.tsym);
205 } else {
206 return t;
207 }
208 }
210 public boolean isStatic() {
211 return
212 (flags() & STATIC) != 0 ||
213 (owner.flags() & INTERFACE) != 0 && kind != MTH;
214 }
216 public boolean isInterface() {
217 return (flags() & INTERFACE) != 0;
218 }
220 public boolean isPrivate() {
221 return (flags_field & Flags.AccessFlags) == PRIVATE;
222 }
224 public boolean isEnum() {
225 return (flags() & ENUM) != 0;
226 }
228 /** Is this symbol declared (directly or indirectly) local
229 * to a method or variable initializer?
230 * Also includes fields of inner classes which are in
231 * turn local to a method or variable initializer.
232 */
233 public boolean isLocal() {
234 return
235 (owner.kind & (VAR | MTH)) != 0 ||
236 (owner.kind == TYP && owner.isLocal());
237 }
239 /** Has this symbol an empty name? This includes anonymous
240 * inner classes.
241 */
242 public boolean isAnonymous() {
243 return name.isEmpty();
244 }
246 /** Is this symbol a constructor?
247 */
248 public boolean isConstructor() {
249 return name == name.table.names.init;
250 }
252 /** The fully qualified name of this symbol.
253 * This is the same as the symbol's name except for class symbols,
254 * which are handled separately.
255 */
256 public Name getQualifiedName() {
257 return name;
258 }
260 /** The fully qualified name of this symbol after converting to flat
261 * representation. This is the same as the symbol's name except for
262 * class symbols, which are handled separately.
263 */
264 public Name flatName() {
265 return getQualifiedName();
266 }
268 /** If this is a class or package, its members, otherwise null.
269 */
270 public Scope members() {
271 return null;
272 }
274 /** A class is an inner class if it it has an enclosing instance class.
275 */
276 public boolean isInner() {
277 return type.getEnclosingType().hasTag(CLASS);
278 }
280 /** An inner class has an outer instance if it is not an interface
281 * it has an enclosing instance class which might be referenced from the class.
282 * Nested classes can see instance members of their enclosing class.
283 * Their constructors carry an additional this$n parameter, inserted
284 * implicitly by the compiler.
285 *
286 * @see #isInner
287 */
288 public boolean hasOuterInstance() {
289 return
290 type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0;
291 }
293 /** The closest enclosing class of this symbol's declaration.
294 */
295 public ClassSymbol enclClass() {
296 Symbol c = this;
297 while (c != null &&
298 ((c.kind & TYP) == 0 || !c.type.hasTag(CLASS))) {
299 c = c.owner;
300 }
301 return (ClassSymbol)c;
302 }
304 /** The outermost class which indirectly owns this symbol.
305 */
306 public ClassSymbol outermostClass() {
307 Symbol sym = this;
308 Symbol prev = null;
309 while (sym.kind != PCK) {
310 prev = sym;
311 sym = sym.owner;
312 }
313 return (ClassSymbol) prev;
314 }
316 /** The package which indirectly owns this symbol.
317 */
318 public PackageSymbol packge() {
319 Symbol sym = this;
320 while (sym.kind != PCK) {
321 sym = sym.owner;
322 }
323 return (PackageSymbol) sym;
324 }
326 /** Is this symbol a subclass of `base'? Only defined for ClassSymbols.
327 */
328 public boolean isSubClass(Symbol base, Types types) {
329 throw new AssertionError("isSubClass " + this);
330 }
332 /** Fully check membership: hierarchy, protection, and hiding.
333 * Does not exclude methods not inherited due to overriding.
334 */
335 public boolean isMemberOf(TypeSymbol clazz, Types types) {
336 return
337 owner == clazz ||
338 clazz.isSubClass(owner, types) &&
339 isInheritedIn(clazz, types) &&
340 !hiddenIn((ClassSymbol)clazz, types);
341 }
343 /** Is this symbol the same as or enclosed by the given class? */
344 public boolean isEnclosedBy(ClassSymbol clazz) {
345 for (Symbol sym = this; sym.kind != PCK; sym = sym.owner)
346 if (sym == clazz) return true;
347 return false;
348 }
350 /** Check for hiding. Note that this doesn't handle multiple
351 * (interface) inheritance. */
352 private boolean hiddenIn(ClassSymbol clazz, Types types) {
353 if (kind == MTH && (flags() & STATIC) == 0) return false;
354 while (true) {
355 if (owner == clazz) return false;
356 Scope.Entry e = clazz.members().lookup(name);
357 while (e.scope != null) {
358 if (e.sym == this) return false;
359 if (e.sym.kind == kind &&
360 (kind != MTH ||
361 (e.sym.flags() & STATIC) != 0 &&
362 types.isSubSignature(e.sym.type, type)))
363 return true;
364 e = e.next();
365 }
366 Type superType = types.supertype(clazz.type);
367 if (!superType.hasTag(CLASS)) return false;
368 clazz = (ClassSymbol)superType.tsym;
369 }
370 }
372 /** Is this symbol inherited into a given class?
373 * PRE: If symbol's owner is a interface,
374 * it is already assumed that the interface is a superinterface
375 * of given class.
376 * @param clazz The class for which we want to establish membership.
377 * This must be a subclass of the member's owner.
378 */
379 public boolean isInheritedIn(Symbol clazz, Types types) {
380 switch ((int)(flags_field & Flags.AccessFlags)) {
381 default: // error recovery
382 case PUBLIC:
383 return true;
384 case PRIVATE:
385 return this.owner == clazz;
386 case PROTECTED:
387 // we model interfaces as extending Object
388 return (clazz.flags() & INTERFACE) == 0;
389 case 0:
390 PackageSymbol thisPackage = this.packge();
391 for (Symbol sup = clazz;
392 sup != null && sup != this.owner;
393 sup = types.supertype(sup.type).tsym) {
394 while (sup.type.hasTag(TYPEVAR))
395 sup = sup.type.getUpperBound().tsym;
396 if (sup.type.isErroneous())
397 return true; // error recovery
398 if ((sup.flags() & COMPOUND) != 0)
399 continue;
400 if (sup.packge() != thisPackage)
401 return false;
402 }
403 return (clazz.flags() & INTERFACE) == 0;
404 }
405 }
407 /** The (variable or method) symbol seen as a member of given
408 * class type`site' (this might change the symbol's type).
409 * This is used exclusively for producing diagnostics.
410 */
411 public Symbol asMemberOf(Type site, Types types) {
412 throw new AssertionError();
413 }
415 /** Does this method symbol override `other' symbol, when both are seen as
416 * members of class `origin'? It is assumed that _other is a member
417 * of origin.
418 *
419 * It is assumed that both symbols have the same name. The static
420 * modifier is ignored for this test.
421 *
422 * See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
423 */
424 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
425 return false;
426 }
428 /** Complete the elaboration of this symbol's definition.
429 */
430 public void complete() throws CompletionFailure {
431 if (completer != null) {
432 Completer c = completer;
433 completer = null;
434 c.complete(this);
435 }
436 }
438 /** True if the symbol represents an entity that exists.
439 */
440 public boolean exists() {
441 return true;
442 }
444 public Type asType() {
445 return type;
446 }
448 public Symbol getEnclosingElement() {
449 return owner;
450 }
452 public ElementKind getKind() {
453 return ElementKind.OTHER; // most unkind
454 }
456 public Set<Modifier> getModifiers() {
457 long flags = flags();
458 return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
459 }
461 public Name getSimpleName() {
462 return name;
463 }
465 /**
466 * This is the implementation for {@code
467 * javax.lang.model.element.Element.getAnnotationMirrors()}.
468 */
469 public final List<? extends AnnotationMirror> getAnnotationMirrors() {
470 return getRawAttributes();
471 }
473 /**
474 * TODO: Should there be a {@code
475 * javax.lang.model.element.Element.getTypeAnnotationMirrors()}.
476 */
477 public final List<Attribute.TypeCompound> getTypeAnnotationMirrors() {
478 return getRawTypeAttributes();
479 }
481 /**
482 * @deprecated this method should never be used by javac internally.
483 */
484 @Deprecated
485 public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
486 return JavacAnnoConstructs.getAnnotation(this, annoType);
487 }
489 // This method is part of the javax.lang.model API, do not use this in javac code.
490 public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(Class<A> annoType) {
491 return JavacAnnoConstructs.getAnnotations(this, annoType);
492 }
494 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
495 public java.util.List<Symbol> getEnclosedElements() {
496 return List.nil();
497 }
499 public List<TypeVariableSymbol> getTypeParameters() {
500 ListBuffer<TypeVariableSymbol> l = ListBuffer.lb();
501 for (Type t : type.getTypeArguments()) {
502 Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
503 l.append((TypeVariableSymbol)t.tsym);
504 }
505 return l.toList();
506 }
508 public static class DelegatedSymbol<T extends Symbol> extends Symbol {
509 protected T other;
510 public DelegatedSymbol(T other) {
511 super(other.kind, other.flags_field, other.name, other.type, other.owner);
512 this.other = other;
513 }
514 public String toString() { return other.toString(); }
515 public Symbol location() { return other.location(); }
516 public Symbol location(Type site, Types types) { return other.location(site, types); }
517 public Symbol baseSymbol() { return other; }
518 public Type erasure(Types types) { return other.erasure(types); }
519 public Type externalType(Types types) { return other.externalType(types); }
520 public boolean isLocal() { return other.isLocal(); }
521 public boolean isConstructor() { return other.isConstructor(); }
522 public Name getQualifiedName() { return other.getQualifiedName(); }
523 public Name flatName() { return other.flatName(); }
524 public Scope members() { return other.members(); }
525 public boolean isInner() { return other.isInner(); }
526 public boolean hasOuterInstance() { return other.hasOuterInstance(); }
527 public ClassSymbol enclClass() { return other.enclClass(); }
528 public ClassSymbol outermostClass() { return other.outermostClass(); }
529 public PackageSymbol packge() { return other.packge(); }
530 public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
531 public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
532 public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
533 public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
534 public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
535 public void complete() throws CompletionFailure { other.complete(); }
537 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
538 return other.accept(v, p);
539 }
541 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
542 return v.visitSymbol(other, p);
543 }
545 public T getUnderlyingSymbol() {
546 return other;
547 }
548 }
550 /** A base class for Symbols representing types.
551 */
552 public static abstract class TypeSymbol extends Symbol {
553 public TypeSymbol(int kind, long flags, Name name, Type type, Symbol owner) {
554 super(kind, flags, name, type, owner);
555 }
556 /** form a fully qualified name from a name and an owner
557 */
558 static public Name formFullName(Name name, Symbol owner) {
559 if (owner == null) return name;
560 if (((owner.kind != ERR)) &&
561 ((owner.kind & (VAR | MTH)) != 0
562 || (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
563 )) return name;
564 Name prefix = owner.getQualifiedName();
565 if (prefix == null || prefix == prefix.table.names.empty)
566 return name;
567 else return prefix.append('.', name);
568 }
570 /** form a fully qualified name from a name and an owner, after
571 * converting to flat representation
572 */
573 static public Name formFlatName(Name name, Symbol owner) {
574 if (owner == null ||
575 (owner.kind & (VAR | MTH)) != 0
576 || (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
577 ) return name;
578 char sep = owner.kind == TYP ? '$' : '.';
579 Name prefix = owner.flatName();
580 if (prefix == null || prefix == prefix.table.names.empty)
581 return name;
582 else return prefix.append(sep, name);
583 }
585 /**
586 * A total ordering between type symbols that refines the
587 * class inheritance graph.
588 *
589 * Typevariables always precede other kinds of symbols.
590 */
591 public final boolean precedes(TypeSymbol that, Types types) {
592 if (this == that)
593 return false;
594 if (this.type.tag == that.type.tag) {
595 if (this.type.hasTag(CLASS)) {
596 return
597 types.rank(that.type) < types.rank(this.type) ||
598 types.rank(that.type) == types.rank(this.type) &&
599 that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
600 } else if (this.type.hasTag(TYPEVAR)) {
601 return types.isSubtype(this.type, that.type);
602 }
603 }
604 return this.type.hasTag(TYPEVAR);
605 }
607 @Override
608 public java.util.List<Symbol> getEnclosedElements() {
609 List<Symbol> list = List.nil();
610 if (kind == TYP && type.hasTag(TYPEVAR)) {
611 return list;
612 }
613 for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
614 if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
615 list = list.prepend(e.sym);
616 }
617 return list;
618 }
620 @Override
621 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
622 return v.visitTypeSymbol(this, p);
623 }
624 }
626 /**
627 * Type variables are represented by instances of this class.
628 */
629 public static class TypeVariableSymbol
630 extends TypeSymbol implements TypeParameterElement {
632 public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) {
633 super(TYP, flags, name, type, owner);
634 }
636 public ElementKind getKind() {
637 return ElementKind.TYPE_PARAMETER;
638 }
640 @Override
641 public Symbol getGenericElement() {
642 return owner;
643 }
645 public List<Type> getBounds() {
646 TypeVar t = (TypeVar)type;
647 Type bound = t.getUpperBound();
648 if (!bound.isCompound())
649 return List.of(bound);
650 ClassType ct = (ClassType)bound;
651 if (!ct.tsym.erasure_field.isInterface()) {
652 return ct.interfaces_field.prepend(ct.supertype_field);
653 } else {
654 // No superclass was given in bounds.
655 // In this case, supertype is Object, erasure is first interface.
656 return ct.interfaces_field;
657 }
658 }
660 @Override
661 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
662 return v.visitTypeParameter(this, p);
663 }
664 }
666 /** A class for package symbols
667 */
668 public static class PackageSymbol extends TypeSymbol
669 implements PackageElement {
671 public Scope members_field;
672 public Name fullname;
673 public ClassSymbol package_info; // see bug 6443073
675 public PackageSymbol(Name name, Type type, Symbol owner) {
676 super(PCK, 0, name, type, owner);
677 this.members_field = null;
678 this.fullname = formFullName(name, owner);
679 }
681 public PackageSymbol(Name name, Symbol owner) {
682 this(name, null, owner);
683 this.type = new PackageType(this);
684 }
686 public String toString() {
687 return fullname.toString();
688 }
690 public Name getQualifiedName() {
691 return fullname;
692 }
694 public boolean isUnnamed() {
695 return name.isEmpty() && owner != null;
696 }
698 public Scope members() {
699 if (completer != null) complete();
700 return members_field;
701 }
703 public long flags() {
704 if (completer != null) complete();
705 return flags_field;
706 }
708 @Override
709 public List<Attribute.Compound> getRawAttributes() {
710 if (completer != null) complete();
711 if (package_info != null && package_info.completer != null) {
712 package_info.complete();
713 mergeAttributes();
714 }
715 return super.getRawAttributes();
716 }
718 private void mergeAttributes() {
719 if (annotations.isEmpty() &&
720 !package_info.annotations.isEmpty()) {
721 annotations.setAttributes(package_info.annotations);
722 }
723 }
725 /** A package "exists" if a type or package that exists has
726 * been seen within it.
727 */
728 public boolean exists() {
729 return (flags_field & EXISTS) != 0;
730 }
732 public ElementKind getKind() {
733 return ElementKind.PACKAGE;
734 }
736 public Symbol getEnclosingElement() {
737 return null;
738 }
740 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
741 return v.visitPackage(this, p);
742 }
744 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
745 return v.visitPackageSymbol(this, p);
746 }
747 }
749 /** A class for class symbols
750 */
751 public static class ClassSymbol extends TypeSymbol implements TypeElement {
753 /** a scope for all class members; variables, methods and inner classes
754 * type parameters are not part of this scope
755 */
756 public Scope members_field;
758 /** the fully qualified name of the class, i.e. pck.outer.inner.
759 * null for anonymous classes
760 */
761 public Name fullname;
763 /** the fully qualified name of the class after converting to flat
764 * representation, i.e. pck.outer$inner,
765 * set externally for local and anonymous classes
766 */
767 public Name flatname;
769 /** the sourcefile where the class came from
770 */
771 public JavaFileObject sourcefile;
773 /** the classfile from where to load this class
774 * this will have extension .class or .java
775 */
776 public JavaFileObject classfile;
778 /** the list of translated local classes (used for generating
779 * InnerClasses attribute)
780 */
781 public List<ClassSymbol> trans_local;
783 /** the constant pool of the class
784 */
785 public Pool pool;
787 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
788 super(TYP, flags, name, type, owner);
789 this.members_field = null;
790 this.fullname = formFullName(name, owner);
791 this.flatname = formFlatName(name, owner);
792 this.sourcefile = null;
793 this.classfile = null;
794 this.pool = null;
795 }
797 public ClassSymbol(long flags, Name name, Symbol owner) {
798 this(
799 flags,
800 name,
801 new ClassType(Type.noType, null, null),
802 owner);
803 this.type.tsym = this;
804 }
806 /** The Java source which this symbol represents.
807 */
808 public String toString() {
809 return className();
810 }
812 public long flags() {
813 if (completer != null) complete();
814 return flags_field;
815 }
817 public Scope members() {
818 if (completer != null) complete();
819 return members_field;
820 }
822 @Override
823 public List<Attribute.Compound> getRawAttributes() {
824 if (completer != null) complete();
825 return super.getRawAttributes();
826 }
828 @Override
829 public List<Attribute.TypeCompound> getRawTypeAttributes() {
830 if (completer != null) complete();
831 return super.getRawTypeAttributes();
832 }
834 public Type erasure(Types types) {
835 if (erasure_field == null)
836 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
837 List.<Type>nil(), this);
838 return erasure_field;
839 }
841 public String className() {
842 if (name.isEmpty())
843 return
844 Log.getLocalizedString("anonymous.class", flatname);
845 else
846 return fullname.toString();
847 }
849 public Name getQualifiedName() {
850 return fullname;
851 }
853 public Name flatName() {
854 return flatname;
855 }
857 public boolean isSubClass(Symbol base, Types types) {
858 if (this == base) {
859 return true;
860 } else if ((base.flags() & INTERFACE) != 0) {
861 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
862 for (List<Type> is = types.interfaces(t);
863 is.nonEmpty();
864 is = is.tail)
865 if (is.head.tsym.isSubClass(base, types)) return true;
866 } else {
867 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
868 if (t.tsym == base) return true;
869 }
870 return false;
871 }
873 /** Complete the elaboration of this symbol's definition.
874 */
875 public void complete() throws CompletionFailure {
876 try {
877 super.complete();
878 } catch (CompletionFailure ex) {
879 // quiet error recovery
880 flags_field |= (PUBLIC|STATIC);
881 this.type = new ErrorType(this, Type.noType);
882 throw ex;
883 }
884 }
886 public List<Type> getInterfaces() {
887 complete();
888 if (type instanceof ClassType) {
889 ClassType t = (ClassType)type;
890 if (t.interfaces_field == null) // FIXME: shouldn't be null
891 t.interfaces_field = List.nil();
892 if (t.all_interfaces_field != null)
893 return Type.getModelTypes(t.all_interfaces_field);
894 return t.interfaces_field;
895 } else {
896 return List.nil();
897 }
898 }
900 public Type getSuperclass() {
901 complete();
902 if (type instanceof ClassType) {
903 ClassType t = (ClassType)type;
904 if (t.supertype_field == null) // FIXME: shouldn't be null
905 t.supertype_field = Type.noType;
906 // An interface has no superclass; its supertype is Object.
907 return t.isInterface()
908 ? Type.noType
909 : t.supertype_field.getModelType();
910 } else {
911 return Type.noType;
912 }
913 }
915 public ElementKind getKind() {
916 long flags = flags();
917 if ((flags & ANNOTATION) != 0)
918 return ElementKind.ANNOTATION_TYPE;
919 else if ((flags & INTERFACE) != 0)
920 return ElementKind.INTERFACE;
921 else if ((flags & ENUM) != 0)
922 return ElementKind.ENUM;
923 else
924 return ElementKind.CLASS;
925 }
927 public NestingKind getNestingKind() {
928 complete();
929 if (owner.kind == PCK)
930 return NestingKind.TOP_LEVEL;
931 else if (name.isEmpty())
932 return NestingKind.ANONYMOUS;
933 else if (owner.kind == MTH)
934 return NestingKind.LOCAL;
935 else
936 return NestingKind.MEMBER;
937 }
939 /**
940 * Since this method works in terms of the runtime representation
941 * of annotations, it should never be used by javac internally.
942 */
943 @Override
944 public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
945 return JavacAnnoConstructs.getAnnotation(this, annoType);
946 }
948 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
949 return v.visitType(this, p);
950 }
952 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
953 return v.visitClassSymbol(this, p);
954 }
955 }
958 /** A class for variable symbols
959 */
960 public static class VarSymbol extends Symbol implements VariableElement {
962 /** The variable's declaration position.
963 */
964 public int pos = Position.NOPOS;
966 /** The variable's address. Used for different purposes during
967 * flow analysis, translation and code generation.
968 * Flow analysis:
969 * If this is a blank final or local variable, its sequence number.
970 * Translation:
971 * If this is a private field, its access number.
972 * Code generation:
973 * If this is a local variable, its logical slot number.
974 */
975 public int adr = -1;
977 /** Construct a variable symbol, given its flags, name, type and owner.
978 */
979 public VarSymbol(long flags, Name name, Type type, Symbol owner) {
980 super(VAR, flags, name, type, owner);
981 }
983 /** Clone this symbol with new owner.
984 */
985 public VarSymbol clone(Symbol newOwner) {
986 VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) {
987 @Override
988 public Symbol baseSymbol() {
989 return VarSymbol.this;
990 }
991 };
992 v.pos = pos;
993 v.adr = adr;
994 v.data = data;
995 // System.out.println("clone " + v + " in " + newOwner);//DEBUG
996 return v;
997 }
999 public String toString() {
1000 return name.toString();
1001 }
1003 public Symbol asMemberOf(Type site, Types types) {
1004 return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
1005 }
1007 public ElementKind getKind() {
1008 long flags = flags();
1009 if ((flags & PARAMETER) != 0) {
1010 if (isExceptionParameter())
1011 return ElementKind.EXCEPTION_PARAMETER;
1012 else
1013 return ElementKind.PARAMETER;
1014 } else if ((flags & ENUM) != 0) {
1015 return ElementKind.ENUM_CONSTANT;
1016 } else if (owner.kind == TYP || owner.kind == ERR) {
1017 return ElementKind.FIELD;
1018 } else if (isResourceVariable()) {
1019 return ElementKind.RESOURCE_VARIABLE;
1020 } else {
1021 return ElementKind.LOCAL_VARIABLE;
1022 }
1023 }
1025 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1026 return v.visitVariable(this, p);
1027 }
1029 public Object getConstantValue() { // Mirror API
1030 return Constants.decode(getConstValue(), type);
1031 }
1033 public void setLazyConstValue(final Env<AttrContext> env,
1034 final Attr attr,
1035 final JCTree.JCExpression initializer)
1036 {
1037 setData(new Callable<Object>() {
1038 public Object call() {
1039 return attr.attribLazyConstantValue(env, initializer, type);
1040 }
1041 });
1042 }
1044 /**
1045 * The variable's constant value, if this is a constant.
1046 * Before the constant value is evaluated, it points to an
1047 * initalizer environment. If this is not a constant, it can
1048 * be used for other stuff.
1049 */
1050 private Object data;
1052 public boolean isExceptionParameter() {
1053 return data == ElementKind.EXCEPTION_PARAMETER;
1054 }
1056 public boolean isResourceVariable() {
1057 return data == ElementKind.RESOURCE_VARIABLE;
1058 }
1060 public Object getConstValue() {
1061 // TODO: Consider if getConstValue and getConstantValue can be collapsed
1062 if (data == ElementKind.EXCEPTION_PARAMETER ||
1063 data == ElementKind.RESOURCE_VARIABLE) {
1064 return null;
1065 } else if (data instanceof Callable<?>) {
1066 // In this case, this is a final variable, with an as
1067 // yet unevaluated initializer.
1068 Callable<?> eval = (Callable<?>)data;
1069 data = null; // to make sure we don't evaluate this twice.
1070 try {
1071 data = eval.call();
1072 } catch (Exception ex) {
1073 throw new AssertionError(ex);
1074 }
1075 }
1076 return data;
1077 }
1079 public void setData(Object data) {
1080 Assert.check(!(data instanceof Env<?>), this);
1081 this.data = data;
1082 }
1084 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1085 return v.visitVarSymbol(this, p);
1086 }
1087 }
1089 /** A class for method symbols.
1090 */
1091 public static class MethodSymbol extends Symbol implements ExecutableElement {
1093 /** The code of the method. */
1094 public Code code = null;
1096 /** The extra (synthetic/mandated) parameters of the method. */
1097 public List<VarSymbol> extraParams = List.nil();
1099 /** The parameters of the method. */
1100 public List<VarSymbol> params = null;
1102 /** The names of the parameters */
1103 public List<Name> savedParameterNames;
1105 /** For an attribute field accessor, its default value if any.
1106 * The value is null if none appeared in the method
1107 * declaration.
1108 */
1109 public Attribute defaultValue = null;
1111 /** Construct a method symbol, given its flags, name, type and owner.
1112 */
1113 public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
1114 super(MTH, flags, name, type, owner);
1115 if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name);
1116 }
1118 /** Clone this symbol with new owner.
1119 */
1120 public MethodSymbol clone(Symbol newOwner) {
1121 MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) {
1122 @Override
1123 public Symbol baseSymbol() {
1124 return MethodSymbol.this;
1125 }
1126 };
1127 m.code = code;
1128 return m;
1129 }
1131 /** The Java source which this symbol represents.
1132 */
1133 public String toString() {
1134 if ((flags() & BLOCK) != 0) {
1135 return owner.name.toString();
1136 } else {
1137 String s = (name == name.table.names.init)
1138 ? owner.name.toString()
1139 : name.toString();
1140 if (type != null) {
1141 if (type.hasTag(FORALL))
1142 s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
1143 s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
1144 }
1145 return s;
1146 }
1147 }
1149 public boolean isDynamic() {
1150 return false;
1151 }
1153 /** find a symbol that this (proxy method) symbol implements.
1154 * @param c The class whose members are searched for
1155 * implementations
1156 */
1157 public Symbol implemented(TypeSymbol c, Types types) {
1158 Symbol impl = null;
1159 for (List<Type> is = types.interfaces(c.type);
1160 impl == null && is.nonEmpty();
1161 is = is.tail) {
1162 TypeSymbol i = is.head.tsym;
1163 impl = implementedIn(i, types);
1164 if (impl == null)
1165 impl = implemented(i, types);
1166 }
1167 return impl;
1168 }
1170 public Symbol implementedIn(TypeSymbol c, Types types) {
1171 Symbol impl = null;
1172 for (Scope.Entry e = c.members().lookup(name);
1173 impl == null && e.scope != null;
1174 e = e.next()) {
1175 if (this.overrides(e.sym, (TypeSymbol)owner, types, true) &&
1176 // FIXME: I suspect the following requires a
1177 // subst() for a parametric return type.
1178 types.isSameType(type.getReturnType(),
1179 types.memberType(owner.type, e.sym).getReturnType())) {
1180 impl = e.sym;
1181 }
1182 }
1183 return impl;
1184 }
1186 /** Will the erasure of this method be considered by the VM to
1187 * override the erasure of the other when seen from class `origin'?
1188 */
1189 public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
1190 if (isConstructor() || _other.kind != MTH) return false;
1192 if (this == _other) return true;
1193 MethodSymbol other = (MethodSymbol)_other;
1195 // check for a direct implementation
1196 if (other.isOverridableIn((TypeSymbol)owner) &&
1197 types.asSuper(owner.type, other.owner) != null &&
1198 types.isSameType(erasure(types), other.erasure(types)))
1199 return true;
1201 // check for an inherited implementation
1202 return
1203 (flags() & ABSTRACT) == 0 &&
1204 other.isOverridableIn(origin) &&
1205 this.isMemberOf(origin, types) &&
1206 types.isSameType(erasure(types), other.erasure(types));
1207 }
1209 /** The implementation of this (abstract) symbol in class origin,
1210 * from the VM's point of view, null if method does not have an
1211 * implementation in class.
1212 * @param origin The class of which the implementation is a member.
1213 */
1214 public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
1215 for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
1216 for (Scope.Entry e = c.members().lookup(name);
1217 e.scope != null;
1218 e = e.next()) {
1219 if (e.sym.kind == MTH &&
1220 ((MethodSymbol)e.sym).binaryOverrides(this, origin, types))
1221 return (MethodSymbol)e.sym;
1222 }
1223 }
1224 return null;
1225 }
1227 /** Does this symbol override `other' symbol, when both are seen as
1228 * members of class `origin'? It is assumed that _other is a member
1229 * of origin.
1230 *
1231 * It is assumed that both symbols have the same name. The static
1232 * modifier is ignored for this test.
1233 *
1234 * See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
1235 */
1236 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
1237 if (isConstructor() || _other.kind != MTH) return false;
1239 if (this == _other) return true;
1240 MethodSymbol other = (MethodSymbol)_other;
1242 // check for a direct implementation
1243 if (other.isOverridableIn((TypeSymbol)owner) &&
1244 types.asSuper(owner.type, other.owner) != null) {
1245 Type mt = types.memberType(owner.type, this);
1246 Type ot = types.memberType(owner.type, other);
1247 if (types.isSubSignature(mt, ot)) {
1248 if (!checkResult)
1249 return true;
1250 if (types.returnTypeSubstitutable(mt, ot))
1251 return true;
1252 }
1253 }
1255 // check for an inherited implementation
1256 if ((flags() & ABSTRACT) != 0 ||
1257 ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
1258 !other.isOverridableIn(origin) ||
1259 !this.isMemberOf(origin, types))
1260 return false;
1262 // assert types.asSuper(origin.type, other.owner) != null;
1263 Type mt = types.memberType(origin.type, this);
1264 Type ot = types.memberType(origin.type, other);
1265 return
1266 types.isSubSignature(mt, ot) &&
1267 (!checkResult || types.resultSubtype(mt, ot, types.noWarnings));
1268 }
1270 private boolean isOverridableIn(TypeSymbol origin) {
1271 // JLS 8.4.6.1
1272 switch ((int)(flags_field & Flags.AccessFlags)) {
1273 case Flags.PRIVATE:
1274 return false;
1275 case Flags.PUBLIC:
1276 return !this.owner.isInterface() ||
1277 (flags_field & STATIC) == 0;
1278 case Flags.PROTECTED:
1279 return (origin.flags() & INTERFACE) == 0;
1280 case 0:
1281 // for package private: can only override in the same
1282 // package
1283 return
1284 this.packge() == origin.packge() &&
1285 (origin.flags() & INTERFACE) == 0;
1286 default:
1287 return false;
1288 }
1289 }
1291 @Override
1292 public boolean isInheritedIn(Symbol clazz, Types types) {
1293 switch ((int)(flags_field & Flags.AccessFlags)) {
1294 case PUBLIC:
1295 return !this.owner.isInterface() ||
1296 clazz == owner ||
1297 (flags_field & STATIC) == 0;
1298 default:
1299 return super.isInheritedIn(clazz, types);
1300 }
1301 }
1303 /** The implementation of this (abstract) symbol in class origin;
1304 * null if none exists. Synthetic methods are not considered
1305 * as possible implementations.
1306 */
1307 public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
1308 return implementation(origin, types, checkResult, implementation_filter);
1309 }
1310 // where
1311 public static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
1312 public boolean accepts(Symbol s) {
1313 return s.kind == Kinds.MTH &&
1314 (s.flags() & SYNTHETIC) == 0;
1315 }
1316 };
1318 public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
1319 MethodSymbol res = types.implementation(this, origin, checkResult, implFilter);
1320 if (res != null)
1321 return res;
1322 // if origin is derived from a raw type, we might have missed
1323 // an implementation because we do not know enough about instantiations.
1324 // in this case continue with the supertype as origin.
1325 if (types.isDerivedRaw(origin.type) && !origin.isInterface())
1326 return implementation(types.supertype(origin.type).tsym, types, checkResult);
1327 else
1328 return null;
1329 }
1331 public List<VarSymbol> params() {
1332 owner.complete();
1333 if (params == null) {
1334 // If ClassReader.saveParameterNames has been set true, then
1335 // savedParameterNames will be set to a list of names that
1336 // matches the types in type.getParameterTypes(). If any names
1337 // were not found in the class file, those names in the list will
1338 // be set to the empty name.
1339 // If ClassReader.saveParameterNames has been set false, then
1340 // savedParameterNames will be null.
1341 List<Name> paramNames = savedParameterNames;
1342 savedParameterNames = null;
1343 // discard the provided names if the list of names is the wrong size.
1344 if (paramNames == null || paramNames.size() != type.getParameterTypes().size()) {
1345 paramNames = List.nil();
1346 }
1347 ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();
1348 List<Name> remaining = paramNames;
1349 // assert: remaining and paramNames are both empty or both
1350 // have same cardinality as type.getParameterTypes()
1351 int i = 0;
1352 for (Type t : type.getParameterTypes()) {
1353 Name paramName;
1354 if (remaining.isEmpty()) {
1355 // no names for any parameters available
1356 paramName = createArgName(i, paramNames);
1357 } else {
1358 paramName = remaining.head;
1359 remaining = remaining.tail;
1360 if (paramName.isEmpty()) {
1361 // no name for this specific parameter
1362 paramName = createArgName(i, paramNames);
1363 }
1364 }
1365 buf.append(new VarSymbol(PARAMETER, paramName, t, this));
1366 i++;
1367 }
1368 params = buf.toList();
1369 }
1370 return params;
1371 }
1373 // Create a name for the argument at position 'index' that is not in
1374 // the exclude list. In normal use, either no names will have been
1375 // provided, in which case the exclude list is empty, or all the names
1376 // will have been provided, in which case this method will not be called.
1377 private Name createArgName(int index, List<Name> exclude) {
1378 String prefix = "arg";
1379 while (true) {
1380 Name argName = name.table.fromString(prefix + index);
1381 if (!exclude.contains(argName))
1382 return argName;
1383 prefix += "$";
1384 }
1385 }
1387 public Symbol asMemberOf(Type site, Types types) {
1388 return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
1389 }
1391 public ElementKind getKind() {
1392 if (name == name.table.names.init)
1393 return ElementKind.CONSTRUCTOR;
1394 else if (name == name.table.names.clinit)
1395 return ElementKind.STATIC_INIT;
1396 else if ((flags() & BLOCK) != 0)
1397 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
1398 else
1399 return ElementKind.METHOD;
1400 }
1402 public boolean isStaticOrInstanceInit() {
1403 return getKind() == ElementKind.STATIC_INIT ||
1404 getKind() == ElementKind.INSTANCE_INIT;
1405 }
1407 /**
1408 * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
1409 * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
1410 * a single variable arity parameter (iii) whose declared type is Object[],
1411 * (iv) has a return type of Object and (v) is native.
1412 */
1413 public boolean isSignaturePolymorphic(Types types) {
1414 List<Type> argtypes = type.getParameterTypes();
1415 Type firstElemType = argtypes.nonEmpty() ?
1416 types.elemtype(argtypes.head) :
1417 null;
1418 return owner == types.syms.methodHandleType.tsym &&
1419 argtypes.length() == 1 &&
1420 firstElemType != null &&
1421 types.isSameType(firstElemType, types.syms.objectType) &&
1422 types.isSameType(type.getReturnType(), types.syms.objectType) &&
1423 (flags() & NATIVE) != 0;
1424 }
1426 public Attribute getDefaultValue() {
1427 return defaultValue;
1428 }
1430 public List<VarSymbol> getParameters() {
1431 return params();
1432 }
1434 public boolean isVarArgs() {
1435 return (flags() & VARARGS) != 0;
1436 }
1438 public boolean isDefault() {
1439 return (flags() & DEFAULT) != 0;
1440 }
1442 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1443 return v.visitExecutable(this, p);
1444 }
1446 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1447 return v.visitMethodSymbol(this, p);
1448 }
1450 public Type getReceiverType() {
1451 return asType().getReceiverType();
1452 }
1454 public Type getReturnType() {
1455 return asType().getReturnType();
1456 }
1458 public List<Type> getThrownTypes() {
1459 return asType().getThrownTypes();
1460 }
1461 }
1463 /** A class for invokedynamic method calls.
1464 */
1465 public static class DynamicMethodSymbol extends MethodSymbol {
1467 public Object[] staticArgs;
1468 public Symbol bsm;
1469 public int bsmKind;
1471 public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
1472 super(0, name, type, owner);
1473 this.bsm = bsm;
1474 this.bsmKind = bsmKind;
1475 this.staticArgs = staticArgs;
1476 }
1478 @Override
1479 public boolean isDynamic() {
1480 return true;
1481 }
1482 }
1484 /** A class for predefined operators.
1485 */
1486 public static class OperatorSymbol extends MethodSymbol {
1488 public int opcode;
1490 public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
1491 super(PUBLIC | STATIC, name, type, owner);
1492 this.opcode = opcode;
1493 }
1495 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1496 return v.visitOperatorSymbol(this, p);
1497 }
1498 }
1500 /** Symbol completer interface.
1501 */
1502 public static interface Completer {
1503 void complete(Symbol sym) throws CompletionFailure;
1504 }
1506 public static class CompletionFailure extends RuntimeException {
1507 private static final long serialVersionUID = 0;
1508 public Symbol sym;
1510 /** A diagnostic object describing the failure
1511 */
1512 public JCDiagnostic diag;
1514 /** A localized string describing the failure.
1515 * @deprecated Use {@code getDetail()} or {@code getMessage()}
1516 */
1517 @Deprecated
1518 public String errmsg;
1520 public CompletionFailure(Symbol sym, String errmsg) {
1521 this.sym = sym;
1522 this.errmsg = errmsg;
1523 // this.printStackTrace();//DEBUG
1524 }
1526 public CompletionFailure(Symbol sym, JCDiagnostic diag) {
1527 this.sym = sym;
1528 this.diag = diag;
1529 // this.printStackTrace();//DEBUG
1530 }
1532 public JCDiagnostic getDiagnostic() {
1533 return diag;
1534 }
1536 @Override
1537 public String getMessage() {
1538 if (diag != null)
1539 return diag.getMessage(null);
1540 else
1541 return errmsg;
1542 }
1544 public Object getDetailValue() {
1545 return (diag != null ? diag : errmsg);
1546 }
1548 @Override
1549 public CompletionFailure initCause(Throwable cause) {
1550 super.initCause(cause);
1551 return this;
1552 }
1554 }
1556 /**
1557 * A visitor for symbols. A visitor is used to implement operations
1558 * (or relations) on symbols. Most common operations on types are
1559 * binary relations and this interface is designed for binary
1560 * relations, that is, operations on the form
1561 * Symbol × P → R.
1562 * <!-- In plain text: Type x P -> R -->
1563 *
1564 * @param <R> the return type of the operation implemented by this
1565 * visitor; use Void if no return type is needed.
1566 * @param <P> the type of the second argument (the first being the
1567 * symbol itself) of the operation implemented by this visitor; use
1568 * Void if a second argument is not needed.
1569 */
1570 public interface Visitor<R,P> {
1571 R visitClassSymbol(ClassSymbol s, P arg);
1572 R visitMethodSymbol(MethodSymbol s, P arg);
1573 R visitPackageSymbol(PackageSymbol s, P arg);
1574 R visitOperatorSymbol(OperatorSymbol s, P arg);
1575 R visitVarSymbol(VarSymbol s, P arg);
1576 R visitTypeSymbol(TypeSymbol s, P arg);
1577 R visitSymbol(Symbol s, P arg);
1578 }
1579 }