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

Mon, 21 Jan 2013 20:19:53 +0000

author
mcimadamore
date
Mon, 21 Jan 2013 20:19:53 +0000
changeset 1513
cf84b07a82db
parent 1491
9f42a06a49c0
child 1521
71f35e4b93a5
permissions
-rw-r--r--

8005166: Add support for static interface methods
Summary: Support public static interface methods
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.getAttributes();
    88     }
    90     /** Fetch a particular annotation from a symbol. */
    91     public Attribute.Compound attribute(Symbol anno) {
    92         for (Attribute.Compound a : getRawAttributes()) {
    93             if (a.type.tsym == anno) return a;
    94         }
    95         return null;
    96     }
    98     /** The name of this symbol in Utf8 representation.
    99      */
   100     public Name name;
   102     /** The type of this symbol.
   103      */
   104     public Type type;
   106     /** The owner of this symbol.
   107      */
   108     public Symbol owner;
   110     /** The completer of this symbol.
   111      */
   112     public Completer completer;
   114     /** A cache for the type erasure of this symbol.
   115      */
   116     public Type erasure_field;
   118     /** Construct a symbol with given kind, flags, name, type and owner.
   119      */
   120     public Symbol(int kind, long flags, Name name, Type type, Symbol owner) {
   121         this.kind = kind;
   122         this.flags_field = flags;
   123         this.type = type;
   124         this.owner = owner;
   125         this.completer = null;
   126         this.erasure_field = null;
   127         this.name = name;
   128     }
   130     /** Clone this symbol with new owner.
   131      *  Legal only for fields and methods.
   132      */
   133     public Symbol clone(Symbol newOwner) {
   134         throw new AssertionError();
   135     }
   137     public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
   138         return v.visitSymbol(this, p);
   139     }
   141     /** The Java source which this symbol represents.
   142      *  A description of this symbol; overrides Object.
   143      */
   144     public String toString() {
   145         return name.toString();
   146     }
   148     /** A Java source description of the location of this symbol; used for
   149      *  error reporting.
   150      *
   151      * @return null if the symbol is a package or a toplevel class defined in
   152      * the default package; otherwise, the owner symbol is returned
   153      */
   154     public Symbol location() {
   155         if (owner.name == null || (owner.name.isEmpty() &&
   156                 (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) {
   157             return null;
   158         }
   159         return owner;
   160     }
   162     public Symbol location(Type site, Types types) {
   163         if (owner.name == null || owner.name.isEmpty()) {
   164             return location();
   165         }
   166         if (owner.type.hasTag(CLASS)) {
   167             Type ownertype = types.asOuterSuper(site, owner);
   168             if (ownertype != null) return ownertype.tsym;
   169         }
   170         return owner;
   171     }
   173     public Symbol baseSymbol() {
   174         return this;
   175     }
   177     /** The symbol's erased type.
   178      */
   179     public Type erasure(Types types) {
   180         if (erasure_field == null)
   181             erasure_field = types.erasure(type);
   182         return erasure_field;
   183     }
   185     /** The external type of a symbol. This is the symbol's erased type
   186      *  except for constructors of inner classes which get the enclosing
   187      *  instance class added as first argument.
   188      */
   189     public Type externalType(Types types) {
   190         Type t = erasure(types);
   191         if (name == name.table.names.init && owner.hasOuterInstance()) {
   192             Type outerThisType = types.erasure(owner.type.getEnclosingType());
   193             return new MethodType(t.getParameterTypes().prepend(outerThisType),
   194                                   t.getReturnType(),
   195                                   t.getThrownTypes(),
   196                                   t.tsym);
   197         } else {
   198             return t;
   199         }
   200     }
   202     public boolean isStatic() {
   203         return
   204             (flags() & STATIC) != 0 ||
   205             (owner.flags() & INTERFACE) != 0 && kind != MTH;
   206     }
   208     public boolean isInterface() {
   209         return (flags() & INTERFACE) != 0;
   210     }
   212     /** Is this symbol declared (directly or indirectly) local
   213      *  to a method or variable initializer?
   214      *  Also includes fields of inner classes which are in
   215      *  turn local to a method or variable initializer.
   216      */
   217     public boolean isLocal() {
   218         return
   219             (owner.kind & (VAR | MTH)) != 0 ||
   220             (owner.kind == TYP && owner.isLocal());
   221     }
   223     /** Has this symbol an empty name? This includes anonymous
   224      *  inner classses.
   225      */
   226     public boolean isAnonymous() {
   227         return name.isEmpty();
   228     }
   230     /** Is this symbol a constructor?
   231      */
   232     public boolean isConstructor() {
   233         return name == name.table.names.init;
   234     }
   236     /** The fully qualified name of this symbol.
   237      *  This is the same as the symbol's name except for class symbols,
   238      *  which are handled separately.
   239      */
   240     public Name getQualifiedName() {
   241         return name;
   242     }
   244     /** The fully qualified name of this symbol after converting to flat
   245      *  representation. This is the same as the symbol's name except for
   246      *  class symbols, which are handled separately.
   247      */
   248     public Name flatName() {
   249         return getQualifiedName();
   250     }
   252     /** If this is a class or package, its members, otherwise null.
   253      */
   254     public Scope members() {
   255         return null;
   256     }
   258     /** A class is an inner class if it it has an enclosing instance class.
   259      */
   260     public boolean isInner() {
   261         return type.getEnclosingType().hasTag(CLASS);
   262     }
   264     /** An inner class has an outer instance if it is not an interface
   265      *  it has an enclosing instance class which might be referenced from the class.
   266      *  Nested classes can see instance members of their enclosing class.
   267      *  Their constructors carry an additional this$n parameter, inserted
   268      *  implicitly by the compiler.
   269      *
   270      *  @see #isInner
   271      */
   272     public boolean hasOuterInstance() {
   273         return
   274             type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0;
   275     }
   277     /** The closest enclosing class of this symbol's declaration.
   278      */
   279     public ClassSymbol enclClass() {
   280         Symbol c = this;
   281         while (c != null &&
   282                ((c.kind & TYP) == 0 || !c.type.hasTag(CLASS))) {
   283             c = c.owner;
   284         }
   285         return (ClassSymbol)c;
   286     }
   288     /** The outermost class which indirectly owns this symbol.
   289      */
   290     public ClassSymbol outermostClass() {
   291         Symbol sym = this;
   292         Symbol prev = null;
   293         while (sym.kind != PCK) {
   294             prev = sym;
   295             sym = sym.owner;
   296         }
   297         return (ClassSymbol) prev;
   298     }
   300     /** The package which indirectly owns this symbol.
   301      */
   302     public PackageSymbol packge() {
   303         Symbol sym = this;
   304         while (sym.kind != PCK) {
   305             sym = sym.owner;
   306         }
   307         return (PackageSymbol) sym;
   308     }
   310     /** Is this symbol a subclass of `base'? Only defined for ClassSymbols.
   311      */
   312     public boolean isSubClass(Symbol base, Types types) {
   313         throw new AssertionError("isSubClass " + this);
   314     }
   316     /** Fully check membership: hierarchy, protection, and hiding.
   317      *  Does not exclude methods not inherited due to overriding.
   318      */
   319     public boolean isMemberOf(TypeSymbol clazz, Types types) {
   320         return
   321             owner == clazz ||
   322             clazz.isSubClass(owner, types) &&
   323             isInheritedIn(clazz, types) &&
   324             !hiddenIn((ClassSymbol)clazz, types);
   325     }
   327     /** Is this symbol the same as or enclosed by the given class? */
   328     public boolean isEnclosedBy(ClassSymbol clazz) {
   329         for (Symbol sym = this; sym.kind != PCK; sym = sym.owner)
   330             if (sym == clazz) return true;
   331         return false;
   332     }
   334     /** Check for hiding.  Note that this doesn't handle multiple
   335      *  (interface) inheritance. */
   336     private boolean hiddenIn(ClassSymbol clazz, Types types) {
   337         if (kind == MTH && (flags() & STATIC) == 0) return false;
   338         while (true) {
   339             if (owner == clazz) return false;
   340             Scope.Entry e = clazz.members().lookup(name);
   341             while (e.scope != null) {
   342                 if (e.sym == this) return false;
   343                 if (e.sym.kind == kind &&
   344                     (kind != MTH ||
   345                      (e.sym.flags() & STATIC) != 0 &&
   346                      types.isSubSignature(e.sym.type, type)))
   347                     return true;
   348                 e = e.next();
   349             }
   350             Type superType = types.supertype(clazz.type);
   351             if (!superType.hasTag(CLASS)) return false;
   352             clazz = (ClassSymbol)superType.tsym;
   353         }
   354     }
   356     /** Is this symbol inherited into a given class?
   357      *  PRE: If symbol's owner is a interface,
   358      *       it is already assumed that the interface is a superinterface
   359      *       of given class.
   360      *  @param clazz  The class for which we want to establish membership.
   361      *                This must be a subclass of the member's owner.
   362      */
   363     public boolean isInheritedIn(Symbol clazz, Types types) {
   364         switch ((int)(flags_field & Flags.AccessFlags)) {
   365         default: // error recovery
   366         case PUBLIC:
   367             return true;
   368         case PRIVATE:
   369             return this.owner == clazz;
   370         case PROTECTED:
   371             // we model interfaces as extending Object
   372             return (clazz.flags() & INTERFACE) == 0;
   373         case 0:
   374             PackageSymbol thisPackage = this.packge();
   375             for (Symbol sup = clazz;
   376                  sup != null && sup != this.owner;
   377                  sup = types.supertype(sup.type).tsym) {
   378                 while (sup.type.hasTag(TYPEVAR))
   379                     sup = sup.type.getUpperBound().tsym;
   380                 if (sup.type.isErroneous())
   381                     return true; // error recovery
   382                 if ((sup.flags() & COMPOUND) != 0)
   383                     continue;
   384                 if (sup.packge() != thisPackage)
   385                     return false;
   386             }
   387             return (clazz.flags() & INTERFACE) == 0;
   388         }
   389     }
   391     /** The (variable or method) symbol seen as a member of given
   392      *  class type`site' (this might change the symbol's type).
   393      *  This is used exclusively for producing diagnostics.
   394      */
   395     public Symbol asMemberOf(Type site, Types types) {
   396         throw new AssertionError();
   397     }
   399     /** Does this method symbol override `other' symbol, when both are seen as
   400      *  members of class `origin'?  It is assumed that _other is a member
   401      *  of origin.
   402      *
   403      *  It is assumed that both symbols have the same name.  The static
   404      *  modifier is ignored for this test.
   405      *
   406      *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
   407      */
   408     public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
   409         return false;
   410     }
   412     /** Complete the elaboration of this symbol's definition.
   413      */
   414     public void complete() throws CompletionFailure {
   415         if (completer != null) {
   416             Completer c = completer;
   417             completer = null;
   418             c.complete(this);
   419         }
   420     }
   422     /** True if the symbol represents an entity that exists.
   423      */
   424     public boolean exists() {
   425         return true;
   426     }
   428     public Type asType() {
   429         return type;
   430     }
   432     public Symbol getEnclosingElement() {
   433         return owner;
   434     }
   436     public ElementKind getKind() {
   437         return ElementKind.OTHER;       // most unkind
   438     }
   440     public Set<Modifier> getModifiers() {
   441         long flags = flags();
   442         return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
   443     }
   445     public Name getSimpleName() {
   446         return name;
   447     }
   449     /**
   450      * This is the implementation for {@code
   451      * javax.lang.model.element.Element.getAnnotationMirrors()}.
   452      */
   453     public final List<? extends AnnotationMirror> getAnnotationMirrors() {
   454         return getRawAttributes();
   455     }
   457     /**
   458      * @deprecated this method should never be used by javac internally.
   459      */
   460     @Deprecated
   461     public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
   462         return JavacElements.getAnnotation(this, annoType);
   463     }
   465     // This method is part of the javax.lang.model API, do not use this in javac code.
   466     public <A extends java.lang.annotation.Annotation> A[] getAnnotations(Class<A> annoType) {
   467         return JavacElements.getAnnotations(this, annoType);
   468     }
   470     // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
   471     public java.util.List<Symbol> getEnclosedElements() {
   472         return List.nil();
   473     }
   475     public List<TypeSymbol> getTypeParameters() {
   476         ListBuffer<TypeSymbol> l = ListBuffer.lb();
   477         for (Type t : type.getTypeArguments()) {
   478             l.append(t.tsym);
   479         }
   480         return l.toList();
   481     }
   483     public static class DelegatedSymbol extends Symbol {
   484         protected Symbol other;
   485         public DelegatedSymbol(Symbol other) {
   486             super(other.kind, other.flags_field, other.name, other.type, other.owner);
   487             this.other = other;
   488         }
   489         public String toString() { return other.toString(); }
   490         public Symbol location() { return other.location(); }
   491         public Symbol location(Type site, Types types) { return other.location(site, types); }
   492         public Symbol baseSymbol() { return other; }
   493         public Type erasure(Types types) { return other.erasure(types); }
   494         public Type externalType(Types types) { return other.externalType(types); }
   495         public boolean isLocal() { return other.isLocal(); }
   496         public boolean isConstructor() { return other.isConstructor(); }
   497         public Name getQualifiedName() { return other.getQualifiedName(); }
   498         public Name flatName() { return other.flatName(); }
   499         public Scope members() { return other.members(); }
   500         public boolean isInner() { return other.isInner(); }
   501         public boolean hasOuterInstance() { return other.hasOuterInstance(); }
   502         public ClassSymbol enclClass() { return other.enclClass(); }
   503         public ClassSymbol outermostClass() { return other.outermostClass(); }
   504         public PackageSymbol packge() { return other.packge(); }
   505         public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
   506         public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
   507         public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
   508         public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
   509         public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
   510         public void complete() throws CompletionFailure { other.complete(); }
   512         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   513             return other.accept(v, p);
   514         }
   516         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
   517             return v.visitSymbol(other, p);
   518         }
   519     }
   521     /** A class for type symbols. Type variables are represented by instances
   522      *  of this class, classes and packages by instances of subclasses.
   523      */
   524     public static class TypeSymbol
   525             extends Symbol implements TypeParameterElement {
   526         // Implements TypeParameterElement because type parameters don't
   527         // have their own TypeSymbol subclass.
   528         // TODO: type parameters should have their own TypeSymbol subclass
   530         public TypeSymbol(long flags, Name name, Type type, Symbol owner) {
   531             super(TYP, flags, name, type, owner);
   532         }
   534         /** form a fully qualified name from a name and an owner
   535          */
   536         static public Name formFullName(Name name, Symbol owner) {
   537             if (owner == null) return name;
   538             if (((owner.kind != ERR)) &&
   539                 ((owner.kind & (VAR | MTH)) != 0
   540                  || (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
   541                  )) return name;
   542             Name prefix = owner.getQualifiedName();
   543             if (prefix == null || prefix == prefix.table.names.empty)
   544                 return name;
   545             else return prefix.append('.', name);
   546         }
   548         /** form a fully qualified name from a name and an owner, after
   549          *  converting to flat representation
   550          */
   551         static public Name formFlatName(Name name, Symbol owner) {
   552             if (owner == null ||
   553                 (owner.kind & (VAR | MTH)) != 0
   554                 || (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
   555                 ) return name;
   556             char sep = owner.kind == TYP ? '$' : '.';
   557             Name prefix = owner.flatName();
   558             if (prefix == null || prefix == prefix.table.names.empty)
   559                 return name;
   560             else return prefix.append(sep, name);
   561         }
   563         /**
   564          * A total ordering between type symbols that refines the
   565          * class inheritance graph.
   566          *
   567          * Typevariables always precede other kinds of symbols.
   568          */
   569         public final boolean precedes(TypeSymbol that, Types types) {
   570             if (this == that)
   571                 return false;
   572             if (this.type.tag == that.type.tag) {
   573                 if (this.type.hasTag(CLASS)) {
   574                     return
   575                         types.rank(that.type) < types.rank(this.type) ||
   576                         types.rank(that.type) == types.rank(this.type) &&
   577                         that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
   578                 } else if (this.type.hasTag(TYPEVAR)) {
   579                     return types.isSubtype(this.type, that.type);
   580                 }
   581             }
   582             return this.type.hasTag(TYPEVAR);
   583         }
   585         // For type params; overridden in subclasses.
   586         public ElementKind getKind() {
   587             return ElementKind.TYPE_PARAMETER;
   588         }
   590         public java.util.List<Symbol> getEnclosedElements() {
   591             List<Symbol> list = List.nil();
   592             if (kind == TYP && type.hasTag(TYPEVAR)) {
   593                 return list;
   594             }
   595             for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
   596                 if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
   597                     list = list.prepend(e.sym);
   598             }
   599             return list;
   600         }
   602         // For type params.
   603         // Perhaps not needed if getEnclosingElement can be spec'ed
   604         // to do the same thing.
   605         // TODO: getGenericElement() might not be needed
   606         public Symbol getGenericElement() {
   607             return owner;
   608         }
   610         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   611             Assert.check(type.hasTag(TYPEVAR)); // else override will be invoked
   612             return v.visitTypeParameter(this, p);
   613         }
   615         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
   616             return v.visitTypeSymbol(this, p);
   617         }
   619         public List<Type> getBounds() {
   620             TypeVar t = (TypeVar)type;
   621             Type bound = t.getUpperBound();
   622             if (!bound.isCompound())
   623                 return List.of(bound);
   624             ClassType ct = (ClassType)bound;
   625             if (!ct.tsym.erasure_field.isInterface()) {
   626                 return ct.interfaces_field.prepend(ct.supertype_field);
   627             } else {
   628                 // No superclass was given in bounds.
   629                 // In this case, supertype is Object, erasure is first interface.
   630                 return ct.interfaces_field;
   631             }
   632         }
   633     }
   635     /** A class for package symbols
   636      */
   637     public static class PackageSymbol extends TypeSymbol
   638         implements PackageElement {
   640         public Scope members_field;
   641         public Name fullname;
   642         public ClassSymbol package_info; // see bug 6443073
   644         public PackageSymbol(Name name, Type type, Symbol owner) {
   645             super(0, name, type, owner);
   646             this.kind = PCK;
   647             this.members_field = null;
   648             this.fullname = formFullName(name, owner);
   649         }
   651         public PackageSymbol(Name name, Symbol owner) {
   652             this(name, null, owner);
   653             this.type = new PackageType(this);
   654         }
   656         public String toString() {
   657             return fullname.toString();
   658         }
   660         public Name getQualifiedName() {
   661             return fullname;
   662         }
   664         public boolean isUnnamed() {
   665             return name.isEmpty() && owner != null;
   666         }
   668         public Scope members() {
   669             if (completer != null) complete();
   670             return members_field;
   671         }
   673         public long flags() {
   674             if (completer != null) complete();
   675             return flags_field;
   676         }
   678         @Override
   679         public List<Attribute.Compound> getRawAttributes() {
   680             if (completer != null) complete();
   681             if (package_info != null && package_info.completer != null) {
   682                 package_info.complete();
   683                 mergeAttributes();
   684             }
   685             return super.getRawAttributes();
   686         }
   688         private void mergeAttributes() {
   689             if (annotations.isEmpty() &&
   690                 !package_info.annotations.isEmpty()) {
   691                 annotations.setAttributes(package_info.annotations);
   692             }
   693         }
   695         /** A package "exists" if a type or package that exists has
   696          *  been seen within it.
   697          */
   698         public boolean exists() {
   699             return (flags_field & EXISTS) != 0;
   700         }
   702         public ElementKind getKind() {
   703             return ElementKind.PACKAGE;
   704         }
   706         public Symbol getEnclosingElement() {
   707             return null;
   708         }
   710         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   711             return v.visitPackage(this, p);
   712         }
   714         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
   715             return v.visitPackageSymbol(this, p);
   716         }
   717     }
   719     /** A class for class symbols
   720      */
   721     public static class ClassSymbol extends TypeSymbol implements TypeElement {
   723         /** a scope for all class members; variables, methods and inner classes
   724          *  type parameters are not part of this scope
   725          */
   726         public Scope members_field;
   728         /** the fully qualified name of the class, i.e. pck.outer.inner.
   729          *  null for anonymous classes
   730          */
   731         public Name fullname;
   733         /** the fully qualified name of the class after converting to flat
   734          *  representation, i.e. pck.outer$inner,
   735          *  set externally for local and anonymous classes
   736          */
   737         public Name flatname;
   739         /** the sourcefile where the class came from
   740          */
   741         public JavaFileObject sourcefile;
   743         /** the classfile from where to load this class
   744          *  this will have extension .class or .java
   745          */
   746         public JavaFileObject classfile;
   748         /** the list of translated local classes (used for generating
   749          * InnerClasses attribute)
   750          */
   751         public List<ClassSymbol> trans_local;
   753         /** the constant pool of the class
   754          */
   755         public Pool pool;
   757         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
   758             super(flags, name, type, owner);
   759             this.members_field = null;
   760             this.fullname = formFullName(name, owner);
   761             this.flatname = formFlatName(name, owner);
   762             this.sourcefile = null;
   763             this.classfile = null;
   764             this.pool = null;
   765         }
   767         public ClassSymbol(long flags, Name name, Symbol owner) {
   768             this(
   769                 flags,
   770                 name,
   771                 new ClassType(Type.noType, null, null),
   772                 owner);
   773             this.type.tsym = this;
   774         }
   776         /** The Java source which this symbol represents.
   777          */
   778         public String toString() {
   779             return className();
   780         }
   782         public long flags() {
   783             if (completer != null) complete();
   784             return flags_field;
   785         }
   787         public Scope members() {
   788             if (completer != null) complete();
   789             return members_field;
   790         }
   792         @Override
   793         public List<Attribute.Compound> getRawAttributes() {
   794             if (completer != null) complete();
   795             return super.getRawAttributes();
   796         }
   798         public Type erasure(Types types) {
   799             if (erasure_field == null)
   800                 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
   801                                               List.<Type>nil(), this);
   802             return erasure_field;
   803         }
   805         public String className() {
   806             if (name.isEmpty())
   807                 return
   808                     Log.getLocalizedString("anonymous.class", flatname);
   809             else
   810                 return fullname.toString();
   811         }
   813         public Name getQualifiedName() {
   814             return fullname;
   815         }
   817         public Name flatName() {
   818             return flatname;
   819         }
   821         public boolean isSubClass(Symbol base, Types types) {
   822             if (this == base) {
   823                 return true;
   824             } else if ((base.flags() & INTERFACE) != 0) {
   825                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
   826                     for (List<Type> is = types.interfaces(t);
   827                          is.nonEmpty();
   828                          is = is.tail)
   829                         if (is.head.tsym.isSubClass(base, types)) return true;
   830             } else {
   831                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
   832                     if (t.tsym == base) return true;
   833             }
   834             return false;
   835         }
   837         /** Complete the elaboration of this symbol's definition.
   838          */
   839         public void complete() throws CompletionFailure {
   840             try {
   841                 super.complete();
   842             } catch (CompletionFailure ex) {
   843                 // quiet error recovery
   844                 flags_field |= (PUBLIC|STATIC);
   845                 this.type = new ErrorType(this, Type.noType);
   846                 throw ex;
   847             }
   848         }
   850         public List<Type> getInterfaces() {
   851             complete();
   852             if (type instanceof ClassType) {
   853                 ClassType t = (ClassType)type;
   854                 if (t.interfaces_field == null) // FIXME: shouldn't be null
   855                     t.interfaces_field = List.nil();
   856                 if (t.all_interfaces_field != null)
   857                     return Type.getModelTypes(t.all_interfaces_field);
   858                 return t.interfaces_field;
   859             } else {
   860                 return List.nil();
   861             }
   862         }
   864         public Type getSuperclass() {
   865             complete();
   866             if (type instanceof ClassType) {
   867                 ClassType t = (ClassType)type;
   868                 if (t.supertype_field == null) // FIXME: shouldn't be null
   869                     t.supertype_field = Type.noType;
   870                 // An interface has no superclass; its supertype is Object.
   871                 return t.isInterface()
   872                     ? Type.noType
   873                     : t.supertype_field.getModelType();
   874             } else {
   875                 return Type.noType;
   876             }
   877         }
   879         public ElementKind getKind() {
   880             long flags = flags();
   881             if ((flags & ANNOTATION) != 0)
   882                 return ElementKind.ANNOTATION_TYPE;
   883             else if ((flags & INTERFACE) != 0)
   884                 return ElementKind.INTERFACE;
   885             else if ((flags & ENUM) != 0)
   886                 return ElementKind.ENUM;
   887             else
   888                 return ElementKind.CLASS;
   889         }
   891         public NestingKind getNestingKind() {
   892             complete();
   893             if (owner.kind == PCK)
   894                 return NestingKind.TOP_LEVEL;
   895             else if (name.isEmpty())
   896                 return NestingKind.ANONYMOUS;
   897             else if (owner.kind == MTH)
   898                 return NestingKind.LOCAL;
   899             else
   900                 return NestingKind.MEMBER;
   901         }
   903         /**
   904          * @deprecated this method should never be used by javac internally.
   905          */
   906         @Override @Deprecated
   907         public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
   908             return JavacElements.getAnnotation(this, annoType);
   909         }
   911         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   912             return v.visitType(this, p);
   913         }
   915         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
   916             return v.visitClassSymbol(this, p);
   917         }
   918     }
   921     /** A class for variable symbols
   922      */
   923     public static class VarSymbol extends Symbol implements VariableElement {
   925         /** The variable's declaration position.
   926          */
   927         public int pos = Position.NOPOS;
   929         /** The variable's address. Used for different purposes during
   930          *  flow analysis, translation and code generation.
   931          *  Flow analysis:
   932          *    If this is a blank final or local variable, its sequence number.
   933          *  Translation:
   934          *    If this is a private field, its access number.
   935          *  Code generation:
   936          *    If this is a local variable, its logical slot number.
   937          */
   938         public int adr = -1;
   940         /** Construct a variable symbol, given its flags, name, type and owner.
   941          */
   942         public VarSymbol(long flags, Name name, Type type, Symbol owner) {
   943             super(VAR, flags, name, type, owner);
   944         }
   946         /** Clone this symbol with new owner.
   947          */
   948         public VarSymbol clone(Symbol newOwner) {
   949             VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) {
   950                 @Override
   951                 public Symbol baseSymbol() {
   952                     return VarSymbol.this;
   953                 }
   954             };
   955             v.pos = pos;
   956             v.adr = adr;
   957             v.data = data;
   958 //          System.out.println("clone " + v + " in " + newOwner);//DEBUG
   959             return v;
   960         }
   962         public String toString() {
   963             return name.toString();
   964         }
   966         public Symbol asMemberOf(Type site, Types types) {
   967             return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
   968         }
   970         public ElementKind getKind() {
   971             long flags = flags();
   972             if ((flags & PARAMETER) != 0) {
   973                 if (isExceptionParameter())
   974                     return ElementKind.EXCEPTION_PARAMETER;
   975                 else
   976                     return ElementKind.PARAMETER;
   977             } else if ((flags & ENUM) != 0) {
   978                 return ElementKind.ENUM_CONSTANT;
   979             } else if (owner.kind == TYP || owner.kind == ERR) {
   980                 return ElementKind.FIELD;
   981             } else if (isResourceVariable()) {
   982                 return ElementKind.RESOURCE_VARIABLE;
   983             } else {
   984                 return ElementKind.LOCAL_VARIABLE;
   985             }
   986         }
   988         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   989             return v.visitVariable(this, p);
   990         }
   992         public Object getConstantValue() { // Mirror API
   993             return Constants.decode(getConstValue(), type);
   994         }
   996         public void setLazyConstValue(final Env<AttrContext> env,
   997                                       final Attr attr,
   998                                       final JCTree.JCExpression initializer)
   999         {
  1000             setData(new Callable<Object>() {
  1001                 public Object call() {
  1002                     return attr.attribLazyConstantValue(env, initializer, type);
  1004             });
  1007         /**
  1008          * The variable's constant value, if this is a constant.
  1009          * Before the constant value is evaluated, it points to an
  1010          * initalizer environment.  If this is not a constant, it can
  1011          * be used for other stuff.
  1012          */
  1013         private Object data;
  1015         public boolean isExceptionParameter() {
  1016             return data == ElementKind.EXCEPTION_PARAMETER;
  1019         public boolean isResourceVariable() {
  1020             return data == ElementKind.RESOURCE_VARIABLE;
  1023         public Object getConstValue() {
  1024             // TODO: Consider if getConstValue and getConstantValue can be collapsed
  1025             if (data == ElementKind.EXCEPTION_PARAMETER ||
  1026                 data == ElementKind.RESOURCE_VARIABLE) {
  1027                 return null;
  1028             } else if (data instanceof Callable<?>) {
  1029                 // In this case, this is a final variable, with an as
  1030                 // yet unevaluated initializer.
  1031                 Callable<?> eval = (Callable<?>)data;
  1032                 data = null; // to make sure we don't evaluate this twice.
  1033                 try {
  1034                     data = eval.call();
  1035                 } catch (Exception ex) {
  1036                     throw new AssertionError(ex);
  1039             return data;
  1042         public void setData(Object data) {
  1043             Assert.check(!(data instanceof Env<?>), this);
  1044             this.data = data;
  1047         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
  1048             return v.visitVarSymbol(this, p);
  1052     /** A class for method symbols.
  1053      */
  1054     public static class MethodSymbol extends Symbol implements ExecutableElement {
  1056         /** The code of the method. */
  1057         public Code code = null;
  1059         /** The parameters of the method. */
  1060         public List<VarSymbol> params = null;
  1062         /** The names of the parameters */
  1063         public List<Name> savedParameterNames;
  1065         /** For an attribute field accessor, its default value if any.
  1066          *  The value is null if none appeared in the method
  1067          *  declaration.
  1068          */
  1069         public Attribute defaultValue = null;
  1071         /** Construct a method symbol, given its flags, name, type and owner.
  1072          */
  1073         public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
  1074             super(MTH, flags, name, type, owner);
  1075             if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name);
  1078         /** Clone this symbol with new owner.
  1079          */
  1080         public MethodSymbol clone(Symbol newOwner) {
  1081             MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) {
  1082                 @Override
  1083                 public Symbol baseSymbol() {
  1084                     return MethodSymbol.this;
  1086             };
  1087             m.code = code;
  1088             return m;
  1091         /** The Java source which this symbol represents.
  1092          */
  1093         public String toString() {
  1094             if ((flags() & BLOCK) != 0) {
  1095                 return owner.name.toString();
  1096             } else {
  1097                 String s = (name == name.table.names.init)
  1098                     ? owner.name.toString()
  1099                     : name.toString();
  1100                 if (type != null) {
  1101                     if (type.hasTag(FORALL))
  1102                         s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
  1103                     s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
  1105                 return s;
  1109         public boolean isDynamic() {
  1110             return false;
  1113         /** find a symbol that this (proxy method) symbol implements.
  1114          *  @param    c       The class whose members are searched for
  1115          *                    implementations
  1116          */
  1117         public Symbol implemented(TypeSymbol c, Types types) {
  1118             Symbol impl = null;
  1119             for (List<Type> is = types.interfaces(c.type);
  1120                  impl == null && is.nonEmpty();
  1121                  is = is.tail) {
  1122                 TypeSymbol i = is.head.tsym;
  1123                 impl = implementedIn(i, types);
  1124                 if (impl == null)
  1125                     impl = implemented(i, types);
  1127             return impl;
  1130         public Symbol implementedIn(TypeSymbol c, Types types) {
  1131             Symbol impl = null;
  1132             for (Scope.Entry e = c.members().lookup(name);
  1133                  impl == null && e.scope != null;
  1134                  e = e.next()) {
  1135                 if (this.overrides(e.sym, (TypeSymbol)owner, types, true) &&
  1136                     // FIXME: I suspect the following requires a
  1137                     // subst() for a parametric return type.
  1138                     types.isSameType(type.getReturnType(),
  1139                                      types.memberType(owner.type, e.sym).getReturnType())) {
  1140                     impl = e.sym;
  1143             return impl;
  1146         /** Will the erasure of this method be considered by the VM to
  1147          *  override the erasure of the other when seen from class `origin'?
  1148          */
  1149         public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
  1150             if (isConstructor() || _other.kind != MTH) return false;
  1152             if (this == _other) return true;
  1153             MethodSymbol other = (MethodSymbol)_other;
  1155             // check for a direct implementation
  1156             if (other.isOverridableIn((TypeSymbol)owner) &&
  1157                 types.asSuper(owner.type, other.owner) != null &&
  1158                 types.isSameType(erasure(types), other.erasure(types)))
  1159                 return true;
  1161             // check for an inherited implementation
  1162             return
  1163                 (flags() & ABSTRACT) == 0 &&
  1164                 other.isOverridableIn(origin) &&
  1165                 this.isMemberOf(origin, types) &&
  1166                 types.isSameType(erasure(types), other.erasure(types));
  1169         /** The implementation of this (abstract) symbol in class origin,
  1170          *  from the VM's point of view, null if method does not have an
  1171          *  implementation in class.
  1172          *  @param origin   The class of which the implementation is a member.
  1173          */
  1174         public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
  1175             for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
  1176                 for (Scope.Entry e = c.members().lookup(name);
  1177                      e.scope != null;
  1178                      e = e.next()) {
  1179                     if (e.sym.kind == MTH &&
  1180                         ((MethodSymbol)e.sym).binaryOverrides(this, origin, types))
  1181                         return (MethodSymbol)e.sym;
  1184             return null;
  1187         /** Does this symbol override `other' symbol, when both are seen as
  1188          *  members of class `origin'?  It is assumed that _other is a member
  1189          *  of origin.
  1191          *  It is assumed that both symbols have the same name.  The static
  1192          *  modifier is ignored for this test.
  1194          *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
  1195          */
  1196         public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
  1197             if (isConstructor() || _other.kind != MTH) return false;
  1199             if (this == _other) return true;
  1200             MethodSymbol other = (MethodSymbol)_other;
  1202             // check for a direct implementation
  1203             if (other.isOverridableIn((TypeSymbol)owner) &&
  1204                 types.asSuper(owner.type, other.owner) != null) {
  1205                 Type mt = types.memberType(owner.type, this);
  1206                 Type ot = types.memberType(owner.type, other);
  1207                 if (types.isSubSignature(mt, ot)) {
  1208                     if (!checkResult)
  1209                         return true;
  1210                     if (types.returnTypeSubstitutable(mt, ot))
  1211                         return true;
  1215             // check for an inherited implementation
  1216             if ((flags() & ABSTRACT) != 0 ||
  1217                     ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
  1218                     !other.isOverridableIn(origin) ||
  1219                     !this.isMemberOf(origin, types))
  1220                 return false;
  1222             // assert types.asSuper(origin.type, other.owner) != null;
  1223             Type mt = types.memberType(origin.type, this);
  1224             Type ot = types.memberType(origin.type, other);
  1225             return
  1226                 types.isSubSignature(mt, ot) &&
  1227                 (!checkResult || types.resultSubtype(mt, ot, types.noWarnings));
  1230         private boolean isOverridableIn(TypeSymbol origin) {
  1231             // JLS 8.4.6.1
  1232             switch ((int)(flags_field & Flags.AccessFlags)) {
  1233             case Flags.PRIVATE:
  1234                 return false;
  1235             case Flags.PUBLIC:
  1236                 return !this.owner.isInterface() ||
  1237                         (flags_field & STATIC) == 0;
  1238             case Flags.PROTECTED:
  1239                 return (origin.flags() & INTERFACE) == 0;
  1240             case 0:
  1241                 // for package private: can only override in the same
  1242                 // package
  1243                 return
  1244                     this.packge() == origin.packge() &&
  1245                     (origin.flags() & INTERFACE) == 0;
  1246             default:
  1247                 return false;
  1251         @Override
  1252         public boolean isInheritedIn(Symbol clazz, Types types) {
  1253             switch ((int)(flags_field & Flags.AccessFlags)) {
  1254                 case PUBLIC:
  1255                     return !this.owner.isInterface() ||
  1256                             clazz == owner ||
  1257                             (flags_field & STATIC) == 0;
  1258                 default:
  1259                     return super.isInheritedIn(clazz, types);
  1263         /** The implementation of this (abstract) symbol in class origin;
  1264          *  null if none exists. Synthetic methods are not considered
  1265          *  as possible implementations.
  1266          */
  1267         public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
  1268             return implementation(origin, types, checkResult, implementation_filter);
  1270         // where
  1271             private static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
  1272                 public boolean accepts(Symbol s) {
  1273                     return s.kind == Kinds.MTH &&
  1274                             (s.flags() & SYNTHETIC) == 0;
  1276             };
  1278         public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
  1279             MethodSymbol res = types.implementation(this, origin, checkResult, implFilter);
  1280             if (res != null)
  1281                 return res;
  1282             // if origin is derived from a raw type, we might have missed
  1283             // an implementation because we do not know enough about instantiations.
  1284             // in this case continue with the supertype as origin.
  1285             if (types.isDerivedRaw(origin.type) && !origin.isInterface())
  1286                 return implementation(types.supertype(origin.type).tsym, types, checkResult);
  1287             else
  1288                 return null;
  1291         public List<VarSymbol> params() {
  1292             owner.complete();
  1293             if (params == null) {
  1294                 // If ClassReader.saveParameterNames has been set true, then
  1295                 // savedParameterNames will be set to a list of names that
  1296                 // matches the types in type.getParameterTypes().  If any names
  1297                 // were not found in the class file, those names in the list will
  1298                 // be set to the empty name.
  1299                 // If ClassReader.saveParameterNames has been set false, then
  1300                 // savedParameterNames will be null.
  1301                 List<Name> paramNames = savedParameterNames;
  1302                 savedParameterNames = null;
  1303                 // discard the provided names if the list of names is the wrong size.
  1304                 if (paramNames == null || paramNames.size() != type.getParameterTypes().size()) {
  1305                     paramNames = List.nil();
  1307                 ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();
  1308                 List<Name> remaining = paramNames;
  1309                 // assert: remaining and paramNames are both empty or both
  1310                 // have same cardinality as type.getParameterTypes()
  1311                 int i = 0;
  1312                 for (Type t : type.getParameterTypes()) {
  1313                     Name paramName;
  1314                     if (remaining.isEmpty()) {
  1315                         // no names for any parameters available
  1316                         paramName = createArgName(i, paramNames);
  1317                     } else {
  1318                         paramName = remaining.head;
  1319                         remaining = remaining.tail;
  1320                         if (paramName.isEmpty()) {
  1321                             // no name for this specific parameter
  1322                             paramName = createArgName(i, paramNames);
  1325                     buf.append(new VarSymbol(PARAMETER, paramName, t, this));
  1326                     i++;
  1328                 params = buf.toList();
  1330             return params;
  1333         // Create a name for the argument at position 'index' that is not in
  1334         // the exclude list. In normal use, either no names will have been
  1335         // provided, in which case the exclude list is empty, or all the names
  1336         // will have been provided, in which case this method will not be called.
  1337         private Name createArgName(int index, List<Name> exclude) {
  1338             String prefix = "arg";
  1339             while (true) {
  1340                 Name argName = name.table.fromString(prefix + index);
  1341                 if (!exclude.contains(argName))
  1342                     return argName;
  1343                 prefix += "$";
  1347         public Symbol asMemberOf(Type site, Types types) {
  1348             return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
  1351         public ElementKind getKind() {
  1352             if (name == name.table.names.init)
  1353                 return ElementKind.CONSTRUCTOR;
  1354             else if (name == name.table.names.clinit)
  1355                 return ElementKind.STATIC_INIT;
  1356             else if ((flags() & BLOCK) != 0)
  1357                 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
  1358             else
  1359                 return ElementKind.METHOD;
  1362         public boolean isStaticOrInstanceInit() {
  1363             return getKind() == ElementKind.STATIC_INIT ||
  1364                     getKind() == ElementKind.INSTANCE_INIT;
  1367         /**
  1368          * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
  1369          * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
  1370          * a single variable arity parameter (iii) whose declared type is Object[],
  1371          * (iv) has a return type of Object and (v) is native.
  1372          */
  1373         public boolean isSignaturePolymorphic(Types types) {
  1374             List<Type> argtypes = type.getParameterTypes();
  1375             Type firstElemType = argtypes.nonEmpty() ?
  1376                     types.elemtype(argtypes.head) :
  1377                     null;
  1378             return owner == types.syms.methodHandleType.tsym &&
  1379                     argtypes.length() == 1 &&
  1380                     firstElemType != null &&
  1381                     types.isSameType(firstElemType, types.syms.objectType) &&
  1382                     types.isSameType(type.getReturnType(), types.syms.objectType) &&
  1383                     (flags() & NATIVE) != 0;
  1386         public Attribute getDefaultValue() {
  1387             return defaultValue;
  1390          public List<VarSymbol> getParameters() {
  1391             return params();
  1394         public boolean isVarArgs() {
  1395             return (flags() & VARARGS) != 0;
  1398         public boolean isDefault() {
  1399             return (flags() & DEFAULT) != 0;
  1402         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
  1403             return v.visitExecutable(this, p);
  1406         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
  1407             return v.visitMethodSymbol(this, p);
  1410         public Type getReturnType() {
  1411             return asType().getReturnType();
  1414         public List<Type> getThrownTypes() {
  1415             return asType().getThrownTypes();
  1419     /** A class for invokedynamic method calls.
  1420      */
  1421     public static class DynamicMethodSymbol extends MethodSymbol {
  1423         public Object[] staticArgs;
  1424         public Symbol bsm;
  1425         public int bsmKind;
  1427         public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
  1428             super(0, name, type, owner);
  1429             this.bsm = bsm;
  1430             this.bsmKind = bsmKind;
  1431             this.staticArgs = staticArgs;
  1434         @Override
  1435         public boolean isDynamic() {
  1436             return true;
  1440     /** A class for predefined operators.
  1441      */
  1442     public static class OperatorSymbol extends MethodSymbol {
  1444         public int opcode;
  1446         public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
  1447             super(PUBLIC | STATIC, name, type, owner);
  1448             this.opcode = opcode;
  1451         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
  1452             return v.visitOperatorSymbol(this, p);
  1456     /** Symbol completer interface.
  1457      */
  1458     public static interface Completer {
  1459         void complete(Symbol sym) throws CompletionFailure;
  1462     public static class CompletionFailure extends RuntimeException {
  1463         private static final long serialVersionUID = 0;
  1464         public Symbol sym;
  1466         /** A diagnostic object describing the failure
  1467          */
  1468         public JCDiagnostic diag;
  1470         /** A localized string describing the failure.
  1471          * @deprecated Use {@code getDetail()} or {@code getMessage()}
  1472          */
  1473         @Deprecated
  1474         public String errmsg;
  1476         public CompletionFailure(Symbol sym, String errmsg) {
  1477             this.sym = sym;
  1478             this.errmsg = errmsg;
  1479 //          this.printStackTrace();//DEBUG
  1482         public CompletionFailure(Symbol sym, JCDiagnostic diag) {
  1483             this.sym = sym;
  1484             this.diag = diag;
  1485 //          this.printStackTrace();//DEBUG
  1488         public JCDiagnostic getDiagnostic() {
  1489             return diag;
  1492         @Override
  1493         public String getMessage() {
  1494             if (diag != null)
  1495                 return diag.getMessage(null);
  1496             else
  1497                 return errmsg;
  1500         public Object getDetailValue() {
  1501             return (diag != null ? diag : errmsg);
  1504         @Override
  1505         public CompletionFailure initCause(Throwable cause) {
  1506             super.initCause(cause);
  1507             return this;
  1512     /**
  1513      * A visitor for symbols.  A visitor is used to implement operations
  1514      * (or relations) on symbols.  Most common operations on types are
  1515      * binary relations and this interface is designed for binary
  1516      * relations, that is, operations on the form
  1517      * Symbol&nbsp;&times;&nbsp;P&nbsp;&rarr;&nbsp;R.
  1518      * <!-- In plain text: Type x P -> R -->
  1520      * @param <R> the return type of the operation implemented by this
  1521      * visitor; use Void if no return type is needed.
  1522      * @param <P> the type of the second argument (the first being the
  1523      * symbol itself) of the operation implemented by this visitor; use
  1524      * Void if a second argument is not needed.
  1525      */
  1526     public interface Visitor<R,P> {
  1527         R visitClassSymbol(ClassSymbol s, P arg);
  1528         R visitMethodSymbol(MethodSymbol s, P arg);
  1529         R visitPackageSymbol(PackageSymbol s, P arg);
  1530         R visitOperatorSymbol(OperatorSymbol s, P arg);
  1531         R visitVarSymbol(VarSymbol s, P arg);
  1532         R visitTypeSymbol(TypeSymbol s, P arg);
  1533         R visitSymbol(Symbol s, P arg);

mercurial