use of org.mybatis.generator.api.dom.java.TopLevelClass in project generator by mybatis.
the class SupersGenerator method getSuperClass.
private TopLevelClass getSuperClass() {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(BASE_PACKAGE + ".sub.SuperClass");
TopLevelClass tlc = new TopLevelClass(fqjt);
tlc.setVisibility(JavaVisibility.PUBLIC);
return tlc;
}
use of org.mybatis.generator.api.dom.java.TopLevelClass in project littlefisher-system by littlefishercoder.
the class SortImportsAndFieldsJavaFormatter method getClassFormattedContent.
/**
* Description: 类format
*/
private String getClassFormattedContent(CompilationUnit compilationUnit) {
StringBuilder sb = new StringBuilder();
TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
topLevelClass.getFileCommentLines().forEach(fileCommentLine -> {
sb.append(fileCommentLine);
newLine(sb);
});
formatPackage(sb, topLevelClass.getType().getPackageName());
formatStaticImports(sb, topLevelClass.getStaticImports());
if (topLevelClass.getStaticImports().size() > 0) {
newLine(sb);
}
Set<String> importStrings = calculateImports(topLevelClass.getImportedTypes());
sortImportTypes(sb, importStrings);
if (importStrings.size() > 0) {
newLine(sb);
}
sb.append(topLevelClass.getFormattedContent(0, compilationUnit));
return sb.toString();
}
use of org.mybatis.generator.api.dom.java.TopLevelClass in project littlefisher-system by littlefishercoder.
the class SortImportsAndFieldsJavaFormatter method formatFields.
/**
* 对model中的field顺序进行重构
* 把serialVersionUID放在首位
*/
private void formatFields(CompilationUnit compilationUnit) {
String serializableFieldName = "serialVersionUID";
TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
Ordering<Field> ordering = new Ordering<Field>() {
@Override
public int compare(Field left, Field right) {
if (serializableFieldName.equals(left.getName())) {
return -1;
} else if (serializableFieldName.equals(right.getName())) {
return 1;
} else {
return 0;
}
}
};
List<Field> fieldList = ordering.sortedCopy(topLevelClass.getFields());
topLevelClass.getFields().clear();
topLevelClass.getFields().addAll(fieldList);
}
use of org.mybatis.generator.api.dom.java.TopLevelClass in project generator by mybatis.
the class DAOGenerator method getTopLevelClassShell.
protected TopLevelClass getTopLevelClassShell() {
FullyQualifiedJavaType interfaceType = new FullyQualifiedJavaType(introspectedTable.getDAOInterfaceType());
FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType(introspectedTable.getDAOImplementationType());
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass answer = new TopLevelClass(implementationType);
answer.setVisibility(JavaVisibility.PUBLIC);
answer.setSuperClass(daoTemplate.getSuperClass());
answer.addImportedType(daoTemplate.getSuperClass());
answer.addSuperInterface(interfaceType);
answer.addImportedType(interfaceType);
for (FullyQualifiedJavaType fqjt : daoTemplate.getImplementationImports()) {
answer.addImportedType(fqjt);
}
commentGenerator.addJavaFileComment(answer);
// add constructor from the template
answer.addMethod(daoTemplate.getConstructorClone(commentGenerator, implementationType, introspectedTable));
// add any fields from the template
for (Field field : daoTemplate.getFieldClones(commentGenerator, introspectedTable)) {
answer.addField(field);
}
// add any methods from the template
for (Method method : daoTemplate.getMethodClones(commentGenerator, introspectedTable)) {
answer.addMethod(method);
}
return answer;
}
use of org.mybatis.generator.api.dom.java.TopLevelClass in project generator by mybatis.
the class PrimaryKeyGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.7", //$NON-NLS-1$
table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getPrimaryKeyType());
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
String rootClass = getRootClass();
if (rootClass != null) {
topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
topLevelClass.addImportedType(topLevelClass.getSuperClass());
}
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
Aggregations