public String getClassJavaDoc(String fallback, int indent) { MetaAttribute c = meta.getMetaAttribute(CLASS_DESCRIPTION); if (c == null) { return c2j.toJavaDoc(fallback, indent); } else { return c2j.toJavaDoc(getMetaAsString(CLASS_DESCRIPTION), indent); } }
public String getFieldJavaDoc(Property property, int indent) { MetaAttribute c = property.getMetaAttribute("field-description"); if (c == null) { return c2j.toJavaDoc("", indent); } else { return c2j.toJavaDoc(c2j.getMetaAsString(property, "field-description"), indent); } }
public String generateHashCode(Property property, String result, String thisName, boolean jdk5) { StringBuffer buf = new StringBuffer(); if (c2j.getMetaAsBool(property, "use-in-equals")) { String javaTypeName = c2j.getJavaTypeName(property, jdk5, this); boolean isPrimitive = c2j.isPrimitive(javaTypeName); if (isPrimitive) { buf.append(result).append(" = 37 * ").append(result).append(" + "); String thisValue = thisName + "." + getGetterSignature(property) + "()"; if ("char".equals(javaTypeName) || "int".equals(javaTypeName) || "short".equals(javaTypeName) || "byte".equals(javaTypeName)) { buf.append(thisValue); } else if ("boolean".equals(javaTypeName)) { buf.append("(" + thisValue + "?1:0)"); } else { buf.append("(int) "); buf.append(thisValue); } buf.append(";"); } else { if (javaTypeName.endsWith("[]")) { if (jdk5) { buf.append(result).append(" = 37 * ").append(result).append(" + "); buf.append("( ") .append(getGetterSignature(property)) .append("() == null ? 0 : " + importType("java.util.Arrays") + ".hashCode(") .append(thisName) .append(".") .append(getGetterSignature(property)) .append("())") .append(" )") .append(";"); } else { buf.append(internalGenerateArrayHashcode(property, javaTypeName, result, thisName)); } } else { buf.append(result).append(" = 37 * ").append(result).append(" + "); buf.append("( ") .append(getGetterSignature(property)) .append("() == null ? 0 : ") .append(thisName) .append(".") .append(getGetterSignature(property)) .append("()") .append(".hashCode()") .append(" )") .append(";"); } } } return buf.toString(); }
private boolean usePropertyInEquals(Property property) { boolean hasEqualsMetaAttribute = c2j.hasMetaAttribute(property, "use-in-equals"); boolean useInEquals = c2j.getMetaAsBool(property, "use-in-equals"); if (property.isNaturalIdentifier()) { if (hasEqualsMetaAttribute && !useInEquals) { return false; } else { return true; } } return useInEquals; }
public String getFieldDescription(Property property) { MetaAttribute c = property.getMetaAttribute("field-description"); if (c == null) { return ""; } else { return c2j.getMetaAsString(property, "field-description"); } }
private boolean needsToString(Iterator<Property> iter) { while (iter.hasNext()) { Property element = (Property) iter.next(); if (c2j.getMetaAsBool(element, "use-in-tostring")) { return true; } } return false; }
private Iterator<Property> getToStringPropertiesIterator(Iterator<Property> iter) { List<Property> properties = new ArrayList<Property>(); while (iter.hasNext()) { Property element = (Property) iter.next(); if (c2j.getMetaAsBool(element, "use-in-tostring")) { properties.add(element); } } return properties.iterator(); }
private String internalgenerateEquals(String typeName, String lh, String rh) { if (c2j.isPrimitive(typeName)) { return "(" + lh + "==" + rh + ")"; } else { if (useCompareTo(typeName)) { return "( (" + lh + "==" + rh + ") || ( " + lh + "!=null && " + rh + "!=null && " + lh + ".compareTo(" + rh + ")==0 ) )"; } else { if (typeName.endsWith("[]")) { return "( (" + lh + "==" + rh + ") || ( " + lh + "!=null && " + rh + "!=null && " + importType("java.util.Arrays") + ".equals(" + lh + ", " + rh + ") ) )"; } else { return "( (" + lh + "==" + rh + ") || ( " + lh + "!=null && " + rh + "!=null && " + lh + ".equals(" + rh + ") ) )"; } } } }
protected String generateEquals( String thisName, String otherName, Iterator<Property> allPropertiesIterator, boolean useGenerics) { StringBuffer buf = new StringBuffer(); while (allPropertiesIterator.hasNext()) { Property property = (Property) allPropertiesIterator.next(); if (buf.length() > 0) buf.append("\n && "); String javaTypeName = c2j.getJavaTypeName(property, useGenerics, this); buf.append( internalgenerateEquals( javaTypeName, thisName + "." + getGetterSignature(property) + "()", otherName + "." + getGetterSignature(property) + "()")); } if (buf.length() == 0) { return "false"; } else { return buf.toString(); } }
public String getFieldInitialization(Property p, boolean useGenerics) { if (hasMetaAttribute(p, "default-value")) { return MetaAttributeHelper.getMetaAsString(p.getMetaAttribute("default-value")); } if (c2j.getJavaTypeName(p, false) == null) { throw new IllegalArgumentException(); } else if (p.getValue() instanceof Collection) { Collection col = (Collection) p.getValue(); DefaultInitializor initialization = (DefaultInitializor) col.accept( new DefaultValueVisitor(true) { public Object accept(Bag o) { return new DefaultInitializor("java.util.ArrayList", true); } public Object accept(org.hibernate.mapping.List o) { return new DefaultInitializor("java.util.ArrayList", true); } public Object accept(org.hibernate.mapping.Map o) { if (o.isSorted()) { return new DefaultInitializor("java.util.TreeMap", false); } else { return new DefaultInitializor("java.util.HashMap", true); } } public Object accept(IdentifierBag o) { return new DefaultInitializor("java.util.ArrayList", true); } public Object accept(Set o) { if (o.isSorted()) { return new DefaultInitializor("java.util.TreeSet", false); } else { return new DefaultInitializor("java.util.HashSet", true); } } public Object accept(PrimitiveArray o) { return null; // TODO: default init for arrays ? } public Object accept(Array o) { return null; // TODO: default init for arrays ? } }); if (initialization != null) { String comparator = null; String decl = null; if (col.isSorted()) { comparator = col.getComparatorClassName(); } if (useGenerics) { decl = c2j.getGenericCollectionDeclaration((Collection) p.getValue(), true, importContext); } return initialization.getDefaultValue(comparator, decl, this); } else { return null; } } else { return null; } }
public String getJavaTypeName(Property p, boolean useGenerics) { return c2j.getJavaTypeName(p, useGenerics, this); }
/** * Method getGetterSignature. * * @return String */ public String getGetterSignature(Property p) { String prefix = c2j.getJavaTypeName(p, false).equals("boolean") ? "is" : "get"; return prefix + beanCapitalize(p.getName()); }