Java Code Examples for com.sun.codemodel.JFieldVar#name()

The following examples show how to use com.sun.codemodel.JFieldVar#name() . 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: PluginImpl.java    From immutable-xjc with MIT License 6 votes vote down vote up
private JMethod addAddMethod(JDefinedClass builderClass, JFieldVar field, boolean inherit) {
    List<JClass> typeParams = ((JClass) getJavaType(field)).getTypeParameters();
    if (!typeParams.iterator().hasNext()) {
        return null;
    }
    JMethod method = builderClass.method(JMod.PUBLIC, builderClass, "add" + StringUtils.capitalize(field.name()));
    JBlock block = method.body();
    String fieldName = field.name();
    JVar param = method.param(JMod.FINAL, typeParams.iterator().next(), fieldName);
    if (inherit) {
        generateSuperCall(method);
    } else {
        JInvocation invocation = JExpr.refthis(fieldName).invoke("add").arg(param);
        block.add(invocation);
    }
    block._return(JExpr._this());
    return method;
}
 
Example 2
Source File: PluginImpl.java    From immutable-xjc with MIT License 5 votes vote down vote up
private void generatePropertyAssignment(final JMethod method, JFieldVar field, boolean wrapUnmodifiable) {
    JBlock block = method.body();
    JCodeModel codeModel = field.type().owner();
    String fieldName = field.name();
    JVar param = generateMethodParameter(method, field);
    if (isCollection(field) && !leaveCollectionsMutable && wrapUnmodifiable) {
        JConditional conditional = block._if(param.eq(JExpr._null()));
        conditional._then().assign(JExpr.refthis(fieldName), JExpr._null());
        conditional._else().assign(JExpr.refthis(fieldName),
                getDefensiveCopyExpression(codeModel, getJavaType(field), param));
    } else {
        block.assign(JExpr.refthis(fieldName), JExpr.ref(fieldName));
    }
}
 
Example 3
Source File: ImmutablePlugin.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
String getImmutableFieldName(final JFieldVar fieldVar) {
	return fieldVar.name() + "_RO";
}
 
Example 4
Source File: PluginImpl.java    From immutable-xjc with MIT License 4 votes vote down vote up
private JVar generateMethodParameter(final JMethod method, JFieldVar field) {
    String fieldName = field.name();
    JType javaType = getJavaType(field);
    return method.param(JMod.FINAL, javaType, fieldName);
}
 
Example 5
Source File: PluginImpl.java    From immutable-xjc with MIT License 4 votes vote down vote up
private void generateDefaultPropertyAssignment(JMethod method, JFieldVar field) {
    JBlock block = method.body();
    String propertyName = field.name();
    block.assign(JExpr.refthis(propertyName), defaultValue(field));
}
 
Example 6
Source File: PluginImpl.java    From immutable-xjc with MIT License 4 votes vote down vote up
private void makePropertiesFinal(JDefinedClass clazz, JFieldVar[] declaredFields) {
    for (JFieldVar field : declaredFields) {
        String fieldName = field.name();
        clazz.fields().get(fieldName).mods().setFinal(!(leaveCollectionsMutable && isCollection(field)));
    }
}