com.sun.codemodel.internal.JExpression Java Examples

The following examples show how to use com.sun.codemodel.internal.JExpression. 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: TypeUseImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example #2
Source File: IsSetField.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
    // add isSetXXX and unsetXXX.
    MethodWriter writer = outline.createMethodWriter();

    JCodeModel codeModel = outline.parent().getCodeModel();

    FieldAccessor acc = core.create(JExpr._this());

    if( generateIsSetMethod ) {
        // [RESULT] boolean isSetXXX()
        JExpression hasSetValue = acc.hasSetValue();
        if( hasSetValue==null ) {
            // this field renderer doesn't support the isSet/unset methods generation.
            // issue an error
            throw new UnsupportedOperationException();
        }
        writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
            .body()._return( hasSetValue );
    }

    if( generateUnSetMethod ) {
        // [RESULT] void unsetXXX()
        acc.unsetValues(
            writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
    }
}
 
Example #3
Source File: IsSetField.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
    // add isSetXXX and unsetXXX.
    MethodWriter writer = outline.createMethodWriter();

    JCodeModel codeModel = outline.parent().getCodeModel();

    FieldAccessor acc = core.create(JExpr._this());

    if( generateIsSetMethod ) {
        // [RESULT] boolean isSetXXX()
        JExpression hasSetValue = acc.hasSetValue();
        if( hasSetValue==null ) {
            // this field renderer doesn't support the isSet/unset methods generation.
            // issue an error
            throw new UnsupportedOperationException();
        }
        writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
            .body()._return( hasSetValue );
    }

    if( generateUnSetMethod ) {
        // [RESULT] void unsetXXX()
        acc.unsetValues(
            writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
    }
}
 
Example #4
Source File: IsSetField.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
    // add isSetXXX and unsetXXX.
    MethodWriter writer = outline.createMethodWriter();

    JCodeModel codeModel = outline.parent().getCodeModel();

    FieldAccessor acc = core.create(JExpr._this());

    if( generateIsSetMethod ) {
        // [RESULT] boolean isSetXXX()
        JExpression hasSetValue = acc.hasSetValue();
        if( hasSetValue==null ) {
            // this field renderer doesn't support the isSet/unset methods generation.
            // issue an error
            throw new UnsupportedOperationException();
        }
        writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
            .body()._return( hasSetValue );
    }

    if( generateUnSetMethod ) {
        // [RESULT] void unsetXXX()
        acc.unsetValues(
            writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
    }
}
 
Example #5
Source File: UnboxedField.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public FieldAccessor create(JExpression targetObject) {
    return new Accessor(targetObject) {

        public void unsetValues( JBlock body ) {
            // you can't unset a value
        }

        public JExpression hasSetValue() {
            return JExpr.TRUE;
        }
    };
}
 
Example #6
Source File: CEnumLeafInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString literal) {
    // correctly identifying which constant it maps to is hard, so
    // here I'm cheating
    JClass type = toType(outline,Aspect.EXPOSED);
    for (CEnumConstant mem : members) {
        if(mem.getLexicalValue().equals(literal.value))
            return type.staticRef(mem.getName());
    }
    return null;
}
 
Example #7
Source File: CBuiltinLeafInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
    return JExpr._new(outline.getCodeModel().ref(QName.class))
        .arg(qn.getNamespaceURI())
        .arg(qn.getLocalPart())
        .arg(qn.getPrefix());
}
 
Example #8
Source File: UnboxedField.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public FieldAccessor create(JExpression targetObject) {
    return new Accessor(targetObject) {

        public void unsetValues( JBlock body ) {
            // you can't unset a value
        }

        public JExpression hasSetValue() {
            return JExpr.TRUE;
        }
    };
}
 
Example #9
Source File: WhitespaceNormalizer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
    // WhitespaceProcessor.replace(<literal>);
    if( literal instanceof JStringLiteral )
        // optimize
        return JExpr.lit( WhiteSpaceProcessor.collapse(((JStringLiteral)literal).str) );
    else
        return codeModel.ref(WhiteSpaceProcessor.class)
            .staticInvoke("collapse").arg(literal);
}
 
Example #10
Source File: CDefaultValue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new {@link CDefaultValue} that computes the default value
 * by applying a lexical representation to a {@link TypeUse}.
 */
public static CDefaultValue create(final TypeUse typeUse, final XmlString defaultValue) {
    return new CDefaultValue() {
        public JExpression compute(Outline outline) {
            return typeUse.createConstant(outline,defaultValue);
        }
    };
}
 
