Class ClassDefinition

  • All Implemented Interfaces:
    Constants, RuntimeConstants
    Direct Known Subclasses:
    AsmClass, BinaryClass, SourceClass

    public abstract class ClassDefinition
    extends java.lang.Object
    implements Constants
    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.
    • Field Detail

      • source

        protected java.lang.Object source
      • where

        protected long where
      • modifiers

        protected int modifiers
      • resolved

        protected boolean resolved
      • documentation

        protected java.lang.String documentation
      • error

        protected boolean error
      • nestError

        protected boolean nestError
      • referencesFrozen

        protected boolean referencesFrozen
      • localClasses

        private java.util.Hashtable<java.lang.String,​ClassDefinition> localClasses
      • classContext

        protected Context classContext
      • supersCheckStarted

        protected boolean supersCheckStarted
      • permanentlyAbstractMethods

        private java.util.List<MemberDefinition> permanentlyAbstractMethods
      • doInheritanceChecks

        protected static boolean doInheritanceChecks
        A flag used by turnOffInheritanceChecks() to indicate if inheritance checks are on or off.
    • Method Detail

      • getClassContext

        public Context getClassContext()
      • getSource

        public final java.lang.Object getSource()
        Get the source of the class
      • getError

        public final boolean getError()
        Check if there were any errors in this class.
      • setError

        public final void setError()
        Mark this class to be erroneous.
      • getNestError

        protected final boolean getNestError()
        Check if there were any errors in our class nest.
      • setNestError

        private void setNestError()
        Mark this class, and all siblings in its class nest, to be erroneous.
      • getWhere

        public final long getWhere()
        Get the position in the input binary
      • getClassDeclaration

        public final ClassDeclaration getClassDeclaration()
        Get the class declaration
      • getModifiers

        public final int getModifiers()
        Get the class' modifiers
      • subModifiers

        public final void subModifiers​(int mod)
      • addModifiers

        public final void addModifiers​(int mod)
      • getSuperClass

        public final ClassDeclaration getSuperClass()
        Get the class' super class
      • getSuperClass

        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.
        See Also:
        resolveTypeStructure(org.glassfish.rmic.tools.java.Environment)
      • getInterfaces

        public final ClassDeclaration[] getInterfaces()
        Get the class' interfaces
      • getOuterClass

        public final ClassDefinition getOuterClass()
        Get the class' enclosing class (or null if not inner)
      • setOuterClass

        protected final void setOuterClass​(ClassDefinition outerClass)
        Set the class' enclosing class. Must be done at most once.
      • setOuterMember

        protected final void setOuterMember​(MemberDefinition outerMember)
        Set the class' enclosing current instance pointer. Must be done at most once.
      • isInnerClass

        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().
      • isMember

        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.
      • isTopLevel

        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.
      • isInsideLocal

        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.
      • getLocalName

        public Identifier getLocalName()
        Return a simple identifier for this class (idNull if anonymous).
      • setLocalName

        protected void setLocalName​(Identifier name)
        Set the local name of a class. Must be a local class.
      • getInnerClassMember

        public final MemberDefinition getInnerClassMember()
        If inner, get the field for this class in the enclosing class
      • findOuterMember

        public final MemberDefinition findOuterMember()
        If inner, return an innermost uplevel self pointer, if any exists. Otherwise, return null.
      • isStatic

        public final boolean isStatic()
        See if this is a (nested) static class.
      • getTopClass

        public final ClassDefinition getTopClass()
        Get the class' top-level enclosing class
      • getFirstMember

        public final MemberDefinition getFirstMember()
        Get the class' first field or first match
      • getName

        public final Identifier getName()
        Get the class' name
      • getType

        public final Type getType()
        Get the class' type
      • containsDeprecated

        public static boolean containsDeprecated​(java.lang.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.
      • inSamePackage

        public final boolean inSamePackage​(ClassDefinition c)
      • inSamePackage

        private boolean inSamePackage​(Identifier packageName)
      • isInterface

        public final boolean isInterface()
        Checks
      • isClass

        public final boolean isClass()
      • isPublic

        public final boolean isPublic()
      • isPrivate

        public final boolean isPrivate()
      • isProtected

        public final boolean isProtected()
      • isPackagePrivate

        public final boolean isPackagePrivate()
      • isFinal

        public final boolean isFinal()
      • isAbstract

        public final boolean isAbstract()
      • isSynthetic

        public final boolean isSynthetic()
      • isDeprecated

        public final boolean isDeprecated()
      • isAnonymous

        public final boolean isAnonymous()
      • isLocal

        public final boolean isLocal()
      • hasConstructor

        public final boolean hasConstructor()
      • mustBeAbstract

        public final boolean mustBeAbstract​(Environment env)
        Check to see if a class must be abstract. This method replaces isAbstract(env)
      • enclosingClassOf

        public boolean enclosingClassOf​(ClassDefinition otherClass)
        Check if this is an enclosing class of another class
      • couldImplement

        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.
      • protectedAccess

        public boolean protectedAccess​(Environment env,
                                       MemberDefinition f,
                                       Type accessorType)
                                throws ClassNotFound
        We know 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
      • getVariable

        public MemberDefinition getVariable​(Environment env,
                                            Identifier nm,
                                            ClassDefinition source)
                                     throws AmbiguousMember,
                                            ClassNotFound
        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)
        Throws:
        AmbiguousMember
        ClassNotFound
      • reportDeprecated

        public boolean reportDeprecated​(Environment env)
        Tells whether to report a deprecation error for this class.
      • noteUsedBy

        public void noteUsedBy​(ClassDefinition ref,
                               long where,
                               Environment env)
        Note that this class is being used somehow by ref. Report deprecation errors, etc.
      • getInnerClass

        public MemberDefinition getInnerClass​(Environment env,
                                              Identifier nm)
                                       throws ClassNotFound
        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
      • matchAnonConstructor

        public MemberDefinition matchAnonConstructor​(Environment env,
                                                     Identifier accessPackage,
                                                     Type[] argumentTypes)
                                              throws AmbiguousMember,
                                                     ClassNotFound
        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.
        Throws:
        AmbiguousMember
        ClassNotFound
      • findMethod

        public MemberDefinition findMethod​(Environment env,
                                           Identifier nm,
                                           Type t)
                                    throws ClassNotFound
        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
      • getPermanentlyAbstractMethods

        protected java.util.Iterator<MemberDefinition> getPermanentlyAbstractMethods()
        This method returns an Iterator of all abstract methods in our superclasses which we are unable to implement.
      • turnOffInheritanceChecks

        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.
      • collectOneClass

        private void collectOneClass​(Environment env,
                                     ClassDeclaration parent,
                                     MethodSet myMethods,
                                     MethodSet allMethods,
                                     MethodSet mirandaMethods)
        Add all of the methods declared in or above `parent' to `allMethods', the set of methods in the current class. `myMethods' is the set of all methods declared in this class, and `mirandaMethods' is a repository for Miranda methods. If mirandaMethods is null, no mirandaMethods will be generated. For a definition of Miranda methods, see the comment above the method addMirandaMethods() which occurs later in this file.
      • collectInheritedMethods

        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.

      • getMethods

        protected java.util.Iterator<MemberDefinition> getMethods​(Environment env)
        Get an Iterator of all methods which could be accessed in an instance of this class.
      • getMethods

        public java.util.Iterator<MemberDefinition> 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.
      • addMirandaMethods

        protected void addMirandaMethods​(Environment env,
                                         java.util.Iterator<MemberDefinition> 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.
      • inlineLocalClass

        public void inlineLocalClass​(Environment env)
      • 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().

      • resolveInnerClass

        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.
      • innerClassExists

        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.)
      • diagnoseMismatch

        public int diagnoseMismatch​(Environment env,
                                    Identifier nm,
                                    Type[] argTypes,
                                    int start,
                                    Type[] margTypeResult)
                             throws ClassNotFound
        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
      • addMember

        protected void addMember​(MemberDefinition field)
        Add a field (no checks)
      • getReference

        public UplevelReference getReference​(LocalMember target)
        Find or create an uplevel reference for the given target.
      • getReferences

        public UplevelReference getReferences()
        Return the list of all uplevel references.
      • getReferencesFrozen

        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.
      • referencesMustNotBeFrozen

        public final void referencesMustNotBeFrozen()
        assertion check
      • getClassLiteralLookup

        public MemberDefinition getClassLiteralLookup​(long fwhere)
        Get helper method for class literal lookup.
      • loadNested

        public void loadNested​(Environment env)
      • getDependencies

        public java.util.Iterator<ClassDeclaration> getDependencies()
      • addDependency

        public void addDependency​(ClassDeclaration c)
        Add a dependency
      • getLocalClass

        public ClassDefinition getLocalClass​(java.lang.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.
      • addLocalClass

        public void addLocalClass​(ClassDefinition c,
                                  java.lang.String name)
      • print

        public void print​(java.io.PrintStream out)
        Print for debugging
      • toString

        public java.lang.String toString()
        Convert to String
        Overrides:
        toString in class java.lang.Object
      • cleanup

        public void cleanup​(Environment env)
        After the class has been written to disk, try to free up some storage.