Skip to content

Commit

Permalink
Fix positioning error messages in JPS
Browse files Browse the repository at this point in the history
(cherry picked from commit e1234df)
  • Loading branch information
konsoletyper committed Jul 4, 2017
1 parent 6a002f9 commit e25050e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ private void reportProblems(ProblemProvider problemProvider, CallGraph callGraph

List<ProblemToReport> problemsToReport = resolveProblemLocation(problem, callGraph);

if (problemsToReport.isEmpty()) {
context.processMessage(new CompilerMessage("TeaVM", kind, problem.getText(), null,
-1, -1, -1, -1, -1));
}
for (ProblemToReport problemToReport : problemsToReport) {
String text = baseText + buildCallStack(problemToReport.locations);
context.processMessage(new CompilerMessage("TeaVM", kind, text, problemToReport.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiParameter;
import com.intellij.psi.PsiType;
Expand Down Expand Up @@ -134,7 +137,16 @@ private String getMethodSignature(PsiMethod method) {
}

private TeaVMElementLocation getMethodLocation(PsiMethod method) {
return new TeaVMElementLocation(method.getTextOffset(), method.getTextOffset() + method.getTextLength(),
-1, -1, method.getContainingFile().getVirtualFile().getPath());
PsiElement element = method.getNameIdentifier();
if (element == null) {
element = method.getNavigationElement();
}
PsiFile psiFile = element.getContainingFile();
Document document = psiFile.getViewProvider().getDocument();
int offset = element.getTextRange().getStartOffset();
int line = offset >= 0 ? document.getLineNumber(offset) + 1 : -1;
int column = offset >= 0 ? offset - document.getLineStartOffset(line) + 1 : -1;
return new TeaVMElementLocation(offset, element.getTextRange().getEndOffset(),
line, column, psiFile.getVirtualFile().getPath());
}
}

0 comments on commit e25050e

Please sign in to comment.