Mon, 15 Apr 2013 14:11:29 +0100
8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
Summary: Fixup for default method modifiers erroneously applies to class-level modifiers
Reviewed-by: jjg
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 return Flags.asModifierSet(flags());
458 }
460 public Name getSimpleName() {
461 return name;
462 }
464 /**
465 * This is the implementation for {@code
466 * javax.lang.model.element.Element.getAnnotationMirrors()}.
467 */
468 public final List<? extends AnnotationMirror> getAnnotationMirrors() {
469 return getRawAttributes();
470 }
472 /**
473 * TODO: Should there be a {@code
474 * javax.lang.model.element.Element.getTypeAnnotationMirrors()}.
475 */
476 public final List<Attribute.TypeCompound> getTypeAnnotationMirrors() {
477 return getRawTypeAttributes();
478 }
480 /**
481 * @deprecated this method should never be used by javac internally.
482 */
483 @Deprecated
484 public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
485 return JavacAnnoConstructs.getAnnotation(this, annoType);
486 }
488 // This method is part of the javax.lang.model API, do not use this in javac code.
489 public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(Class<A> annoType) {
490 return JavacAnnoConstructs.getAnnotations(this, annoType);
491 }
493 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
494 public java.util.List<Symbol> getEnclosedElements() {
495 return List.nil();
496 }
498 public List<TypeVariableSymbol> getTypeParameters() {
499 ListBuffer<TypeVariableSymbol> l = ListBuffer.lb();
500 for (Type t : type.getTypeArguments()) {
501 Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
502 l.append((TypeVariableSymbol)t.tsym);
503 }
504 return l.toList();
505 }
507 public static class DelegatedSymbol<T extends Symbol> extends Symbol {
508 protected T other;
509 public DelegatedSymbol(T other) {
510 super(other.kind, other.flags_field, other.name, other.type, other.owner);
511 this.other = other;
512 }
513 public String toString() { return other.toString(); }
514 public Symbol location() { return other.location(); }
515 public Symbol location(Type site, Types types) { return other.location(site, types); }
516 public Symbol baseSymbol() { return other; }
517 public Type erasure(Types types) { return other.erasure(types); }
518 public Type externalType(Types types) { return other.externalType(types); }
519 public boolean isLocal() { return other.isLocal(); }
520 public boolean isConstructor() { return other.isConstructor(); }
521 public Name getQualifiedName() { return other.getQualifiedName(); }
522 public Name flatName() { return other.flatName(); }
523 public Scope members() { return other.members(); }
524 public boolean isInner() { return other.isInner(); }
525 public boolean hasOuterInstance() { return other.hasOuterInstance(); }
526 public ClassSymbol enclClass() { return other.enclClass(); }
527 public ClassSymbol outermostClass() { return other.outermostClass(); }
528 public PackageSymbol packge() { return other.packge(); }
529 public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
530 public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
531 public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
532 public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
533 public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
534 public void complete() throws CompletionFailure { other.complete(); }
536 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
537 return other.accept(v, p);
538 }
540 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
541 return v.visitSymbol(other, p);
542 }
544 public T getUnderlyingSymbol() {
545 return other;
546 }
547 }
549 /** A base class for Symbols representing types.
550 */
551 public static abstract class TypeSymbol extends Symbol {
552 public TypeSymbol(int kind, long flags, Name name, Type type, Symbol owner) {
553 super(kind, flags, name, type, owner);
554 }
555 /** form a fully qualified name from a name and an owner
556 */
557 static public Name formFullName(Name name, Symbol owner) {
558 if (owner == null) return name;
559 if (((owner.kind != ERR)) &&
560 ((owner.kind & (VAR | MTH)) != 0
561 || (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
562 )) return name;
563 Name prefix = owner.getQualifiedName();
564 if (prefix == null || prefix == prefix.table.names.empty)
565 return name;
566 else return prefix.append('.', name);
567 }
569 /** form a fully qualified name from a name and an owner, after
570 * converting to flat representation
571 */
572 static public Name formFlatName(Name name, Symbol owner) {
573 if (owner == null ||
574 (owner.kind & (VAR | MTH)) != 0
575 || (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
576 ) return name;
577 char sep = owner.kind == TYP ? '$' : '.';
578 Name prefix = owner.flatName();
579 if (prefix == null || prefix == prefix.table.names.empty)
580 return name;
581 else return prefix.append(sep, name);
582 }
584 /**
585 * A total ordering between type symbols that refines the
586 * class inheritance graph.
587 *
588 * Typevariables always precede other kinds of symbols.
589 */
590 public final boolean precedes(TypeSymbol that, Types types) {
591 if (this == that)
592 return false;
593 if (this.type.tag == that.type.tag) {
594 if (this.type.hasTag(CLASS)) {
595 return
596 types.rank(that.type) < types.rank(this.type) ||
597 types.rank(that.type) == types.rank(this.type) &&
598 that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
599 } else if (this.type.hasTag(TYPEVAR)) {
600 return types.isSubtype(this.type, that.type);
601 }
602 }
603 return this.type.hasTag(TYPEVAR);
604 }
606 @Override
607 public java.util.List<Symbol> getEnclosedElements() {
608 List<Symbol> list = List.nil();
609 if (kind == TYP && type.hasTag(TYPEVAR)) {
610 return list;
611 }
612 for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
613 if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
614 list = list.prepend(e.sym);
615 }
616 return list;
617 }
619 @Override
620 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
621 return v.visitTypeSymbol(this, p);
622 }
623 }
625 /**
626 * Type variables are represented by instances of this class.
627 */
628 public static class TypeVariableSymbol
629 extends TypeSymbol implements TypeParameterElement {
631 public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) {
632 super(TYP, flags, name, type, owner);
633 }
635 public ElementKind getKind() {
636 return ElementKind.TYPE_PARAMETER;
637 }
639 @Override
640 public Symbol getGenericElement() {
641 return owner;
642 }
644 public List<Type> getBounds() {
645 TypeVar t = (TypeVar)type;
646 Type bound = t.getUpperBound();
647 if (!bound.isCompound())
648 return List.of(bound);
649 ClassType ct = (ClassType)bound;
650 if (!ct.tsym.erasure_field.isInterface()) {
651 return ct.interfaces_field.prepend(ct.supertype_field);
652 } else {
653 // No superclass was given in bounds.
654 // In this case, supertype is Object, erasure is first interface.
655 return ct.interfaces_field;
656 }
657 }
659 @Override
660 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
661 return v.visitTypeParameter(this, p);
662 }
663 }
665 /** A class for package symbols
666 */
667 public static class PackageSymbol extends TypeSymbol
668 implements PackageElement {
670 public Scope members_field;
671 public Name fullname;
672 public ClassSymbol package_info; // see bug 6443073
674 public PackageSymbol(Name name, Type type, Symbol owner) {
675 super(PCK, 0, name, type, owner);
676 this.members_field = null;
677 this.fullname = formFullName(name, owner);
678 }
680 public PackageSymbol(Name name, Symbol owner) {
681 this(name, null, owner);
682 this.type = new PackageType(this);
683 }
685 public String toString() {
686 return fullname.toString();
687 }
689 public Name getQualifiedName() {
690 return fullname;
691 }
693 public boolean isUnnamed() {
694 return name.isEmpty() && owner != null;
695 }
697 public Scope members() {
698 if (completer != null) complete();
699 return members_field;
700 }
702 public long flags() {
703 if (completer != null) complete();
704 return flags_field;
705 }
707 @Override
708 public List<Attribute.Compound> getRawAttributes() {
709 if (completer != null) complete();
710 if (package_info != null && package_info.completer != null) {
711 package_info.complete();
712 mergeAttributes();
713 }
714 return super.getRawAttributes();
715 }
717 private void mergeAttributes() {
718 if (annotations.isEmpty() &&
719 !package_info.annotations.isEmpty()) {
720 annotations.setAttributes(package_info.annotations);
721 }
722 }
724 /** A package "exists" if a type or package that exists has
725 * been seen within it.
726 */
727 public boolean exists() {
728 return (flags_field & EXISTS) != 0;
729 }
731 public ElementKind getKind() {
732 return ElementKind.PACKAGE;
733 }
735 public Symbol getEnclosingElement() {
736 return null;
737 }
739 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
740 return v.visitPackage(this, p);
741 }
743 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
744 return v.visitPackageSymbol(this, p);
745 }
746 }
748 /** A class for class symbols
749 */
750 public static class ClassSymbol extends TypeSymbol implements TypeElement {
752 /** a scope for all class members; variables, methods and inner classes
753 * type parameters are not part of this scope
754 */
755 public Scope members_field;
757 /** the fully qualified name of the class, i.e. pck.outer.inner.
758 * null for anonymous classes
759 */
760 public Name fullname;
762 /** the fully qualified name of the class after converting to flat
763 * representation, i.e. pck.outer$inner,
764 * set externally for local and anonymous classes
765 */
766 public Name flatname;
768 /** the sourcefile where the class came from
769 */
770 public JavaFileObject sourcefile;
772 /** the classfile from where to load this class
773 * this will have extension .class or .java
774 */
775 public JavaFileObject classfile;
777 /** the list of translated local classes (used for generating
778 * InnerClasses attribute)
779 */
780 public List<ClassSymbol> trans_local;
782 /** the constant pool of the class
783 */
784 public Pool pool;
786 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
787 super(TYP, flags, name, type, owner);
788 this.members_field = null;
789 this.fullname = formFullName(name, owner);
790 this.flatname = formFlatName(name, owner);
791 this.sourcefile = null;
792 this.classfile = null;
793 this.pool = null;
794 }
796 public ClassSymbol(long flags, Name name, Symbol owner) {
797 this(
798 flags,
799 name,
800 new ClassType(Type.noType, null, null),
801 owner);
802 this.type.tsym = this;
803 }
805 /** The Java source which this symbol represents.
806 */
807 public String toString() {
808 return className();
809 }
811 public long flags() {
812 if (completer != null) complete();
813 return flags_field;
814 }
816 public Scope members() {
817 if (completer != null) complete();
818 return members_field;
819 }
821 @Override
822 public List<Attribute.Compound> getRawAttributes() {
823 if (completer != null) complete();
824 return super.getRawAttributes();
825 }
827 @Override
828 public List<Attribute.TypeCompound> getRawTypeAttributes() {
829 if (completer != null) complete();
830 return super.getRawTypeAttributes();
831 }
833 public Type erasure(Types types) {
834 if (erasure_field == null)
835 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
836 List.<Type>nil(), this);
837 return erasure_field;
838 }
840 public String className() {
841 if (name.isEmpty())
842 return
843 Log.getLocalizedString("anonymous.class", flatname);
844 else
845 return fullname.toString();
846 }
848 public Name getQualifiedName() {
849 return fullname;
850 }
852 public Name flatName() {
853 return flatname;
854 }
856 public boolean isSubClass(Symbol base, Types types) {
857 if (this == base) {
858 return true;
859 } else if ((base.flags() & INTERFACE) != 0) {
860 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
861 for (List<Type> is = types.interfaces(t);
862 is.nonEmpty();
863 is = is.tail)
864 if (is.head.tsym.isSubClass(base, types)) return true;
865 } else {
866 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
867 if (t.tsym == base) return true;
868 }
869 return false;
870 }
872 /** Complete the elaboration of this symbol's definition.
873 */
874 public void complete() throws CompletionFailure {
875 try {
876 super.complete();
877 } catch (CompletionFailure ex) {
878 // quiet error recovery
879 flags_field |= (PUBLIC|STATIC);
880 this.type = new ErrorType(this, Type.noType);
881 throw ex;
882 }
883 }
885 public List<Type> getInterfaces() {
886 complete();
887 if (type instanceof ClassType) {
888 ClassType t = (ClassType)type;
889 if (t.interfaces_field == null) // FIXME: shouldn't be null
890 t.interfaces_field = List.nil();
891 if (t.all_interfaces_field != null)
892 return Type.getModelTypes(t.all_interfaces_field);
893 return t.interfaces_field;
894 } else {
895 return List.nil();
896 }
897 }
899 public Type getSuperclass() {
900 complete();
901 if (type instanceof ClassType) {
902 ClassType t = (ClassType)type;
903 if (t.supertype_field == null) // FIXME: shouldn't be null
904 t.supertype_field = Type.noType;
905 // An interface has no superclass; its supertype is Object.
906 return t.isInterface()
907 ? Type.noType
908 : t.supertype_field.getModelType();
909 } else {
910 return Type.noType;
911 }
912 }
914 public ElementKind getKind() {
915 long flags = flags();
916 if ((flags & ANNOTATION) != 0)
917 return ElementKind.ANNOTATION_TYPE;
918 else if ((flags & INTERFACE) != 0)
919 return ElementKind.INTERFACE;
920 else if ((flags & ENUM) != 0)
921 return ElementKind.ENUM;
922 else
923 return ElementKind.CLASS;
924 }
926 public NestingKind getNestingKind() {
927 complete();
928 if (owner.kind == PCK)
929 return NestingKind.TOP_LEVEL;
930 else if (name.isEmpty())
931 return NestingKind.ANONYMOUS;
932 else if (owner.kind == MTH)
933 return NestingKind.LOCAL;
934 else
935 return NestingKind.MEMBER;
936 }
938 /**
939 * Since this method works in terms of the runtime representation
940 * of annotations, it should never be used by javac internally.
941 */
942 @Override
943 public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
944 return JavacAnnoConstructs.getAnnotation(this, annoType);
945 }
947 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
948 return v.visitType(this, p);
949 }
951 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
952 return v.visitClassSymbol(this, p);
953 }
954 }
957 /** A class for variable symbols
958 */
959 public static class VarSymbol extends Symbol implements VariableElement {
961 /** The variable's declaration position.
962 */
963 public int pos = Position.NOPOS;
965 /** The variable's address. Used for different purposes during
966 * flow analysis, translation and code generation.
967 * Flow analysis:
968 * If this is a blank final or local variable, its sequence number.
969 * Translation:
970 * If this is a private field, its access number.
971 * Code generation:
972 * If this is a local variable, its logical slot number.
973 */
974 public int adr = -1;
976 /** Construct a variable symbol, given its flags, name, type and owner.
977 */
978 public VarSymbol(long flags, Name name, Type type, Symbol owner) {
979 super(VAR, flags, name, type, owner);
980 }
982 /** Clone this symbol with new owner.
983 */
984 public VarSymbol clone(Symbol newOwner) {
985 VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) {
986 @Override
987 public Symbol baseSymbol() {
988 return VarSymbol.this;
989 }
990 };
991 v.pos = pos;
992 v.adr = adr;
993 v.data = data;
994 // System.out.println("clone " + v + " in " + newOwner);//DEBUG
995 return v;
996 }
998 public String toString() {
999 return name.toString();
1000 }
1002 public Symbol asMemberOf(Type site, Types types) {
1003 return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
1004 }
1006 public ElementKind getKind() {
1007 long flags = flags();
1008 if ((flags & PARAMETER) != 0) {
1009 if (isExceptionParameter())
1010 return ElementKind.EXCEPTION_PARAMETER;
1011 else
1012 return ElementKind.PARAMETER;
1013 } else if ((flags & ENUM) != 0) {
1014 return ElementKind.ENUM_CONSTANT;
1015 } else if (owner.kind == TYP || owner.kind == ERR) {
1016 return ElementKind.FIELD;
1017 } else if (isResourceVariable()) {
1018 return ElementKind.RESOURCE_VARIABLE;
1019 } else {
1020 return ElementKind.LOCAL_VARIABLE;
1021 }
1022 }
1024 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1025 return v.visitVariable(this, p);
1026 }
1028 public Object getConstantValue() { // Mirror API
1029 return Constants.decode(getConstValue(), type);
1030 }
1032 public void setLazyConstValue(final Env<AttrContext> env,
1033 final Attr attr,
1034 final JCTree.JCExpression initializer)
1035 {
1036 setData(new Callable<Object>() {
1037 public Object call() {
1038 return attr.attribLazyConstantValue(env, initializer, type);
1039 }
1040 });
1041 }
1043 /**
1044 * The variable's constant value, if this is a constant.
1045 * Before the constant value is evaluated, it points to an
1046 * initalizer environment. If this is not a constant, it can
1047 * be used for other stuff.
1048 */
1049 private Object data;
1051 public boolean isExceptionParameter() {
1052 return data == ElementKind.EXCEPTION_PARAMETER;
1053 }
1055 public boolean isResourceVariable() {
1056 return data == ElementKind.RESOURCE_VARIABLE;
1057 }
1059 public Object getConstValue() {
1060 // TODO: Consider if getConstValue and getConstantValue can be collapsed
1061 if (data == ElementKind.EXCEPTION_PARAMETER ||
1062 data == ElementKind.RESOURCE_VARIABLE) {
1063 return null;
1064 } else if (data instanceof Callable<?>) {
1065 // In this case, this is a final variable, with an as
1066 // yet unevaluated initializer.
1067 Callable<?> eval = (Callable<?>)data;
1068 data = null; // to make sure we don't evaluate this twice.
1069 try {
1070 data = eval.call();
1071 } catch (Exception ex) {
1072 throw new AssertionError(ex);
1073 }
1074 }
1075 return data;
1076 }
1078 public void setData(Object data) {
1079 Assert.check(!(data instanceof Env<?>), this);
1080 this.data = data;
1081 }
1083 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1084 return v.visitVarSymbol(this, p);
1085 }
1086 }
1088 /** A class for method symbols.
1089 */
1090 public static class MethodSymbol extends Symbol implements ExecutableElement {
1092 /** The code of the method. */
1093 public Code code = null;
1095 /** The extra (synthetic/mandated) parameters of the method. */
1096 public List<VarSymbol> extraParams = List.nil();
1098 /** The parameters of the method. */
1099 public List<VarSymbol> params = null;
1101 /** The names of the parameters */
1102 public List<Name> savedParameterNames;
1104 /** For an attribute field accessor, its default value if any.
1105 * The value is null if none appeared in the method
1106 * declaration.
1107 */
1108 public Attribute defaultValue = null;
1110 /** Construct a method symbol, given its flags, name, type and owner.
1111 */
1112 public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
1113 super(MTH, flags, name, type, owner);
1114 if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name);
1115 }
1117 /** Clone this symbol with new owner.
1118 */
1119 public MethodSymbol clone(Symbol newOwner) {
1120 MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) {
1121 @Override
1122 public Symbol baseSymbol() {
1123 return MethodSymbol.this;
1124 }
1125 };
1126 m.code = code;
1127 return m;
1128 }
1130 @Override
1131 public Set<Modifier> getModifiers() {
1132 long flags = flags();
1133 return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
1134 }
1136 /** The Java source which this symbol represents.
1137 */
1138 public String toString() {
1139 if ((flags() & BLOCK) != 0) {
1140 return owner.name.toString();
1141 } else {
1142 String s = (name == name.table.names.init)
1143 ? owner.name.toString()
1144 : name.toString();
1145 if (type != null) {
1146 if (type.hasTag(FORALL))
1147 s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
1148 s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
1149 }
1150 return s;
1151 }
1152 }
1154 public boolean isDynamic() {
1155 return false;
1156 }
1158 /** find a symbol that this (proxy method) symbol implements.
1159 * @param c The class whose members are searched for
1160 * implementations
1161 */
1162 public Symbol implemented(TypeSymbol c, Types types) {
1163 Symbol impl = null;
1164 for (List<Type> is = types.interfaces(c.type);
1165 impl == null && is.nonEmpty();
1166 is = is.tail) {
1167 TypeSymbol i = is.head.tsym;
1168 impl = implementedIn(i, types);
1169 if (impl == null)
1170 impl = implemented(i, types);
1171 }
1172 return impl;
1173 }
1175 public Symbol implementedIn(TypeSymbol c, Types types) {
1176 Symbol impl = null;
1177 for (Scope.Entry e = c.members().lookup(name);
1178 impl == null && e.scope != null;
1179 e = e.next()) {
1180 if (this.overrides(e.sym, (TypeSymbol)owner, types, true) &&
1181 // FIXME: I suspect the following requires a
1182 // subst() for a parametric return type.
1183 types.isSameType(type.getReturnType(),
1184 types.memberType(owner.type, e.sym).getReturnType())) {
1185 impl = e.sym;
1186 }
1187 }
1188 return impl;
1189 }
1191 /** Will the erasure of this method be considered by the VM to
1192 * override the erasure of the other when seen from class `origin'?
1193 */
1194 public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
1195 if (isConstructor() || _other.kind != MTH) return false;
1197 if (this == _other) return true;
1198 MethodSymbol other = (MethodSymbol)_other;
1200 // check for a direct implementation
1201 if (other.isOverridableIn((TypeSymbol)owner) &&
1202 types.asSuper(owner.type, other.owner) != null &&
1203 types.isSameType(erasure(types), other.erasure(types)))
1204 return true;
1206 // check for an inherited implementation
1207 return
1208 (flags() & ABSTRACT) == 0 &&
1209 other.isOverridableIn(origin) &&
1210 this.isMemberOf(origin, types) &&
1211 types.isSameType(erasure(types), other.erasure(types));
1212 }
1214 /** The implementation of this (abstract) symbol in class origin,
1215 * from the VM's point of view, null if method does not have an
1216 * implementation in class.
1217 * @param origin The class of which the implementation is a member.
1218 */
1219 public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
1220 for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
1221 for (Scope.Entry e = c.members().lookup(name);
1222 e.scope != null;
1223 e = e.next()) {
1224 if (e.sym.kind == MTH &&
1225 ((MethodSymbol)e.sym).binaryOverrides(this, origin, types))
1226 return (MethodSymbol)e.sym;
1227 }
1228 }
1229 return null;
1230 }
1232 /** Does this symbol override `other' symbol, when both are seen as
1233 * members of class `origin'? It is assumed that _other is a member
1234 * of origin.
1235 *
1236 * It is assumed that both symbols have the same name. The static
1237 * modifier is ignored for this test.
1238 *
1239 * See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
1240 */
1241 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
1242 if (isConstructor() || _other.kind != MTH) return false;
1244 if (this == _other) return true;
1245 MethodSymbol other = (MethodSymbol)_other;
1247 // check for a direct implementation
1248 if (other.isOverridableIn((TypeSymbol)owner) &&
1249 types.asSuper(owner.type, other.owner) != null) {
1250 Type mt = types.memberType(owner.type, this);
1251 Type ot = types.memberType(owner.type, other);
1252 if (types.isSubSignature(mt, ot)) {
1253 if (!checkResult)
1254 return true;
1255 if (types.returnTypeSubstitutable(mt, ot))
1256 return true;
1257 }
1258 }
1260 // check for an inherited implementation
1261 if ((flags() & ABSTRACT) != 0 ||
1262 ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
1263 !other.isOverridableIn(origin) ||
1264 !this.isMemberOf(origin, types))
1265 return false;
1267 // assert types.asSuper(origin.type, other.owner) != null;
1268 Type mt = types.memberType(origin.type, this);
1269 Type ot = types.memberType(origin.type, other);
1270 return
1271 types.isSubSignature(mt, ot) &&
1272 (!checkResult || types.resultSubtype(mt, ot, types.noWarnings));
1273 }
1275 private boolean isOverridableIn(TypeSymbol origin) {
1276 // JLS 8.4.6.1
1277 switch ((int)(flags_field & Flags.AccessFlags)) {
1278 case Flags.PRIVATE:
1279 return false;
1280 case Flags.PUBLIC:
1281 return !this.owner.isInterface() ||
1282 (flags_field & STATIC) == 0;
1283 case Flags.PROTECTED:
1284 return (origin.flags() & INTERFACE) == 0;
1285 case 0:
1286 // for package private: can only override in the same
1287 // package
1288 return
1289 this.packge() == origin.packge() &&
1290 (origin.flags() & INTERFACE) == 0;
1291 default:
1292 return false;
1293 }
1294 }
1296 @Override
1297 public boolean isInheritedIn(Symbol clazz, Types types) {
1298 switch ((int)(flags_field & Flags.AccessFlags)) {
1299 case PUBLIC:
1300 return !this.owner.isInterface() ||
1301 clazz == owner ||
1302 (flags_field & STATIC) == 0;
1303 default:
1304 return super.isInheritedIn(clazz, types);
1305 }
1306 }
1308 /** The implementation of this (abstract) symbol in class origin;
1309 * null if none exists. Synthetic methods are not considered
1310 * as possible implementations.
1311 */
1312 public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
1313 return implementation(origin, types, checkResult, implementation_filter);
1314 }
1315 // where
1316 public static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
1317 public boolean accepts(Symbol s) {
1318 return s.kind == Kinds.MTH &&
1319 (s.flags() & SYNTHETIC) == 0;
1320 }
1321 };
1323 public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
1324 MethodSymbol res = types.implementation(this, origin, checkResult, implFilter);
1325 if (res != null)
1326 return res;
1327 // if origin is derived from a raw type, we might have missed
1328 // an implementation because we do not know enough about instantiations.
1329 // in this case continue with the supertype as origin.
1330 if (types.isDerivedRaw(origin.type) && !origin.isInterface())
1331 return implementation(types.supertype(origin.type).tsym, types, checkResult);
1332 else
1333 return null;
1334 }
1336 public List<VarSymbol> params() {
1337 owner.complete();
1338 if (params == null) {
1339 // If ClassReader.saveParameterNames has been set true, then
1340 // savedParameterNames will be set to a list of names that
1341 // matches the types in type.getParameterTypes(). If any names
1342 // were not found in the class file, those names in the list will
1343 // be set to the empty name.
1344 // If ClassReader.saveParameterNames has been set false, then
1345 // savedParameterNames will be null.
1346 List<Name> paramNames = savedParameterNames;
1347 savedParameterNames = null;
1348 // discard the provided names if the list of names is the wrong size.
1349 if (paramNames == null || paramNames.size() != type.getParameterTypes().size()) {
1350 paramNames = List.nil();
1351 }
1352 ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();
1353 List<Name> remaining = paramNames;
1354 // assert: remaining and paramNames are both empty or both
1355 // have same cardinality as type.getParameterTypes()
1356 int i = 0;
1357 for (Type t : type.getParameterTypes()) {
1358 Name paramName;
1359 if (remaining.isEmpty()) {
1360 // no names for any parameters available
1361 paramName = createArgName(i, paramNames);
1362 } else {
1363 paramName = remaining.head;
1364 remaining = remaining.tail;
1365 if (paramName.isEmpty()) {
1366 // no name for this specific parameter
1367 paramName = createArgName(i, paramNames);
1368 }
1369 }
1370 buf.append(new VarSymbol(PARAMETER, paramName, t, this));
1371 i++;
1372 }
1373 params = buf.toList();
1374 }
1375 return params;
1376 }
1378 // Create a name for the argument at position 'index' that is not in
1379 // the exclude list. In normal use, either no names will have been
1380 // provided, in which case the exclude list is empty, or all the names
1381 // will have been provided, in which case this method will not be called.
1382 private Name createArgName(int index, List<Name> exclude) {
1383 String prefix = "arg";
1384 while (true) {
1385 Name argName = name.table.fromString(prefix + index);
1386 if (!exclude.contains(argName))
1387 return argName;
1388 prefix += "$";
1389 }
1390 }
1392 public Symbol asMemberOf(Type site, Types types) {
1393 return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
1394 }
1396 public ElementKind getKind() {
1397 if (name == name.table.names.init)
1398 return ElementKind.CONSTRUCTOR;
1399 else if (name == name.table.names.clinit)
1400 return ElementKind.STATIC_INIT;
1401 else if ((flags() & BLOCK) != 0)
1402 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
1403 else
1404 return ElementKind.METHOD;
1405 }
1407 public boolean isStaticOrInstanceInit() {
1408 return getKind() == ElementKind.STATIC_INIT ||
1409 getKind() == ElementKind.INSTANCE_INIT;
1410 }
1412 /**
1413 * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
1414 * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
1415 * a single variable arity parameter (iii) whose declared type is Object[],
1416 * (iv) has a return type of Object and (v) is native.
1417 */
1418 public boolean isSignaturePolymorphic(Types types) {
1419 List<Type> argtypes = type.getParameterTypes();
1420 Type firstElemType = argtypes.nonEmpty() ?
1421 types.elemtype(argtypes.head) :
1422 null;
1423 return owner == types.syms.methodHandleType.tsym &&
1424 argtypes.length() == 1 &&
1425 firstElemType != null &&
1426 types.isSameType(firstElemType, types.syms.objectType) &&
1427 types.isSameType(type.getReturnType(), types.syms.objectType) &&
1428 (flags() & NATIVE) != 0;
1429 }
1431 public Attribute getDefaultValue() {
1432 return defaultValue;
1433 }
1435 public List<VarSymbol> getParameters() {
1436 return params();
1437 }
1439 public boolean isVarArgs() {
1440 return (flags() & VARARGS) != 0;
1441 }
1443 public boolean isDefault() {
1444 return (flags() & DEFAULT) != 0;
1445 }
1447 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1448 return v.visitExecutable(this, p);
1449 }
1451 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1452 return v.visitMethodSymbol(this, p);
1453 }
1455 public Type getReceiverType() {
1456 return asType().getReceiverType();
1457 }
1459 public Type getReturnType() {
1460 return asType().getReturnType();
1461 }
1463 public List<Type> getThrownTypes() {
1464 return asType().getThrownTypes();
1465 }
1466 }
1468 /** A class for invokedynamic method calls.
1469 */
1470 public static class DynamicMethodSymbol extends MethodSymbol {
1472 public Object[] staticArgs;
1473 public Symbol bsm;
1474 public int bsmKind;
1476 public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
1477 super(0, name, type, owner);
1478 this.bsm = bsm;
1479 this.bsmKind = bsmKind;
1480 this.staticArgs = staticArgs;
1481 }
1483 @Override
1484 public boolean isDynamic() {
1485 return true;
1486 }
1487 }
1489 /** A class for predefined operators.
1490 */
1491 public static class OperatorSymbol extends MethodSymbol {
1493 public int opcode;
1495 public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
1496 super(PUBLIC | STATIC, name, type, owner);
1497 this.opcode = opcode;
1498 }
1500 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1501 return v.visitOperatorSymbol(this, p);
1502 }
1503 }
1505 /** Symbol completer interface.
1506 */
1507 public static interface Completer {
1508 void complete(Symbol sym) throws CompletionFailure;
1509 }
1511 public static class CompletionFailure extends RuntimeException {
1512 private static final long serialVersionUID = 0;
1513 public Symbol sym;
1515 /** A diagnostic object describing the failure
1516 */
1517 public JCDiagnostic diag;
1519 /** A localized string describing the failure.
1520 * @deprecated Use {@code getDetail()} or {@code getMessage()}
1521 */
1522 @Deprecated
1523 public String errmsg;
1525 public CompletionFailure(Symbol sym, String errmsg) {
1526 this.sym = sym;
1527 this.errmsg = errmsg;
1528 // this.printStackTrace();//DEBUG
1529 }
1531 public CompletionFailure(Symbol sym, JCDiagnostic diag) {
1532 this.sym = sym;
1533 this.diag = diag;
1534 // this.printStackTrace();//DEBUG
1535 }
1537 public JCDiagnostic getDiagnostic() {
1538 return diag;
1539 }
1541 @Override
1542 public String getMessage() {
1543 if (diag != null)
1544 return diag.getMessage(null);
1545 else
1546 return errmsg;
1547 }
1549 public Object getDetailValue() {
1550 return (diag != null ? diag : errmsg);
1551 }
1553 @Override
1554 public CompletionFailure initCause(Throwable cause) {
1555 super.initCause(cause);
1556 return this;
1557 }
1559 }
1561 /**
1562 * A visitor for symbols. A visitor is used to implement operations
1563 * (or relations) on symbols. Most common operations on types are
1564 * binary relations and this interface is designed for binary
1565 * relations, that is, operations on the form
1566 * Symbol × P → R.
1567 * <!-- In plain text: Type x P -> R -->
1568 *
1569 * @param <R> the return type of the operation implemented by this
1570 * visitor; use Void if no return type is needed.
1571 * @param <P> the type of the second argument (the first being the
1572 * symbol itself) of the operation implemented by this visitor; use
1573 * Void if a second argument is not needed.
1574 */
1575 public interface Visitor<R,P> {
1576 R visitClassSymbol(ClassSymbol s, P arg);
1577 R visitMethodSymbol(MethodSymbol s, P arg);
1578 R visitPackageSymbol(PackageSymbol s, P arg);
1579 R visitOperatorSymbol(OperatorSymbol s, P arg);
1580 R visitVarSymbol(VarSymbol s, P arg);
1581 R visitTypeSymbol(TypeSymbol s, P arg);
1582 R visitSymbol(Symbol s, P arg);
1583 }
1584 }