use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls by eclipse.
the class LinkedNodeFinder method findByProblems.
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
ArrayList<SimpleName> res = new ArrayList<>();
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()]);
}
use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls by eclipse.
the class AbstractQuickFixTest method evaluateCodeActions.
protected List<Command> evaluateCodeActions(ICompilationUnit cu) throws JavaModelException {
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
IProblem[] problems = astRoot.getProblems();
Range range = getRange(cu, problems);
CodeActionParams parms = new CodeActionParams();
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
parms.setTextDocument(textDocument);
parms.setRange(range);
CodeActionContext context = new CodeActionContext();
context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems)));
parms.setContext(context);
List<Command> commands = new CodeActionHandler().getCodeActionCommands(parms, new NullProgressMonitor());
if (this.ignoredCommands != null) {
List<Command> filteredList = new ArrayList<>();
for (Command command : commands) {
for (String str : this.ignoredCommands) {
if (command.getTitle().matches(str)) {
filteredList.add(command);
break;
}
}
}
commands.removeAll(filteredList);
}
return commands;
}
use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls by eclipse.
the class RefactoringAnalyzeUtil method getIntroducedCompileProblems.
//
// public static LambdaExpression getLambdaExpression(TextEdit edit, TextChange change, CompilationUnit cuNode) {
// ASTNode decl = RefactoringAnalyzeUtil.findSimpleNameNode(RefactoringAnalyzeUtil.getNewTextRange(edit, change), cuNode);
// return ((LambdaExpression) ASTNodes.getParent(decl, LambdaExpression.class));
// }
//
// public static MethodDeclaration getMethodDeclaration(TextEdit edit, TextChange change, CompilationUnit cuNode) {
// ASTNode decl = RefactoringAnalyzeUtil.findSimpleNameNode(RefactoringAnalyzeUtil.getNewTextRange(edit, change), cuNode);
// return ((MethodDeclaration) ASTNodes.getParent(decl, MethodDeclaration.class));
// }
//
// public static Block getBlock(TextEdit edit, TextChange change, CompilationUnit cuNode) {
// ASTNode decl = RefactoringAnalyzeUtil.findSimpleNameNode(RefactoringAnalyzeUtil.getNewTextRange(edit, change), cuNode);
// return ((Block) ASTNodes.getParent(decl, Block.class));
// }
public static IProblem[] getIntroducedCompileProblems(CompilationUnit newCUNode, CompilationUnit oldCuNode) {
Set<IProblem> subResult = new HashSet<>();
Set<IProblem> oldProblems = getOldProblems(oldCuNode);
IProblem[] newProblems = ASTNodes.getProblems(newCUNode, ASTNodes.INCLUDE_ALL_PARENTS, ASTNodes.PROBLEMS);
for (int i = 0; i < newProblems.length; i++) {
IProblem correspondingOld = findCorrespondingProblem(oldProblems, newProblems[i]);
if (correspondingOld == null) {
subResult.add(newProblems[i]);
}
}
return subResult.toArray(new IProblem[subResult.size()]);
}
use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls by eclipse.
the class DiagnosticHandlerTest method testMultipleLineRange.
@Test
public void testMultipleLineRange() throws Exception {
IJavaProject javaProject = newEmptyProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public boolean foo(boolean b1) {\n");
buf.append(" if (false) {\n");
buf.append(" return true;\n");
buf.append(" }\n");
buf.append(" return false;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, monitor);
IProblem[] problems = astRoot.getProblems();
List<Diagnostic> diagnostics = DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems));
assertEquals(diagnostics.size(), 1);
Range range = diagnostics.get(0).getRange();
assertNotEquals(range.getStart().getLine(), range.getEnd().getLine());
}
use of org.eclipse.jdt.core.compiler.IProblem in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method getCodeActions.
protected List<Command> getCodeActions(ICompilationUnit cu) throws JavaModelException {
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
IProblem[] problems = astRoot.getProblems();
Range range = getRange(cu, problems);
CodeActionParams parms = new CodeActionParams();
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
parms.setTextDocument(textDocument);
parms.setRange(range);
CodeActionContext context = new CodeActionContext();
context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems)));
parms.setContext(context);
return new CodeActionHandler().getCodeActionCommands(parms, new NullProgressMonitor());
}
Aggregations