private void updateSetter(ClassOutline co, FieldOutline fo, JDefinedClass dc) { String fieldName = fo.getPropertyInfo().getName(false); JType type = fo.getRawType(); String typeName = type.fullName(); + fo.getPropertyInfo().getName(true); JMethod method = dc.getMethod(getterName, new JType[0]); JType mtype = method.type(); String setterName = "set" + fo.getPropertyInfo().getName(true); method = dc.getMethod(setterName, new JType[] {mtype}); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Updating setter: " + setterName); JDocComment doc = method.javadoc(); dc.methods().remove(method); method.javadoc().append(doc); method.param(mtype, "value"); method = dc.method(mods, method.type(), "unset" + fo.getPropertyInfo().getName(true)); method.body().assign(fr, JExpr._null()); method = dc.getMethod("isSet" + fo.getPropertyInfo().getName(true), new JType[0]); if (method != null) {
private JVar addProperty(JDefinedClass clazz, FieldOutline field) { JType jType = getJavaType(field); if (field.getPropertyInfo().isCollection()) { return clazz.field(JMod.PRIVATE, jType, field.getPropertyInfo().getName(false), getNewCollectionExpression(field.parent().implClass.owner(), jType)); } else { return clazz.field(JMod.PRIVATE, jType, field.getPropertyInfo().getName(false)); } }
protected boolean isHomoField(PrincipalStrategy principalStrategy, FieldOutline fieldOutline, Options options) { return fieldOutline.getPropertyInfo().ref().size() == 1; }
public SingleEnumValueWrappingField(ClassOutlineImpl context, CPropertyInfo prop, CPropertyInfo core) { super(context, prop, core); // Single assert !core.isCollection(); // Builtin assert core.ref().size() == 1; assert core.ref().iterator().next() instanceof CEnumLeafInfo; this.enumType = (CEnumLeafInfo) core.ref().iterator().next(); this.enumClass = this.enumType.toType(context.parent(), Aspect.EXPOSED); }
@Override public boolean test(FieldOutline fieldOutline){ CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); if(("extensions").equals(propertyInfo.getName(false)) && propertyInfo.isCollection()){ JType elementType = CodeModelUtil.getElementType(fieldOutline.getRawType()); return checkType(elementType, "org.dmg.pmml.Extension"); } return false; } };
@Override public void generateAccessors() { super.generateAccessors(); final MethodWriter writer = outline.createMethodWriter(); $set = writer.declareMethod(codeModel.VOID, "set" + prop.getName(true)); JVar var = writer.addParameter(listT, prop.getName(false)); writer.javadoc().append(prop.javadoc); JBlock block = $set.body(); block.assign(JExpr._this().ref(field), var); } }
private JMethod generateLazyProxyInitGetter(final ClassOutline classOutline, final FieldOutline fieldOutline) { final JCodeModel m = classOutline.parent().getCodeModel(); final JDefinedClass definedClass = classOutline.implClass; final String fieldName = fieldOutline.getPropertyInfo().getName(false); final String getterName = "get" + fieldOutline.getPropertyInfo().getName(true); final JFieldVar collectionField = definedClass.fields().get(fieldName); final JClass elementType = ((JClass) collectionField.type()).getTypeParameters().get(0); final JClass proxyFieldType = m.ref(BoundList.class).narrow(elementType); final JFieldRef collectionFieldRef = JExpr._this().ref(collectionField); final JFieldRef proxyField = JExpr._this().ref(collectionField.name() + BoundPropertiesPlugin.PROXY_SUFFIX); final JMethod oldGetter = definedClass.getMethod(getterName, new JType[0]); definedClass.methods().remove(oldGetter); final JMethod newGetter = definedClass.method(JMod.PUBLIC, proxyFieldType, getterName); newGetter.body()._if(collectionFieldRef.eq(JExpr._null()))._then().assign(collectionFieldRef, JExpr._new(m.ref(ArrayList.class).narrow(elementType))); final JBlock ifProxyNull = newGetter.body()._if(proxyField.eq(JExpr._null()))._then(); ifProxyNull.assign(proxyField, JExpr._new(m.ref(BoundListProxy.class).narrow(elementType)).arg(collectionFieldRef)); newGetter.body()._return(proxyField); return newGetter; }
boolean remapRet) { String fieldName = fo.getPropertyInfo().getName(false); JType type = fo.getRawType(); String typeName = type.fullName(); + fo.getPropertyInfo().getName(true); JMethod method = dc.getMethod(getterName, new JType[0]); JDocComment doc = method.javadoc(); int mods = method.mods().getValue(); JType mtype = method.type(); if (remapRet) { mtype = mtype.unboxify(); dc.methods().remove(method); method = dc.method(mods, mtype, getterName); method.javadoc().append(doc); JFieldRef fr = JExpr.ref(fieldName); if (dvExpr != null) { JExpression test = JOp.eq(JExpr._null(), fr); JConditional jc = method.body()._if(test); jc._then()._return(dvExpr); jc._else()._return(fr); } else { method.body()._return(fr);
private JMethod addWithIfNotNullMethod(JDefinedClass builderClass, FieldOutline field, JMethod unconditionalWithMethod) { if (field.getRawType().isPrimitive()) return null; String fieldName = field.getPropertyInfo().getName(true); JMethod method = builderClass.method(JMod.PUBLIC, builderClass, "with" + fieldName + "IfNotNull"); JVar param = generateMethodParameter(method, field); JBlock block = method.body(); JConditional conditional = block._if(param.eq(JExpr._null())); conditional._then()._return(JExpr.direct("this")); conditional._else()._return(JExpr.invoke(unconditionalWithMethod).arg(param)); return method; }
private JMethod addAddMethod(JDefinedClass builderClass, FieldOutline field) { List<JClass> typeParams = ((JClass) getJavaType(field)).getTypeParameters(); if (!typeParams.iterator().hasNext()) { return null; } JMethod method = builderClass.method(JMod.PUBLIC, builderClass, "add" + field.getPropertyInfo().getName(true)); JBlock block = method.body(); String fieldName = field.getPropertyInfo().getName(false); JVar param = method.param(JMod.FINAL, typeParams.iterator().next(), fieldName); JInvocation invocation = JExpr.refthis(fieldName).invoke("add").arg(param); block.add(invocation); block._return(JExpr.direct("this")); return method; }
private void generatePropertyAssignment(final JMethod method, FieldOutline fieldOutline, boolean wrapUnmodifiable) { JBlock block = method.body(); JCodeModel codeModel = fieldOutline.parent().implClass.owner(); String fieldName = fieldOutline.getPropertyInfo().getName(false); JVar param = generateMethodParameter(method, fieldOutline); if (fieldOutline.getPropertyInfo().isCollection()) { if (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(fieldOutline), param)); } else { block.assign(JExpr.refthis(fieldName), JExpr.ref(fieldName)); } replaceCollectionGetter(fieldOutline, getGetterProperty(fieldOutline)); } else { block.assign(JExpr.refthis(fieldName), JExpr.ref(fieldName)); } }
private JMethod addBuildMethod(JDefinedClass clazz, JDefinedClass builderClass, FieldOutline[] declaredFields, FieldOutline[] superclassFields) { JMethod method = builderClass.method(JMod.PUBLIC, clazz, "build"); JInvocation constructorInvocation = JExpr._new(clazz); for (FieldOutline field : superclassFields) { constructorInvocation.arg(JExpr.ref(field.getPropertyInfo().getName(false))); } for (FieldOutline field : declaredFields) { constructorInvocation.arg(JExpr.ref(field.getPropertyInfo().getName(false))); } method.body()._return(constructorInvocation); return method; }
private JMethod addWithMethod(JDefinedClass builderClass, FieldOutline field) { String fieldName = field.getPropertyInfo().getName(true); JMethod method = builderClass.method(JMod.PUBLIC, builderClass, "with" + fieldName); generatePropertyAssignment(method, field); method.body()._return(JExpr.direct("this")); return method; }
@Override protected void fix(JBlock body) { body._if(wrappingPropertyField.eq(JExpr._null())) ._then() .assign(wrappingPropertyField, JExpr._new(codeModel.ref(ArrayList.class).narrow( wrappingPropertyExposedType.boxify()))); final JClass utilsClass = codeModel.ref(TransformUtils.class); // // (wrappedProperty instanceof CReferencePropertyInfo && // ((CReferencePropertyInfo) wrappedProperty) // .isMixed()) ? codeModel.ref(MixedItemUtils.class) : codeModel // .ref(ItemUtils.class); body._if( utilsClass.staticInvoke("shouldBeWrapped").arg( wrappedPropertyField)) ._then() .assign(wrappedPropertyField, utilsClass .staticInvoke("wrap") .arg(wrappedPropertyField) .arg(wrappingPropertyField) .arg(wrappingProperty.getAdapter() .getAdapterClass(outline.parent()) .dotclass())); }
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() ); } }
private JMethod generatePropertyConstructor(JDefinedClass clazz, FieldOutline[] declaredFields, FieldOutline[] superclassFields, int constAccess) { final JMethod ctor = createConstructor(clazz, constAccess); if (superclassFields.length > 0) { JInvocation superInvocation = ctor.body().invoke("super"); for (FieldOutline fieldOutline : superclassFields) { superInvocation.arg(JExpr.ref(fieldOutline.getPropertyInfo().getName(false))); generateMethodParameter(ctor, fieldOutline); } } for (FieldOutline fieldOutline : declaredFields) { generatePropertyAssignment(ctor, fieldOutline, true); } return ctor; }
private void generateDefaultPropertyAssignment(JMethod method, FieldOutline fieldOutline) { JBlock block = method.body(); String propertyName = fieldOutline.getPropertyInfo().getName(false); block.assign(JExpr.refthis(propertyName), defaultValue(getJavaType(fieldOutline), fieldOutline)); }
public static JMethod getter(FieldOutline fieldOutline) { final JDefinedClass theClass = fieldOutline.parent().implClass; final String publicName = fieldOutline.getPropertyInfo().getName(true); final String name = "get" + publicName; return theClass.getMethod(name, NONE); }