Search in sources :

Example 51 with IProblem

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

the class DiagnosticsHandler method toDiagnosticsArray.

public static List<Diagnostic> toDiagnosticsArray(IOpenable openable, List<IProblem> problems) {
    List<Diagnostic> array = new ArrayList<>(problems.size());
    for (IProblem problem : problems) {
        Diagnostic diag = new Diagnostic();
        diag.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
        diag.setMessage(problem.getMessage());
        diag.setCode(Integer.toString(problem.getID()));
        diag.setSeverity(convertSeverity(problem));
        diag.setRange(convertRange(openable, problem));
        array.add(diag);
    }
    return array;
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 52 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls 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(IASTSharedValues.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.ls.core.internal.corext.refactoring.util.RefactoringASTParser) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) JavaStringStatusContext(org.eclipse.jdt.ls.core.internal.corext.refactoring.base.JavaStringStatusContext) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 53 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls 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]);
        boolean isError = problems[i].isError();
        int problemId = problems[i].getID();
        int length = problems[i].getSourceEnd() - problems[i].getSourceStart();
        int offset = problems[i].getSourceStart();
        locations[i] = new ProblemLocation(offset, length, problemId, isError);
    }
    return createCleanUp(compilationUnit, locations, addSerialVersionIds);
}
Also used : IProblemLocation(org.eclipse.jdt.ls.core.internal.corrections.IProblemLocation) ProblemLocation(org.eclipse.jdt.ls.core.internal.corrections.ProblemLocation) IProblemLocation(org.eclipse.jdt.ls.core.internal.corrections.IProblemLocation) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 54 with IProblem

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

the class ExtractTempRefactoring method checkNewSource.

private void checkNewSource(SubProgressMonitor monitor, RefactoringStatus result) throws CoreException {
    String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
    CompilationUnit newCUNode = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(newCuSource, fCu, true, true, monitor);
    IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCompilationUnitNode);
    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 : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringASTParser(org.eclipse.jdt.ls.core.internal.corext.refactoring.util.RefactoringASTParser) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) JavaStringStatusContext(org.eclipse.jdt.ls.core.internal.corext.refactoring.base.JavaStringStatusContext) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 55 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls 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)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