From e1234df7e13fd32b0d0a8bf7ae3f64fbeecfaa13 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 5 Jul 2017 00:08:28 +0300 Subject: [PATCH] Fix positioning error messages in JPS --- .../main/java/org/teavm/idea/jps/TeaVMBuild.java | 4 ++++ .../org/teavm/idea/TeaVMJPSRemoteService.java | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java index fec193394..6bc1b9e36 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java @@ -206,6 +206,10 @@ class TeaVMBuild { List 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, diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java b/tools/idea/plugin/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java index b0df6331d..75da5ec14 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java @@ -17,10 +17,13 @@ package org.teavm.idea; 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; @@ -134,7 +137,16 @@ public class TeaVMJPSRemoteService extends UnicastRemoteObject implements Applic } 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()); } }