Search in sources :

Example 61 with CUCorrectionProposal

use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.

the class ReorgQuickFixTest method testWrongPackageStatementInEnum.

@Test
public void testWrongPackageStatementInEnum() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test2;\n");
    buf.append("\n");
    buf.append("public enum E {\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);
    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);
    boolean hasRename = true, hasMove = true;
    for (int i = 0; i < proposals.size(); i++) {
        ChangeCorrectionProposal curr = (ChangeCorrectionProposal) proposals.get(i);
        if (curr instanceof CorrectPackageDeclarationProposal) {
            assertTrue("Duplicated proposal", hasRename);
            hasRename = false;
            CUCorrectionProposal proposal = (CUCorrectionProposal) curr;
            String preview = getPreviewContent(proposal);
            buf = new StringBuffer();
            buf.append("package test1;\n");
            buf.append("\n");
            buf.append("public enum E {\n");
            buf.append("}\n");
            assertEqualString(preview, buf.toString());
        } else {
            assertTrue("Duplicated proposal", hasMove);
            hasMove = false;
            curr.apply(null);
            IPackageFragment pack2 = fSourceFolder.getPackageFragment("test2");
            ICompilationUnit cu2 = pack2.getCompilationUnit("E.java");
            assertTrue("CU does not exist", cu2.exists());
            buf = new StringBuffer();
            buf.append("package test2;\n");
            buf.append("\n");
            buf.append("public enum E {\n");
            buf.append("}\n");
            assertEqualStringIgnoreDelim(cu2.getSource(), buf.toString());
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CorrectPackageDeclarationProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) Test(org.junit.Test)

Example 62 with CUCorrectionProposal

use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.

the class ReorgQuickFixTest method testTodoTasks4.

@Test
public void testTodoTasks4() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        /**\n");
    buf.append("        TODO: XXX\n");
    buf.append("        */\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    String str = "TODO: XXX";
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
    ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER);
    ArrayList proposals = collectCorrections(context, problem);
    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);
    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
    String preview = getPreviewContent(proposal);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    assertEqualString(preview, buf.toString());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) Test(org.junit.Test)

Example 63 with CUCorrectionProposal

use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.

the class ReorgQuickFixTest method testWrongTypeNameInEnum.

@Test
public void testWrongTypeNameInEnum() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public enum X {\n");
    buf.append("    A;\n");
    buf.append("    X() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class X {\n");
    buf.append("}\n");
    pack1.createCompilationUnit("X.java", buf.toString(), false, null);
    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);
    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);
    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
    String preview = getPreviewContent(proposal);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public enum E {\n");
    buf.append("    A;\n");
    buf.append("    E() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    assertEqualString(preview, buf.toString());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 64 with CUCorrectionProposal

use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.

the class ReorgQuickFixTest method testUnusedImportsInDefaultPackage.

@Test
public void testUnusedImportsInDefaultPackage() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("import java.util.Vector;\n");
    buf.append("public class E {\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);
    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);
    Object p1 = proposals.get(0);
    if (!(p1 instanceof CUCorrectionProposal)) {
        p1 = proposals.get(1);
    }
    CUCorrectionProposal proposal = (CUCorrectionProposal) p1;
    String preview = getPreviewContent(proposal);
    buf = new StringBuffer();
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("}\n");
    assertEqualString(preview, buf.toString());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 65 with CUCorrectionProposal

use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.

the class ReorgQuickFixTest method testWrongPackageStatement.

@Test
public void testWrongPackageStatement() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test2;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);
    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);
    boolean hasRename = true, hasMove = true;
    for (int i = 0; i < proposals.size(); i++) {
        ChangeCorrectionProposal curr = (ChangeCorrectionProposal) proposals.get(i);
        if (curr instanceof CorrectPackageDeclarationProposal) {
            assertTrue("Duplicated proposal", hasRename);
            hasRename = false;
            CUCorrectionProposal proposal = (CUCorrectionProposal) curr;
            String preview = getPreviewContent(proposal);
            buf = new StringBuffer();
            buf.append("package test1;\n");
            buf.append("\n");
            buf.append("public class E {\n");
            buf.append("}\n");
            assertEqualString(preview, buf.toString());
        } else {
            assertTrue("Duplicated proposal", hasMove);
            hasMove = false;
            curr.apply(null);
            IPackageFragment pack2 = fSourceFolder.getPackageFragment("test2");
            ICompilationUnit cu2 = pack2.getCompilationUnit("E.java");
            assertTrue("CU does not exist", cu2.exists());
            buf = new StringBuffer();
            buf.append("package test2;\n");
            buf.append("\n");
            buf.append("public class E {\n");
            buf.append("}\n");
            assertEqualStringIgnoreDelim(cu2.getSource(), buf.toString());
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CorrectPackageDeclarationProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) Test(org.junit.Test)

Aggregations

CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)290 ArrayList (java.util.ArrayList)285 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)285 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)284 Test (org.junit.Test)284 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)228 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)57 List (java.util.List)48 Hashtable (java.util.Hashtable)47 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)7 Ignore (org.junit.Ignore)7 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)6 ChangeCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal)6 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)5 CorrectPackageDeclarationProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)3 Iterator (java.util.Iterator)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)2 IDocument (org.eclipse.jface.text.IDocument)2