public class

ClassDefinition

extends Object
implements Constants
java.lang.Object
   ↳ sun.tools.java.ClassDefinition
Known Direct Subclasses

Class Overview

This class is a Java class definition WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.

Summary

[Expand]
Inherited Constants
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Fields
protected Context classContext
protected ClassDeclaration declaration
protected static boolean doInheritanceChecks A flag used by turnOffInheritanceChecks() to indicate if inheritance checks are on or off.
protected String documentation
protected boolean error
protected MemberDefinition firstMember
protected MemberDefinition innerClassMember
protected IdentifierToken[] interfaceIds
protected ClassDeclaration[] interfaces
protected MemberDefinition lastMember
protected Identifier localName
protected int modifiers
protected boolean nestError
protected ClassDefinition outerClass
protected MemberDefinition outerMember
protected UplevelReference references
protected boolean referencesFrozen
protected boolean resolved
protected Object source
protected ClassDeclaration superClass
protected IdentifierToken superClassId
protected boolean supersCheckStarted
protected long where
[Expand]
Inherited Fields
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Protected Constructors
ClassDefinition(Object source, long where, ClassDeclaration declaration, int modifiers, IdentifierToken superClass, IdentifierToken[] interfaces)
Constructor
Public Methods
void addDependency(ClassDeclaration c)
Add a dependency
void addLocalClass(ClassDefinition c, String name)
void addMember(Environment env, MemberDefinition field)
Add a field (subclasses make checks)
void addMember(MemberDefinition field)
Add a field (no checks)
final void addModifiers(int mod)
boolean canAccess(Environment env, ClassDeclaration c)
Check if another class can be accessed from within the body of this class.
boolean canAccess(Environment env, MemberDefinition f)
Check if a field can be accessed from a class
void check(Environment env)
Check this class.
Vset checkLocalClass(Environment env, Context ctx, Vset vset, ClassDefinition sup, Expression[] args, Type[] argTypes)
void cleanup(Environment env)
After the class has been written to disk, try to free up some storage.
static boolean containsDeprecated(String documentation)
Return true if the given documentation string contains a deprecation paragraph.
boolean couldImplement(ClassDefinition intDef)
Check to see if a class which implements interface `this' could possibly implement the interface `intDef'.
int diagnoseMismatch(Environment env, Identifier nm, Type[] argTypes, int start, Type[] margTypeResult)
Given the fact that this class has no method "nm" matching "argTypes", find out if the mismatch can be blamed on a particular actual argument which disagrees with all of the overloadings.
boolean enclosingClassOf(ClassDefinition otherClass)
Check if this is an enclosing class of another class
boolean extendsCanAccess(Environment env, ClassDeclaration c)
Check if another class can be accessed from the 'extends' or 'implements' clause of this class.
MemberDefinition findAnyMethod(Environment env, Identifier nm)
Find any method with a given name.
MemberDefinition findMethod(Environment env, Identifier nm, Type t)
Find a method, ie: exact match in this class or any of the super classes.
final MemberDefinition findOuterMember()
If inner, return an innermost uplevel self pointer, if any exists.
MemberDefinition getAccessMember(Environment env, Context ctx, MemberDefinition field, boolean isSuper)
Find or create an access method for a private member, or return null if this is not possible.
Context getClassContext()
final ClassDeclaration getClassDeclaration()
Get the class declaration
MemberDefinition getClassLiteralLookup(long fwhere)
Get helper method for class literal lookup.
String getDocumentation()
Get the class' documentation
final boolean getError()
Check if there were any errors in this class.
final MemberDefinition getFirstMatch(Identifier name)
final MemberDefinition getFirstMember()
Get the class' first field or first match
MemberDefinition getInnerClass(Environment env, Identifier nm)
Get an inner class.
final MemberDefinition getInnerClassMember()
If inner, get the field for this class in the enclosing class
final ClassDeclaration[] getInterfaces()
Get the class' interfaces
ClassDefinition getLocalClass(String name)
Maintain a hash table of local and anonymous classes whose internal names are prefixed by the current class.
Identifier getLocalName()
Return a simple identifier for this class (idNull if anonymous).
Iterator getMethods(Environment env)
Get an Iterator of all methods which could be accessed in an instance of this class.
Iterator getMethods()
Get an Iterator of all methods which could be accessed in an instance of this class.
final int getModifiers()
Get the class' modifiers
final Identifier getName()
Get the class' name
final boolean getNestError()
Check if there were any errors in our class nest.
final ClassDefinition getOuterClass()
Get the class' enclosing class (or null if not inner)
UplevelReference getReference(LocalMember target)
Find or create an uplevel reference for the given target.
UplevelReference getReferences()
Return the list of all uplevel references.
UplevelReference getReferencesFrozen()
Return the same value as getReferences.
final Object getSource()
Get the source of the class
final ClassDeclaration getSuperClass()
Get the class' super class
ClassDeclaration getSuperClass(Environment env)
Get the super class, and resolve names now if necessary.
final ClassDefinition getTopClass()
Get the class' top-level enclosing class
final Type getType()
Get the class' type
MemberDefinition getUpdateMember(Environment env, Context ctx, MemberDefinition field, boolean isSuper)
Find or create an update method for a private member, or return null if this is not possible.
MemberDefinition getVariable(Environment env, Identifier nm, ClassDefinition source)
Get a field from this class.
final long getWhere()
Get the position in the input
final boolean hasConstructor()
boolean implementedBy(Environment env, ClassDeclaration c)
Check if this class is implemented by another class
final boolean inSamePackage(Identifier packageName)
final boolean inSamePackage(ClassDefinition c)
final boolean inSamePackage(ClassDeclaration c)
void inlineLocalClass(Environment env)
boolean innerClassExists(Identifier nm)
While resolving import directives, the question has arisen: does a given inner class exist? If the top-level class exists, we ask it about an inner class via this method.
final boolean isAbstract()
final boolean isAnonymous()
final boolean isClass()
final boolean isDeprecated()
final boolean isFinal()
final boolean isInnerClass()
Tell if the class is inner.
final boolean isInsideLocal()
Tell if the class is local or inside a local class, which means it cannot be mentioned outside of its file.
final boolean isInsideLocalOrAnonymous()
Tell if the class is local or or anonymous class, or inside such a class, which means it cannot be mentioned outside of its file.
final boolean isInterface()
Checks
final boolean isLocal()
final boolean isMember()
Tell if the class is a member of another class.
final boolean isPackagePrivate()
final boolean isPrivate()
final boolean isProtected()
final boolean isPublic()
final boolean isStatic()
See if this is a (nested) static class.
final boolean isSynthetic()
final boolean isTopLevel()
Tell if the class is "top-level", which is either a package member, or a static member of another top-level class.
MemberDefinition matchAnonConstructor(Environment env, Identifier accessPackage, Type[] argumentTypes)
A version of matchMethod to be used only for constructors when we cannot pass in a sourceClass argument.
MemberDefinition matchMethod(Environment env, ClassDefinition accessor, Identifier methodName, Type[] argumentTypes)
Lookup a method.
MemberDefinition matchMethod(Environment env, ClassDefinition accessor, Identifier methodName)
Lookup a method.
final boolean mustBeAbstract(Environment env)
Check to see if a class must be abstract.
void noteUsedBy(ClassDefinition ref, long where, Environment env)
Note that this class is being used somehow by ref.
boolean permitInlinedAccess(Environment env, MemberDefinition f)
Check if a class is entitled to inline access to a method from another class.
boolean permitInlinedAccess(Environment env, ClassDeclaration c)
Check if a class is entitled to inline access to a class from another class.
void print(PrintStream out)
Print for debugging
boolean protectedAccess(Environment env, MemberDefinition f, Type accessorType)
We know the the field is marked protected (and not public) and that the field is visible (as per canAccess).
final void referencesMustNotBeFrozen()
assertion check
boolean reportDeprecated(Environment env)
Tells whether to report a deprecation error for this class.
Identifier resolveInnerClass(Environment env, Identifier nm)
Interpret a qualified class name, which may have further subcomponents..
Identifier resolveName(Environment env, Identifier name)
Look up an inner class name, from somewhere inside this class.
void resolveTypeStructure(Environment env)
We create a stub for this.
final void setError()
Mark this class to be erroneous.
void setLocalName(Identifier name)
Set the local name of a class.
final void setNestError()
Mark this class, and all siblings in its class nest, to be erroneous.
boolean subClassOf(Environment env, ClassDeclaration otherClass)
Check if this is a sub class of another class
final void subModifiers(int mod)
boolean superClassOf(Environment env, ClassDeclaration otherClass)
Check if this is a super class of another class
String toString()
Convert to String
static void turnOffInheritanceChecks()
This is a workaround to allow javadoc to turn off certain inheritance/override checks which interfere with javadoc badly.
Protected Methods
void addMirandaMethods(Environment env, Iterator mirandas)
Add a list of methods to this class as miranda methods.
UplevelReference addReference(LocalMember target)
void basicCheck(Environment env)
void collectInheritedMethods(Environment env)

