Search in sources :

Example 61 with IProblem

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

the class LinkedNodeFinder method findByProblems.

public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
    ArrayList<SimpleName> res = new ArrayList<SimpleName>();
    ASTNode astRoot = parent.getRoot();
    if (!(astRoot instanceof CompilationUnit)) {
        return null;
    }
    IProblem[] problems = ((CompilationUnit) astRoot).getProblems();
    int nameNodeKind = getNameNodeProblemKind(problems, nameNode);
    if (nameNodeKind == 0) {
        // no problem on node
        return null;
    }
    int bodyStart = parent.getStartPosition();
    int bodyEnd = bodyStart + parent.getLength();
    String name = nameNode.getIdentifier();
    for (int i = 0; i < problems.length; i++) {
        IProblem curr = problems[i];
        int probStart = curr.getSourceStart();
        int probEnd = curr.getSourceEnd() + 1;
        if (probStart > bodyStart && probEnd < bodyEnd) {
            int currKind = getProblemKind(curr);
            if ((nameNodeKind & currKind) != 0) {
                ASTNode node = NodeFinder.perform(parent, probStart, (probEnd - probStart));
                if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
                    res.add((SimpleName) node);
                }
            }
        }
    }
    return res.toArray(new SimpleName[res.size()]);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ArrayList(java.util.ArrayList) ASTNode(org.eclipse.jdt.core.dom.ASTNode) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Aggregations

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