sun.tools.java.ClassDefinition Java Examples

The following examples show how to use sun.tools.java.ClassDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassType.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected boolean initParents(ContextStack stack) {

        stack.setNewContextCode(ContextStack.EXTENDS);
        BatchEnvironment env = stack.getEnv();

        // Init parent...

        boolean result = true;

        try {
            ClassDeclaration parentDecl = getClassDefinition().getSuperClass(env);
            if (parentDecl != null) {
                ClassDefinition parentDef = parentDecl.getClassDefinition(env);
                parent = (ClassType) makeType(parentDef.getType(),parentDef,stack);
                if (parent == null) {
                    result = false;
                }
            }
        } catch (ClassNotFound e) {
            classNotFound(stack,e);
            throw new CompilerError("ClassType constructor");
        }

        return result;
    }
 
Example #2
Source File: CompoundType.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a CompoundType instance for the given class. NOTE: This constructor
 * is ONLY for SpecialClassType and SpecialInterfaceType.
 */
protected CompoundType(ContextStack stack, int typeCode, ClassDefinition classDef) {
    super(stack,typeCode);
    this.classDef = classDef;
    classDecl = classDef.getClassDeclaration();
    interfaces = new InterfaceType[0];
    methods = new Method[0];
    members = new Member[0];

    // If we are an inner class/interface, reset the type codes...

    if (classDef.isInnerClass()) {
        setTypeCode(typeCode | TM_INNER);
    }

    // Set special flags...

    setFlags();
}
 
Example #3
Source File: ImplementationType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static boolean couldBeImplementation(boolean quiet, ContextStack stack,
                                             ClassDefinition classDef) {
    boolean result = false;
    BatchEnvironment env = stack.getEnv();

    try {
        if (!classDef.isClass()) {
            failedConstraint(17,quiet,stack,classDef.getName());
        } else {
            result = env.defRemote.implementedBy(env, classDef.getClassDeclaration());
            if (!result) failedConstraint(8,quiet,stack,classDef.getName());
        }
    } catch (ClassNotFound e) {
        classNotFound(stack,e);
    }

    return result;
}
 
Example #4
Source File: CompoundType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected boolean inheritsFrom(ClassDefinition def, ClassDefinition otherDef) {
    if (def == otherDef)
        return true;

    ClassDefinition superDef;
    if (def.getSuperClass() != null) {
        superDef = def.getSuperClass().getClassDefinition();
        if (inheritsFrom(superDef, otherDef))
            return true;
    }

    ClassDeclaration[] interfaces = def.getInterfaces();
    for (int i=0; i<interfaces.length; i++) {
        superDef = interfaces[i].getClassDefinition();
        if (inheritsFrom(superDef, otherDef))
            return true;
    }
    return false;
}
 
Example #5
Source File: SpecialInterfaceType.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isSpecial(sun.tools.java.Type type,
                                 ClassDefinition theClass,
                                 ContextStack stack) {
    if (type.isType(TC_CLASS)) {
        Identifier id = type.getClassName();

        if (id.equals(idRemote)) return true;
        if (id == idJavaIoSerializable) return true;
        if (id == idJavaIoExternalizable) return true;
        if (id == idCorbaObject) return true;
        if (id == idIDLEntity) return true;
        BatchEnvironment env = stack.getEnv();
        try {
            if (env.defCorbaObject.implementedBy(env,theClass.getClassDeclaration())) return true;
        } catch (ClassNotFound e) {
            classNotFound(stack,e);
        }
    }
    return false;
}
 
Example #6
Source File: CompoundType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add to the supplied list all exceptions in the "from" array
 * that are subclasses of an exception in the "with" array.
 */
private void collectCompatibleExceptions(
        ValueType[] from, ValueType[] with, Vector list)
        throws ClassNotFound {

    for (int i = 0; i < from.length; i++) {
        ClassDefinition exceptionDef = from[i].getClassDefinition();
        if (!list.contains(from[i])) {
            for (int j = 0; j < with.length; j++) {
                if (exceptionDef.subClassOf(
                        enclosing.getEnv(),
                        with[j].getClassDeclaration())) {
                    list.addElement(from[i]);
                    break;
                }
            }
        }
    }
}
 
