예제 #1
0
 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;
 }
예제 #2
0
 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();
 }
예제 #3
0
  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();
  }
예제 #4
0
  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;
  }