com.sun.tools.javac.code
Class Symbol

java.lang.Object
  extended by com.sun.tools.javac.code.Symbol
All Implemented Interfaces:
Element
Direct Known Subclasses:
Resolve.ResolveError, Symbol.DelegatedSymbol, Symbol.MethodSymbol, Symbol.TypeSymbol, Symbol.VarSymbol

public abstract class Symbol
extends java.lang.Object
implements Element

Root class for Java symbols. It contains subclasses for specific sorts of symbols, such as variables, methods and operators, types, packages. Each subclass is represented as a static inner class inside Symbol.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Nested Class Summary
static class Symbol.ClassSymbol
          A class for class symbols
static interface Symbol.Completer
          Symbol completer interface.
static class Symbol.CompletionFailure
           
static class Symbol.DelegatedSymbol
           
static class Symbol.Level
           
static class Symbol.MethodSymbol
          A class for method symbols.
static class Symbol.OperatorSymbol
          A class for predefined operators.
static class Symbol.PackageSymbol
          A class for package symbols
static class Symbol.TypeSymbol
          A class for type symbols.
static class Symbol.VarSymbol
          A class for variable symbols
static interface Symbol.Visitor<R,P>
          A visitor for symbols.
 
Field Summary
 List<Attribute.Compound> attributes_field
          The attributes of this symbol.
 Symbol.Completer completer
          The completer of this symbol.
 Type erasure_field
          A cache for the type erasure of this symbol.
 long flags_field
          The flags of this symbol.
 int kind
          The kind of this symbol.
 Symbol.Level level
           
 Name name
          The name of this symbol in Utf8 representation.
 Symbol owner
          The owner of this symbol.
 Type type
          The type of this symbol.
 
Constructor Summary
Symbol(int kind, long flags, Name name, Type type, Symbol owner)
          Construct a symbol with given kind, flags, name, type and owner.
 
Method Summary
<R,P> R
accept(Symbol.Visitor<R,P> v, P p)
           
 void addParentLevel(Symbol.Level l)
           
 Symbol asMemberOf(Type site, Types types)
          The (variable or method) symbol seen as a member of given class type`site' (this might change the symbol's type).
 Type asType()
          Returns the type defined by this element.
 Attribute.Compound attribute(Symbol anno)
          Fetch a particular annotation from a symbol.
 Symbol clone(Symbol newOwner)
          Clone this symbol with new owner.
 void complete()
          Complete the elaboration of this symbol's definition.
 Symbol.ClassSymbol enclClass()
          The closest enclosing class of this symbol's declaration.
 Type erasure(Types types)
          The symbol's erased type.
 boolean exists()
          True if the symbol represents an entity that exists.
 Type externalType(Types types)
          The external type of a symbol.
 long flags()
          An accessor method for the flags of this symbol.
 Name flatName()
          The fully qualified name of this symbol after converting to flat representation.
<A extends java.lang.annotation.Annotation>
A
getAnnotation(java.lang.Class<A> annoType)
          Deprecated. this method should never be used by javac internally.
 List<Attribute.Compound> getAnnotationMirrors()
          An accessor method for the attributes of this symbol.
 java.util.List<Symbol> getEnclosedElements()
          Returns the elements that are, loosely speaking, directly enclosed by this element.
 Symbol getEnclosingElement()
          Returns the innermost element within which this element is, loosely speaking, enclosed.
 ElementKind getKind()
          Returns the kind of this element.
 int getLevel()
           
 java.util.Set<Modifier> getModifiers()
          Returns the modifiers of this element, excluding annotations.
 Name getQualifiedName()
          The fully qualified name of this symbol.
 Name getSimpleName()
          Returns the simple (unqualified) name of this element.
 List<Symbol.TypeSymbol> getTypeParameters()
           
 boolean hasOuterInstance()
          An inner class has an outer instance if it is not an interface it has an enclosing instance class which might be referenced from the class.
private  boolean hiddenIn(Symbol.ClassSymbol clazz, Types types)
          Check for hiding.
 boolean isConstructor()
          Is this symbol a constructor?
 boolean isEnclosedBy(Symbol.ClassSymbol clazz)
          Is this symbol the same as or enclosed by the given class?
 boolean isInheritedIn(Symbol clazz, Types types)
          Is this symbol inherited into a given class? PRE: If symbol's owner is a interface, it is already assumed that the interface is a superinterface of given class.
 boolean isInner()
          A class is an inner class if it it has an enclosing instance class.
 boolean isInterface()
           
 boolean isLocal()
          Is this symbol declared (directly or indirectly) local to a method or variable initializer? Also includes fields of inner classes which are in turn local to a method or variable initializer.
 boolean isMemberOf(Symbol.TypeSymbol clazz, Types types)
          Fully check membership: hierarchy, protection, and hiding.
 boolean isStatic()
           
 boolean isSubClass(Symbol base, Types types)
          Is this symbol a subclass of `base'? Only defined for ClassSymbols.
 Symbol location()
          A Java source description of the location of this symbol; used for error reporting.
 Symbol location(Type site, Types types)
           
 Scope members()
          If this is a class or package, its members, otherwise null.
 Symbol.ClassSymbol outermostClass()
          The outermost class which indirectly owns this symbol.
 boolean overrides(Symbol _other, Symbol.TypeSymbol origin, Types types, boolean checkResult)
          Does this method symbol override `other' symbol, when both are seen as members of class `origin'? It is assumed that _other is a member of origin.
 Symbol.PackageSymbol packge()
          The package which indirectly owns this symbol.
 void removeParentLevel(Symbol.Level l)
           
 java.lang.String toString()
          The Java source which this symbol represents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.lang.model.element.Element
