Search in sources :

Example 1 with ProblemLocation

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

the class QuickFixTest method collectCorrections.

protected static final ArrayList collectCorrections(ICompilationUnit cu, IProblem curr, IInvocationContext context) throws CoreException {
    int offset = curr.getSourceStart();
    int length = curr.getSourceEnd() + 1 - offset;
    if (context == null) {
        context = new AssistContext(cu, offset, length);
    }
    ProblemLocation problem = new ProblemLocation(curr);
    ArrayList proposals = collectCorrections(context, problem);
    if (!proposals.isEmpty()) {
        assertCorrectContext(context, problem);
    }
    return proposals;
}
Also used : AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation)

Example 2 with ProblemLocation

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

the class ReorgQuickFixTest method testTodoTasks5.

@Test
public void testTodoTasks5() 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("        Some other text: 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("        Some other text: \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 3 with ProblemLocation

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

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

use of org.eclipse.jdt.internal.ui.text.correction.ProblemLocation 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)

Aggregations

ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)15 ArrayList (java.util.ArrayList)11 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)9 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)8 IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)8 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)7 IProblem (org.eclipse.jdt.core.compiler.IProblem)7 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)7 Test (org.junit.Test)7