Search in sources :

Example 36 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext 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 37 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class ReorgQuickFixTest method testTodoTasks2.

@Test
public void testTodoTasks2() 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("        // Some other text TODO: XXX\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("        // Some other text \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 38 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class ReorgQuickFixTest method testTodoTasks7.

@Test
public void testTodoTasks7() 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("        /* TODO: XXX*/;\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");
    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 39 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest method testSplitDeclaration3.

@Test
public void testSplitDeclaration3() 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("        final int i[] = null;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    String str = "i[]";
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
    List proposals = collectAssists(context, false);
    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        final int i[];\n");
    buf.append("        i = null;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String ex1 = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    private int is[];\n");
    buf.append("\n");
    buf.append("    public void foo() {\n");
    buf.append("        is = null;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String ex2 = buf.toString();
    assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 40 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest method testGenerateForImportsAndFormat1.

@Test
public void testGenerateForImportsAndFormat1() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    class Iterator {}\n");
    buf.append("    void foo() {\n");
    buf.append("        B.get( /*important: empty*/ );\n");
    buf.append("    }\n");
    buf.append("}\n");
    StringBuffer buf2 = new StringBuffer();
    buf2.append("package test1;\n");
    buf2.append("import java.util.ArrayList;\n");
    buf2.append("import java.util.Date;\n");
    buf2.append("import java.util.Set;\n");
    buf2.append("public class B {\n");
    buf2.append("    static ArrayList<Date> get() {\n");
    buf2.append("        return new ArrayList<Date>();\n");
    buf2.append("    }\n");
    buf2.append("    static Set raw(int i) {\n");
    buf2.append("        return java.util.Collections.emptySet();\n");
    buf2.append("    }\n");
    buf2.append("}");
    ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
    pack1.createCompilationUnit("B.java", buf2.toString(), false, null);
    Map saveOptions = fJProject1.getOptions(false);
    Map newOptions = new HashMap();
    JavaCore.setComplianceOptions(org.eclipse.jdt.core.JavaCore.VERSION_1_5, newOptions);
    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true");
    try {
        fJProject1.setOptions(newOptions);
        String selection = "B.get( /*important: empty*/ );";
        AssistContext context = getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0);
        List proposals = collectAssists(context, false);
        assertNumberOfProposals(proposals, 5);
        assertCorrectLabels(proposals);
        String[] expected = new String[3];
        buf = new StringBuffer();
        buf.append("package test1;\n");
        buf.append("\n");
        buf.append("import java.util.Date;\n");
        buf.append("\n");
        buf.append("public class A {\n");
        buf.append("    class Iterator {}\n");
        buf.append("    void foo() {\n");
        buf.append("        for (Date date : B.get( /*important: empty*/ )) {\n");
        buf.append("            \n");
        buf.append("        }\n");
        buf.append("    }\n");
        buf.append("}\n");
        expected[0] = buf.toString();
        buf = new StringBuffer();
        buf.append("package test1;\n");
        buf.append("\n");
        buf.append("import java.util.Date;\n");
        buf.append("\n");
        buf.append("public class A {\n");
        buf.append("    class Iterator {}\n");
        buf.append("    void foo() {\n");
        buf.append("        for (java.util.Iterator<Date> iterator = B.get( /*important: empty*/ ).iterator(); iterator\n");
        buf.append("                .hasNext();) {\n");
        buf.append("            Date date = iterator.next();\n");
        buf.append("            \n");
        buf.append("        }\n");
        buf.append("    }\n");
        buf.append("}\n");
        expected[1] = buf.toString();
        buf = new StringBuffer();
        buf.append("package test1;\n");
        buf.append("\n");
        buf.append("import java.util.Date;\n");
        buf.append("\n");
        buf.append("public class A {\n");
        buf.append("    class Iterator {}\n");
        buf.append("    void foo() {\n");
        buf.append("        for (int i = 0; i < B.get( /*important: empty*/ ).size(); i++) {\n");
        buf.append("            Date date = B.get( /*important: empty*/ ).get(i);\n");
        buf.append("            \n");
        buf.append("        }\n");
        buf.append("    }\n");
        buf.append("}\n");
        expected[2] = buf.toString();
        assertExpectedExistInProposals(proposals, expected);
    } finally {
        fJProject1.setOptions(saveOptions);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) HashMap(java.util.HashMap) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)390 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)385 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)384 Test (org.junit.Test)384 List (java.util.List)378 ArrayList (java.util.ArrayList)313 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)57 HashMap (java.util.HashMap)15 Map (java.util.Map)15 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)8 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 Ignore (org.junit.Ignore)4 IDocument (org.eclipse.jface.text.IDocument)3 Iterator (java.util.Iterator)2 IBuffer (org.eclipse.jdt.core.IBuffer)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Point (org.eclipse.swt.graphics.Point)2 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)1 LinkedModeModelImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl)1