1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,1296 @@ 1.4 +/* 1.5 + * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javac.code; 1.30 + 1.31 +import java.util.ArrayList; 1.32 +import java.util.Collections; 1.33 +import java.util.Set; 1.34 +import java.util.concurrent.Callable; 1.35 +import javax.lang.model.element.*; 1.36 +import javax.lang.model.type.ReferenceType; 1.37 +import javax.lang.model.type.TypeMirror; 1.38 +import javax.tools.JavaFileObject; 1.39 + 1.40 +import com.sun.tools.javac.util.*; 1.41 +import com.sun.tools.javac.util.Name; 1.42 +import com.sun.tools.javac.code.Type.*; 1.43 +import com.sun.tools.javac.comp.Attr; 1.44 +import com.sun.tools.javac.comp.AttrContext; 1.45 +import com.sun.tools.javac.comp.Env; 1.46 +import com.sun.tools.javac.jvm.*; 1.47 +import com.sun.tools.javac.model.*; 1.48 +import com.sun.tools.javac.tree.JCTree; 1.49 + 1.50 +import static com.sun.tools.javac.code.Flags.*; 1.51 +import static com.sun.tools.javac.code.Kinds.*; 1.52 +import static com.sun.tools.javac.code.TypeTags.*; 1.53 + 1.54 +/** Root class for Java symbols. It contains subclasses 1.55 + * for specific sorts of symbols, such as variables, methods and operators, 1.56 + * types, packages. Each subclass is represented as a static inner class 1.57 + * inside Symbol. 1.58 + * 1.59 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 1.60 + * you write code that depends on this, you do so at your own risk. 1.61 + * This code and its internal interfaces are subject to change or 1.62 + * deletion without notice.</b> 1.63 + */ 1.64 +public abstract class Symbol implements Element { 1.65 + // public Throwable debug = new Throwable(); 1.66 + 1.67 + /** The kind of this symbol. 1.68 + * @see Kinds 1.69 + */ 1.70 + public int kind; 1.71 + 1.72 + /** The flags of this symbol. 1.73 + */ 1.74 + public long flags_field; 1.75 + 1.76 + /** An accessor method for the flags of this symbol. 1.77 + * Flags of class symbols should be accessed through the accessor 1.78 + * method to make sure that the class symbol is loaded. 1.79 + */ 1.80 + public long flags() { return flags_field; } 1.81 + 1.82 + /** The attributes of this symbol. 1.83 + */ 1.84 + public List<Attribute.Compound> attributes_field; 1.85 + 1.86 + /** An accessor method for the attributes of this symbol. 1.87 + * Attributes of class symbols should be accessed through the accessor 1.88 + * method to make sure that the class symbol is loaded. 1.89 + */ 1.90 + public List<Attribute.Compound> getAnnotationMirrors() { 1.91 + assert attributes_field != null; 1.92 + return attributes_field; 1.93 + } 1.94 + 1.95 + /** Fetch a particular annotation from a symbol. */ 1.96 + public Attribute.Compound attribute(Symbol anno) { 1.97 + for (Attribute.Compound a : getAnnotationMirrors()) 1.98 + if (a.type.tsym == anno) return a; 1.99 + return null; 1.100 + } 1.101 + 1.102 + /** The name of this symbol in Utf8 representation. 1.103 + */ 1.104 + public Name name; 1.105 + 1.106 + /** The type of this symbol. 1.107 + */ 1.108 + public Type type; 1.109 + 1.110 + /** The owner of this symbol. 1.111 + */ 1.112 + public Symbol owner; 1.113 + 1.114 + /** The completer of this symbol. 1.115 + */ 1.116 + public Completer completer; 1.117 + 1.118 + /** A cache for the type erasure of this symbol. 1.119 + */ 1.120 + public Type erasure_field; 1.121 + 1.122 + /** Construct a symbol with given kind, flags, name, type and owner. 1.123 + */ 1.124 + public Symbol(int kind, long flags, Name name, Type type, Symbol owner) { 1.125 + this.kind = kind; 1.126 + this.flags_field = flags; 1.127 + this.type = type; 1.128 + this.owner = owner; 1.129 + this.completer = null; 1.130 + this.erasure_field = null; 1.131 + this.attributes_field = List.nil(); 1.132 + this.name = name; 1.133 + } 1.134 + 1.135 + /** Clone this symbol with new owner. 1.136 + * Legal only for fields and methods. 1.137 + */ 1.138 + public Symbol clone(Symbol newOwner) { 1.139 + throw new AssertionError(); 1.140 + } 1.141 + 1.142 + /** The Java source which this symbol represents. 1.143 + * A description of this symbol; overrides Object. 1.144 + */ 1.145 + public String toString() { 1.146 + return name.toString(); 1.147 + } 1.148 + 1.149 + /** A Java source description of the location of this symbol; used for 1.150 + * error reporting. Use of this method may result in the loss of the 1.151 + * symbol's description. 1.152 + */ 1.153 + public String location() { 1.154 + if (owner.name == null || (owner.name.len == 0 && owner.kind != PCK)) { 1.155 + return ""; 1.156 + } 1.157 + return owner.toString(); 1.158 + } 1.159 + 1.160 + public String location(Type site, Types types) { 1.161 + if (owner.name == null || owner.name.len == 0) { 1.162 + return location(); 1.163 + } 1.164 + if (owner.type.tag == CLASS) { 1.165 + Type ownertype = types.asOuterSuper(site, owner); 1.166 + if (ownertype != null) return ownertype.toString(); 1.167 + } 1.168 + return owner.toString(); 1.169 + } 1.170 + 1.171 + /** The symbol's erased type. 1.172 + */ 1.173 + public Type erasure(Types types) { 1.174 + if (erasure_field == null) 1.175 + erasure_field = types.erasure(type); 1.176 + return erasure_field; 1.177 + } 1.178 + 1.179 + /** The external type of a symbol. This is the symbol's erased type 1.180 + * except for constructors of inner classes which get the enclosing 1.181 + * instance class added as first argument. 1.182 + */ 1.183 + public Type externalType(Types types) { 1.184 + Type t = erasure(types); 1.185 + if (name == name.table.init && owner.hasOuterInstance()) { 1.186 + Type outerThisType = types.erasure(owner.type.getEnclosingType()); 1.187 + return new MethodType(t.getParameterTypes().prepend(outerThisType), 1.188 + t.getReturnType(), 1.189 + t.getThrownTypes(), 1.190 + t.tsym); 1.191 + } else { 1.192 + return t; 1.193 + } 1.194 + } 1.195 + 1.196 + public boolean isStatic() { 1.197 + return 1.198 + (flags() & STATIC) != 0 || 1.199 + (owner.flags() & INTERFACE) != 0 && kind != MTH; 1.200 + } 1.201 + 1.202 + public boolean isInterface() { 1.203 + return (flags() & INTERFACE) != 0; 1.204 + } 1.205 + 1.206 + /** Is this symbol declared (directly or indirectly) local 1.207 + * to a method or variable initializer? 1.208 + * Also includes fields of inner classes which are in 1.209 + * turn local to a method or variable initializer. 1.210 + */ 1.211 + public boolean isLocal() { 1.212 + return 1.213 + (owner.kind & (VAR | MTH)) != 0 || 1.214 + (owner.kind == TYP && owner.isLocal()); 1.215 + } 1.216 + 1.217 + /** Is this symbol a constructor? 1.218 + */ 1.219 + public boolean isConstructor() { 1.220 + return name == name.table.init; 1.221 + } 1.222 + 1.223 + /** The fully qualified name of this symbol. 1.224 + * This is the same as the symbol's name except for class symbols, 1.225 + * which are handled separately. 1.226 + */ 1.227 + public Name getQualifiedName() { 1.228 + return name; 1.229 + } 1.230 + 1.231 + /** The fully qualified name of this symbol after converting to flat 1.232 + * representation. This is the same as the symbol's name except for 1.233 + * class symbols, which are handled separately. 1.234 + */ 1.235 + public Name flatName() { 1.236 + return getQualifiedName(); 1.237 + } 1.238 + 1.239 + /** If this is a class or package, its members, otherwise null. 1.240 + */ 1.241 + public Scope members() { 1.242 + return null; 1.243 + } 1.244 + 1.245 + /** A class is an inner class if it it has an enclosing instance class. 1.246 + */ 1.247 + public boolean isInner() { 1.248 + return type.getEnclosingType().tag == CLASS; 1.249 + } 1.250 + 1.251 + /** An inner class has an outer instance if it is not an interface 1.252 + * it has an enclosing instance class which might be referenced from the class. 1.253 + * Nested classes can see instance members of their enclosing class. 1.254 + * Their constructors carry an additional this$n parameter, inserted 1.255 + * implicitly by the compiler. 1.256 + * 1.257 + * @see #isInner 1.258 + */ 1.259 + public boolean hasOuterInstance() { 1.260 + return 1.261 + type.getEnclosingType().tag == CLASS && (flags() & (INTERFACE | NOOUTERTHIS)) == 0; 1.262 + } 1.263 + 1.264 + /** The closest enclosing class of this symbol's declaration. 1.265 + */ 1.266 + public ClassSymbol enclClass() { 1.267 + Symbol c = this; 1.268 + while (c != null && 1.269 + ((c.kind & TYP) == 0 || c.type.tag != CLASS)) { 1.270 + c = c.owner; 1.271 + } 1.272 + return (ClassSymbol)c; 1.273 + } 1.274 + 1.275 + /** The outermost class which indirectly owns this symbol. 1.276 + */ 1.277 + public ClassSymbol outermostClass() { 1.278 + Symbol sym = this; 1.279 + Symbol prev = null; 1.280 + while (sym.kind != PCK) { 1.281 + prev = sym; 1.282 + sym = sym.owner; 1.283 + } 1.284 + return (ClassSymbol) prev; 1.285 + } 1.286 + 1.287 + /** The package which indirectly owns this symbol. 1.288 + */ 1.289 + public PackageSymbol packge() { 1.290 + Symbol sym = this; 1.291 + while (sym.kind != PCK) { 1.292 + sym = sym.owner; 1.293 + } 1.294 + return (PackageSymbol) sym; 1.295 + } 1.296 + 1.297 + /** Is this symbol a subclass of `base'? Only defined for ClassSymbols. 1.298 + */ 1.299 + public boolean isSubClass(Symbol base, Types types) { 1.300 + throw new AssertionError("isSubClass " + this); 1.301 + } 1.302 + 1.303 + /** Fully check membership: hierarchy, protection, and hiding. 1.304 + * Does not exclude methods not inherited due to overriding. 1.305 + */ 1.306 + public boolean isMemberOf(TypeSymbol clazz, Types types) { 1.307 + return 1.308 + owner == clazz || 1.309 + clazz.isSubClass(owner, types) && 1.310 + isInheritedIn(clazz, types) && 1.311 + !hiddenIn((ClassSymbol)clazz, types); 1.312 + } 1.313 + 1.314 + /** Is this symbol the same as or enclosed by the given class? */ 1.315 + public boolean isEnclosedBy(ClassSymbol clazz) { 1.316 + for (Symbol sym = this; sym.kind != PCK; sym = sym.owner) 1.317 + if (sym == clazz) return true; 1.318 + return false; 1.319 + } 1.320 + 1.321 + /** Check for hiding. Note that this doesn't handle multiple 1.322 + * (interface) inheritance. */ 1.323 + private boolean hiddenIn(ClassSymbol clazz, Types types) { 1.324 + if (kind == MTH && (flags() & STATIC) == 0) return false; 1.325 + while (true) { 1.326 + if (owner == clazz) return false; 1.327 + Scope.Entry e = clazz.members().lookup(name); 1.328 + while (e.scope != null) { 1.329 + if (e.sym == this) return false; 1.330 + if (e.sym.kind == kind && 1.331 + (kind != MTH || 1.332 + (e.sym.flags() & STATIC) != 0 && 1.333 + types.isSubSignature(e.sym.type, type))) 1.334 + return true; 1.335 + e = e.next(); 1.336 + } 1.337 + Type superType = types.supertype(clazz.type); 1.338 + if (superType.tag != TypeTags.CLASS) return false; 1.339 + clazz = (ClassSymbol)superType.tsym; 1.340 + } 1.341 + } 1.342 + 1.343 + /** Is this symbol inherited into a given class? 1.344 + * PRE: If symbol's owner is a interface, 1.345 + * it is already assumed that the interface is a superinterface 1.346 + * of given class. 1.347 + * @param clazz The class for which we want to establish membership. 1.348 + * This must be a subclass of the member's owner. 1.349 + */ 1.350 + public boolean isInheritedIn(Symbol clazz, Types types) { 1.351 + switch ((int)(flags_field & Flags.AccessFlags)) { 1.352 + default: // error recovery 1.353 + case PUBLIC: 1.354 + return true; 1.355 + case PRIVATE: 1.356 + return this.owner == clazz; 1.357 + case PROTECTED: 1.358 + // we model interfaces as extending Object 1.359 + return (clazz.flags() & INTERFACE) == 0; 1.360 + case 0: 1.361 + PackageSymbol thisPackage = this.packge(); 1.362 + for (Symbol sup = clazz; 1.363 + sup != null && sup != this.owner; 1.364 + sup = types.supertype(sup.type).tsym) { 1.365 + if (sup.type.isErroneous()) 1.366 + return true; // error recovery 1.367 + if ((sup.flags() & COMPOUND) != 0) 1.368 + continue; 1.369 + if (sup.packge() != thisPackage) 1.370 + return false; 1.371 + } 1.372 + return (clazz.flags() & INTERFACE) == 0; 1.373 + } 1.374 + } 1.375 + 1.376 + /** The (variable or method) symbol seen as a member of given 1.377 + * class type`site' (this might change the symbol's type). 1.378 + * This is used exclusively for producing diagnostics. 1.379 + */ 1.380 + public Symbol asMemberOf(Type site, Types types) { 1.381 + throw new AssertionError(); 1.382 + } 1.383 + 1.384 + /** Does this method symbol override `other' symbol, when both are seen as 1.385 + * members of class `origin'? It is assumed that _other is a member 1.386 + * of origin. 1.387 + * 1.388 + * It is assumed that both symbols have the same name. The static 1.389 + * modifier is ignored for this test. 1.390 + * 1.391 + * See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 1.392 + */ 1.393 + public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { 1.394 + return false; 1.395 + } 1.396 + 1.397 + /** Complete the elaboration of this symbol's definition. 1.398 + */ 1.399 + public void complete() throws CompletionFailure { 1.400 + if (completer != null) { 1.401 + Completer c = completer; 1.402 + completer = null; 1.403 + c.complete(this); 1.404 + } 1.405 + } 1.406 + 1.407 + /** True if the symbol represents an entity that exists. 1.408 + */ 1.409 + public boolean exists() { 1.410 + return true; 1.411 + } 1.412 + 1.413 + public Type asType() { 1.414 + return type; 1.415 + } 1.416 + 1.417 + public Symbol getEnclosingElement() { 1.418 + return owner; 1.419 + } 1.420 + 1.421 + public ElementKind getKind() { 1.422 + return ElementKind.OTHER; // most unkind 1.423 + } 1.424 + 1.425 + public Set<Modifier> getModifiers() { 1.426 + return Flags.asModifierSet(flags()); 1.427 + } 1.428 + 1.429 + public Name getSimpleName() { 1.430 + return name; 1.431 + } 1.432 + 1.433 + /** 1.434 + * @deprecated this method should never be used by javac internally. 1.435 + */ 1.436 + @Deprecated 1.437 + public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) { 1.438 + return JavacElements.getAnnotation(this, annoType); 1.439 + } 1.440 + 1.441 + // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList 1.442 + public java.util.List<Symbol> getEnclosedElements() { 1.443 + return List.nil(); 1.444 + } 1.445 + 1.446 + public List<TypeSymbol> getTypeParameters() { 1.447 + ListBuffer<TypeSymbol> l = ListBuffer.lb(); 1.448 + for (Type t : type.getTypeArguments()) { 1.449 + l.append(t.tsym); 1.450 + } 1.451 + return l.toList(); 1.452 + } 1.453 + 1.454 + public static class DelegatedSymbol extends Symbol { 1.455 + protected Symbol other; 1.456 + public DelegatedSymbol(Symbol other) { 1.457 + super(other.kind, other.flags_field, other.name, other.type, other.owner); 1.458 + this.other = other; 1.459 + } 1.460 + public String toString() { return other.toString(); } 1.461 + public String location() { return other.location(); } 1.462 + public String location(Type site, Types types) { return other.location(site, types); } 1.463 + public Type erasure(Types types) { return other.erasure(types); } 1.464 + public Type externalType(Types types) { return other.externalType(types); } 1.465 + public boolean isLocal() { return other.isLocal(); } 1.466 + public boolean isConstructor() { return other.isConstructor(); } 1.467 + public Name getQualifiedName() { return other.getQualifiedName(); } 1.468 + public Name flatName() { return other.flatName(); } 1.469 + public Scope members() { return other.members(); } 1.470 + public boolean isInner() { return other.isInner(); } 1.471 + public boolean hasOuterInstance() { return other.hasOuterInstance(); } 1.472 + public ClassSymbol enclClass() { return other.enclClass(); } 1.473 + public ClassSymbol outermostClass() { return other.outermostClass(); } 1.474 + public PackageSymbol packge() { return other.packge(); } 1.475 + public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); } 1.476 + public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); } 1.477 + public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); } 1.478 + public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); } 1.479 + public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); } 1.480 + public void complete() throws CompletionFailure { other.complete(); } 1.481 + 1.482 + public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1.483 + return other.accept(v, p); 1.484 + } 1.485 + } 1.486 + 1.487 + /** A class for type symbols. Type variables are represented by instances 1.488 + * of this class, classes and packages by instances of subclasses. 1.489 + */ 1.490 + public static class TypeSymbol 1.491 + extends Symbol implements TypeParameterElement { 1.492 + // Implements TypeParameterElement because type parameters don't 1.493 + // have their own TypeSymbol subclass. 1.494 + // TODO: type parameters should have their own TypeSymbol subclass 1.495 + 1.496 + public TypeSymbol(long flags, Name name, Type type, Symbol owner) { 1.497 + super(TYP, flags, name, type, owner); 1.498 + } 1.499 + 1.500 + /** form a fully qualified name from a name and an owner 1.501 + */ 1.502 + static public Name formFullName(Name name, Symbol owner) { 1.503 + if (owner == null) return name; 1.504 + if (((owner.kind != ERR)) && 1.505 + ((owner.kind & (VAR | MTH)) != 0 1.506 + || (owner.kind == TYP && owner.type.tag == TYPEVAR) 1.507 + )) return name; 1.508 + Name prefix = owner.getQualifiedName(); 1.509 + if (prefix == null || prefix == prefix.table.empty) 1.510 + return name; 1.511 + else return prefix.append('.', name); 1.512 + } 1.513 + 1.514 + /** form a fully qualified name from a name and an owner, after 1.515 + * converting to flat representation 1.516 + */ 1.517 + static public Name formFlatName(Name name, Symbol owner) { 1.518 + if (owner == null || 1.519 + (owner.kind & (VAR | MTH)) != 0 1.520 + || (owner.kind == TYP && owner.type.tag == TYPEVAR) 1.521 + ) return name; 1.522 + char sep = owner.kind == TYP ? '$' : '.'; 1.523 + Name prefix = owner.flatName(); 1.524 + if (prefix == null || prefix == prefix.table.empty) 1.525 + return name; 1.526 + else return prefix.append(sep, name); 1.527 + } 1.528 + 1.529 + /** 1.530 + * A total ordering between type symbols that refines the 1.531 + * class inheritance graph. 1.532 + * 1.533 + * Typevariables always precede other kinds of symbols. 1.534 + */ 1.535 + public final boolean precedes(TypeSymbol that, Types types) { 1.536 + if (this == that) 1.537 + return false; 1.538 + if (this.type.tag == that.type.tag) { 1.539 + if (this.type.tag == CLASS) { 1.540 + return 1.541 + types.rank(that.type) < types.rank(this.type) || 1.542 + types.rank(that.type) == types.rank(this.type) && 1.543 + that.getQualifiedName().compareTo(this.getQualifiedName()) < 0; 1.544 + } else if (this.type.tag == TYPEVAR) { 1.545 + return types.isSubtype(this.type, that.type); 1.546 + } 1.547 + } 1.548 + return this.type.tag == TYPEVAR; 1.549 + } 1.550 + 1.551 + // For type params; overridden in subclasses. 1.552 + public ElementKind getKind() { 1.553 + return ElementKind.TYPE_PARAMETER; 1.554 + } 1.555 + 1.556 + public java.util.List<Symbol> getEnclosedElements() { 1.557 + List<Symbol> list = List.nil(); 1.558 + for (Scope.Entry e = members().elems; e != null; e = e.sibling) { 1.559 + if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this) 1.560 + list = list.prepend(e.sym); 1.561 + } 1.562 + return list; 1.563 + } 1.564 + 1.565 + // For type params. 1.566 + // Perhaps not needed if getEnclosingElement can be spec'ed 1.567 + // to do the same thing. 1.568 + // TODO: getGenericElement() might not be needed 1.569 + public Symbol getGenericElement() { 1.570 + return owner; 1.571 + } 1.572 + 1.573 + public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1.574 + assert type.tag == TYPEVAR; // else override will be invoked 1.575 + return v.visitTypeParameter(this, p); 1.576 + } 1.577 + 1.578 + public List<Type> getBounds() { 1.579 + TypeVar t = (TypeVar)type; 1.580 + Type bound = t.getUpperBound(); 1.581 + if (!bound.isCompound()) 1.582 + return List.of(bound); 1.583 + ClassType ct = (ClassType)bound; 1.584 + if (!ct.tsym.erasure_field.isInterface()) { 1.585 + return ct.interfaces_field.prepend(ct.supertype_field); 1.586 + } else { 1.587 + // No superclass was given in bounds. 1.588 + // In this case, supertype is Object, erasure is first interface. 1.589 + return ct.interfaces_field; 1.590 + } 1.591 + } 1.592 + } 1.593 + 1.594 + /** A class for package symbols 1.595 + */ 1.596 + public static class PackageSymbol extends TypeSymbol 1.597 + implements PackageElement { 1.598 + 1.599 + public Scope members_field; 1.600 + public Name fullname; 1.601 + public ClassSymbol package_info; // see bug 6443073 1.602 + 1.603 + public PackageSymbol(Name name, Type type, Symbol owner) { 1.604 + super(0, name, type, owner); 1.605 + this.kind = PCK; 1.606 + this.members_field = null; 1.607 + this.fullname = formFullName(name, owner); 1.608 + } 1.609 + 1.610 + public PackageSymbol(Name name, Symbol owner) { 1.611 + this(name, null, owner); 1.612 + this.type = new PackageType(this); 1.613 + } 1.614 + 1.615 + public String toString() { 1.616 + return fullname.toString(); 1.617 + } 1.618 + 1.619 + public Name getQualifiedName() { 1.620 + return fullname; 1.621 + } 1.622 + 1.623 + public boolean isUnnamed() { 1.624 + return name.isEmpty() && owner != null; 1.625 + } 1.626 + 1.627 + public Scope members() { 1.628 + if (completer != null) complete(); 1.629 + return members_field; 1.630 + } 1.631 + 1.632 + public long flags() { 1.633 + if (completer != null) complete(); 1.634 + return flags_field; 1.635 + } 1.636 + 1.637 + public List<Attribute.Compound> getAnnotationMirrors() { 1.638 + if (completer != null) complete(); 1.639 + assert attributes_field != null; 1.640 + return attributes_field; 1.641 + } 1.642 + 1.643 + /** A package "exists" if a type or package that exists has 1.644 + * been seen within it. 1.645 + */ 1.646 + public boolean exists() { 1.647 + return (flags_field & EXISTS) != 0; 1.648 + } 1.649 + 1.650 + public ElementKind getKind() { 1.651 + return ElementKind.PACKAGE; 1.652 + } 1.653 + 1.654 + public Symbol getEnclosingElement() { 1.655 + return null; 1.656 + } 1.657 + 1.658 + public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1.659 + return v.visitPackage(this, p); 1.660 + } 1.661 + } 1.662 + 1.663 + /** A class for class symbols 1.664 + */ 1.665 + public static class ClassSymbol extends TypeSymbol implements TypeElement { 1.666 + 1.667 + /** a scope for all class members; variables, methods and inner classes 1.668 + * type parameters are not part of this scope 1.669 + */ 1.670 + public Scope members_field; 1.671 + 1.672 + /** the fully qualified name of the class, i.e. pck.outer.inner. 1.673 + * null for anonymous classes 1.674 + */ 1.675 + public Name fullname; 1.676 + 1.677 + /** the fully qualified name of the class after converting to flat 1.678 + * representation, i.e. pck.outer$inner, 1.679 + * set externally for local and anonymous classes 1.680 + */ 1.681 + public Name flatname; 1.682 + 1.683 + /** the sourcefile where the class came from 1.684 + */ 1.685 + public JavaFileObject sourcefile; 1.686 + 1.687 + /** the classfile from where to load this class 1.688 + * this will have extension .class or .java 1.689 + */ 1.690 + public JavaFileObject classfile; 1.691 + 1.692 + /** the constant pool of the class 1.693 + */ 1.694 + public Pool pool; 1.695 + 1.696 + public ClassSymbol(long flags, Name name, Type type, Symbol owner) { 1.697 + super(flags, name, type, owner); 1.698 + this.members_field = null; 1.699 + this.fullname = formFullName(name, owner); 1.700 + this.flatname = formFlatName(name, owner); 1.701 + this.sourcefile = null; 1.702 + this.classfile = null; 1.703 + this.pool = null; 1.704 + } 1.705 + 1.706 + public ClassSymbol(long flags, Name name, Symbol owner) { 1.707 + this( 1.708 + flags, 1.709 + name, 1.710 + new ClassType(Type.noType, null, null), 1.711 + owner); 1.712 + this.type.tsym = this; 1.713 + } 1.714 + 1.715 + /** The Java source which this symbol represents. 1.716 + */ 1.717 + public String toString() { 1.718 + return className(); 1.719 + } 1.720 + 1.721 + public long flags() { 1.722 + if (completer != null) complete(); 1.723 + return flags_field; 1.724 + } 1.725 + 1.726 + public Scope members() { 1.727 + if (completer != null) complete(); 1.728 + return members_field; 1.729 + } 1.730 + 1.731 + public List<Attribute.Compound> getAnnotationMirrors() { 1.732 + if (completer != null) complete(); 1.733 + assert attributes_field != null; 1.734 + return attributes_field; 1.735 + } 1.736 + 1.737 + public Type erasure(Types types) { 1.738 + if (erasure_field == null) 1.739 + erasure_field = new ClassType(types.erasure(type.getEnclosingType()), 1.740 + List.<Type>nil(), this); 1.741 + return erasure_field; 1.742 + } 1.743 + 1.744 + public String className() { 1.745 + if (name.len == 0) 1.746 + return 1.747 + Log.getLocalizedString("anonymous.class", flatname); 1.748 + else 1.749 + return fullname.toString(); 1.750 + } 1.751 + 1.752 + public Name getQualifiedName() { 1.753 + return fullname; 1.754 + } 1.755 + 1.756 + public Name flatName() { 1.757 + return flatname; 1.758 + } 1.759 + 1.760 + public boolean isSubClass(Symbol base, Types types) { 1.761 + if (this == base) { 1.762 + return true; 1.763 + } else if ((base.flags() & INTERFACE) != 0) { 1.764 + for (Type t = type; t.tag == CLASS; t = types.supertype(t)) 1.765 + for (List<Type> is = types.interfaces(t); 1.766 + is.nonEmpty(); 1.767 + is = is.tail) 1.768 + if (is.head.tsym.isSubClass(base, types)) return true; 1.769 + } else { 1.770 + for (Type t = type; t.tag == CLASS; t = types.supertype(t)) 1.771 + if (t.tsym == base) return true; 1.772 + } 1.773 + return false; 1.774 + } 1.775 + 1.776 + /** Complete the elaboration of this symbol's definition. 1.777 + */ 1.778 + public void complete() throws CompletionFailure { 1.779 + try { 1.780 + super.complete(); 1.781 + } catch (CompletionFailure ex) { 1.782 + // quiet error recovery 1.783 + flags_field |= (PUBLIC|STATIC); 1.784 + this.type = new ErrorType(this); 1.785 + throw ex; 1.786 + } 1.787 + } 1.788 + 1.789 + public List<Type> getInterfaces() { 1.790 + complete(); 1.791 + if (type instanceof ClassType) { 1.792 + ClassType t = (ClassType)type; 1.793 + if (t.interfaces_field == null) // FIXME: shouldn't be null 1.794 + t.interfaces_field = List.nil(); 1.795 + return t.interfaces_field; 1.796 + } else { 1.797 + return List.nil(); 1.798 + } 1.799 + } 1.800 + 1.801 + public Type getSuperclass() { 1.802 + complete(); 1.803 + if (type instanceof ClassType) { 1.804 + ClassType t = (ClassType)type; 1.805 + if (t.supertype_field == null) // FIXME: shouldn't be null 1.806 + t.supertype_field = Type.noType; 1.807 + // An interface has no superclass; its supertype is Object. 1.808 + return t.isInterface() 1.809 + ? Type.noType 1.810 + : t.supertype_field; 1.811 + } else { 1.812 + return Type.noType; 1.813 + } 1.814 + } 1.815 + 1.816 + public ElementKind getKind() { 1.817 + long flags = flags(); 1.818 + if ((flags & ANNOTATION) != 0) 1.819 + return ElementKind.ANNOTATION_TYPE; 1.820 + else if ((flags & INTERFACE) != 0) 1.821 + return ElementKind.INTERFACE; 1.822 + else if ((flags & ENUM) != 0) 1.823 + return ElementKind.ENUM; 1.824 + else 1.825 + return ElementKind.CLASS; 1.826 + } 1.827 + 1.828 + public NestingKind getNestingKind() { 1.829 + complete(); 1.830 + if (owner.kind == PCK) 1.831 + return NestingKind.TOP_LEVEL; 1.832 + else if (name.isEmpty()) 1.833 + return NestingKind.ANONYMOUS; 1.834 + else if (owner.kind == MTH) 1.835 + return NestingKind.LOCAL; 1.836 + else 1.837 + return NestingKind.MEMBER; 1.838 + } 1.839 + 1.840 + /** 1.841 + * @deprecated this method should never be used by javac internally. 1.842 + */ 1.843 + @Override @Deprecated 1.844 + public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) { 1.845 + return JavacElements.getAnnotation(this, annoType); 1.846 + } 1.847 + 1.848 + public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1.849 + return v.visitType(this, p); 1.850 + } 1.851 + } 1.852 + 1.853 + 1.854 + /** A class for variable symbols 1.855 + */ 1.856 + public static class VarSymbol extends Symbol implements VariableElement { 1.857 + 1.858 + /** The variable's declaration position. 1.859 + */ 1.860 + public int pos = Position.NOPOS; 1.861 + 1.862 + /** The variable's address. Used for different purposes during 1.863 + * flow analysis, translation and code generation. 1.864 + * Flow analysis: 1.865 + * If this is a blank final or local variable, its sequence number. 1.866 + * Translation: 1.867 + * If this is a private field, its access number. 1.868 + * Code generation: 1.869 + * If this is a local variable, its logical slot number. 1.870 + */ 1.871 + public int adr = -1; 1.872 + 1.873 + /** Construct a variable symbol, given its flags, name, type and owner. 1.874 + */ 1.875 + public VarSymbol(long flags, Name name, Type type, Symbol owner) { 1.876 + super(VAR, flags, name, type, owner); 1.877 + } 1.878 + 1.879 + /** Clone this symbol with new owner. 1.880 + */ 1.881 + public VarSymbol clone(Symbol newOwner) { 1.882 + VarSymbol v = new VarSymbol(flags_field, name, type, newOwner); 1.883 + v.pos = pos; 1.884 + v.adr = adr; 1.885 + v.data = data; 1.886 +// System.out.println("clone " + v + " in " + newOwner);//DEBUG 1.887 + return v; 1.888 + } 1.889 + 1.890 + public String toString() { 1.891 + return name.toString(); 1.892 + } 1.893 + 1.894 + public Symbol asMemberOf(Type site, Types types) { 1.895 + return new VarSymbol(flags_field, name, types.memberType(site, this), owner); 1.896 + } 1.897 + 1.898 + public ElementKind getKind() { 1.899 + long flags = flags(); 1.900 + if ((flags & PARAMETER) != 0) { 1.901 + if (isExceptionParameter()) 1.902 + return ElementKind.EXCEPTION_PARAMETER; 1.903 + else 1.904 + return ElementKind.PARAMETER; 1.905 + } else if ((flags & ENUM) != 0) { 1.906 + return ElementKind.ENUM_CONSTANT; 1.907 + } else if (owner.kind == TYP || owner.kind == ERR) { 1.908 + return ElementKind.FIELD; 1.909 + } else { 1.910 + return ElementKind.LOCAL_VARIABLE; 1.911 + } 1.912 + } 1.913 + 1.914 + public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1.915 + return v.visitVariable(this, p); 1.916 + } 1.917 + 1.918 + public Object getConstantValue() { // Mirror API 1.919 + return Constants.decode(getConstValue(), type); 1.920 + } 1.921 + 1.922 + public void setLazyConstValue(final Env<AttrContext> env, 1.923 + final Log log, 1.924 + final Attr attr, 1.925 + final JCTree.JCExpression initializer) 1.926 + { 1.927 + setData(new Callable<Object>() { 1.928 + public Object call() { 1.929 + JavaFileObject source = log.useSource(env.toplevel.sourcefile); 1.930 + try { 1.931 + // In order to catch self-references, we set 1.932 + // the variable's declaration position to 1.933 + // maximal possible value, effectively marking 1.934 + // the variable as undefined. 1.935 + int pos = VarSymbol.this.pos; 1.936 + VarSymbol.this.pos = Position.MAXPOS; 1.937 + Type itype = attr.attribExpr(initializer, env, type); 1.938 + VarSymbol.this.pos = pos; 1.939 + if (itype.constValue() != null) 1.940 + return attr.coerce(itype, type).constValue(); 1.941 + else 1.942 + return null; 1.943 + } finally { 1.944 + log.useSource(source); 1.945 + } 1.946 + } 1.947 + }); 1.948 + } 1.949 + 1.950 + /** 1.951 + * The variable's constant value, if this is a constant. 1.952 + * Before the constant value is evaluated, it points to an 1.953 + * initalizer environment. If this is not a constant, it can 1.954 + * be used for other stuff. 1.955 + */ 1.956 + private Object data; 1.957 + 1.958 + public boolean isExceptionParameter() { 1.959 + return data == ElementKind.EXCEPTION_PARAMETER; 1.960 + } 1.961 + 1.962 + public Object getConstValue() { 1.963 + // TODO: Consider if getConstValue and getConstantValue can be collapsed 1.964 + if (data == ElementKind.EXCEPTION_PARAMETER) { 1.965 + return null; 1.966 + } else if (data instanceof Callable<?>) { 1.967 + // In this case, this is final a variable, with an as 1.968 + // yet unevaluated initializer. 1.969 + Callable<?> eval = (Callable<?>)data; 1.970 + data = null; // to make sure we don't evaluate this twice. 1.971 + try { 1.972 + data = eval.call(); 1.973 + } catch (Exception ex) { 1.974 + throw new AssertionError(ex); 1.975 + } 1.976 + } 1.977 + return data; 1.978 + } 1.979 + 1.980 + public void setData(Object data) { 1.981 + assert !(data instanceof Env<?>) : this; 1.982 + this.data = data; 1.983 + } 1.984 + } 1.985 + 1.986 + /** A class for method symbols. 1.987 + */ 1.988 + public static class MethodSymbol extends Symbol implements ExecutableElement { 1.989 + 1.990 + /** The code of the method. */ 1.991 + public Code code = null; 1.992 + 1.993 + /** The parameters of the method. */ 1.994 + public List<VarSymbol> params = null; 1.995 + 1.996 + /** The names of the parameters */ 1.997 + public List<Name> savedParameterNames; 1.998 + 1.999 + /** For an attribute field accessor, its default value if any. 1.1000 + * The value is null if none appeared in the method 1.1001 + * declaration. 1.1002 + */ 1.1003 + public Attribute defaultValue = null; 1.1004 + 1.1005 + /** Construct a method symbol, given its flags, name, type and owner. 1.1006 + */ 1.1007 + public MethodSymbol(long flags, Name name, Type type, Symbol owner) { 1.1008 + super(MTH, flags, name, type, owner); 1.1009 + assert owner.type.tag != TYPEVAR : owner + "." + name; 1.1010 + } 1.1011 + 1.1012 + /** Clone this symbol with new owner. 1.1013 + */ 1.1014 + public MethodSymbol clone(Symbol newOwner) { 1.1015 + MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner); 1.1016 + m.code = code; 1.1017 + return m; 1.1018 + } 1.1019 + 1.1020 + /** The Java source which this symbol represents. 1.1021 + */ 1.1022 + public String toString() { 1.1023 + if ((flags() & BLOCK) != 0) { 1.1024 + return owner.name.toString(); 1.1025 + } else { 1.1026 + String s = (name == name.table.init) 1.1027 + ? owner.name.toString() 1.1028 + : name.toString(); 1.1029 + if (type != null) { 1.1030 + if (type.tag == FORALL) 1.1031 + s = "<" + ((ForAll)type).getTypeArguments() + ">" + s; 1.1032 + s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")"; 1.1033 + } 1.1034 + return s; 1.1035 + } 1.1036 + } 1.1037 + 1.1038 + /** find a symbol that this (proxy method) symbol implements. 1.1039 + * @param c The class whose members are searched for 1.1040 + * implementations 1.1041 + */ 1.1042 + public Symbol implemented(TypeSymbol c, Types types) { 1.1043 + Symbol impl = null; 1.1044 + for (List<Type> is = types.interfaces(c.type); 1.1045 + impl == null && is.nonEmpty(); 1.1046 + is = is.tail) { 1.1047 + TypeSymbol i = is.head.tsym; 1.1048 + for (Scope.Entry e = i.members().lookup(name); 1.1049 + impl == null && e.scope != null; 1.1050 + e = e.next()) { 1.1051 + if (this.overrides(e.sym, (TypeSymbol)owner, types, true) && 1.1052 + // FIXME: I suspect the following requires a 1.1053 + // subst() for a parametric return type. 1.1054 + types.isSameType(type.getReturnType(), 1.1055 + types.memberType(owner.type, e.sym).getReturnType())) { 1.1056 + impl = e.sym; 1.1057 + } 1.1058 + if (impl == null) 1.1059 + impl = implemented(i, types); 1.1060 + } 1.1061 + } 1.1062 + return impl; 1.1063 + } 1.1064 + 1.1065 + /** Will the erasure of this method be considered by the VM to 1.1066 + * override the erasure of the other when seen from class `origin'? 1.1067 + */ 1.1068 + public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) { 1.1069 + if (isConstructor() || _other.kind != MTH) return false; 1.1070 + 1.1071 + if (this == _other) return true; 1.1072 + MethodSymbol other = (MethodSymbol)_other; 1.1073 + 1.1074 + // check for a direct implementation 1.1075 + if (other.isOverridableIn((TypeSymbol)owner) && 1.1076 + types.asSuper(owner.type, other.owner) != null && 1.1077 + types.isSameType(erasure(types), other.erasure(types))) 1.1078 + return true; 1.1079 + 1.1080 + // check for an inherited implementation 1.1081 + return 1.1082 + (flags() & ABSTRACT) == 0 && 1.1083 + other.isOverridableIn(origin) && 1.1084 + this.isMemberOf(origin, types) && 1.1085 + types.isSameType(erasure(types), other.erasure(types)); 1.1086 + } 1.1087 + 1.1088 + /** The implementation of this (abstract) symbol in class origin, 1.1089 + * from the VM's point of view, null if method does not have an 1.1090 + * implementation in class. 1.1091 + * @param origin The class of which the implementation is a member. 1.1092 + */ 1.1093 + public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) { 1.1094 + for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) { 1.1095 + for (Scope.Entry e = c.members().lookup(name); 1.1096 + e.scope != null; 1.1097 + e = e.next()) { 1.1098 + if (e.sym.kind == MTH && 1.1099 + ((MethodSymbol)e.sym).binaryOverrides(this, origin, types)) 1.1100 + return (MethodSymbol)e.sym; 1.1101 + } 1.1102 + } 1.1103 + return null; 1.1104 + } 1.1105 + 1.1106 + /** Does this symbol override `other' symbol, when both are seen as 1.1107 + * members of class `origin'? It is assumed that _other is a member 1.1108 + * of origin. 1.1109 + * 1.1110 + * It is assumed that both symbols have the same name. The static 1.1111 + * modifier is ignored for this test. 1.1112 + * 1.1113 + * See JLS 8.4.6.1 (without transitivity) and 8.4.6.4 1.1114 + */ 1.1115 + public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) { 1.1116 + if (isConstructor() || _other.kind != MTH) return false; 1.1117 + 1.1118 + if (this == _other) return true; 1.1119 + MethodSymbol other = (MethodSymbol)_other; 1.1120 + 1.1121 + // check for a direct implementation 1.1122 + if (other.isOverridableIn((TypeSymbol)owner) && 1.1123 + types.asSuper(owner.type, other.owner) != null) { 1.1124 + Type mt = types.memberType(owner.type, this); 1.1125 + Type ot = types.memberType(owner.type, other); 1.1126 + if (types.isSubSignature(mt, ot)) { 1.1127 + if (!checkResult) 1.1128 + return true; 1.1129 + if (types.returnTypeSubstitutable(mt, ot)) 1.1130 + return true; 1.1131 + } 1.1132 + } 1.1133 + 1.1134 + // check for an inherited implementation 1.1135 + if ((flags() & ABSTRACT) != 0 || 1.1136 + (other.flags() & ABSTRACT) == 0 || 1.1137 + !other.isOverridableIn(origin) || 1.1138 + !this.isMemberOf(origin, types)) 1.1139 + return false; 1.1140 + 1.1141 + // assert types.asSuper(origin.type, other.owner) != null; 1.1142 + Type mt = types.memberType(origin.type, this); 1.1143 + Type ot = types.memberType(origin.type, other); 1.1144 + return 1.1145 + types.isSubSignature(mt, ot) && 1.1146 + (!checkResult || types.resultSubtype(mt, ot, Warner.noWarnings)); 1.1147 + } 1.1148 + 1.1149 + private boolean isOverridableIn(TypeSymbol origin) { 1.1150 + // JLS3 8.4.6.1 1.1151 + switch ((int)(flags_field & Flags.AccessFlags)) { 1.1152 + case Flags.PRIVATE: 1.1153 + return false; 1.1154 + case Flags.PUBLIC: 1.1155 + return true; 1.1156 + case Flags.PROTECTED: 1.1157 + return (origin.flags() & INTERFACE) == 0; 1.1158 + case 0: 1.1159 + // for package private: can only override in the same 1.1160 + // package 1.1161 + return 1.1162 + this.packge() == origin.packge() && 1.1163 + (origin.flags() & INTERFACE) == 0; 1.1164 + default: 1.1165 + return false; 1.1166 + } 1.1167 + } 1.1168 + 1.1169 + /** The implementation of this (abstract) symbol in class origin; 1.1170 + * null if none exists. Synthetic methods are not considered 1.1171 + * as possible implementations. 1.1172 + */ 1.1173 + public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { 1.1174 + for (Type t = origin.type; t.tag == CLASS; t = types.supertype(t)) { 1.1175 + TypeSymbol c = t.tsym; 1.1176 + for (Scope.Entry e = c.members().lookup(name); 1.1177 + e.scope != null; 1.1178 + e = e.next()) { 1.1179 + if (e.sym.kind == MTH) { 1.1180 + MethodSymbol m = (MethodSymbol) e.sym; 1.1181 + if (m.overrides(this, origin, types, checkResult) && 1.1182 + (m.flags() & SYNTHETIC) == 0) 1.1183 + return m; 1.1184 + } 1.1185 + } 1.1186 + } 1.1187 + // if origin is derived from a raw type, we might have missed 1.1188 + // an implementation because we do not know enough about instantiations. 1.1189 + // in this case continue with the supertype as origin. 1.1190 + if (types.isDerivedRaw(origin.type)) 1.1191 + return implementation(types.supertype(origin.type).tsym, types, checkResult); 1.1192 + else 1.1193 + return null; 1.1194 + } 1.1195 + 1.1196 + public List<VarSymbol> params() { 1.1197 + owner.complete(); 1.1198 + if (params == null) { 1.1199 + List<Name> names = savedParameterNames; 1.1200 + savedParameterNames = null; 1.1201 + if (names == null) { 1.1202 + names = List.nil(); 1.1203 + int i = 0; 1.1204 + for (Type t : type.getParameterTypes()) 1.1205 + names = names.prepend(name.table.fromString("arg" + i++)); 1.1206 + names = names.reverse(); 1.1207 + } 1.1208 + ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>(); 1.1209 + for (Type t : type.getParameterTypes()) { 1.1210 + buf.append(new VarSymbol(PARAMETER, names.head, t, this)); 1.1211 + names = names.tail; 1.1212 + } 1.1213 + params = buf.toList(); 1.1214 + } 1.1215 + return params; 1.1216 + } 1.1217 + 1.1218 + public Symbol asMemberOf(Type site, Types types) { 1.1219 + return new MethodSymbol(flags_field, name, types.memberType(site, this), owner); 1.1220 + } 1.1221 + 1.1222 + public ElementKind getKind() { 1.1223 + if (name == name.table.init) 1.1224 + return ElementKind.CONSTRUCTOR; 1.1225 + else if (name == name.table.clinit) 1.1226 + return ElementKind.STATIC_INIT; 1.1227 + else 1.1228 + return ElementKind.METHOD; 1.1229 + } 1.1230 + 1.1231 + public Attribute getDefaultValue() { 1.1232 + return defaultValue; 1.1233 + } 1.1234 + 1.1235 + public List<VarSymbol> getParameters() { 1.1236 + return params(); 1.1237 + } 1.1238 + 1.1239 + public boolean isVarArgs() { 1.1240 + return (flags() & VARARGS) != 0; 1.1241 + } 1.1242 + 1.1243 + public <R, P> R accept(ElementVisitor<R, P> v, P p) { 1.1244 + return v.visitExecutable(this, p); 1.1245 + } 1.1246 + 1.1247 + public Type getReturnType() { 1.1248 + return asType().getReturnType(); 1.1249 + } 1.1250 + 1.1251 + public List<Type> getThrownTypes() { 1.1252 + return asType().getThrownTypes(); 1.1253 + } 1.1254 + } 1.1255 + 1.1256 + /** A class for predefined operators. 1.1257 + */ 1.1258 + public static class OperatorSymbol extends MethodSymbol { 1.1259 + 1.1260 + public int opcode; 1.1261 + 1.1262 + public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) { 1.1263 + super(PUBLIC | STATIC, name, type, owner); 1.1264 + this.opcode = opcode; 1.1265 + } 1.1266 + } 1.1267 + 1.1268 + /** Symbol completer interface. 1.1269 + */ 1.1270 + public static interface Completer { 1.1271 + void complete(Symbol sym) throws CompletionFailure; 1.1272 + } 1.1273 + 1.1274 + public static class CompletionFailure extends RuntimeException { 1.1275 + private static final long serialVersionUID = 0; 1.1276 + public Symbol sym; 1.1277 + 1.1278 + /** A localized string describing the failure. 1.1279 + */ 1.1280 + public String errmsg; 1.1281 + 1.1282 + public CompletionFailure(Symbol sym, String errmsg) { 1.1283 + this.sym = sym; 1.1284 + this.errmsg = errmsg; 1.1285 +// this.printStackTrace();//DEBUG 1.1286 + } 1.1287 + 1.1288 + public String getMessage() { 1.1289 + return errmsg; 1.1290 + } 1.1291 + 1.1292 + @Override 1.1293 + public CompletionFailure initCause(Throwable cause) { 1.1294 + super.initCause(cause); 1.1295 + return this; 1.1296 + } 1.1297 + 1.1298 + } 1.1299 +}