Java Code Examples for org.mybatis.generator.api.dom.OutputUtilities#javaIndent()
The following examples show how to use
org.mybatis.generator.api.dom.OutputUtilities#javaIndent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BodyLineRenderer.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
public List<String> render(List<String> bodyLines) { List<String> lines = new ArrayList<>(); int indentLevel = 1; StringBuilder sb = new StringBuilder(); ListIterator<String> listIter = bodyLines.listIterator(); while (listIter.hasNext()) { sb.setLength(0); String line = listIter.next(); if (line.startsWith("}")) { indentLevel--; } OutputUtilities.javaIndent(sb, indentLevel); sb.append(line); lines.add(sb.toString()); if (isCodeBlockStartExceptSwitchStatement(line) || line.endsWith(":")) { indentLevel++; } if (line.startsWith("break")) { // if the next line is '}', then don't outdent if (listIter.hasNext()) { String nextLine = listIter.next(); if (nextLine.startsWith("}")) { indentLevel++; } // set back to the previous element listIter.previous(); } indentLevel--; } } return lines; }
Example 2
Source File: Field.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
public String getFormattedContent(int indentLevel) { StringBuilder sb = new StringBuilder(); addFormattedJavadoc(sb, indentLevel); addFormattedAnnotations(sb, indentLevel); OutputUtilities.javaIndent(sb, indentLevel); sb.append(getVisibility().getValue()); if (isStatic()) { sb.append("static "); //$NON-NLS-1$ } if (isFinal()) { sb.append("final "); //$NON-NLS-1$ } if (isTransient()) { sb.append("transient "); //$NON-NLS-1$ } if (isVolatile()) { sb.append("volatile "); //$NON-NLS-1$ } sb.append(type.getShortName()); sb.append(' '); sb.append(name); if (initializationString != null && initializationString.length() > 0) { sb.append(" = "); //$NON-NLS-1$ sb.append(initializationString); } sb.append(';'); return sb.toString(); }
Example 3
Source File: JavaElement.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public void addFormattedJavadoc(StringBuilder sb, int indentLevel) { for (String javaDocLine : javaDocLines) { OutputUtilities.javaIndent(sb, indentLevel); sb.append(javaDocLine); OutputUtilities.newLine(sb); } }
Example 4
Source File: JavaElement.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public void addFormattedAnnotations(StringBuilder sb, int indentLevel) { for (String annotation : annotations) { OutputUtilities.javaIndent(sb, indentLevel); sb.append(annotation); OutputUtilities.newLine(sb); } }
Example 5
Source File: InnerInterface.java From mybatis-generator-plugin with Apache License 2.0 | 4 votes |
/** * 格式化后内容,因为是内部接口,需要增加缩进 * * @param indentLevel the indent level * @param compilationUnit the compilation unit * @return the formatted content */ @Override public String getFormattedContent(int indentLevel, CompilationUnit compilationUnit) { StringBuilder sb = new StringBuilder(); for (String commentLine : getFileCommentLines()) { sb.append(commentLine); newLine(sb); } if (stringHasValue(getType().getPackageName())) { sb.append("package "); sb.append(getType().getPackageName()); sb.append(';'); newLine(sb); newLine(sb); } for (String staticImport : getStaticImports()) { sb.append("import static "); sb.append(staticImport); sb.append(';'); newLine(sb); } if (getStaticImports().size() > 0) { newLine(sb); } Set<String> importStrings = calculateImports(getImportedTypes()); for (String importString : importStrings) { sb.append(importString); newLine(sb); } if (importStrings.size() > 0) { newLine(sb); } addFormattedJavadoc(sb, indentLevel); addFormattedAnnotations(sb, indentLevel); OutputUtilities.javaIndent(sb, indentLevel); sb.append(getVisibility().getValue()); if (isFinal()) { sb.append("final "); } sb.append("interface "); sb.append(getType().getShortName()); if (getSuperInterfaceTypes().size() > 0) { sb.append(" extends "); boolean comma = false; for (FullyQualifiedJavaType fqjt : getSuperInterfaceTypes()) { if (comma) { sb.append(", "); } else { comma = true; } sb.append(JavaDomUtils.calculateTypeName(this, fqjt)); } } sb.append(" {"); indentLevel++; Iterator<Method> mtdIter = getMethods().iterator(); while (mtdIter.hasNext()) { newLine(sb); Method method = mtdIter.next(); sb.append(method.getFormattedContent(indentLevel, true, this)); if (mtdIter.hasNext()) { newLine(sb); } } indentLevel--; newLine(sb); javaIndent(sb, indentLevel); sb.append('}'); return sb.toString(); }
Example 6
Source File: InitializationBlock.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
public String getFormattedContent(int indentLevel) { StringBuilder sb = new StringBuilder(); for (String javaDocLine : javaDocLines) { OutputUtilities.javaIndent(sb, indentLevel); sb.append(javaDocLine); OutputUtilities.newLine(sb); } OutputUtilities.javaIndent(sb, indentLevel); if (isStatic) { sb.append("static "); //$NON-NLS-1$ } sb.append('{'); indentLevel++; ListIterator<String> listIter = bodyLines.listIterator(); while (listIter.hasNext()) { String line = listIter.next(); if (line.startsWith("}")) { //$NON-NLS-1$ indentLevel--; } OutputUtilities.newLine(sb); OutputUtilities.javaIndent(sb, indentLevel); sb.append(line); if ((line.endsWith("{") && !line.startsWith("switch")) //$NON-NLS-1$ //$NON-NLS-2$ || line.endsWith(":")) { //$NON-NLS-1$ indentLevel++; } if (line.startsWith("break")) { //$NON-NLS-1$ // if the next line is '}', then don't outdent if (listIter.hasNext()) { String nextLine = listIter.next(); if (nextLine.startsWith("}")) { //$NON-NLS-1$ indentLevel++; } // set back to the previous element listIter.previous(); } indentLevel--; } } indentLevel--; OutputUtilities.newLine(sb); OutputUtilities.javaIndent(sb, indentLevel); sb.append('}'); return sb.toString(); }
Example 7
Source File: InitializationBlock.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
public String getFormattedContent(int indentLevel) { StringBuilder sb = new StringBuilder(); for (String javaDocLine : javaDocLines) { OutputUtilities.javaIndent(sb, indentLevel); sb.append(javaDocLine); OutputUtilities.newLine(sb); } OutputUtilities.javaIndent(sb, indentLevel); if (isStatic) { sb.append("static "); //$NON-NLS-1$ } sb.append('{'); indentLevel++; ListIterator<String> listIter = bodyLines.listIterator(); while (listIter.hasNext()) { String line = listIter.next(); if (line.startsWith("}")) { //$NON-NLS-1$ indentLevel--; } OutputUtilities.newLine(sb); OutputUtilities.javaIndent(sb, indentLevel); sb.append(line); if ((line.endsWith("{") && !line.startsWith("switch")) //$NON-NLS-1$ //$NON-NLS-2$ || line.endsWith(":")) { //$NON-NLS-1$ indentLevel++; } if (line.startsWith("break")) { //$NON-NLS-1$ // if the next line is '}', then don't outdent if (listIter.hasNext()) { String nextLine = listIter.next(); if (nextLine.startsWith("}")) { //$NON-NLS-1$ indentLevel++; } // set back to the previous element listIter.previous(); } indentLevel--; } } indentLevel--; OutputUtilities.newLine(sb); OutputUtilities.javaIndent(sb, indentLevel); sb.append('}'); return sb.toString(); }
Example 8
Source File: Field.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
public String getFormattedContent(int indentLevel) { StringBuilder sb = new StringBuilder(); addFormattedJavadoc(sb, indentLevel); addFormattedAnnotations(sb, indentLevel); OutputUtilities.javaIndent(sb, indentLevel); sb.append(getVisibility().getValue()); if (isStatic()) { sb.append("static "); //$NON-NLS-1$ } if (isFinal()) { sb.append("final "); //$NON-NLS-1$ } if (isTransient()) { sb.append("transient "); //$NON-NLS-1$ } if (isVolatile()) { sb.append("volatile "); //$NON-NLS-1$ } sb.append(type.getShortName()); sb.append(' '); sb.append(name); if (initializationString != null && initializationString.length() > 0) { sb.append(" = "); //$NON-NLS-1$ sb.append(initializationString); } sb.append(';'); if(comments!=null){ sb.append("//").append(comments); } return sb.toString(); }
Example 9
Source File: EqualsHashCodePlugin.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
/** * Generates an <tt>equals</tt> method that does a comparison of all fields. * <p> * The generated <tt>equals</tt> method will be correct unless: * <ul> * <li>Other fields have been added to the generated classes</li> * <li>A <tt>rootClass</tt> is specified that holds state</li> * </ul> * * @param topLevelClass * the class to which the method will be added * @param introspectedColumns * column definitions of this class and any superclass of this * class * @param introspectedTable * the table corresponding to this class */ protected void generateEquals(TopLevelClass topLevelClass, List<IntrospectedColumn> introspectedColumns, IntrospectedTable introspectedTable) { Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType .getBooleanPrimitiveInstance()); method.setName("equals"); //$NON-NLS-1$ method.addParameter(new Parameter(FullyQualifiedJavaType .getObjectInstance(), "that")); //$NON-NLS-1$ if (introspectedTable.isJava5Targeted()) { method.addAnnotation("@Override"); //$NON-NLS-1$ } context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("if (this == that) {"); //$NON-NLS-1$ method.addBodyLine("return true;"); //$NON-NLS-1$ method.addBodyLine("}"); //$NON-NLS-1$ method.addBodyLine("if (that == null) {"); //$NON-NLS-1$ method.addBodyLine("return false;"); //$NON-NLS-1$ method.addBodyLine("}"); //$NON-NLS-1$ method.addBodyLine("if (getClass() != that.getClass()) {"); //$NON-NLS-1$ method.addBodyLine("return false;"); //$NON-NLS-1$ method.addBodyLine("}"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append(topLevelClass.getType().getShortName()); sb.append(" other = ("); //$NON-NLS-1$ sb.append(topLevelClass.getType().getShortName()); sb.append(") that;"); //$NON-NLS-1$ method.addBodyLine(sb.toString()); boolean first = true; Iterator<IntrospectedColumn> iter = introspectedColumns.iterator(); while (iter.hasNext()) { IntrospectedColumn introspectedColumn = iter.next(); sb.setLength(0); if (first) { sb.append("return ("); //$NON-NLS-1$ first = false; } else { OutputUtilities.javaIndent(sb, 1); sb.append("&& ("); //$NON-NLS-1$ } String getterMethod = getGetterMethodName( introspectedColumn.getJavaProperty(), introspectedColumn .getFullyQualifiedJavaType()); if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { sb.append("this."); //$NON-NLS-1$ sb.append(getterMethod); sb.append("() == "); //$NON-NLS-1$ sb.append("other."); //$NON-NLS-1$ sb.append(getterMethod); sb.append("())"); //$NON-NLS-1$ } else { sb.append("this."); //$NON-NLS-1$ sb.append(getterMethod); sb.append("() == null ? other."); //$NON-NLS-1$ sb.append(getterMethod); sb.append("() == null : this."); //$NON-NLS-1$ sb.append(getterMethod); sb.append("().equals(other."); //$NON-NLS-1$ sb.append(getterMethod); sb.append("()))"); //$NON-NLS-1$ } if (!iter.hasNext()) { sb.append(';'); } method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example 10
Source File: JavaElement.java From mybatis-generator-core-fix with Apache License 2.0 | 3 votes |
/** * Adds the formatted javadoc. * * @param sb * the sb * @param indentLevel * the indent level */ public void addFormattedJavadoc(StringBuilder sb, int indentLevel) { for (String javaDocLine : javaDocLines) { OutputUtilities.javaIndent(sb, indentLevel); sb.append(javaDocLine); OutputUtilities.newLine(sb); } }
Example 11
Source File: JavaElement.java From mybatis-generator-core-fix with Apache License 2.0 | 3 votes |
/** * Adds the formatted annotations. * * @param sb * the sb * @param indentLevel * the indent level */ public void addFormattedAnnotations(StringBuilder sb, int indentLevel) { for (String annotation : annotations) { OutputUtilities.javaIndent(sb, indentLevel); sb.append(annotation); OutputUtilities.newLine(sb); } }