Collect all methods defined in this class or inherited from any of our superclasses or interfaces.

Iterator getPermanentlyAbstractMethods()
This method returns an Iterator of all abstract methods in our superclasses which we are unable to implement.
final void setOuterClass(ClassDefinition outerClass)
Set the class' enclosing class.
final void setOuterMember(MemberDefinition outerMember)
Set the class' enclosing current instance pointer.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected Context classContext

protected ClassDeclaration declaration

protected static boolean doInheritanceChecks

A flag used by turnOffInheritanceChecks() to indicate if inheritance checks are on or off.

protected String documentation

protected boolean error

protected MemberDefinition firstMember

protected MemberDefinition innerClassMember

protected IdentifierToken[] interfaceIds

protected ClassDeclaration[] interfaces

protected MemberDefinition lastMember

protected Identifier localName

protected int modifiers

protected boolean nestError

protected ClassDefinition outerClass

protected MemberDefinition outerMember

protected UplevelReference references

protected boolean referencesFrozen

protected boolean resolved

protected Object source

protected ClassDeclaration superClass

protected IdentifierToken superClassId

protected boolean supersCheckStarted

protected long where

Protected Constructors

protected ClassDefinition (Object source, long where, ClassDeclaration declaration, int modifiers, IdentifierToken superClass, IdentifierToken[] interfaces)

