Search in sources :

Example 1 with JavaFileMerger

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);
    }
}
Also used : InvalidExistingFileException(org.mybatis.generator.eclipse.core.merge.InvalidExistingFileException) JavaFileMerger(org.mybatis.generator.eclipse.core.merge.JavaFileMerger)

Example 2 with JavaFileMerger

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())));
}
Also used : CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) JavaFileMerger(org.mybatis.generator.eclipse.core.merge.JavaFileMerger) Test(org.junit.Test)

Example 3 with JavaFileMerger

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()")));
}
Also used : CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) JavaFileMerger(org.mybatis.generator.eclipse.core.merge.JavaFileMerger) Test(org.junit.Test)

Aggregations

JavaFileMerger (org.mybatis.generator.eclipse.core.merge.JavaFileMerger)3 Test (org.junit.Test)2 CompilationUnitSummary (org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary)2 InvalidExistingFileException (org.mybatis.generator.eclipse.core.merge.InvalidExistingFileException)1