Example #7
Source File: ImplementationType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkMethods(ClassDefinition theClass, Vector list,
                             ContextStack stack, boolean quiet) {

    // Convert vector to array...

    Method[] methods = new Method[list.size()];
    list.copyInto(methods);

    for (MemberDefinition member = theClass.getFirstMember();
         member != null;
         member = member.getNextMember()) {

        if (member.isMethod() && !member.isConstructor()
            && !member.isInitializer()) {

            // It's a method...

            if (!updateExceptions(member,methods,stack,quiet)) {
                return false;
            }
        }
    }
    return true;
}
 
Example #8
Source File: AbstractType.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean couldBeAbstract(ContextStack stack, ClassDefinition classDef,
                                       boolean quiet) {

    // Return true if interface and not remote...

    boolean result = false;

    if (classDef.isInterface()) {
        BatchEnvironment env = stack.getEnv();

        try {
            result = ! env.defRemote.implementedBy(env, classDef.getClassDeclaration());
            if (!result) failedConstraint(15,quiet,stack,classDef.getName());
        } catch (ClassNotFound e) {
            classNotFound(stack,e);
        }
    } else {
        failedConstraint(14,quiet,stack,classDef.getName());
    }


    return result;
}
 
Example #9
Source File: CompoundType.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected boolean inheritsFrom(ClassDefinition def, ClassDefinition otherDef) {
    if (def == otherDef)
        return true;

    ClassDefinition superDef;
    if (def.getSuperClass() != null) {
        superDef = def.getSuperClass().getClassDefinition();
        if (inheritsFrom(superDef, otherDef))
            return true;
    }

    ClassDeclaration[] interfaces = def.getInterfaces();
    for (int i=0; i<interfaces.length; i++) {
        superDef = interfaces[i].getClassDefinition();
        if (inheritsFrom(superDef, otherDef))
            return true;
    }
    return false;
}
 
Example #10
Source File: RemoteClass.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add to the supplied list all exceptions in the "from" array
 * that are subclasses of an exception in the "with" array.
 */
private void collectCompatibleExceptions(ClassDeclaration[] from,
                                         ClassDeclaration[] with,
                                         Vector<ClassDeclaration> list)
    throws ClassNotFound
{
    for (int i = 0; i < from.length; i++) {
        ClassDefinition exceptionDef = from[i].getClassDefinition(env);
        if (!list.contains(from[i])) {
            for (int j = 0; j < with.length; j++) {
                if (exceptionDef.subClassOf(env, with[j])) {
                    list.addElement(from[i]);
                    break;
                }
            }
        }
    }
}
 
Example #11
Source File: RemoteClass.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add to the supplied list all exceptions in the "from" array
 * that are subclasses of an exception in the "with" array.
 */
private void collectCompatibleExceptions(ClassDeclaration[] from,
                                         ClassDeclaration[] with,
                                         Vector<ClassDeclaration> list)
    throws ClassNotFound
{
    for (int i = 0; i < from.length; i++) {
        ClassDefinition exceptionDef = from[i].getClassDefinition(env);
        if (!list.contains(from[i])) {
            for (int j = 0; j < with.length; j++) {
                if (exceptionDef.subClassOf(env, with[j])) {
                    list.addElement(from[i]);
                    break;
                }
            }
        }
    }
}
 
Example #12
Source File: ImplementationType.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkMethods(ClassDefinition theClass, Vector list,
                             ContextStack stack, boolean quiet) {

    // Convert vector to array...

    Method[] methods = new Method[list.size()];
    list.copyInto(methods);

    for (MemberDefinition member = theClass.getFirstMember();
         member != null;
         member = member.getNextMember()) {

        if (member.isMethod() && !member.isConstructor()
            && !member.isInitializer()) {

            // It's a method...

            if (!updateExceptions(member,methods,stack,quiet)) {
                return false;
            }
        }
    }
    return true;
}
 
Example #13
Source File: CompoundType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a CompoundType instance for the given class. NOTE: This constructor
 * is ONLY for SpecialClassType and SpecialInterfaceType.
 */
