Author: tchemit Date: 2011-10-20 06:20:56 +0200 (Thu, 20 Oct 2011) New Revision: 1116 Url: http://nuiton.org/repositories/revision/eugene/1116 Log: Evolution #1781: Permits not to generate getXXX() methods for boolean properties Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2011-10-20 02:59:54 UTC (rev 1115) +++ trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2011-10-20 04:20:56 UTC (rev 1116) @@ -110,4 +110,15 @@ @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class}, documentation = "Sets the i18n prefix to use on I18n keys generated") String TAG_I18N_PREFIX = "i18n"; + + /** + * Tag value to specify to not generate only the {@code isXXX} methods for + * a boolean property. + * + * @see JavaGeneratorUtil#getDoNotGenerateBooleanGetMethods(ObjectModel, ObjectModelClassifier) + * @since 2.4.1 + */ + @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class}, + documentation = "To specify to NOT generate getXXX methods for boolean properties") + String TAG_DO_NOT_GENERATE_BOOLEAN_GET_METHODS = "doNotGenerateBooleanGetMethods"; } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2011-10-20 02:59:54 UTC (rev 1115) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2011-10-20 04:20:56 UTC (rev 1116) @@ -98,7 +98,13 @@ String noPCSTagValue = JavaGeneratorUtil.getNoPCSTagValue(model, input); boolean usePCS = StringUtils.isEmpty(noPCSTagValue) || !"true".equals(noPCSTagValue.trim()); - + + String noGenerateBooleanGetMethods = + JavaGeneratorUtil.getDoNotGenerateBooleanGetMethods(model, input); + boolean generateBooleanGetMethods = + StringUtils.isEmpty(noGenerateBooleanGetMethods) || + !"true".equals(noGenerateBooleanGetMethods.trim()); + String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX); setConstantPrefix(prefix); @@ -123,7 +129,7 @@ // Add properties field + javabean methods for (ObjectModelAttribute attr : properties) { - createProperty(output, attr, usePCS); + createProperty(output, attr, usePCS, generateBooleanGetMethods); } // Add operations @@ -222,7 +228,8 @@ protected void createProperty(ObjectModelClass output, ObjectModelAttribute attr, - boolean usePCS) { + boolean usePCS, + boolean generateBooleanGetMethods) { String attrName = getAttributeName(attr); String attrType = getAttributeType(attr); @@ -305,13 +312,29 @@ simpleType = JavaGeneratorUtil.getSimpleName(attrType); } - createGetMethod(output, - attrName, - attrNameCapitalized, - attrType, - null - ); + boolean booleanProperty = attrType.toLowerCase().contains("boolean"); + if (booleanProperty && ! multiple) { + + // creates a isXXX method + createGetMethod(output, + attrName, + attrNameCapitalized, + attrType, + JavaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX + ); + } + + if (multiple || !booleanProperty || generateBooleanGetMethods) { + + createGetMethod(output, + attrName, + attrNameCapitalized, + attrType, + JavaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX + ); + + } createSetMethod(output, attrName, attrNameCapitalized, @@ -364,10 +387,6 @@ String attrType, String methodPrefix) { - if (methodPrefix == null) { - methodPrefix = JavaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX; - } - ObjectModelOperation getter = addOperation( output, methodPrefix + attrNameCapitalized, @@ -379,13 +398,6 @@ return <%=attrName%>; }*/ ); - - // Create also getter for boolean with 'is' prefix - if (attrType.toLowerCase().contains("boolean") && - !methodPrefix.equals(JavaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX)) { - createGetMethod(output, attrName, attrNameCapitalized, attrType, - JavaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX); - } } protected void createGetChildMethod(ObjectModelClass output, Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java 2011-10-20 02:59:54 UTC (rev 1115) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java 2011-10-20 04:20:56 UTC (rev 1116) @@ -157,6 +157,24 @@ } /** + * Obtain the value of the {@link EugeneTagValues#TAG_DO_NOT_GENERATE_BOOLEAN_GET_METHODS} + * tag value on the given model or classifier. + * <p/> + * It will first look on the model, and then in the given classifier. + * + * @param model model to seek + * @param classifier classifier to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see EugeneTagValues#TAG_DO_NOT_GENERATE_BOOLEAN_GET_METHODS + * @since 2.4.1 + */ + public static String getDoNotGenerateBooleanGetMethods(ObjectModel model, + ObjectModelClassifier classifier) { + String value = findTagValue(EugeneTagValues.TAG_DO_NOT_GENERATE_BOOLEAN_GET_METHODS, classifier, model); + return value; + } + + /** * Obtain the value of the {@link EugeneTagValues#TAG_NO_PCS} * tag value on the given model or classifier. * <p/>