Search in sources :

Example 1 with ExistingJavaFileVisitor

use of org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor in project generator by mybatis.

the class ExistingJavaFileVisitorTest method testRegularClass.

@Test
public void testRegularClass() throws Exception {
    InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTable.java.src");
    String source = getResourceAsString(resource);
    IDocument document = new Document(source);
    CompilationUnit cu = getCompilationUnitFromSource(source);
    cu.recordModifications();
    ExistingJavaFileVisitor visitor = new ExistingJavaFileVisitor(MergeConstants.OLD_ELEMENT_TAGS);
    // delete all the old generated stuff
    cu.accept(visitor);
    assertThat(visitor.getTypeDeclaration(), is(notNullValue()));
    assertThat(visitor.getTypeDeclaration().isInterface(), is(false));
    assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTable"));
    // generate a new compilation unit that is stripped of old stuff
    TextEdit textEdit = cu.rewrite(document, null);
    textEdit.apply(document);
    CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(document.get());
    assertThat(summary, hasImportCount(1));
    assertThat(summary, hasClass("AwfulTable", withSuperClass("AwfulTableKey")));
    assertThat(summary, hasClass("AwfulTable", withSuperInterfaceCount(0)));
    assertThat(summary, hasClass("AwfulTable", withMethodCount(0)));
    assertThat(summary, hasClass("AwfulTable", withFieldCount(0)));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) InputStream(java.io.InputStream) TextEdit(org.eclipse.text.edits.TextEdit) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) Utilities.getResourceAsString(org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ExistingJavaFileVisitor(org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 2 with ExistingJavaFileVisitor

use of org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor in project generator by mybatis.

the class ExistingJavaFileVisitorTest method testComplexClass.

@Test
public void testComplexClass() throws Exception {
    InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTableExample.java.src");
    String source = getResourceAsString(resource);
    IDocument document = new Document(source);
    CompilationUnit cu = getCompilationUnitFromSource(source);
    cu.recordModifications();
    ExistingJavaFileVisitor visitor = new ExistingJavaFileVisitor(MergeConstants.OLD_ELEMENT_TAGS);
    // delete all the old generated stuff
    cu.accept(visitor);
    assertThat(visitor.getTypeDeclaration(), is(notNullValue()));
    assertThat(visitor.getTypeDeclaration().isInterface(), is(false));
    assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTableExample"));
    assertThat(visitor.containsInnerClass("Criteria"), is(true));
    // generate a new compilation unit that is stripped of old stuff
    TextEdit textEdit = cu.rewrite(document, null);
    textEdit.apply(document);
    CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(document.get());
    assertThat(summary, hasImportCount(2));
    assertThat(summary, hasClass("AwfulTableExample", withSuperClass(nullValue())));
    assertThat(summary, hasClass("AwfulTableExample", withSuperInterfaceCount(0)));
    assertThat(summary, hasClass("AwfulTableExample", withMethodCount(0)));
    assertThat(summary, hasClass("AwfulTableExample", withFieldCount(0)));
    assertThat(summary, hasClass("AwfulTableExample", withClass("Criteria")));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) InputStream(java.io.InputStream) TextEdit(org.eclipse.text.edits.TextEdit) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) Utilities.getResourceAsString(org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ExistingJavaFileVisitor(org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 3 with ExistingJavaFileVisitor

use of org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor in project generator by mybatis.

the class ExistingJavaFileVisitorTest method testRegularInterface.

@Test
public void testRegularInterface() throws Exception {
    InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTableMapper.java.src");
    String source = getResourceAsString(resource);
    IDocument document = new Document(source);
    CompilationUnit cu = getCompilationUnitFromSource(source);
    cu.recordModifications();
    ExistingJavaFileVisitor visitor = new ExistingJavaFileVisitor(MergeConstants.OLD_ELEMENT_TAGS);
    // delete all the old generated stuff
    cu.accept(visitor);
    assertThat(visitor.getTypeDeclaration(), is(notNullValue()));
    assertThat(visitor.getTypeDeclaration().isInterface(), is(true));
    assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTableMapper"));
    // generate a new compilation unit that is stripped of old stuff
    TextEdit textEdit = cu.rewrite(document, null);
    textEdit.apply(document);
    CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(document.get());
    assertThat(summary, hasImportCount(11));
    assertThat(summary, hasInterface("AwfulTableMapper"));
    assertThat(summary, hasInterface("AwfulTableMapper", withSuperInterfaceCount(0)));
    assertThat(summary, hasInterface("AwfulTableMapper", withMethodCount(0)));
    assertThat(summary, hasInterface("AwfulTableMapper", withFieldCount(0)));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) InputStream(java.io.InputStream) TextEdit(org.eclipse.text.edits.TextEdit) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) Utilities.getResourceAsString(org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ExistingJavaFileVisitor(org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 Document (org.eclipse.jface.text.Document)3 IDocument (org.eclipse.jface.text.IDocument)3 TextEdit (org.eclipse.text.edits.TextEdit)3 Test (org.junit.Test)3 ExistingJavaFileVisitor (org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor)3 Utilities.getResourceAsString (org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString)3 CompilationUnitSummary (org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary)3