Search in sources :

Example 36 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class ExtractConstantRefactoring method checkSource.

private void checkSource(SubProgressMonitor monitor, RefactoringStatus result) throws CoreException {
    String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
    CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, fCu, true, true, monitor);
    IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCuRewrite.getRoot());
    for (int i = 0; i < newProblems.length; i++) {
        IProblem problem = newProblems[i];
        if (problem.isError())
            result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringASTParser(org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) JavaStringStatusContext(org.eclipse.jdt.internal.corext.refactoring.base.JavaStringStatusContext) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 37 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class ModifierCorrectionsQuickFixTest method testAbstractMethodInNonAbstractClass.

@Test
public void testAbstractMethodInNonAbstractClass() 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 abstract int foo();\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    CompilationUnit astRoot = getASTRoot(cu);
    IProblem[] problems = astRoot.getProblems();
    assertNumberOfProblems(2, problems);
    ArrayList proposals = collectCorrections(cu, problems[0], null);
    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);
    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
    String preview1 = getPreviewContent(proposal);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public abstract class E {\n");
    buf.append("    public abstract int foo();\n");
    buf.append("}\n");
    String expectedMakeClassAbstract = buf.toString();
    assertEquals(preview1, expectedMakeClassAbstract);
    proposals = collectCorrections(cu, problems[1], null);
    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);
    proposal = (CUCorrectionProposal) proposals.get(0);
    preview1 = getPreviewContent(proposal);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public int foo() {\n");
    buf.append("        return 0;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected1 = buf.toString();
    proposal = (CUCorrectionProposal) proposals.get(1);
    String preview2 = getPreviewContent(proposal);
    assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expectedMakeClassAbstract });
}
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) IProblem(org.eclipse.jdt.core.compiler.IProblem) Test(org.junit.Test)

Example 38 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class QuickFixTest method collectCorrections2.

protected static final ArrayList collectCorrections2(ICompilationUnit cu, int nProblems) throws CoreException {
    final ArrayList problemsList = new ArrayList();
    final IProblemRequestor requestor = new IProblemRequestor() {

        public void acceptProblem(IProblem problem) {
            problemsList.add(problem);
        }

        public void beginReporting() {
            problemsList.clear();
        }

        public void endReporting() {
        }

        public boolean isActive() {
            return true;
        }
    };
    WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {

        public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
            return requestor;
        }
    };
    ICompilationUnit wc = cu.getWorkingCopy(workingCopyOwner, null);
    try {
        wc.reconcile(ICompilationUnit.NO_AST, true, true, wc.getOwner(), null);
    } finally {
        wc.discardWorkingCopy();
    }
    IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
    assertNumberOfProblems(nProblems, problems);
    return collectCorrections(cu, problems[0], null);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IProblemRequestor(org.eclipse.jdt.core.IProblemRequestor) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) DefaultWorkingCopyOwner(org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner) ArrayList(java.util.ArrayList) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 39 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem 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 40 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class LinkedNodeFinder method getNameNodeProblemKind.

private static int getNameNodeProblemKind(IProblem[] problems, SimpleName nameNode) {
    int nameOffset = nameNode.getStartPosition();
    int nameInclEnd = nameOffset + nameNode.getLength() - 1;
    for (int i = 0; i < problems.length; i++) {
        IProblem curr = problems[i];
        if (curr.getSourceStart() == nameOffset && curr.getSourceEnd() == nameInclEnd) {
            int kind = getProblemKind(curr);
            if (kind != 0) {
                return kind;
            }
        }
    }
    return 0;
}
Also used : IProblem(org.eclipse.jdt.core.compiler.IProblem)

Aggregations

IProblem (org.eclipse.jdt.core.compiler.IProblem)62 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)28 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)25 ArrayList (java.util.ArrayList)21 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)10 File (java.io.File)9 ASTParser (org.eclipse.jdt.core.dom.ASTParser)9 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)7 IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)5 RefactoringStatusEntry (org.eclipse.ltk.core.refactoring.RefactoringStatusEntry)5 URI (java.net.URI)4 HashSet (java.util.HashSet)4 StringTokenizer (java.util.StringTokenizer)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4