accept, equals, hashCode
 

Field Detail

kind

public int kind
The kind of this symbol.

See Also:
Kinds

flags_field

public long flags_field
The flags of this symbol.


attributes_field

public List<Attribute.Compound> attributes_field
The attributes of this symbol.


name

public Name name
The name of this symbol in Utf8 representation.


type

public Type type
The type of this symbol.


owner

public Symbol owner
The owner of this symbol.


completer

public Symbol.Completer completer
The completer of this symbol.


erasure_field

public Type erasure_field
A cache for the type erasure of this symbol.


level

public Symbol.Level level
Constructor Detail

Symbol

public Symbol(int kind,
              long flags,
              Name name,
              Type type,
              Symbol owner)
Construct a symbol with given kind, flags, name, type and owner.

Method Detail

flags

public long flags()
An accessor method for the flags of this symbol. Flags of class symbols should be accessed through the accessor method to make sure that the class symbol is loaded.


getAnnotationMirrors

public List<Attribute.Compound> getAnnotationMirrors()
An accessor method for the attributes of this symbol. Attributes of class symbols should be accessed through the accessor method to make sure that the class symbol is loaded.

Specified by:
getAnnotationMirrors in interface Element
Returns:
the annotations directly present on this element; an empty list if there are none
See Also:
ElementFilter

attribute

public Attribute.Compound attribute(Symbol anno)
Fetch a particular annotation from a symbol.


clone

public Symbol clone(Symbol newOwner)
Clone this symbol with new owner. Legal only for fields and methods.


accept

public <R,P> R accept(Symbol.Visitor<R,P> v,
                      P p)

toString

public java.lang.String toString()
The Java source which this symbol represents. A description of this symbol; overrides Object.

Overrides:
toString in class java.lang.Object

getLevel

public int getLevel()

addParentLevel

public void addParentLevel(Symbol.Level l)

removeParentLevel

public void removeParentLevel(Symbol.Level l)

location

public Symbol location()
A Java source description of the location of this symbol; used for error reporting.

Returns:
null if the symbol is a package or a toplevel class defined in the default package; otherwise, the owner symbol is returned

location

public Symbol location(Type site,
                       Types types)

erasure

public Type erasure(Types types)
The symbol's erased type.


externalType

public Type externalType(Types types)
The external type of a symbol. This is the symbol's erased type except for constructors of inner classes which get the enclosing instance class added as first argument.


isStatic

public boolean isStatic()

isInterface

public boolean isInterface()

isLocal

public boolean isLocal()
Is this symbol declared (directly or indirectly) local to a method or variable initializer? Also includes fields of inner classes which are in turn local to a method or variable initializer.


isConstructor

public boolean isConstructor()
Is this symbol a constructor?


getQualifiedName

public Name getQualifiedName()
The fully qualified name of this symbol. This is the same as the symbol's name except for class symbols, which are handled separately.


flatName

public Name flatName()
The fully qualified name of this symbol after converting to flat representation. This is the same as the symbol's name except for class symbols, which are handled separately.


members

public Scope members()
If this is a class or package, its members, otherwise null.


isInner

public boolean isInner()
A class is an inner class if it it has an enclosing instance class.


hasOuterInstance

public boolean hasOuterInstance()
An inner class has an outer instance if it is not an interface it has an enclosing instance class which might be referenced from the class. Nested classes can see instance members of their enclosing class. Their constructors carry an additional this$n parameter, inserted implicitly by the compiler.

See Also:
isInner()

enclClass

public Symbol.ClassSymbol enclClass()
The closest enclosing class of this symbol's declaration.


outermostClass

public Symbol.ClassSymbol outermostClass()
The outermost class which indirectly owns this symbol.


packge

public Symbol.PackageSymbol packge()
The package which indirectly owns this symbol.


isSubClass

public boolean isSubClass(Symbol base,
                          Types types)
