/** * Return a copy of the correct code format. */ private CodeFormat newCodeFormat() { return (_format == null) ? new CodeFormat() : (CodeFormat) _format.clone(); }
private String getHashCodeByteArrayCode() { CodeFormat code = newCodeFormat(); code.tab().append("private static int hashCode").openParen(true). append("byte[] b").closeParen().openBrace(2).endl(); code.tab(2).append("if").openParen(true).append("b == null"). closeParen().endl(); code.tab(3).append("return 0;").endl(); code.tab(2).append("int sum = 0;").endl(); code.tab(2).append("for").openParen(true). append("int i = 0; i < b.length; i++").closeParen().endl(); code.tab(3).append("sum += b[i];").endl(); code.tab(2).append("return sum;").endl(); code.closeBrace(2); return code.toString(); }
/** * Implements declaration. Uses configuration of {@link #openBrace}, * but prints "implements" instead of a brace. */ public String getImplementsDec(int tabLevel) { if (_braceOnSameLine) return " implements"; if (_braceAtSameTabLevel) return getEndl() + getTab(tabLevel) + "implements"; return getEndl() + getTab(tabLevel) + "implements"; }
Class elmCls = fmd.getElement().getDeclaredType(); elementType = ClassUtil.getClassName(elmCls); paramType = decs.getParametrizedType( new String[] {elementType}); } else if (fmd.getDeclaredTypeCode() == JavaTypes.MAP) { keyType = ClassUtil.getClassName(keyCls); elementType = ClassUtil.getClassName(elmCls); paramType = decs.getParametrizedType( new String[] {keyType, elementType}); if (fieldValue == null) { if ("Set".equals(fieldType)) fieldValue = "new HashSet" + paramType + decs.getParens(); else if ("TreeSet".equals(fieldType)) fieldValue = "new TreeSet" + paramType + decs.getParens(); else if ("Collection".equals(fieldType)) fieldValue = "new ArrayList" + paramType + decs.getParens(); else if ("Map".equals(fieldType)) fieldValue = "new HashMap" + paramType + decs.getParens(); else if ("TreeMap".equals(fieldType)) fieldValue = "new TreeMap" + paramType + decs.getParens(); else if (fmd.getDeclaredTypeCode() == JavaTypes.COLLECTION || fmd.getDeclaredTypeCode() == JavaTypes.MAP) fieldValue = "new " + fieldType + paramType + decs.getParens(); else fieldValue = ""; if (decs.length() > 0)
CodeFormat code = newCodeFormat(); if (packageDec.length() > 0) code.append(packageDec).afterSection(); if (imports.length() > 0) code.append(imports).afterSection(); code.append("/**").endl(). append(" * Auto-generated by:").endl(). append(" * ").append(getClass().getName()).endl(). append(" */").endl(); code.append("public class ").append(className); if (extendsName.length() > 0) code.extendsDec(1).append(" ").append(extendsName); openClassBrace(code); code.append(fieldDecs).afterSection(); code.tab().append("public ").append(className).parens(); code.openBrace(2).endl().closeBrace(2); code.afterSection().append(constructor); if (fieldCode.length() > 0) code.afterSection().append(fieldCode); code.endl(); return code.toString();
/** * Return the code to declare all primary key fields. */ private String getFieldDeclarations() { CodeFormat code = newCodeFormat(); for (int i = 0; i < _fields.length; i++) { if (i > 0) code.endl(); code.tab().append("public ").append(getTypeName(_fields[i])). append(" ").append(_fields[i].getName()).append(";"); } return code.toString(); }
/** * If there is an inner application identity class, then * add it to the bottom of the class code. */ protected void closeClassBrace(CodeFormat code) { if (_appid != null) { code.afterSection(); code.append(_appid.getCode()); code.endl(); } super.closeClassBrace(code); }
/** * Appends the given list of annotations to code buffer. */ private void writeAnnotations (CodeFormat code, List ann, int tabLevel) { if (ann == null || ann.size() == 0) return; for (Iterator i = ann.iterator(); i.hasNext();) { if (tabLevel > 0) code.tab(tabLevel); String s = (String) i.next(); code.append(s).endl(); } }
/** * Default constructor. */ public ReverseMappingToolTask() { flags.metaDataLevel = "package"; flags.format = new CodeFormat(); }
/** * Tab string. Users can choose to use spaces or tab characters. */ public String getTab() { return getTab(1); }
/** * Append the given value to the internal buffer. * * @see #getParens */ public CodeFormat parens() { _buf.append(getParens()); return this; }
/** * Append the closing code-level brace to the code; this can be * overridden to add code to the bottom of the class. */ protected void closeClassBrace(CodeFormat code) { code.closeBrace(1); }
Class elmCls = fmd.getElement().getDeclaredType(); elementType = Strings.getClassName(elmCls); paramType = decs.getParametrizedType( new String[] {elementType}); } else if (fmd.getDeclaredTypeCode() == JavaTypes.MAP) { keyType = Strings.getClassName(keyCls); elementType = Strings.getClassName(elmCls); paramType = decs.getParametrizedType( new String[] {keyType, elementType}); if (fieldValue == null) { if ("Set".equals(fieldType)) fieldValue = "new HashSet" + paramType + decs.getParens(); else if ("TreeSet".equals(fieldType)) fieldValue = "new TreeSet" + paramType + decs.getParens(); else if ("Collection".equals(fieldType)) fieldValue = "new ArrayList" + paramType + decs.getParens(); else if ("Map".equals(fieldType)) fieldValue = "new HashMap" + paramType + decs.getParens(); else if ("TreeMap".equals(fieldType)) fieldValue = "new TreeMap" + paramType + decs.getParens(); else if (fmd.getDeclaredTypeCode() == JavaTypes.COLLECTION || fmd.getDeclaredTypeCode() == JavaTypes.MAP) fieldValue = "new " + fieldType + paramType + decs.getParens(); else fieldValue = ""; if (decs.length() > 0)
CodeFormat code = newCodeFormat(); if (packageDec.length() > 0) code.append(packageDec).afterSection(); if (imports.length() > 0) code.append(imports).afterSection(); code.append("/**").endl(). append(" * Auto-generated by:").endl(). append(" * ").append(getClass().getName()).endl(). append(" */").endl(); code.append("public class ").append(className); if (extendsName.length() > 0) code.extendsDec(1).append(" ").append(extendsName); openClassBrace(code); code.append(fieldDecs).afterSection(); code.tab().append("public ").append(className).parens(); code.openBrace(2).endl().closeBrace(2); code.afterSection().append(constructor); if (fieldCode.length() > 0) code.afterSection().append(fieldCode); code.endl(); return code.toString();
/** * Return the code to declare all primary key fields. */ private String getFieldDeclarations() { CodeFormat code = newCodeFormat(); for (int i = 0; i < _fields.length; i++) { if (i > 0) code.endl(); code.tab().append("public ").append(getTypeName(_fields[i])). append(" ").append(_fields[i].getName()).append(";"); } return code.toString(); }
/** * If there is an inner application identity class, then * add it to the bottom of the class code. */ protected void closeClassBrace(CodeFormat code) { if (_appid != null) { code.afterSection(); code.append(_appid.getCode()); code.endl(); } super.closeClassBrace(code); }
/** * Appends the given list of annotations to code buffer. */ private void writeAnnotations (CodeFormat code, List ann, int tabLevel) { if (ann == null || ann.size() == 0) return; for (Iterator i = ann.iterator(); i.hasNext();) { if (tabLevel > 0) code.tab(tabLevel); String s = (String) i.next(); code.append(s).endl(); } }
/** * Default constructor. */ public ReverseMappingToolTask() { flags.metaDataLevel = "package"; flags.format = new CodeFormat(); }