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); }
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); }
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); }