Constructor

Public Methods

public void addDependency (ClassDeclaration c)

Add a dependency

public void addLocalClass (ClassDefinition c, String name)

public void addMember (Environment env, MemberDefinition field)

Add a field (subclasses make checks)

public void addMember (MemberDefinition field)

Add a field (no checks)

public final void addModifiers (int mod)

public boolean canAccess (Environment env, ClassDeclaration c)

Check if another class can be accessed from within the body of this class.

Throws
ClassNotFound

public boolean canAccess (Environment env, MemberDefinition f)

Check if a field can be accessed from a class

Throws
ClassNotFound

public void check (Environment env)

Check this class.

Throws
ClassNotFound

public Vset checkLocalClass (Environment env, Context ctx, Vset vset, ClassDefinition sup, Expression[] args, Type[] argTypes)

Throws
ClassNotFound

public void cleanup (Environment env)

After the class has been written to disk, try to free up some storage.

public static boolean containsDeprecated (String documentation)

Return true if the given documentation string contains a deprecation paragraph. This is true if the string contains the tag @deprecated is the first word in a line.

public boolean couldImplement (ClassDefinition intDef)

Check to see if a class which implements interface `this' could possibly implement the interface `intDef'. Note that the only way that this can fail is if `this' and `intDef' have methods which are of the same signature and different return types. This method is used by Environment.explicitCast() to determine if a cast between two interfaces is legal. This method should only be called on a class after it has been basicCheck()'ed.

public int diagnoseMismatch (Environment env, Identifier nm, Type[] argTypes, int start, Type[] margTypeResult)

Given the fact that this class has no method "nm" matching "argTypes", find out if the mismatch can be blamed on a particular actual argument which disagrees with all of the overloadings. If so, return the code (i<<2)+(castOK<<1)+ambig, where "i" is the number of the offending argument, and "castOK" is 1 if a cast could fix the problem. The target type for the argument is returned in margTypeResult[0]. If not all methods agree on this type, "ambig" is 1. If there is more than one method, the choice of target type is arbitrary.

Return -1 if every argument is acceptable to at least one method. Return -2 if there are no methods of the required arity. The value "start" gives the index of the first argument to begin checking.

Throws
ClassNotFound

public boolean enclosingClassOf (ClassDefinition otherClass)

Check if this is an enclosing class of another class

public boolean extendsCanAccess (Environment env, ClassDeclaration c)

Check if another class can be accessed from the 'extends' or 'implements' clause of this class.

Throws
ClassNotFound

public MemberDefinition findAnyMethod (Environment env, Identifier nm)

Find any method with a given name.

Throws
ClassNotFound

public MemberDefinition findMethod (Environment env, Identifier nm, Type t)

Find a method, ie: exact match in this class or any of the super classes. Only called by javadoc. For now I am holding off rewriting this code to rely on collectInheritedMethods(), as that code has not gotten along with javadoc in the past.

Throws
ClassNotFound

public final MemberDefinition findOuterMember ()

If inner, return an innermost uplevel self pointer, if any exists. Otherwise, return null.

public MemberDefinition getAccessMember (Environment env, Context ctx, MemberDefinition field, boolean isSuper)

Find or create an access method for a private member, or return null if this is not possible.

public Context getClassContext ()

public final ClassDeclaration getClassDeclaration ()

Get the class declaration

public MemberDefinition getClassLiteralLookup (long fwhere)

Get helper method for class literal lookup.

public String getDocumentation ()

Get the class' documentation

public final boolean getError ()

Check if there were any errors in this class.

public final MemberDefinition getFirstMatch (Identifier name)

public final MemberDefinition getFirstMember ()

Get the class' first field or first match

public MemberDefinition getInnerClass (Environment env, Identifier nm)

Get an inner class. Look in supers but not outers. (This is used directly to resolve expressions like "site.K", and inside a loop to resolve lone names like "K" or the "K" in "K.L".) Called from 'Context' and 'FieldExpression' as well as this class.

Throws
ClassNotFound
See Also
  • FieldExpression.checkCommon
  • resolveName

public final MemberDefinition getInnerClassMember ()

If inner, get the field for this class in the enclosing class

public final ClassDeclaration[] getInterfaces ()

Get the class' interfaces

public ClassDefinition getLocalClass (String name)

Maintain a hash table of local and anonymous classes whose internal names are prefixed by the current class. The key is the simple internal name, less the prefix.

public Identifier getLocalName ()

Return a simple identifier for this class (idNull if anonymous).

public Iterator getMethods (Environment env)

Get an Iterator of all methods which could be accessed in an instance of this class.

public Iterator getMethods ()

Get an Iterator of all methods which could be accessed in an instance of this class. Throw a compiler error if we haven't generated this information yet.

public final int getModifiers ()

Get the class' modifiers

public final Identifier getName ()

Get the class' name

public final boolean getNestError ()

Check if there were any errors in our class nest.

public final ClassDefinition getOuterClass ()

Get the class' enclosing class (or null if not inner)

public UplevelReference getReference (LocalMember target)

Find or create an uplevel reference for the given target.

public UplevelReference getReferences ()

Return the list of all uplevel references.

public UplevelReference getReferencesFrozen ()

Return the same value as getReferences. Also, mark the set of references frozen. After that, it is an error to add new references.

public final Object getSource ()

Get the source of the class

public final ClassDeclaration getSuperClass ()

Get the class' super class

public ClassDeclaration getSuperClass (Environment env)

Get the super class, and resolve names now if necessary. It is only possible to resolve names at this point if we are a source class. The provision of this method at this level in the class hierarchy is dubious, but see 'getInnerClass' below. All other calls to 'getSuperClass(env)' appear in 'SourceClass'. NOTE: An older definition of this method has been moved to 'SourceClass', where it overrides this one.

public final ClassDefinition getTopClass ()

Get the class' top-level enclosing class

public final Type getType ()

Get the class' type

public MemberDefinition getUpdateMember (Environment env, Context ctx, MemberDefinition field, boolean isSuper)

Find or create an update method for a private member, or return null if this is not possible.

public MemberDefinition getVariable (Environment env, Identifier nm, ClassDefinition source)

Get a field from this class. Report ambiguous fields. If no accessible field is found, this method may return an inaccessible field to allow a useful error message. getVariable now takes the source class `source' as an argument. This allows getVariable to check whether a field is inaccessible before it signals that a field is ambiguous. The compiler used to signal an ambiguity even when one of the fields involved was not accessible. (bug 4053724)

