branch develop updated (9a08336 -> 39952d8)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository eugene. See http://git.nuiton.org/eugene.git from 9a08336 [jgitflow-maven-plugin]Updating develop poms back to pre merge state new dd8b076 Pouvoir générer des méthodes utiles (predicat, function) sur des beans (refs #3745) new 253148f Add usefull method to get the wrap primitive type new dc50706 Generate predicates and function in helper classes (simpleBeanWithNoInterface generator) (termine #3745) Merge branch 'feature/3745' into develop new 75a7c1f Make works prefix and suffix on simpleBeanWithNoInterface generator (refs #3746) new 39952d8 Can't use prefix and suffix in simpleBeanWithNoInterface generator (termine #3746) Merge branch 'feature/3746' into develop The 5 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 39952d8f0ed145eacd9a3feeb01f35517c776296 Merge: dc50706 75a7c1f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:53:56 2015 +0200 Can't use prefix and suffix in simpleBeanWithNoInterface generator (termine #3746) Merge branch 'feature/3746' into develop commit 75a7c1f1a4f06922246f123818e4d7a6280a225e Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:53:49 2015 +0200 Make works prefix and suffix on simpleBeanWithNoInterface generator (refs #3746) commit dc50706895dde7d7aa2c5a2c467ed6c05555e0df Merge: 9a08336 253148f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:50:55 2015 +0200 Generate predicates and function in helper classes (simpleBeanWithNoInterface generator) (termine #3745) Merge branch 'feature/3745' into develop commit 253148f80d06a2c118c0cc3260dd16a129e79869 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:50:04 2015 +0200 Add usefull method to get the wrap primitive type commit dd8b0765c2d755cff6d42a1d839cf77da4ce279e Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 15:36:37 2015 +0200 Pouvoir générer des méthodes utiles (predicat, function) sur des beans (refs #3745) Summary of changes: .../eugene/java/AbstractJavaBeanTransformer.java | 5 +- .../nuiton/eugene/java/JavaTemplatesTagValues.java | 65 ++++ .../SimpleJavaBeanWithNoInterfaceTransformer.java | 333 +++++++++++++++++---- .../main/java/org/nuiton/eugene/GeneratorUtil.java | 34 +++ 4 files changed, 384 insertions(+), 53 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See http://git.nuiton.org/eugene.git commit dd8b0765c2d755cff6d42a1d839cf77da4ce279e Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 15:36:37 2015 +0200 Pouvoir générer des méthodes utiles (predicat, function) sur des beans (refs #3745) --- .../nuiton/eugene/java/JavaTemplatesTagValues.java | 65 ++++++++ .../SimpleJavaBeanWithNoInterfaceTransformer.java | 176 ++++++++++++++++++++- 2 files changed, 239 insertions(+), 2 deletions(-) diff --git a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java index 77ad643..cf8b1e9 100644 --- a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java +++ b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java @@ -516,6 +516,36 @@ public class JavaTemplatesTagValues extends TagValueDefinitionProvider { public static final String TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_DEFAULTS_CLASS_NAME_SUFFIX = "simpleBeanWithNoInterfaceDefaultsClassNameSuffix"; /** + * To generate or not guava predicates on each property of the bean. + * + * You can globaly use it on the complete model or to a specific classifier. + * + * @see #isSimpleBeanWithNoInterfaceGeneratePredicates(ObjectModelClassifier, ObjectModelPackage, ObjectModel) + * @since 3.0 + */ + @TagValueDefinition( + target = {ObjectModel.class, ObjectModelPackage.class, ObjectModelClassifier.class}, + defaultValue = "true", + documentation = "To generate or not guava predicates on propertyes on beans.\n" + + "(only effective with simple bean with no interface generator)") + public static final String TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_PREDICATES = "simpleBeanWithNoInterfaceGeneratePredicates"; + + /** + * To generate or not guava functions on each property of the bean. + * + * You can globaly use it on the complete model or to a specific classifier. + * + * @see #isSimpleBeanWithNoInterfaceGenerateFunctions(ObjectModelClassifier, ObjectModelPackage, ObjectModel) + * @since 3.0 + */ + @TagValueDefinition( + target = {ObjectModel.class, ObjectModelPackage.class, ObjectModelClassifier.class}, + defaultValue = "true", + documentation = "To generate or not guava predicates on propertyes on beans.\n" + + "(only effective with simple bean with no interface generator)") + public static final String TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_FUNCTIONS= "simpleBeanWithNoInterfaceGenerateFunctions"; + + /** * Obtain the value of the {@link #TAG_GENERATE_PROPERTY_CHANGE_SUPPORT} tag value on the given model, package or classifier. * * It will first look on the model, then and package and then in the given classifier. @@ -880,4 +910,39 @@ public class JavaTemplatesTagValues extends TagValueDefinitionProvider { return value; } + /** + * Obtain the value of the {@link #TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_PREDICATES} tag value on the given model or classifier. + * + * It will first look on the model, and then in the given classifier. + * + * <strong>If not filled, then use default {@code s} value.</strong> + * + * @param classifier classifier to seek + * @param model model to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see #TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_PREDICATES + * @since 3.0 + */ + public boolean isSimpleBeanWithNoInterfaceGeneratePredicates(ObjectModelClassifier classifier, ObjectModelPackage aPackage, ObjectModel model) { + boolean value = findBooleanTagValue(TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_PREDICATES, classifier, aPackage, model); + return value; + } +/** + * Obtain the value of the {@link #TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_FUNCTIONS} tag value on the given model or classifier. + * + * It will first look on the model, and then in the given classifier. + * + * <strong>If not filled, then use default {@code s} value.</strong> + * + * @param classifier classifier to seek + * @param model model to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see #TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_FUNCTIONS + * @since 3.0 + */ + public boolean isSimpleBeanWithNoInterfaceGenerateFunctions(ObjectModelClassifier classifier, ObjectModelPackage aPackage, ObjectModel model) { + boolean value = findBooleanTagValue(TAG_SIMPLE_BEAN_WITH_NO_INTERFACE_GENERATE_FUNCTIONS, classifier, aPackage, model); + return value; + } + } diff --git a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java index 94a8b3f..b904c55 100644 --- a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java +++ b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java @@ -25,6 +25,11 @@ package org.nuiton.eugene.java; /*{generator option: parentheses = false}*/ /*{generator option: writeString = +}*/ +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -40,6 +45,7 @@ import org.nuiton.util.beans.BinderFactory; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * Generates a java bean and a utility class around it. This transformer acts like {@link SimpleJavaBeanTransformer} @@ -270,6 +276,9 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr if (!isInClassPath(packageName, abstractClassName)) { + boolean generatePredicates = getJavaTemplatesTagValues().isSimpleBeanWithNoInterfaceGeneratePredicates(aClass, aPackage, model); + boolean generateFunctions = getJavaTemplatesTagValues().isSimpleBeanWithNoInterfaceGenerateFunctions(aClass, aPackage, model); + // generate abstract defaults class // try to find a super class by tag-value @@ -324,7 +333,7 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr setOperationBody(operation, "" /*{ Class<BeanType> sourceType = typeOf<%=typeName%>(); - Binder<BeanType,BeanType> binder = BinderFactory.newBinder(sourceType); + Binder<BeanType, BeanType> binder = BinderFactory.newBinder(sourceType); BeanType result = new<%=typeName%>(source, binder); return result; }*/ @@ -359,7 +368,7 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr setOperationBody(operation, "" /*{ Class<BeanType> sourceType = typeOf<%=typeName%>(); - Binder<BeanType,BeanType> binder = BinderFactory.newBinder(sourceType); + Binder<BeanType, BeanType> binder = BinderFactory.newBinder(sourceType); binder.copy(source, target); }*/ ); @@ -379,7 +388,170 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr binder.copy(source, target); }*/ ); + + if (generatePredicates) { + generatePredicates(aClass, output, typeName); + } + + if (generateFunctions) { + generateFunctions(aClass, output, typeName); + } + } + } + + protected void generatePredicates(ObjectModelClass input, ObjectModelClass output, String typeName) { + + List<ObjectModelAttribute> properties = getProperties(input); + + if (!properties.isEmpty()) { + addImport(output, Predicate.class); + addImport(output, Objects.class); + addImport(output, Iterable.class); + addImport(output, Iterables.class); + } + + for (ObjectModelAttribute attribute : properties) { + + boolean multiple = JavaGeneratorUtil.isNMultiplicity(attribute); + + if (multiple) { + continue; + } + + String attrName = getAttributeName(attribute); + String attrType = getAttributeType(attribute); + + String simpleType = JavaGeneratorUtil.getSimpleName(attrType); + + String capitalizeAttrName = JavaGeneratorUtil.capitalizeJavaBeanPropertyName(attrName); + String newPreficateMethodName= "new" + capitalizeAttrName + "Predicate"; + ObjectModelOperation operation = addOperation( + output, + newPreficateMethodName, + "<BeanType extends " + typeName + "> Predicate<BeanType>", + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, simpleType, attrName); + + String getterName = getGetterName(attrName, attribute); + setOperationBody(operation, "" + /*{ + final <%=simpleType%> $tmp = <%=attrName%>; + return new Predicate<BeanType>() { + + @Override + public boolean apply(BeanType input) { + return Objects.equals($tmp, input.<%=getterName%>()); + } + }; + + }*/ + ); + + operation = addOperation( + output, + "filterBy" + capitalizeAttrName, + "<BeanType extends " + typeName + "> Iterable<BeanType>", + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "Iterable<BeanType>", "source"); + addParameter(operation, simpleType, attrName); + setOperationBody(operation, "" + /*{ + return Iterables.filter(source, <%=newPreficateMethodName%>(<%=attrName%>)); + }*/ + ); + } + + } + + protected void generateFunctions(ObjectModelClass input, ObjectModelClass output, String typeName) { + + List<ObjectModelAttribute> properties = getProperties(input); + if (!properties.isEmpty()) { + addImport(output, Function.class); + addImport(output, Objects.class); + addImport(output, ImmutableMap.class); + addImport(output, Iterable.class); + addImport(output, Maps.class); + } + + for (ObjectModelAttribute attribute : properties) { + + boolean multiple = JavaGeneratorUtil.isNMultiplicity(attribute); + + if (multiple) { + continue; + } + + String attrName = getAttributeName(attribute); + String attrType = getAttributeType(attribute); + + String simpleType = JavaGeneratorUtil.getSimpleName(attrType); + String capitalizeAttrName = JavaGeneratorUtil.capitalizeJavaBeanPropertyName(attrName); + String newFunctionMethodName= "new" + capitalizeAttrName + "Function"; + String newFunctionTypeName= "Function<BeanType, " + simpleType + ">"; + + ObjectModelOperation operation = addOperation( + output, + newFunctionMethodName, + "<BeanType extends " + typeName + "> "+newFunctionTypeName, + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + + String getterName = getGetterName(attrName, attribute); + setOperationBody(operation, "" + /*{ + return new <%=newFunctionTypeName%>() { + + @Override + public <%=simpleType%> apply(BeanType input) { + return input.<%=getterName%>(); + } + }; + + }*/ + ); + + String getFunctionFieldName = JavaGeneratorUtil.convertVariableNameToConstantName("get" + capitalizeAttrName); + addAttribute( + output, + getFunctionFieldName, + "Function<" + typeName + ", " + simpleType + ">", + newFunctionMethodName + "()", + ObjectModelJavaModifier.FINAL, + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PROTECTED + ); + + operation = addOperation( + output, + "uniqueIndexBy" + capitalizeAttrName, + "<BeanType extends " + typeName + "> ImmutableMap<" + simpleType + ", BeanType>", + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "Iterable<BeanType>", "source"); + setOperationBody(operation, "" + /*{ + return Maps.uniqueIndex(source, <%=getFunctionFieldName%>); + }*/ + ); + } + + } + + private String getGetterName(String attrName, ObjectModelAttribute attribute) { + boolean booleanProperty = JavaGeneratorUtil.isBooleanPrimitive(attribute); + String methodPrefix = JavaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX; + if (booleanProperty) { + methodPrefix = JavaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX; } + String getterName = getJavaBeanMethodName(methodPrefix, attrName); + return getterName; } protected Collection<ObjectModelOperation> getPublicOperations(ObjectModelClass clazz) { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See http://git.nuiton.org/eugene.git commit 253148f80d06a2c118c0cc3260dd16a129e79869 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:50:04 2015 +0200 Add usefull method to get the wrap primitive type --- .../main/java/org/nuiton/eugene/GeneratorUtil.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java b/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java index bb3afdf..3e5ada9 100644 --- a/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java +++ b/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java @@ -159,6 +159,40 @@ public class GeneratorUtil { } /** + * @param type primitive type + * @return the wrap primitive type + * @since 3.0 + */ + public static String getPRimitiveWrapType(String type) { + if ("byte".equals(type)) { + return "Byte"; + } + if ("short".equals(type)) { + return "Short"; + } + if ("int".equals(type)) { + return "Integer"; + } + if ("long".equals(type)) { + return "Long"; + } + if ("float".equals(type)) { + return "Float"; + } + if ("double".equals(type)) { + return "Double"; + } + if ("char".equals(type)) { + return "Character"; + } + if ("boolean".equals(type)) { + return "Boolean"; + } + + return null; + } + + /** * return an init value for the specified attribute * * @param attribute the attribute to test -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See http://git.nuiton.org/eugene.git commit dc50706895dde7d7aa2c5a2c467ed6c05555e0df Merge: 9a08336 253148f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:50:55 2015 +0200 Generate predicates and function in helper classes (simpleBeanWithNoInterface generator) (termine #3745) Merge branch 'feature/3745' into develop .../nuiton/eugene/java/JavaTemplatesTagValues.java | 65 ++++++++ .../SimpleJavaBeanWithNoInterfaceTransformer.java | 176 ++++++++++++++++++++- .../main/java/org/nuiton/eugene/GeneratorUtil.java | 34 ++++ 3 files changed, 273 insertions(+), 2 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See http://git.nuiton.org/eugene.git commit 75a7c1f1a4f06922246f123818e4d7a6280a225e Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:53:49 2015 +0200 Make works prefix and suffix on simpleBeanWithNoInterface generator (refs #3746) --- .../eugene/java/AbstractJavaBeanTransformer.java | 5 +- .../SimpleJavaBeanWithNoInterfaceTransformer.java | 209 +++++++++++++-------- 2 files changed, 137 insertions(+), 77 deletions(-) diff --git a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java index 84f5cba..6c6c053 100644 --- a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java +++ b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java @@ -186,8 +186,7 @@ public abstract class AbstractJavaBeanTransformer extends ObjectModelTransformer ); // Change type for Multiple attribute - attrType = JavaGeneratorUtil.getAttributeInterfaceType(attr, true); - + attrType = JavaGeneratorUtil.getAttributeInterfaceType(attr, getAttributeType(attr), true); simpleType = JavaGeneratorUtil.getSimpleName(attrType); } @@ -195,7 +194,7 @@ public abstract class AbstractJavaBeanTransformer extends ObjectModelTransformer if (multiple) { - String collectionImplementationType = JavaGeneratorUtil.getAttributeImplementationType(attr, true); + String collectionImplementationType = JavaGeneratorUtil.getAttributeImplementationType(attr, getAttributeType(attr), true); // creates a getXXX (multiple) method createGetMethod(output, diff --git a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java index b904c55..e051166 100644 --- a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java +++ b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/SimpleJavaBeanWithNoInterfaceTransformer.java @@ -42,7 +42,6 @@ import org.nuiton.eugene.models.object.ObjectModelPackage; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Objects; @@ -138,10 +137,8 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr if (withInput) { - // class in not abstract // class is a bean - - canGenerate = !input.isAbstract() && JavaTemplatesStereoTypes.hasBeanStereotype(input, aPackage); + canGenerate = JavaTemplatesStereoTypes.hasBeanStereotype(input, aPackage); } } @@ -278,13 +275,33 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr boolean generatePredicates = getJavaTemplatesTagValues().isSimpleBeanWithNoInterfaceGeneratePredicates(aClass, aPackage, model); boolean generateFunctions = getJavaTemplatesTagValues().isSimpleBeanWithNoInterfaceGenerateFunctions(aClass, aPackage, model); + boolean generateContructors = !aClass.isAbstract(); + + String superClassName = null; + + // test if a super class has bean stereotype + boolean superClassIsBean = false; + Collection<ObjectModelClass> superclasses = aClass.getSuperclasses(); + if (CollectionUtils.isNotEmpty(superclasses)) { + for (ObjectModelClass superclass : superclasses) { + if (JavaTemplatesStereoTypes.hasBeanStereotype(superclass, aPackage)) { + superClassIsBean = true; + superClassName = superclass.getPackageName() + "." + getBeanDefaultsClassName(aPackage, superclass); + break; + } else { + superClassName = superclass.getQualifiedName(); + } + } + } - // generate abstract defaults class + if (!superClassIsBean) { - // try to find a super class by tag-value - String superClassName = - getJavaTemplatesTagValues().getSimpleBeanWithNoInterfaceDefaultsSuperClassTagValue( - aClass, aPackage, model); + // try to find a super class by tag-value + superClassName = getJavaTemplatesTagValues().getSimpleBeanWithNoInterfaceDefaultsSuperClassTagValue(aClass, aPackage, model); + + } + + // generate abstract defaults class ObjectModelClass output = createAbstractClass(abstractClassName, packageName); if (StringUtils.isNotBlank(superClassName)) { @@ -295,6 +312,9 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr log.debug("will generate " + output.getQualifiedName()); } + addImport(output, Binder.class); + addImport(output, BinderFactory.class); + ObjectModelOperation operation = addOperation( output, "typeOf" + typeName, @@ -307,54 +327,58 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr return (Class<BeanType>) <%=typeName%>.class; }*/ ); - operation = addOperation( - output, - "new" + typeName, - typeName, - ObjectModelJavaModifier.STATIC, - ObjectModelJavaModifier.PUBLIC - ); - setOperationBody(operation, "" + + if (generateContructors) { + + operation = addOperation( + output, + "new" + typeName, + typeName, + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + setOperationBody(operation, "" /*{ return new <%=typeName%>(); }*/ - ); - - addImport(output, Binder.class); - addImport(output, BinderFactory.class); - operation = addOperation( - output, - "new" + typeName, - "<BeanType extends " + typeName + "> BeanType", - ObjectModelJavaModifier.STATIC, - ObjectModelJavaModifier.PUBLIC - ); - addParameter(operation, "BeanType", "source"); - setOperationBody(operation, "" + ); + + operation = addOperation( + output, + "new" + typeName, + "<BeanType extends " + typeName + "> BeanType", + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "BeanType", "source"); + setOperationBody(operation, "" /*{ Class<BeanType> sourceType = typeOf<%=typeName%>(); Binder<BeanType, BeanType> binder = BinderFactory.newBinder(sourceType); BeanType result = new<%=typeName%>(source, binder); return result; }*/ - ); - - operation = addOperation( - output, - "new" + typeName, - "<BeanType extends " + typeName + "> BeanType", - ObjectModelJavaModifier.STATIC, - ObjectModelJavaModifier.PUBLIC - ); - addParameter(operation, "BeanType", "source"); - addParameter(operation, "Binder<BeanType, BeanType>", "binder"); - setOperationBody(operation, "" + ); + + operation = addOperation( + output, + "new" + typeName, + "<BeanType extends " + typeName + "> BeanType", + ObjectModelJavaModifier.STATIC, + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "BeanType", "source"); + addParameter(operation, "Binder<BeanType, BeanType>", "binder"); + setOperationBody(operation, "" /*{ BeanType result = (BeanType) new<%=typeName%>(); binder.copy(source, result); return result; }*/ - ); + ); + + } + operation = addOperation( output, @@ -399,18 +423,35 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr } } - protected void generatePredicates(ObjectModelClass input, ObjectModelClass output, String typeName) { + @Override + protected String getAttributeType(ObjectModelAttribute attr) { + String attrType = super.getAttributeType(attr); + if (!JavaGeneratorUtil.isPrimitiveType(attrType)) { - List<ObjectModelAttribute> properties = getProperties(input); + boolean hasClass = model.hasClass(attrType); + if (hasClass) { + ObjectModelClass attributeClass = model.getClass(attrType); + String packageName = attributeClass.getPackageName(); + ObjectModelPackage attributePackage = model.getPackage(packageName); + if (JavaTemplatesStereoTypes.hasBeanStereotype(attributeClass, attributePackage)) { + + String classNamePrefix = getJavaTemplatesTagValues().getSimpleBeanWithNoInterfaceClassNamePrefixTagValue(attributeClass, attributePackage, model); + String classNameSuffix = getJavaTemplatesTagValues().getSimpleBeanWithNoInterfaceClassNameSuffixTagValue(attributeClass, attributePackage, model); + + String simpleType = JavaGeneratorUtil.getSimpleName(attrType); + attrType = generateName(classNamePrefix, simpleType, classNameSuffix); + + } + } - if (!properties.isEmpty()) { - addImport(output, Predicate.class); - addImport(output, Objects.class); - addImport(output, Iterable.class); - addImport(output, Iterables.class); } + return attrType; + } - for (ObjectModelAttribute attribute : properties) { + protected void generatePredicates(ObjectModelClass input, ObjectModelClass output, String typeName) { + + boolean atLeastOnePropertyfound=false; + for (ObjectModelAttribute attribute : getProperties(input)) { boolean multiple = JavaGeneratorUtil.isNMultiplicity(attribute); @@ -418,8 +459,10 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr continue; } + atLeastOnePropertyfound = true; String attrName = getAttributeName(attribute); String attrType = getAttributeType(attribute); + addImport(output, attrType); String simpleType = JavaGeneratorUtil.getSimpleName(attrType); @@ -465,20 +508,19 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr ); } - } - - protected void generateFunctions(ObjectModelClass input, ObjectModelClass output, String typeName) { - - List<ObjectModelAttribute> properties = getProperties(input); - if (!properties.isEmpty()) { - addImport(output, Function.class); + if (atLeastOnePropertyfound) { + addImport(output, Predicate.class); addImport(output, Objects.class); - addImport(output, ImmutableMap.class); addImport(output, Iterable.class); - addImport(output, Maps.class); + addImport(output, Iterables.class); } - for (ObjectModelAttribute attribute : properties) { + } + + protected void generateFunctions(ObjectModelClass input, ObjectModelClass output, String typeName) { + + boolean atLeastOnePropertyfound = false; + for (ObjectModelAttribute attribute : getProperties(input)) { boolean multiple = JavaGeneratorUtil.isNMultiplicity(attribute); @@ -486,10 +528,14 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr continue; } + atLeastOnePropertyfound = true; + String attrName = getAttributeName(attribute); String attrType = getAttributeType(attribute); + addImport(output, attrType); String simpleType = JavaGeneratorUtil.getSimpleName(attrType); + simpleType = wrapPrimitiveType(simpleType); String capitalizeAttrName = JavaGeneratorUtil.capitalizeJavaBeanPropertyName(attrName); String newFunctionMethodName= "new" + capitalizeAttrName + "Function"; String newFunctionTypeName= "Function<BeanType, " + simpleType + ">"; @@ -497,7 +543,7 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr ObjectModelOperation operation = addOperation( output, newFunctionMethodName, - "<BeanType extends " + typeName + "> "+newFunctionTypeName, + "<BeanType extends " + typeName + "> " + newFunctionTypeName, ObjectModelJavaModifier.STATIC, ObjectModelJavaModifier.PUBLIC ); @@ -542,6 +588,21 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr ); } + if (atLeastOnePropertyfound) { + addImport(output, Function.class); + addImport(output, Objects.class); + addImport(output, ImmutableMap.class); + addImport(output, Iterable.class); + addImport(output, Maps.class); + } + + } + + protected String wrapPrimitiveType(String attrType) { + if (JavaGeneratorUtil.isPrimitiveType(attrType)) { + attrType = JavaGeneratorUtil.getPRimitiveWrapType(attrType); + } + return attrType; } private String getGetterName(String attrName, ObjectModelAttribute attribute) { @@ -554,18 +615,18 @@ public class SimpleJavaBeanWithNoInterfaceTransformer extends AbstractJavaBeanTr return getterName; } - protected Collection<ObjectModelOperation> getPublicOperations(ObjectModelClass clazz) { - - Collection<ObjectModelOperation> result = new ArrayList<ObjectModelOperation>(); - for (ObjectModelOperation operation : clazz.getOperations()) { - - ObjectModelJavaModifier visibility = ObjectModelJavaModifier.fromVisibility(operation.getVisibility()); - if (ObjectModelJavaModifier.PUBLIC == visibility) { - result.add(operation); - } - } - return result; - } +// protected Collection<ObjectModelOperation> getPublicOperations(ObjectModelClass clazz) { +// +// Collection<ObjectModelOperation> result = new ArrayList<ObjectModelOperation>(); +// for (ObjectModelOperation operation : clazz.getOperations()) { +// +// ObjectModelJavaModifier visibility = ObjectModelJavaModifier.fromVisibility(operation.getVisibility()); +// if (ObjectModelJavaModifier.PUBLIC == visibility) { +// result.add(operation); +// } +// } +// return result; +// } protected String getBeanClassName(ObjectModelPackage aPackage, ObjectModelClass input) { String classNamePrefix = getJavaTemplatesTagValues().getSimpleBeanWithNoInterfaceClassNamePrefixTagValue(input, aPackage, model); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See http://git.nuiton.org/eugene.git commit 39952d8f0ed145eacd9a3feeb01f35517c776296 Merge: dc50706 75a7c1f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 14 18:53:56 2015 +0200 Can't use prefix and suffix in simpleBeanWithNoInterface generator (termine #3746) Merge branch 'feature/3746' into develop .../eugene/java/AbstractJavaBeanTransformer.java | 5 +- .../SimpleJavaBeanWithNoInterfaceTransformer.java | 209 +++++++++++++-------- 2 files changed, 137 insertions(+), 77 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm