Java inspection: When the element to be processed by information-level inspections is a whitespace process the nearest previous non-space element instead. (IDEA-157727)

This commit is contained in:
Pavel Dolgov
2016-07-14 20:12:08 +03:00
parent cf5453a5cf
commit f0752dd7b0
@@ -47,7 +47,6 @@ import com.intellij.openapi.editor.ex.MarkupModelEx;
import com.intellij.openapi.editor.ex.RangeHighlighterEx;
import com.intellij.openapi.editor.impl.DocumentMarkupModel;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
@@ -314,7 +313,17 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass {
}
if (HighlightingLevelManager.getInstance(project).shouldInspect(hostFile)) {
collectIntentionsFromDoNotShowLeveledInspections(project, hostFile, psiElement, offset, intentions);
PsiElement adjustedElement = psiElement;
int adjustedOffset = offset;
if (psiElement instanceof PsiWhiteSpace) {
final PsiElement prev = psiElement.getPrevSibling();
if (prev != null) {
adjustedElement = prev;
final TextRange range = prev.getTextRange();
adjustedOffset = range.isEmpty() ? range.getEndOffset() : range.getEndOffset() - 1;
}
}
collectIntentionsFromDoNotShowLeveledInspections(project, hostFile, adjustedElement, adjustedOffset, intentions);
}
final int line = hostDocument.getLineNumber(offset);
@@ -377,7 +386,7 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass {
super.registerProblem(problemDescriptor);
if (problemDescriptor instanceof ProblemDescriptorBase) {
final TextRange range = ((ProblemDescriptorBase)problemDescriptor).getTextRange();
if (range != null && range.contains(offset)) {
if (range != null && range.contains(offset)) { //add whitespace at the right
final QuickFix[] fixes = problemDescriptor.getFixes();
if (fixes != null) {
for (int k = 0; k < fixes.length; k++) {