use of org.mybatis.generator.eclipse.core.merge.JavaFileMerger in project generator by mybatis.
the class EclipseShellCallback method mergeJavaFile.
public String mergeJavaFile(String newFileSource, File existingFile, String[] javadocTags, String fileEncoding) throws ShellException {
String existingFileContent = getExistingFileContents(existingFile, fileEncoding);
JavaFileMerger merger = new JavaFileMerger(newFileSource, existingFileContent, javadocTags);
try {
return merger.getMergedSource();
} catch (InvalidExistingFileException e) {
throw translateInvalidExistingFileException(e, existingFile);
}
}
use of org.mybatis.generator.eclipse.core.merge.JavaFileMerger in project generator by mybatis.
the class JavaFileMergerTest method testMergeOnRegularClasses.
@Test
public void testMergeOnRegularClasses() throws Exception {
String newJavaSource = simpleClassWithAllGeneratedItems();
String existingJavaSource = simpleClassWithGeneratedAndCustomItems();
JavaFileMerger merger = new JavaFileMerger(newJavaSource, existingJavaSource, MergeConstants.OLD_ELEMENT_TAGS);
String mergedSource = merger.getMergedSource();
CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(mergedSource);
assertThat(summary, hasImportCount(1));
assertThat(summary, hasImport("import java.math.BigDecimal"));
assertThat(summary, hasClassCount(1));
assertThat(summary, hasClass("SimpleClass", withSuperInterfaceCount(0)));
assertThat(summary, hasClass("SimpleClass", withMethodCount(4)));
assertThat(summary, hasClass("SimpleClass", withMethod("getAmount()")));
assertThat(summary, hasClass("SimpleClass", withMethod("setAmount(BigDecimal)")));
assertThat(summary, hasClass("SimpleClass", withMethod("getId()")));
assertThat(summary, hasClass("SimpleClass", withMethod("setId(int)")));
assertThat(summary, hasClass("SimpleClass", withFieldCount(2)));
assertThat(summary, hasClass("SimpleClass", withField("amount")));
assertThat(summary, hasClass("SimpleClass", withField("id")));
assertThat(summary, hasClass("SimpleClass", withSuperClass(nullValue())));
}
use of org.mybatis.generator.eclipse.core.merge.JavaFileMerger in project generator by mybatis.
the class JavaFileMergerTest method testMergeOnRegularInterfaces.
@Test
public void testMergeOnRegularInterfaces() throws Exception {
String newJavaSource = simpleInterfaceWithAllGeneratedItems();
String existingJavaSource = simpleInterfaceWithGeneratedAndCustomItems();
JavaFileMerger merger = new JavaFileMerger(newJavaSource, existingJavaSource, MergeConstants.OLD_ELEMENT_TAGS);
String mergedSource = merger.getMergedSource();
CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(mergedSource);
assertThat(summary, hasImportCount(0));
assertThat(summary, hasInterfaceCount(1));
assertThat(summary, hasInterface("SimpleInterface", withSuperInterfaceCount(0)));
assertThat(summary, hasInterface("SimpleInterface", withMethodCount(3)));
assertThat(summary, hasInterface("SimpleInterface", withMethod("add(int,int)")));
assertThat(summary, hasInterface("SimpleInterface", withMethod("count()")));
assertThat(summary, hasInterface("SimpleInterface", withMethod("nonGeneratedMethod()")));
}
Aggregations