Java Code Examples for com.sun.codemodel.internal.JClassAlreadyExistsException#getExistingClass()

The following examples show how to use com.sun.codemodel.internal.JClassAlreadyExistsException#getExistingClass() . 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: BIConversion.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public TypeUse getTypeUse(XSSimpleType owner) {
    if(typeUse!=null)
        return typeUse;

    JCodeModel cm = getCodeModel();

    JDefinedClass a;
    try {
        a = cm._class(adapter);
        a.hide();   // we assume this is given by the user
        a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
                cm.ref(type)));
    } catch (JClassAlreadyExistsException e) {
        a = e.getExistingClass();
    }

    // TODO: it's not correct to say that it adapts from String,
    // but OTOH I don't think we can compute that.
    typeUse = TypeUseFactory.adapt(
            CBuiltinLeafInfo.STRING,
            new CAdapter(a));

    return typeUse;
}
 
Example 2
Source File: BindInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superInterface customization if it's turned on. */
public JClass getSuperInterface() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superInterface");
    if (sc == null) return null;

    String name = DOMUtil.getAttribute(sc,"name");
    if (name == null) return null;

    JDefinedClass c;

    try {
        c = codeModel._class(name, ClassType.INTERFACE);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example 3
Source File: BindInfo.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example 4
Source File: BeanGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
    ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
    JClass implRef;

    if (bean.getUserSpecifiedImplClass() != null) {
        // create a place holder for a user-specified class.
        JDefinedClass usr;
        try {
            usr = codeModel._class(bean.getUserSpecifiedImplClass());
            // but hide that file so that it won't be generated.
            usr.hide();
        } catch (JClassAlreadyExistsException e) {
            // it's OK for this to collide.
            usr = e.getExistingClass();
        }
        usr._extends(r.implementation);
        implRef = usr;
    } else {
        implRef = r.implementation;
    }

    return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
}
 
Example 5
Source File: BeanGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
    ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
    JClass implRef;

    if (bean.getUserSpecifiedImplClass() != null) {
        // create a place holder for a user-specified class.
        JDefinedClass usr;
        try {
            usr = codeModel._class(bean.getUserSpecifiedImplClass());
            // but hide that file so that it won't be generated.
            usr.hide();
        } catch (JClassAlreadyExistsException e) {
            // it's OK for this to collide.
            usr = e.getExistingClass();
        }
        usr._extends(r.implementation);
        implRef = usr;
    } else {
        implRef = r.implementation;
    }

    return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
}
 
Example 6
Source File: BindInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example 7
Source File: BIConversion.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public TypeUse getTypeUse(XSSimpleType owner) {
    if(typeUse!=null)
        return typeUse;

    JCodeModel cm = getCodeModel();

    JDefinedClass a;
    try {
        a = cm._class(adapter);
        a.hide();   // we assume this is given by the user
        a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
                cm.ref(type)));
    } catch (JClassAlreadyExistsException e) {
        a = e.getExistingClass();
    }

    // TODO: it's not correct to say that it adapts from String,
    // but OTOH I don't think we can compute that.
    typeUse = TypeUseFactory.adapt(
            CBuiltinLeafInfo.STRING,
            new CAdapter(a));

    return typeUse;
}
 
Example 8
Source File: BIConversion.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public TypeUse getTypeUse(XSSimpleType owner) {
    if(typeUse!=null)
        return typeUse;

    JCodeModel cm = getCodeModel();

    JDefinedClass a;
    try {
        a = cm._class(adapter);
        a.hide();   // we assume this is given by the user
        a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
                cm.ref(type)));
    } catch (JClassAlreadyExistsException e) {
        a = e.getExistingClass();
    }

    // TODO: it's not correct to say that it adapts from String,
    // but OTOH I don't think we can compute that.
    typeUse = TypeUseFactory.adapt(
            CBuiltinLeafInfo.STRING,
            new CAdapter(a));

    return typeUse;
}
 
Example 9
Source File: BindInfo.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example 10
Source File: BIConversion.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public TypeUse getTypeUse(XSSimpleType owner) {
    if(typeUse!=null)
        return typeUse;

    JCodeModel cm = getCodeModel();

    JDefinedClass a;
    try {
        a = cm._class(adapter);
        a.hide();   // we assume this is given by the user
        a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
                cm.ref(type)));
    } catch (JClassAlreadyExistsException e) {
        a = e.getExistingClass();
    }

    // TODO: it's not correct to say that it adapts from String,
    // but OTOH I don't think we can compute that.
    typeUse = TypeUseFactory.adapt(
            CBuiltinLeafInfo.STRING,
            new CAdapter(a));

    return typeUse;
}
 