public final long getWhere ()

Get the position in the input

public final boolean hasConstructor ()

public boolean implementedBy (Environment env, ClassDeclaration c)

Check if this class is implemented by another class

Throws
ClassNotFound

public final boolean inSamePackage (Identifier packageName)

public final boolean inSamePackage (ClassDefinition c)

public final boolean inSamePackage (ClassDeclaration c)

public void inlineLocalClass (Environment env)

public boolean innerClassExists (Identifier nm)

While resolving import directives, the question has arisen: does a given inner class exist? If the top-level class exists, we ask it about an inner class via this method. This method looks only at the literal name of the class, and does not attempt to follow inheritance links. This is necessary, since at the time imports are being processed, inheritance links have not been resolved yet. (Thus, an import directive must always spell a class name exactly.)

public final boolean isAbstract ()

public final boolean isAnonymous ()

public final boolean isClass ()

public final boolean isDeprecated ()

public final boolean isFinal ()

public final boolean isInnerClass ()

Tell if the class is inner. This predicate also returns true for top-level nested types. To test for a true inner class as seen by the programmer, use !isTopLevel().

public final boolean isInsideLocal ()

Tell if the class is local or inside a local class, which means it cannot be mentioned outside of its file.

public final boolean isInsideLocalOrAnonymous ()

