org.mybatis.generator.api.dom.java.CompilationUnit Java Examples
The following examples show how to use
org.mybatis.generator.api.dom.java.CompilationUnit.
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: LombokPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 6 votes |
/** * 测试具体生成(只有keys的特殊情况,尽量使用Builder) */ @Test public void testGenerateWithOnlyKeys() throws Exception { MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LombokPlugin/mybatis-generator-with-only-keys.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) { CompilationUnit compilationUnit = file.getCompilationUnit(); if (compilationUnit instanceof TopLevelClass) { TopLevelClass topLevelClass = (TopLevelClass) compilationUnit; String name = topLevelClass.getType().getShortName(); if (name.equals("TbOnlyKeysKey")){ Assert.assertTrue(topLevelClass.getAnnotations().contains("@Builder")); } } } }
Example #2
Source File: InnerInterfaceRenderer.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
public List<String> render(InnerInterface innerInterface, CompilationUnit compilationUnit) { List<String> lines = new ArrayList<>(); lines.addAll(innerInterface.getJavaDocLines()); lines.addAll(innerInterface.getAnnotations()); lines.add(renderFirstLine(innerInterface, compilationUnit)); lines.addAll(RenderingUtilities.renderFields(innerInterface.getFields(), compilationUnit)); lines.addAll(RenderingUtilities.renderInterfaceMethods(innerInterface.getMethods(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerClasses(innerInterface.getInnerClasses(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerInterfaces(innerInterface.getInnerInterfaces(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerEnums(innerInterface.getInnerEnums(), compilationUnit)); lines = RenderingUtilities.removeLastEmptyLine(lines); lines.add("}"); return lines; }
Example #3
Source File: MapperAnnotationPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 6 votes |
/** * 测试配置Repository * @throws Exception */ @Test public void testWithRepository() throws Exception{ MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/MapperAnnotationPlugin/mybatis-generator-with-repository.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) { CompilationUnit compilationUnit = file.getCompilationUnit(); if (compilationUnit instanceof Interface && compilationUnit.getType().getShortName().endsWith("Mapper")) { Interface interfaze = (Interface) compilationUnit; Assert.assertEquals(interfaze.getAnnotations().size(), 2); Assert.assertEquals(interfaze.getAnnotations().get(0), "@Mapper"); Assert.assertEquals(interfaze.getAnnotations().get(1), "@Repository"); Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper"))); Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.springframework.stereotype.Repository"))); } } }
Example #4
Source File: InnerClassRenderer.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
public List<String> render(InnerClass innerClass, CompilationUnit compilationUnit) { List<String> lines = new ArrayList<>(); lines.addAll(innerClass.getJavaDocLines()); lines.addAll(innerClass.getAnnotations()); lines.add(renderFirstLine(innerClass, compilationUnit)); lines.addAll(RenderingUtilities.renderFields(innerClass.getFields(), compilationUnit)); lines.addAll(RenderingUtilities.renderInitializationBlocks(innerClass.getInitializationBlocks())); lines.addAll(RenderingUtilities.renderClassOrEnumMethods(innerClass.getMethods(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerClasses(innerClass.getInnerClasses(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerInterfaces(innerClass.getInnerInterfaces(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerEnums(innerClass.getInnerEnums(), compilationUnit)); lines = RenderingUtilities.removeLastEmptyLine(lines); lines.add("}"); return lines; }
Example #5
Source File: InnerEnumRenderer.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
public List<String> render(InnerEnum innerEnum, CompilationUnit compilationUnit) { List<String> lines = new ArrayList<>(); lines.addAll(innerEnum.getJavaDocLines()); lines.addAll(innerEnum.getAnnotations()); lines.add(renderFirstLine(innerEnum, compilationUnit)); lines.addAll(renderEnumConstants(innerEnum)); lines.addAll(RenderingUtilities.renderFields(innerEnum.getFields(), compilationUnit)); lines.addAll(RenderingUtilities.renderInitializationBlocks(innerEnum.getInitializationBlocks())); lines.addAll(RenderingUtilities.renderClassOrEnumMethods(innerEnum.getMethods(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerClasses(innerEnum.getInnerClasses(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerInterfaces(innerEnum.getInnerInterfaces(), compilationUnit)); lines.addAll(RenderingUtilities.renderInnerEnums(innerEnum.getInnerEnums(), compilationUnit)); lines = RenderingUtilities.removeLastEmptyLine(lines); lines.add("}"); return lines; }
Example #6
Source File: IntrospectedTableMyBatis3Impl.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
@Override public List<GeneratedJavaFile> getGeneratedJavaFiles() { List<GeneratedJavaFile> answer = new ArrayList<>(); for (AbstractJavaGenerator javaGenerator : javaGenerators) { List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits(); for (CompilationUnit compilationUnit : compilationUnits) { GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit, javaGenerator.getProject(), context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING), context.getJavaFormatter()); answer.add(gjf); } } return answer; }
Example #7
Source File: CommentGenerator.java From HIS with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #8
Source File: CommentGenerator.java From mall-swarm with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #9
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #10
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #11
Source File: CommentGenerator.java From HIS with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #12
Source File: SimpleJavaClientGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public List<CompilationUnit> getCompilationUnits() { progressCallback.startTask(getString("Progress.17", introspectedTable.getFullyQualifiedTable().toString())); CommentGenerator commentGenerator = context.getCommentGenerator(); FullyQualifiedJavaType type = new FullyQualifiedJavaType( introspectedTable.getMyBatis3JavaMapperType()); Interface interfaze = new Interface(type); interfaze.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(interfaze); String rootInterface = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE); if (!stringHasValue(rootInterface)) { rootInterface = context.getJavaClientGeneratorConfiguration().getProperty(PropertyRegistry.ANY_ROOT_INTERFACE); } if (stringHasValue(rootInterface)) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(rootInterface); interfaze.addSuperInterface(fqjt); interfaze.addImportedType(fqjt); } addDeleteByPrimaryKeyMethod(interfaze); addInsertMethod(interfaze); addSelectByPrimaryKeyMethod(interfaze); addSelectAllMethod(interfaze); addUpdateByPrimaryKeyMethod(interfaze); List<CompilationUnit> answer = new ArrayList<>(); if (context.getPlugins().clientGenerated(interfaze, introspectedTable)) { answer.add(interfaze); } List<CompilationUnit> extraCompilationUnits = getExtraCompilationUnits(); if (extraCompilationUnits != null) { answer.addAll(extraCompilationUnits); } return answer; }
Example #13
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #14
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #15
Source File: CommentGenerator.java From HIS with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #16
Source File: SqlProviderGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public List<CompilationUnit> getCompilationUnits() { progressCallback.startTask(getString("Progress.18", //$NON-NLS-1$ introspectedTable.getFullyQualifiedTable().toString())); CommentGenerator commentGenerator = context.getCommentGenerator(); FullyQualifiedJavaType type = new FullyQualifiedJavaType( introspectedTable.getMyBatis3SqlProviderType()); TopLevelClass topLevelClass = new TopLevelClass(type); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); boolean addApplyWhereMethod = false; addApplyWhereMethod |= addCountByExampleMethod(topLevelClass); addApplyWhereMethod |= addDeleteByExampleMethod(topLevelClass); addInsertSelectiveMethod(topLevelClass); addApplyWhereMethod |= addSelectByExampleWithBLOBsMethod(topLevelClass); addApplyWhereMethod |= addSelectByExampleWithoutBLOBsMethod(topLevelClass); addApplyWhereMethod |= addUpdateByExampleSelectiveMethod(topLevelClass); addApplyWhereMethod |= addUpdateByExampleWithBLOBsMethod(topLevelClass); addApplyWhereMethod |= addUpdateByExampleWithoutBLOBsMethod(topLevelClass); addUpdateByPrimaryKeySelectiveMethod(topLevelClass); if (addApplyWhereMethod) { addApplyWhereMethod(topLevelClass); } List<CompilationUnit> answer = new ArrayList<CompilationUnit>(); if (topLevelClass.getMethods().size() > 0) { if (context.getPlugins().providerGenerated(topLevelClass, introspectedTable)) { answer.add(topLevelClass); } } return answer; }
Example #17
Source File: CommentGenerator.java From HIS with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #18
Source File: CommentGenerator.java From HIS with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #19
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #20
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #21
Source File: CommentGenerator.java From mall with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #22
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #23
Source File: RenderingUtilities.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
public static List<String> renderImports(CompilationUnit compilationUnit) { Set<String> imports = renderImports(compilationUnit.getImportedTypes()); if (imports.isEmpty()) { return Collections.emptyList(); } return addEmptyLine(imports.stream()).collect(Collectors.toList()); }
Example #24
Source File: CommentGenerator.java From mall-learning with Apache License 2.0 | 5 votes |
@Override public void addJavaFileComment(CompilationUnit compilationUnit) { super.addJavaFileComment(compilationUnit); //只在model中添加swagger注解类的导入 if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); } }
Example #25
Source File: DAOGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); progressCallback.startTask(getString( "Progress.14", table.toString())); //$NON-NLS-1$ TopLevelClass topLevelClass = getTopLevelClassShell(); Interface interfaze = getInterfaceShell(); addCountByExampleMethod(topLevelClass, interfaze); addDeleteByExampleMethod(topLevelClass, interfaze); addDeleteByPrimaryKeyMethod(topLevelClass, interfaze); addInsertMethod(topLevelClass, interfaze); addInsertSelectiveMethod(topLevelClass, interfaze); addSelectByExampleWithBLOBsMethod(topLevelClass, interfaze); addSelectByExampleWithoutBLOBsMethod(topLevelClass, interfaze); addSelectByPrimaryKeyMethod(topLevelClass, interfaze); addUpdateByExampleParmsInnerclass(topLevelClass, interfaze); addUpdateByExampleSelectiveMethod(topLevelClass, interfaze); addUpdateByExampleWithBLOBsMethod(topLevelClass, interfaze); addUpdateByExampleWithoutBLOBsMethod(topLevelClass, interfaze); addUpdateByPrimaryKeySelectiveMethod(topLevelClass, interfaze); addUpdateByPrimaryKeyWithBLOBsMethod(topLevelClass, interfaze); addUpdateByPrimaryKeyWithoutBLOBsMethod(topLevelClass, interfaze); List<CompilationUnit> answer = new ArrayList<CompilationUnit>(); if (context.getPlugins().clientGenerated(interfaze, topLevelClass, introspectedTable)) { answer.add(topLevelClass); answer.add(interfaze); } return answer; }
Example #26
Source File: SqlProviderGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public List<CompilationUnit> getCompilationUnits() { progressCallback.startTask(getString("Progress.18", introspectedTable.getFullyQualifiedTable().toString())); CommentGenerator commentGenerator = context.getCommentGenerator(); FullyQualifiedJavaType type = new FullyQualifiedJavaType( introspectedTable.getMyBatis3SqlProviderType()); TopLevelClass topLevelClass = new TopLevelClass(type); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); boolean addApplyWhereMethod = false; addApplyWhereMethod |= addCountByExampleMethod(topLevelClass); addApplyWhereMethod |= addDeleteByExampleMethod(topLevelClass); addInsertSelectiveMethod(topLevelClass); addApplyWhereMethod |= addSelectByExampleWithBLOBsMethod(topLevelClass); addApplyWhereMethod |= addSelectByExampleWithoutBLOBsMethod(topLevelClass); addApplyWhereMethod |= addUpdateByExampleSelectiveMethod(topLevelClass); addApplyWhereMethod |= addUpdateByExampleWithBLOBsMethod(topLevelClass); addApplyWhereMethod |= addUpdateByExampleWithoutBLOBsMethod(topLevelClass); addUpdateByPrimaryKeySelectiveMethod(topLevelClass); if (addApplyWhereMethod) { addApplyWhereMethod(topLevelClass); } List<CompilationUnit> answer = new ArrayList<>(); if (!topLevelClass.getMethods().isEmpty() && context.getPlugins().providerGenerated(topLevelClass, introspectedTable)) { answer.add(topLevelClass); } return answer; }
Example #27
Source File: ParameterRenderer.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
public String render(Parameter parameter, CompilationUnit compilationUnit) { return renderAnnotations(parameter) + JavaDomUtils.calculateTypeName(compilationUnit, parameter.getType()) + " " + (parameter.isVarargs() ? "... " : "") //$NON-NLS-2$ + parameter.getName(); }
Example #28
Source File: GeneratedJavaFile.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
/** * Default constructor */ public GeneratedJavaFile(CompilationUnit compilationUnit, String targetProject, String fileEncoding, JavaFormatter javaFormatter) { super(targetProject); this.compilationUnit = compilationUnit; this.fileEncoding = fileEncoding; this.javaFormatter = javaFormatter; }
Example #29
Source File: MethodRenderer.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
public List<String> render(Method method, boolean inInterface, CompilationUnit compilationUnit) { List<String> lines = new ArrayList<>(); lines.addAll(method.getJavaDocLines()); lines.addAll(method.getAnnotations()); lines.add(getFirstLine(method, inInterface, compilationUnit)); if (!method.isAbstract() && !method.isNative()) { lines.addAll(bodyLineRenderer.render(method.getBodyLines())); lines.add("}"); } return lines; }
Example #30
Source File: DynamicSqlPlugin.java From mybatis-generator-plugins with Apache License 2.0 | 5 votes |
@Override public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) { List<GeneratedJavaFile> models = new ArrayList<>(); CompilationUnit unit = DynamicSqlSupportClassGenerator .of(introspectedTable, context.getCommentGenerator(), tableClassSuffix, addAliasedColumns, addTableAlias, tableAliasFieldName, properties) .generate(); GeneratedJavaFile dynamicSqlModel = new GeneratedJavaFile(unit, context.getJavaClientGeneratorConfiguration().getTargetProject(), new DefaultJavaFormatter()); models.add(dynamicSqlModel); return models; }