From 908a7adf2815fa507b091f4d4dfba9ac18943092 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 9 Mar 2011 13:39:34 +0100 Subject: [PATCH] cache line number because it is expensive to calculate and is used for sorting the inspection results tree --- .../ex/ProblemDescriptorImpl.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java index d558064fdc00..cbb5a9709b0c 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java @@ -49,6 +49,7 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement private final boolean myShowTooltip; private final HintAction myHintAction; private TextAttributesKey myEnforcedTextAttributes; + private int myLineNumber = -1; public ProblemDescriptorImpl(@NotNull PsiElement startElement, @NotNull PsiElement endElement, String descriptionTemplate, LocalQuickFix[] fixes, ProblemHighlightType highlightType, @@ -132,17 +133,20 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement } public int getLineNumber() { - PsiElement psiElement = getPsiElement(); - if (psiElement == null) return -1; - if (!psiElement.isValid()) return -1; - LOG.assertTrue(psiElement.isPhysical()); - PsiFile containingFile = InjectedLanguageUtil.getTopLevelFile(psiElement); - Document document = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(containingFile); - if (document == null) return -1; - TextRange textRange = getTextRange(); - if (textRange == null) return -1; - textRange = InjectedLanguageManager.getInstance(containingFile.getProject()).injectedToHost(psiElement, textRange); - return document.getLineNumber(textRange.getStartOffset()) + 1; + if (myLineNumber == -1) { + PsiElement psiElement = getPsiElement(); + if (psiElement == null) return -1; + if (!psiElement.isValid()) return -1; + LOG.assertTrue(psiElement.isPhysical()); + PsiFile containingFile = InjectedLanguageUtil.getTopLevelFile(psiElement); + Document document = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(containingFile); + if (document == null) return -1; + TextRange textRange = getTextRange(); + if (textRange == null) return -1; + textRange = InjectedLanguageManager.getInstance(containingFile.getProject()).injectedToHost(psiElement, textRange); + myLineNumber = document.getLineNumber(textRange.getStartOffset()) + 1; + } + return myLineNumber; } public ProblemHighlightType getHighlightType() {