Tell if the class is local or or anonymous class, or inside such a class, which means it cannot be mentioned outside of its file.

public final boolean isInterface ()

Checks

public final boolean isLocal ()

public final boolean isMember ()

Tell if the class is a member of another class. This is false for package members and for block-local classes.

public final boolean isPackagePrivate ()

public final boolean isPrivate ()

public final boolean isProtected ()

public final boolean isPublic ()

public final boolean isStatic ()

See if this is a (nested) static class.

public final boolean isSynthetic ()

public final boolean isTopLevel ()

Tell if the class is "top-level", which is either a package member, or a static member of another top-level class.

public MemberDefinition matchAnonConstructor (Environment env, Identifier accessPackage, Type[] argumentTypes)

A version of matchMethod to be used only for constructors when we cannot pass in a sourceClass argument. We just assert our package name. This is used only for anonymous classes, where we have to look up a (potentially) protected constructor with no valid sourceClass parameter available.

public MemberDefinition matchMethod (Environment env, ClassDefinition accessor, Identifier methodName, Type[] argumentTypes)

Lookup a method. This code implements the method lookup mechanism specified in JLS 15.11.2. This mechanism cannot be used to lookup synthetic methods.

public MemberDefinition matchMethod (Environment env, ClassDefinition accessor, Identifier methodName)

Lookup a method. This code implements the method lookup mechanism specified in JLS 15.11.2. This mechanism cannot be used to lookup synthetic methods.

public final boolean mustBeAbstract (Environment env)

Check to see if a class must be abstract. This method replaces isAbstract(env)

public void noteUsedBy (ClassDefinition ref, long where, Environment env)

Note that this class is being used somehow by ref. Report deprecation errors, etc.

public boolean permitInlinedAccess (Environment env, MemberDefinition f)

Check if a class is entitled to inline access to a method from another class.

Throws
ClassNotFound

public boolean permitInlinedAccess (Environment env, ClassDeclaration c)

Check if a class is entitled to inline access to a class from another class.

