diff options
Diffstat (limited to 'platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java')
-rw-r--r-- | platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java index aaccbfffbe18..418890ce17d9 100644 --- a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java +++ b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java @@ -38,11 +38,9 @@ import com.intellij.reference.SoftReference; import com.intellij.ui.SimpleTextAttributes; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewBundle; +import com.intellij.usages.impl.rules.UsageType; import com.intellij.usages.rules.*; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.NotNullFunction; -import com.intellij.util.Processor; +import com.intellij.util.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -79,7 +77,8 @@ public class UsageInfo2UsageAdapter implements UsageInModule, private final int myLineNumber; private final int myOffset; protected Icon myIcon; - private Reference<TextChunk[]> myTextChunks; // allow to be gced and recreated on-demand because it requires a lot of memory + private volatile Reference<TextChunk[]> myTextChunks; // allow to be gced and recreated on-demand because it requires a lot of memory + private volatile UsageType myUsageType; public UsageInfo2UsageAdapter(@NotNull final UsageInfo usageInfo) { myUsageInfo = usageInfo; @@ -336,7 +335,7 @@ public class UsageInfo2UsageAdapter implements UsageInModule, UsageInfo[] merged = ArrayUtil.mergeArrays(getMergedInfos(), u2.getMergedInfos()); myMergedUsageInfos = merged.length == 1 ? merged[0] : merged; Arrays.sort(getMergedInfos(), BY_NAVIGATION_OFFSET); - initChunks(); + myTextChunks = null; // chunks will be rebuilt lazily (IDEA-126048) return true; } @@ -493,4 +492,44 @@ public class UsageInfo2UsageAdapter implements UsageInModule, public String getTooltipText() { return myUsageInfo.getTooltipText(); } + + public @Nullable UsageType getUsageType() { + UsageType usageType = myUsageType; + + if (usageType == null) { + usageType = UsageType.UNCLASSIFIED; + PsiFile file = getPsiFile(); + + if (file != null) { + ChunkExtractor extractor = ChunkExtractor.getExtractor(file); + Segment segment = getFirstSegment(); + + if (segment != null) { + Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file); + + if (document != null) { + SmartList<TextChunk> chunks = new SmartList<TextChunk>(); + extractor.createTextChunks( + this, + document.getCharsSequence(), + segment.getStartOffset(), + segment.getEndOffset(), + false, + chunks + ); + + for(TextChunk chunk:chunks) { + UsageType chunkUsageType = chunk.getType(); + if (chunkUsageType != null) { + usageType = chunkUsageType; + break; + } + } + } + } + } + myUsageType = usageType; + } + return usageType; + } } |