protected CompoundType(ContextStack stack, int typeCode, ClassDefinition classDef) {
    super(stack,typeCode);
    this.classDef = classDef;
    classDecl = classDef.getClassDeclaration();
    interfaces = new InterfaceType[0];
    methods = new Method[0];
    members = new Member[0];

    // If we are an inner class/interface, reset the type codes...

    if (classDef.isInnerClass()) {
        setTypeCode(typeCode | TM_INNER);
    }

    // Set special flags...

    setFlags();
}
 
Example #14
Source File: ClassType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a ClassType instance for the given class. NOTE: This constructor
 * is ONLY for SpecialClassType.
 */
protected ClassType(ContextStack stack, int typeCode, ClassDefinition classDef) {
    super(stack,typeCode,classDef); // Call special parent constructor.
    if ((typeCode & TM_CLASS) == 0 && classDef.isInterface()) {
        throw new CompilerError("Not a class");
    }
    parent = null;
}
 
Example #15
Source File: NCInterfaceType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an NCInterfaceType for the given class.
 *
 * If the class is not a properly formed or if some other error occurs, the
 * return value will be null, and errors will have been reported to the
 * supplied BatchEnvironment.
 */
public static NCInterfaceType forNCInterface( ClassDefinition classDef,
                                              ContextStack stack) {
    if (stack.anyErrors()) return null;

    boolean doPop = false;
    try {
        // Do we already have it?

        sun.tools.java.Type theType = classDef.getType();
        Type existing = getType(theType,stack);

        if (existing != null) {

            if (!(existing instanceof NCInterfaceType)) return null; // False hit.

                            // Yep, so return it...

            return (NCInterfaceType) existing;
        }

        NCInterfaceType it = new NCInterfaceType(stack, classDef);
        putType(theType,it,stack);
        stack.push(it);
        doPop = true;

        if (it.initialize(stack)) {
            stack.pop(true);
            return it;
        } else {
            removeType(theType,stack);
            stack.pop(false);
            return null;
        }
    } catch (CompilerError e) {
        if (doPop) stack.pop(false);
        return null;
    }
}
 
Example #16
Source File: CompoundType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a CompoundType object for the given class.
 *
 * If the class is not a properly formed or if some other error occurs, the
 * return value will be null, and errors will have been reported to the
 * supplied BatchEnvironment.
 */
public static CompoundType forCompound (ClassDefinition classDef,
                                        ContextStack stack) {
    CompoundType result = null;

    try {
        result = (CompoundType) makeType(classDef.getType(),classDef,stack);
    } catch (ClassCastException e) {}

    return result;
}
 
Example #17
Source File: SpecialClassType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) {
    if (type.isType(TC_CLASS)) {
        Identifier id = type.getClassName();
        if (id == idJavaLangString) return TYPE_STRING;
        if (id == idJavaLangObject) return TYPE_ANY;
    }
    return TYPE_NONE;
}
 
Example #18
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate the source files for the stub and/or skeleton classes
 * needed by RMI for the given remote implementation class.
 *
 * @param env       compiler environment
 * @param cdef      definition of remote implementation class
 *                  to generate stubs and/or skeletons for
 * @param destDir   directory for the root of the package hierarchy
 *                  for generated files
 */
public void generate(BatchEnvironment env, ClassDefinition cdef, File destDir) {
    RemoteClass remoteClass = RemoteClass.forClass(env, cdef);
    if (remoteClass == null)        // exit if an error occurred
        return;

    RMIGenerator gen;
    try {
        gen = new RMIGenerator(env, cdef, destDir, remoteClass, version);
    } catch (ClassNotFound e) {
        env.error(0, "rmic.class.not.found", e.name);
        return;
    }
    gen.generate();
}
 
Example #19
Source File: ValueType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize this instance.
 */

private static boolean couldBeValue(ContextStack stack, ClassDefinition classDef) {

    boolean result = false;
    ClassDeclaration classDecl = classDef.getClassDeclaration();
    BatchEnvironment env = stack.getEnv();

    try {
        // Make sure it's not remote...

        if (env.defRemote.implementedBy(env, classDecl)) {
            failedConstraint(10,false,stack,classDef.getName());
        } else {

            // Make sure it's Serializable...

            if (!env.defSerializable.implementedBy(env, classDecl)) {
                failedConstraint(11,false,stack,classDef.getName());
            } else {
                result = true;
            }
        }
    } catch (ClassNotFound e) {
        classNotFound(stack,e);
    }

    return result;
}
 