Throws
ClassNotFound

public void print (PrintStream out)

Print for debugging

public boolean protectedAccess (Environment env, MemberDefinition f, Type accessorType)

We know the the field is marked protected (and not public) and that the field is visible (as per canAccess). Can we access the field as ., where has the type ? Protected fields can only be accessed when the accessorType is a subclass of the current class

Throws
ClassNotFound

public final void referencesMustNotBeFrozen ()

assertion check

public boolean reportDeprecated (Environment env)

Tells whether to report a deprecation error for this class.

public Identifier resolveInnerClass (Environment env, Identifier nm)

Interpret a qualified class name, which may have further subcomponents.. Follow inheritance links, as in: class C { class N { } } class D extends C { } ... new D.N() ... Ignore outer scopes and packages.

See Also
  • resolveName

public Identifier resolveName (Environment env, Identifier name)

Look up an inner class name, from somewhere inside this class. Since supers and outers are in scope, search them too.

If no inner class is found, env.resolveName() is then called, to interpret the ambient package and import directives.

This routine operates on a "best-efforts" basis. If at some point a class is not found, the partially-resolved identifier is returned. Eventually, someone else has to try to get the ClassDefinition and diagnose the ClassNotFound.

resolveName() looks at surrounding scopes, and hence pulling in both inherited and uplevel types. By contrast, resolveInnerClass() is intended only for interpreting explicitly qualified names, and so look only at inherited types. Also, resolveName() looks for package prefixes, which appear similar to "very uplevel" outer classes.

A similar (but more complex) name-lookup process happens when field and identifier expressions denoting qualified names are type-checked. The added complexity comes from the fact that variables may occur in such names, and take precedence over class and package names.

In the expression type-checker, resolveInnerClass() is paralleled by code in FieldExpression.checkAmbigName(), which also calls ClassDefinition.getInnerClass() to interpret names of the form "OuterClass.Inner" (and also outerObject.Inner). The checking of an identifier expression that fails to be a variable is referred directly to resolveName().

public void resolveTypeStructure (Environment env)

We create a stub for this. Source classes do more work. Some calls from 'SourceClass.checkSupers' execute this method.

public final void setError ()

Mark this class to be erroneous.

public void setLocalName (Identifier name)

Set the local name of a class. Must be a local class.

public final void setNestError ()

Mark this class, and all siblings in its class nest, to be erroneous.

public boolean subClassOf (Environment env, ClassDeclaration otherClass)

Check if this is a sub class of another class

Throws
ClassNotFound

public final void subModifiers (int mod)

public boolean superClassOf (Environment env, ClassDeclaration otherClass)

Check if this is a super class of another class

Throws
ClassNotFound

public String toString ()

Convert to String

Returns
  • a string representation of the object.

public static void turnOffInheritanceChecks ()

This is a workaround to allow javadoc to turn off certain inheritance/override checks which interfere with javadoc badly. In the future it might be good to eliminate the shared sources of javadoc and javac to avoid the need for this sort of workaround.

Protected Methods

protected void addMirandaMethods (Environment env, Iterator mirandas)

Add a list of methods to this class as miranda methods. This gets overridden with a meaningful implementation in SourceClass. BinaryClass should not need to do anything -- it should already have its miranda methods and, if it doesn't, then that doesn't affect our compilation.

protected UplevelReference addReference (LocalMember target)

protected void basicCheck (Environment env)

Throws
ClassNotFound

protected void collectInheritedMethods (Environment env)

Collect all methods defined in this class or inherited from any of our superclasses or interfaces. Look for any incompatible definitions.

This function is also responsible for collecting the Miranda methods for a class. For a definition of Miranda methods, see the comment in addMirandaMethods() below.

protected Iterator getPermanentlyAbstractMethods ()

This method returns an Iterator of all abstract methods in our superclasses which we are unable to implement.

protected final void setOuterClass (ClassDefinition outerClass)

Set the class' enclosing class. Must be done at most once.

protected final void setOuterMember (MemberDefinition outerMember)

Set the class' enclosing current instance pointer. Must be done at most once.