Example #11
Source File: AbstractField.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Case from {@link #exposedType} to {@link #implType} if necessary.
 */
protected final JExpression castToImplType( JExpression exp ) {
    if(implType==exposedType)
        return exp;
    else
        return JExpr.cast(implType,exp);
}
 
Example #12
Source File: ElementAdapter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Wraps a type value into a {@link JAXBElement}.
 */
protected final JInvocation createJAXBElement(JExpression $var) {
    JCodeModel cm = codeModel();

    return JExpr._new(cm.ref(JAXBElement.class))
        .arg(JExpr._new(cm.ref(QName.class))
            .arg(ei.getElementName().getNamespaceURI())
            .arg(ei.getElementName().getLocalPart()))
        .arg(getRawType().boxify().erasure().dotclass())
        .arg($var);
}
 
Example #13
Source File: WhitespaceNormalizer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
    // WhitespaceProcessor.replace(<literal>);
    if( literal instanceof JStringLiteral )
        // optimize
        return JExpr.lit( WhiteSpaceProcessor.collapse(((JStringLiteral)literal).str) );
    else
        return codeModel.ref(WhiteSpaceProcessor.class)
            .staticInvoke("collapse").arg(literal);
}
 
Example #14
Source File: WhitespaceNormalizer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
    // WhitespaceProcessor.replace(<literal>);
    if( literal instanceof JStringLiteral )
        // optimize
        return JExpr.lit( WhiteSpaceProcessor.collapse(((JStringLiteral)literal).str) );
    else
        return codeModel.ref(WhiteSpaceProcessor.class)
            .staticInvoke("collapse").arg(literal);
}
 
Example #15
Source File: UnboxedField.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public FieldAccessor create(JExpression targetObject) {
    return new Accessor(targetObject) {

        public void unsetValues( JBlock body ) {
            // you can't unset a value
        }

        public JExpression hasSetValue() {
            return JExpr.TRUE;
        }
    };
}
 
Example #16
Source File: WhitespaceNormalizer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
    // WhitespaceProcessor.replace(<literal>);
    if( literal instanceof JStringLiteral )
        // optimize
        return JExpr.lit( WhiteSpaceProcessor.replace(((JStringLiteral)literal).str) );
    else
        return codeModel.ref(WhiteSpaceProcessor.class)
            .staticInvoke("replace").arg(literal);
}
 
Example #17
Source File: CDefaultValue.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new {@link CDefaultValue} that computes the default value
 * by applying a lexical representation to a {@link TypeUse}.
 */
public static CDefaultValue create(final TypeUse typeUse, final XmlString defaultValue) {
    return new CDefaultValue() {
        public JExpression compute(Outline outline) {
            return typeUse.createConstant(outline,defaultValue);
        }
    };
}
 
Example #18
Source File: ElementCollectionAdapter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public FieldAccessorImpl(JExpression target) {
    super(target);
}
 
Example #19
Source File: ConstField.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
    throw new UnsupportedOperationException();
}
 
Example #20
Source File: CBuiltinLeafInfo.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    return JExpr.cast(
            outline.getCodeModel().SHORT,
            JExpr.lit(DatatypeConverter.parseShort(lexical.value)));
}
 
Example #21
Source File: IsSetField.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
    core.fromRawValue(block,uniqueName,$var);
}
 
Example #22
Source File: UntypedListField.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
    // [RESULT]
    // bean.getLIST().addAll($<var>);
    JVar $list = block.decl(listT,uniqueName+'l',$target.invoke($get));
    block.invoke($list,"addAll").arg($var);
}
 
Example #23
Source File: CBuiltinLeafInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    return null;
}
 
Example #24
Source File: ContentListField.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected Accessor( JExpression $target ) {
    super($target);
}
 
Example #25
Source File: CBuiltinLeafInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    return null;
}
 
Example #26
Source File: CBuiltinLeafInfo.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    return JExpr.lit(DatatypeConverter.parseBoolean(lexical.value));
}
 
Example #27
Source File: ElementCollectionAdapter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public FieldAccessor create(JExpression targetObject) {
    return new FieldAccessorImpl(targetObject);
}
 
Example #28
Source File: ElementAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public JExpression hasSetValue() {
    return acc.hasSetValue();
}
 
Example #29
Source File: AbstractListField.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private JExpression newCoreList() {
    return JExpr._new(getCoreListType());
}
 
Example #30
Source File: ElementSingleAdapter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public FieldAccessor create(JExpression targetObject) {
    return new FieldAccessorImpl(targetObject);
}