Java 类com.sun.codemodel.JStringLiteral 实例源码

项目:org.ops4j.ramler    文件:EnumsTest.java   
@SuppressWarnings("unchecked")
@Test
public void shouldFindEnumValues() throws IllegalAccessException {
    klass = modelPackage._getClass("Colour");
    assertThat(klass.getClassType()).isEqualTo(ClassType.ENUM);
    Map<String,JEnumConstant> enums = (Map<String, JEnumConstant>) FieldUtils.readField(klass, "enumConstantsByName", true);
    assertThat(enums.keySet()).contains("LIGHT_BLUE", "RED");

    JEnumConstant lightBlue = enums.get("LIGHT_BLUE");
    assertThat(lightBlue.javadoc().get(0)).isEqualTo("Colour of the sky");

    List<JExpression> args = (List<JExpression>) FieldUtils.readField(lightBlue, "args", true);
    assertThat(args).hasSize(1);

    assertThat(args.get(0)).isInstanceOf(JStringLiteral.class);

    String literal = (String) FieldUtils.readField(args.get(0), "str", true);
    assertThat(literal).isEqualTo("lightBlue");
}
项目:springmvc-raml-plugin    文件:RamlInterpreterTest.java   
private void assertPatternValue(JAnnotationUse jAnnotationUse, String expectedPattern) throws Exception {
    JAnnotationValue jAnnotationValue = jAnnotationUse.getAnnotationMembers().get("pattern");
    Field value = jAnnotationValue.getClass().getDeclaredField("value");
    value.setAccessible(true);
    JStringLiteral object = (JStringLiteral) value.get(jAnnotationValue);
    assertThat(object.str, is(expectedPattern));
}
项目:hyperjaxb3    文件:DefaultTypeUse.java   
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);
    @SuppressWarnings("unchecked")
    Class<? extends XmlAdapter<?, ?>> atype = (Class<? extends XmlAdapter<?, ?>>) adapter
            .getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if (cons instanceof JStringLiteral && atype != null) {
        JStringLiteral scons = (JStringLiteral) cons;
        @SuppressWarnings("unchecked")
        XmlAdapter<Object, String> a = (XmlAdapter<Object, String>) 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);
}
项目:jpmml-model    文件:PMMLPlugin.java   
@Override
public JExpression compute(Outline outline){
    JExpression expression = computeInit(outline);

    if((expression instanceof JFieldRef) || (expression instanceof JStringLiteral)){
        setField(null);

        return expression;
    }

    return JExpr.ref(getField());
}