Example 11
Source File: BindInfo.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example 12
Source File: BindInfo.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superInterface customization if it's turned on. */
public JClass getSuperInterface() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superInterface");
    if (sc == null) return null;

    String name = DOMUtil.getAttribute(sc,"name");
    if (name == null) return null;

    JDefinedClass c;

    try {
        c = codeModel._class(name, ClassType.INTERFACE);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example 13
Source File: CodeModelClassFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a dummy class to recover from an error.
 *
 * We won't generate the code, so the client will never see this class
 * getting generated.
 */
private JDefinedClass createDummyClass(JClassContainer parent) {
    try {
        return parent._class("$$$garbage$$$"+(ticketMaster++));
    } catch( JClassAlreadyExistsException ee ) {
        return ee.getExistingClass();
    }
}
 
Example 14
Source File: BIGlobalBinding.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
JDefinedClass getClazz(ClassType t) {
    if (clazz != null) return clazz;
    try {
        JCodeModel codeModel = Ring.get(JCodeModel.class);
        clazz = codeModel._class(name, t);
        clazz.hide();
        return clazz;
    } catch (JClassAlreadyExistsException e) {
        return e.getExistingClass();
    }
}
 
Example 15
Source File: CodeModelClassFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a dummy class to recover from an error.
 *
 * We won't generate the code, so the client will never see this class
 * getting generated.
 */
private JDefinedClass createDummyClass(JClassContainer parent) {
    try {
        return parent._class("$$$garbage$$$"+(ticketMaster++));
    } catch( JClassAlreadyExistsException ee ) {
        return ee.getExistingClass();
    }
}
 
Example 16
Source File: CodeModelClassFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a dummy class to recover from an error.
 *
 * We won't generate the code, so the client will never see this class
 * getting generated.
 */
private JDefinedClass createDummyClass(JClassContainer parent) {
    try {
        return parent._class("$$$garbage$$$"+(ticketMaster++));
    } catch( JClassAlreadyExistsException ee ) {
        return ee.getExistingClass();
    }
}
 
Example 17
Source File: CodeModelClassFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public JDefinedClass createClass(
    JClassContainer parent, int mod, String name, Locator source, ClassType kind ) {

    if(!JJavaName.isJavaIdentifier(name)) {
        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source ));
        return createDummyClass(parent);
    }


    try {
        if(parent.isClass() && kind==ClassType.CLASS)
            mod |= JMod.STATIC;

        JDefinedClass r = parent._class(mod,name,kind);
        // use the metadata field to store the source location,
        // so that we can report class name collision errors.
        r.metadata = source;

        return r;
    } catch( JClassAlreadyExistsException e ) {
        // class collision.
        JDefinedClass cls = e.getExistingClass();

        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ),
            (Locator)cls.metadata ));
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ),
            source ));

        if( !name.equals(cls.name()) ) {
            // on Windows, FooBar and Foobar causes name collision
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION,
                    name, cls.name() ), null ) );
        }

        if(Util.equals((Locator)cls.metadata,source)) {
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ),
                source ));
        }

        return createDummyClass(parent);
    }
}
 
Example 18
Source File: CodeModelClassFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public JDefinedClass createClass(
    JClassContainer parent, int mod, String name, Locator source, ClassType kind ) {

    if(!JJavaName.isJavaIdentifier(name)) {
        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source ));
        return createDummyClass(parent);
    }


    try {
        if(parent.isClass() && kind==ClassType.CLASS)
            mod |= JMod.STATIC;

        JDefinedClass r = parent._class(mod,name,kind);
        // use the metadata field to store the source location,
        // so that we can report class name collision errors.
        r.metadata = source;

        return r;
    } catch( JClassAlreadyExistsException e ) {
        // class collision.
        JDefinedClass cls = e.getExistingClass();

        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ),
            (Locator)cls.metadata ));
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ),
            source ));

        if( !name.equals(cls.name()) ) {
            // on Windows, FooBar and Foobar causes name collision
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION,
                    name, cls.name() ), null ) );
        }

        if(Util.equals((Locator)cls.metadata,source)) {
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ),
                source ));
        }

        return createDummyClass(parent);
    }
}
 
Example 19
Source File: CodeModelClassFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public JDefinedClass createClass(
    JClassContainer parent, int mod, String name, Locator source, ClassType kind ) {

    if(!JJavaName.isJavaIdentifier(name)) {
        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source ));
        return createDummyClass(parent);
    }


    try {
        if(parent.isClass() && kind==ClassType.CLASS)
            mod |= JMod.STATIC;

        JDefinedClass r = parent._class(mod,name,kind);
        // use the metadata field to store the source location,
        // so that we can report class name collision errors.
        r.metadata = source;

        return r;
    } catch( JClassAlreadyExistsException e ) {
        // class collision.
        JDefinedClass cls = e.getExistingClass();

        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ),
            (Locator)cls.metadata ));
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ),
            source ));

        if( !name.equals(cls.name()) ) {
            // on Windows, FooBar and Foobar causes name collision
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION,
                    name, cls.name() ), null ) );
        }

        if(Util.equals((Locator)cls.metadata,source)) {
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ),
                source ));
        }

        return createDummyClass(parent);
    }
}
 
Example 20
Source File: CodeModelClassFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public JDefinedClass createClass(
    JClassContainer parent, int mod, String name, Locator source, ClassType kind ) {

    if(!JJavaName.isJavaIdentifier(name)) {
        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source ));
        return createDummyClass(parent);
    }


    try {
        if(parent.isClass() && kind==ClassType.CLASS)
            mod |= JMod.STATIC;

        JDefinedClass r = parent._class(mod,name,kind);
        // use the metadata field to store the source location,
        // so that we can report class name collision errors.
        r.metadata = source;

        return r;
    } catch( JClassAlreadyExistsException e ) {
        // class collision.
        JDefinedClass cls = e.getExistingClass();

        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ),
            (Locator)cls.metadata ));
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ),
            source ));

        if( !name.equals(cls.name()) ) {
            // on Windows, FooBar and Foobar causes name collision
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION,
                    name, cls.name() ), null ) );
        }

        if(Util.equals((Locator)cls.metadata,source)) {
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ),
                source ));
        }

        return createDummyClass(parent);
    }
}