Is this symbol a subclass of `base'? Only defined for ClassSymbols.


isMemberOf

public boolean isMemberOf(Symbol.TypeSymbol clazz,
                          Types types)
Fully check membership: hierarchy, protection, and hiding. Does not exclude methods not inherited due to overriding.


isEnclosedBy

public boolean isEnclosedBy(Symbol.ClassSymbol clazz)
Is this symbol the same as or enclosed by the given class?


hiddenIn

private boolean hiddenIn(Symbol.ClassSymbol clazz,
                         Types types)
Check for hiding. Note that this doesn't handle multiple (interface) inheritance.


isInheritedIn

public boolean isInheritedIn(Symbol clazz,
                             Types types)
Is this symbol inherited into a given class? PRE: If symbol's owner is a interface, it is already assumed that the interface is a superinterface of given class.

Parameters:
clazz - The class for which we want to establish membership. This must be a subclass of the member's owner.

asMemberOf

public Symbol asMemberOf(Type site,
                         Types types)
The (variable or method) symbol seen as a member of given class type`site' (this might change the symbol's type). This is used exclusively for producing diagnostics.


overrides

public boolean overrides(Symbol _other,
                         Symbol.TypeSymbol origin,
                         Types types,
                         boolean checkResult)
Does this method symbol override `other' symbol, when both are seen as members of class `origin'? It is assumed that _other is a member of origin. It is assumed that both symbols have the same name. The static modifier is ignored for this test. See JLS 8.4.6.1 (without transitivity) and 8.4.6.4


complete

public void complete()
              throws Symbol.CompletionFailure
Complete the elaboration of this symbol's definition.

Throws:
Symbol.CompletionFailure

exists

public boolean exists()
True if the symbol represents an entity that exists.


asType

public Type asType()
Description copied from interface: Element
Returns the type defined by this element.

A generic element defines a family of types, not just one. If this is a generic element, a prototypical type is returned. This is the element's invocation on the type variables corresponding to its own formal type parameters. For example, for the generic class element C<N extends Number>, the parameterized type C<N> is returned. The Types utility interface has more general methods for obtaining the full range of types defined by an element.

Specified by:
asType in interface Element
Returns:
the type defined by this element
See Also:
Types

getEnclosingElement

public Symbol getEnclosingElement()
Description copied from interface: Element
Returns the innermost element within which this element is, loosely speaking, enclosed.

Specified by:
getEnclosingElement in interface Element
Returns:
the enclosing element, or null if there is none
See Also:
Elements.getPackageOf(javax.lang.model.element.Element)

getKind

public ElementKind getKind()
Description copied from interface: Element
Returns the kind of this element.

Specified by:
getKind in interface Element
Returns:
the kind of this element

getModifiers

public java.util.Set<Modifier> getModifiers()
Description copied from interface: Element
Returns the modifiers of this element, excluding annotations. Implicit modifiers, such as the public and static modifiers of interface members, are included.

Specified by:
getModifiers in interface Element
Returns:
the modifiers of this element, or an empty set if there are none

getSimpleName

public Name getSimpleName()
Description copied from interface: Element
Returns the simple (unqualified) name of this element. The name of a generic type does not include any reference to its formal type parameters. For example, the simple name of the type element java.util.Set<E> is "Set". If this element represents an unnamed package, an empty name is returned. If it represents a constructor, the name "<init>" is returned. If it represents a static initializer, the name "<clinit>" is returned. If it represents an anonymous class or instance initializer, an empty name is returned.

Specified by:
getSimpleName in interface Element
Returns:
the simple name of this element

getAnnotation

@Deprecated
public <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.Class<A> annoType)
Deprecated. this method should never be used by javac internally.

Description copied from interface: Element
Returns this element's annotation for the specified type if such an annotation is present, else null. The annotation may be either inherited or directly present on this element.

The annotation returned by this method could contain an element whose value is of type Class. This value cannot be returned directly: information necessary to locate and load a class (such as the class loader to use) is not available, and the class might not be loadable at all. Attempting to read a Class object by invoking the relevant method on the returned annotation will result in a MirroredTypeException, from which the corresponding TypeMirror may be extracted. Similarly, attempting to read a Class[]-valued element will result in a MirroredTypesException.

Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation types currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation types.

Specified by:
getAnnotation in interface Element
Type Parameters:
A - the annotation type
Parameters:
annoType - the Class object corresponding to the annotation type
Returns:
this element's annotation for the specified annotation type if present on this element, else null
See Also:
Element.getAnnotationMirrors(), AnnotatedElement.getAnnotation(java.lang.Class), EnumConstantNotPresentException, AnnotationTypeMismatchException, IncompleteAnnotationException, MirroredTypeException, MirroredTypesException

getEnclosedElements

public java.util.List<Symbol> getEnclosedElements()
Description copied from interface: Element
Returns the elements that are, loosely speaking, directly enclosed by this element. A class or interface is considered to enclose the fields, methods, constructors, and member types that it directly declares. This includes any (implicit) default constructor and the implicit values and valueOf methods of an enum type. A package encloses the top-level classes and interfaces within it, but is not considered to enclose subpackages. Other kinds of elements are not currently considered to enclose any elements; however, that may change as this API or the programming language evolves.

Note that elements of certain kinds can be isolated using methods in ElementFilter.

Specified by:
getEnclosedElements in interface Element
Returns:
the enclosed elements, or an empty list if none
See Also:
Elements.getAllMembers(javax.lang.model.element.TypeElement)

getTypeParameters

public List<Symbol.TypeSymbol> getTypeParameters()