Example #20
Source File: RemoteClass.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a RemoteClass object representing the remote meta-information
 * of the given class.
 *
 * Returns true if successful.  If the class is not a properly formed
 * remote implementation class or if some other error occurs, the
 * return value will be null, and errors will have been reported to
 * the supplied BatchEnvironment.
 */
public static RemoteClass forClass(BatchEnvironment env,
                                   ClassDefinition implClassDef)
{
    RemoteClass rc = new RemoteClass(env, implClassDef);
    if (rc.initialize()) {
        return rc;
    } else {
        return null;
    }
}
 
Example #21
Source File: RMIGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate the source files for the stub and/or skeleton classes
 * needed by RMI for the given remote implementation class.
 *
 * @param env       compiler environment
 * @param cdef      definition of remote implementation class
 *                  to generate stubs and/or skeletons for
 * @param destDir   directory for the root of the package hierarchy
 *                  for generated files
 */
public void generate(BatchEnvironment env, ClassDefinition cdef, File destDir) {
    RemoteClass remoteClass = RemoteClass.forClass(env, cdef);
    if (remoteClass == null)        // exit if an error occurred
        return;

    RMIGenerator gen;
    try {
        gen = new RMIGenerator(env, cdef, destDir, remoteClass, version);
    } catch (ClassNotFound e) {
        env.error(0, "rmic.class.not.found", e.name);
        return;
    }
    gen.generate();
}
 
Example #22
Source File: CompoundType.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a CompoundType object for the given class.
 *
 * If the class is not a properly formed or if some other error occurs, the
 * return value will be null, and errors will have been reported to the
 * supplied BatchEnvironment.
 */
public static CompoundType forCompound (ClassDefinition classDef,
                                        ContextStack stack) {
    CompoundType result = null;

    try {
        result = (CompoundType) makeType(classDef.getType(),classDef,stack);
    } catch (ClassCastException e) {}

    return result;
}
 
Example #23
Source File: StubGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Overridden in order to set the standardPackage flag.
 */
public void generate(
        sun.rmi.rmic.BatchEnvironment env,
        ClassDefinition cdef, File destDir) {
    ((sun.rmi.rmic.iiop.BatchEnvironment)env).
            setStandardPackage(standardPackage);
    super.generate(env, cdef, destDir);
}
 
Example #24
Source File: InterfaceType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a InterfaceType instance for the given class.  The resulting
 * object is not yet completely initialized. Subclasses must call
 * initialize(directInterfaces,directInterfaces,directConstants);
 */
protected InterfaceType(ContextStack stack,
                        ClassDefinition classDef,
                        int typeCode) {
    super(stack,classDef,typeCode);

    if ((typeCode & TM_INTERFACE) == 0 || ! classDef.isInterface()) {
        throw new CompilerError("Not an interface");
    }
}
 
Example #25
Source File: InterfaceType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a InterfaceType instance for the given class.  The resulting
 * object is not yet completely initialized. Subclasses must call
 * initialize(directInterfaces,directInterfaces,directConstants);
 */
protected InterfaceType(ContextStack stack,
                        ClassDefinition classDef,
                        int typeCode) {
    super(stack,classDef,typeCode);

    if ((typeCode & TM_INTERFACE) == 0 || ! classDef.isInterface()) {
        throw new CompilerError("Not an interface");
    }
}
 
Example #26
Source File: InterfaceType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a InterfaceType instance for the given class.  The resulting
 * object is not yet completely initialized. Subclasses must call
 * initialize(directInterfaces,directInterfaces,directConstants);
 */
protected InterfaceType(ContextStack stack,
                        ClassDefinition classDef,
                        int typeCode) {
    super(stack,classDef,typeCode);

    if ((typeCode & TM_INTERFACE) == 0 || ! classDef.isInterface()) {
        throw new CompilerError("Not an interface");
    }
}
 
Example #27
Source File: ClassType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an ClassType instance for the given class.  The resulting
 * object is not yet completely initialized. Subclasses must call
 * initialize(directInterfaces,directInterfaces,directConstants);
 */
