Search in sources :

Example 6 with ProblemLocation

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

the class CodeStyleFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addThisQualifier, boolean changeNonStaticAccessToStatic, boolean qualifyStaticFieldAccess, boolean changeIndirectStaticAccessToDirect, boolean qualifyMethodAccess, boolean qualifyStaticMethodAccess, boolean removeFieldQualifier, boolean removeMethodQualifier) {
    if (!addThisQualifier && !changeNonStaticAccessToStatic && !qualifyStaticFieldAccess && !changeIndirectStaticAccessToDirect && !qualifyMethodAccess && !qualifyStaticMethodAccess && !removeFieldQualifier && !removeMethodQualifier)
        return null;
    List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
    if (addThisQualifier || qualifyStaticFieldAccess || qualifyMethodAccess || qualifyStaticMethodAccess) {
        CodeStyleVisitor codeStyleVisitor = new CodeStyleVisitor(compilationUnit, addThisQualifier, qualifyStaticFieldAccess, qualifyMethodAccess, qualifyStaticMethodAccess, operations);
        compilationUnit.accept(codeStyleVisitor);
    }
    IProblem[] problems = compilationUnit.getProblems();
    IProblemLocation[] locations = new IProblemLocation[problems.length];
    for (int i = 0; i < problems.length; i++) {
        locations[i] = new ProblemLocation(problems[i]);
    }
    addToStaticAccessOperations(compilationUnit, locations, changeNonStaticAccessToStatic, changeIndirectStaticAccessToDirect, operations);
    if (removeFieldQualifier || removeMethodQualifier) {
        ThisQualifierVisitor visitor = new ThisQualifierVisitor(removeFieldQualifier, removeMethodQualifier, compilationUnit, operations);
        compilationUnit.accept(visitor);
    }
    if (operations.isEmpty())
        return null;
    CompilationUnitRewriteOperation[] operationsArray = operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
    return new CodeStyleFix(FixMessages.CodeStyleFix_change_name, compilationUnit, operationsArray);
}
Also used : 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 7 with ProblemLocation

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

the class StringFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addNLSTag, boolean removeNLSTag) throws CoreException, JavaModelException {
    if (!addNLSTag && !removeNLSTag)
        return null;
    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, addNLSTag, removeNLSTag, locations);
}
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)

Example 8 with ProblemLocation

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

the class TypeParametersFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean insertInferredTypeArguments, boolean removeRedundantTypeArguments) {
    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, insertInferredTypeArguments, removeRedundantTypeArguments);
}
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)

Example 9 with ProblemLocation

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

the class UnusedCodeFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean removeUnusedPrivateMethods, boolean removeUnusedPrivateConstructors, boolean removeUnusedPrivateFields, boolean removeUnusedPrivateTypes, boolean removeUnusedLocalVariables, boolean removeUnusedImports, boolean removeUnusedCast) {
    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, removeUnusedPrivateMethods, removeUnusedPrivateConstructors, removeUnusedPrivateFields, removeUnusedPrivateTypes, removeUnusedLocalVariables, removeUnusedImports, removeUnusedCast);
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 10 with ProblemLocation

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

the class ReorgQuickFixTest method testTodoTasks1.

@Test
public void testTodoTasks1() 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)

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