Search in sources :

Example 11 with ProblemLocation

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

the class ReorgQuickFixTest method testTodoTasks6.

@Test
public void testTodoTasks6() 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 12 with ProblemLocation

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

the class ReorgQuickFixTest method testTodoTasks3.

@Test
public void testTodoTasks3() 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");
    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 13 with ProblemLocation

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

the class Java50Fix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addOverrideAnnotation, boolean addOverrideInterfaceAnnotation, boolean addDeprecatedAnnotation, boolean rawTypeReference) {
    ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
    if (!JavaModelUtil.is50OrHigher(cu.getJavaProject()))
        return null;
    if (!addOverrideAnnotation && !addDeprecatedAnnotation && !rawTypeReference)
        return null;
    List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
    IProblem[] problems = compilationUnit.getProblems();
    IProblemLocation[] locations = new IProblemLocation[problems.length];
    for (int i = 0; i < problems.length; i++) {
        locations[i] = new ProblemLocation(problems[i]);
    }
    if (addOverrideAnnotation)
        createAddOverrideAnnotationOperations(compilationUnit, addOverrideInterfaceAnnotation, locations, operations);
    if (addDeprecatedAnnotation)
        createAddDeprecatedAnnotationOperations(compilationUnit, locations, operations);
    if (rawTypeReference)
        createRawTypeReferenceOperations(compilationUnit, locations, operations);
    if (operations.size() == 0)
        return null;
    String fixName;
    if (rawTypeReference) {
        fixName = FixMessages.Java50Fix_add_type_parameters_change_name;
    } else {
        fixName = FixMessages.Java50Fix_add_annotations_change_name;
    }
    CompilationUnitRewriteOperation[] operationsArray = operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
    return new Java50Fix(fixName, compilationUnit, operationsArray);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblem(org.eclipse.jdt.core.compiler.IProblem) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)

Example 14 with ProblemLocation

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

the class NullAnnotationsFix method createCleanUp.

// Entry for NullAnnotationsCleanup:
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] locations, int problemID) {
    ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
    if (!JavaModelUtil.is50OrHigher(cu.getJavaProject()))
        return null;
    List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
    if (locations == null) {
        org.eclipse.jdt.core.compiler.IProblem[] problems = compilationUnit.getProblems();
        locations = new IProblemLocation[problems.length];
        for (int i = 0; i < problems.length; i++) {
            if (problems[i].getID() == problemID)
                locations[i] = new ProblemLocation(problems[i]);
        }
    }
    createAddNullAnnotationOperations(compilationUnit, locations, operations);
    createRemoveRedundantNullAnnotationsOperations(compilationUnit, locations, operations);
    if (operations.size() == 0)
        return null;
    CompilationUnitRewriteOperation[] operationsArray = operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
    return new NullAnnotationsFix(FixMessages.NullAnnotationsFix_add_annotation_change_name, compilationUnit, operationsArray);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ArrayList(java.util.ArrayList) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 15 with ProblemLocation

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

the class PotentialProgrammingProblemsFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addSerialVersionIds) {
    IProblem[] problems = compilationUnit.getProblems();
    IProblemLocation[] locations = new IProblemLocation[problems.length];
    for (int i = 0; i < problems.length; i++) {
        locations[i] = new ProblemLocation(problems[i]);
    }
    return createCleanUp(compilationUnit, locations, addSerialVersionIds);
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblem(org.eclipse.jdt.core.compiler.IProblem)

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