protected ClassType(ContextStack stack,
                    ClassDefinition classDef,
                    int typeCode) {
    super(stack,classDef,typeCode);
    if ((typeCode & TM_CLASS) == 0 && classDef.isInterface()) {
        throw new CompilerError("Not a class");
    }
    parent = null;
}
 
Example #28
Source File: InterfaceType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a InterfaceType instance for the given class.  The resulting
 * object is not yet completely initialized. Subclasses must call
 * initialize(directInterfaces,directInterfaces,directConstants);
 */
protected InterfaceType(ContextStack stack,
                        ClassDefinition classDef,
                        int typeCode) {
    super(stack,classDef,typeCode);

    if ((typeCode & TM_INTERFACE) == 0 || ! classDef.isInterface()) {
        throw new CompilerError("Not an interface");
    }
}
 
Example #29
Source File: CompoundType.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return an array containing only those exceptions which
 * need to be caught.  Removes java.rmi.RemoteException,
 * java.lang.RuntimeException, java.lang.Error, and their
 * subclasses, then removes any exceptions which are more
 * derived than another in the list. Returns null if no
 * exceptions need to be caught.
 */
public ValueType[] getUniqueCatchList(ValueType[] list) {
    ValueType[] result = list;
    int newSize = list.length;

    try {

        // First, remove RemoteException, RuntimeException, Error, and their subclasses...
        for (int i = 0; i < list.length; i++) {
            ClassDeclaration decl = list[i].getClassDeclaration();
            if (env.defRemoteException.superClassOf(env, decl) ||
                env.defRuntimeException.superClassOf(env, decl) ||
                env.defError.superClassOf(env, decl)) {
                list[i] = null;
                newSize--;
            }
        }

        // Now remove derived types...
        for (int i = 0; i < list.length; i++) {
            if (list[i] != null) {
                ClassDefinition current = list[i].getClassDefinition();
                for (int j = 0; j < list.length; j++) {
                    if (j != i && list[i] != null && list[j] != null &&
                        current.superClassOf(env, list[j].getClassDeclaration())) {
                        list[j] = null;
                        newSize--;
                    }
                }
            }
        }

    } catch (ClassNotFound e) {
        classNotFound(stack,e); // Report error but do not stop.
    }

    // Create new list if we removed anything...

    if (newSize < list.length) {
        ValueType[] temp = new ValueType[newSize];
        int offset = 0;
        for (int i = 0; i < list.length; i++) {
            if (list[i] != null) {
                temp[offset++] = list[i];
            }
        }
        list = temp;
    }

    if (list.length == 0) {
        return null;
    } else {
        return list;
    }
}
 
Example #30
Source File: ImplementationType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize this instance.
 */
private boolean initialize (ContextStack stack, boolean quiet) {

    boolean result = false;
    ClassDefinition theClass = getClassDefinition();

    if (initParents(stack)) {

        // Make up our collections...

        Vector directInterfaces = new Vector();
        Vector directMethods = new Vector();

        // Check interfaces...

        try {
            if (addRemoteInterfaces(directInterfaces,true,stack) != null) {

                boolean haveRemote = false;

                // Get methods from all interfaces...

                for (int i = 0; i < directInterfaces.size(); i++) {
                    InterfaceType theInt = (InterfaceType) directInterfaces.elementAt(i);
                    if (theInt.isType(TYPE_REMOTE) ||
                        theInt.isType(TYPE_JAVA_RMI_REMOTE)) {
                        haveRemote = true;
                    }

                    copyRemoteMethods(theInt,directMethods);
                }

                // Make sure we have at least one remote interface...

                if (!haveRemote) {
                    failedConstraint(8,quiet,stack,getQualifiedName());
                    return false;
                }

                // Now check the methods to ensure we have the
                // correct throws clauses...

                if (checkMethods(theClass,directMethods,stack,quiet)) {

                    // We're ok, so pass 'em up...

                    result = initialize(directInterfaces,directMethods,null,stack,quiet);
                }
            }
        } catch (ClassNotFound e) {
            classNotFound(stack,e);
        }
    }

    return result;
}