From a79b28fa1aa26fade9d861607d04a1333e536237 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 23 Nov 2010 18:20:53 +0300 Subject: [PATCH] WI-4013 --- .../impl/smartPointers/AnchorElementInfo.java | 7 +++ .../ImplicitVariableElementInfoFactory.java | 4 ++ .../ImportListElementInfoFactory.java | 4 ++ .../daemon/impl/LocalInspectionsPass.java | 56 +++++++++++++++---- .../folding/impl/EditorFoldingInfo.java | 11 +++- .../ex/ProblemDescriptorImpl.java | 12 +++- .../util/LayeredLexerEditorHighlighter.java | 12 ++-- .../impl/smartPointers/FileElementInfo.java | 6 +- .../impl/smartPointers/LazyPointerImpl.java | 4 ++ .../impl/smartPointers/SelfElementInfo.java | 7 +++ .../SmartPointerElementInfo.java | 2 + .../impl/smartPointers/SmartPointerEx.java | 1 + .../SmartPsiElementPointerImpl.java | 10 +++- 13 files changed, 113 insertions(+), 23 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfo.java b/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfo.java index 6cdf6b4d49aa..efaf4626a856 100644 --- a/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfo.java +++ b/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfo.java @@ -115,4 +115,11 @@ class AnchorElementInfo implements SmartPointerElementInfo { return null; } } + + @Override + public void dispose() { + if (myMarker != null) { + myMarker.dispose(); + } + } } diff --git a/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImplicitVariableElementInfoFactory.java b/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImplicitVariableElementInfoFactory.java index e6a6f36bfb42..ad95e90b3b6e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImplicitVariableElementInfoFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImplicitVariableElementInfoFactory.java @@ -43,6 +43,10 @@ public class ImplicitVariableElementInfoFactory implements SmartPointerElementIn return null; } + @Override + public void dispose() { + } + @Nullable public Document getDocumentToSynchronize() { return null; diff --git a/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImportListElementInfoFactory.java b/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImportListElementInfoFactory.java index f798857e0346..853a82691117 100644 --- a/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImportListElementInfoFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/smartPointers/ImportListElementInfoFactory.java @@ -42,6 +42,10 @@ public class ImportListElementInfoFactory implements SmartPointerElementInfoFact return myFile.getImportList(); } + @Override + public void dispose() { + } + public Document getDocumentToSynchronize() { return null; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index ab001ac96da3..8b670d4abea0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -112,11 +112,27 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } protected void collectInformationWithProgress(final ProgressIndicator progress) { - if (!HighlightLevelUtil.shouldInspect(myFile)) return; - final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(myProject); - final InspectionProfileWrapper profile = myProfileWrapper; - final List tools = DumbService.getInstance(myProject).filterByDumbAwareness(getInspectionTools(profile)); - inspect(tools, iManager, true, true, true, progress); + try { + if (!HighlightLevelUtil.shouldInspect(myFile)) return; + final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(myProject); + final InspectionProfileWrapper profile = myProfileWrapper; + final List tools = DumbService.getInstance(myProject).filterByDumbAwareness(getInspectionTools(profile)); + inspect(tools, iManager, true, true, true, progress); + } + finally { + disposeDescriptors(); + } + } + + private void disposeDescriptors() { + for (List list : result.values()) { + for (InspectionResult inspectionResult : list) { + for (ProblemDescriptor pd: inspectionResult.foundProblems) { + ((ProblemDescriptorImpl)pd).dispose(); + } + } + } + result.clear(); } public void doInspectInBatch(final InspectionManagerEx iManager, List toolWrappers, boolean ignoreSuppressed) { @@ -202,8 +218,26 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass final LocalInspectionToolSession session = new LocalInspectionToolSession(myFile, myStartOffset, myEndOffset); List> init = new ArrayList>(); - visitPriorityElementsAndInit(tools, iManager, isOnTheFly, ignoreSuppressed, indicator, inside, session, init); - visitRestElementsAndCleanup(tools,iManager,isOnTheFly,ignoreSuppressed, indicator, outside, session, init); + boolean finished = false; + try { + visitPriorityElementsAndInit(tools, iManager, isOnTheFly, ignoreSuppressed, indicator, inside, session, init); + visitRestElementsAndCleanup(tools,iManager,isOnTheFly,ignoreSuppressed, indicator, outside, session, init); + finished = true; + } + finally { + if (!finished) { + synchronized (init) { + for (Trinity trinity : init) { + List results = trinity.second.getResults(); + if (results != null) { + for (ProblemDescriptor pd : results) { + ((ProblemDescriptorImpl)pd).dispose(); + } + } + } + } + } + } indicator.checkCanceled(); @@ -553,8 +587,10 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass return highlightInfo; } - private static void registerQuickFixes(final LocalInspectionTool tool, final ProblemDescriptor descriptor, - final HighlightInfo highlightInfo, final Set emptyActionRegistered) { + private static void registerQuickFixes(final LocalInspectionTool tool, + final ProblemDescriptor descriptor, + final HighlightInfo highlightInfo, + final Set emptyActionRegistered) { final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName()); boolean needEmptyAction = true; final QuickFix[] fixes = descriptor.getFixes(); @@ -572,7 +608,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass needEmptyAction = false; } if (((ProblemDescriptorImpl)descriptor).getEnforcedTextAttributes() != null) { - needEmptyAction = false; + needEmptyAction = false; } if (needEmptyAction && emptyActionRegistered.add(new TextRange(highlightInfo.fixStartOffset, highlightInfo.fixEndOffset))) { EmptyIntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/EditorFoldingInfo.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/EditorFoldingInfo.java index f5e9f16a1052..e7460e1abe13 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/EditorFoldingInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/EditorFoldingInfo.java @@ -24,6 +24,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.SmartPsiElementPointer; +import com.intellij.psi.impl.smartPointers.SmartPointerEx; import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,6 +37,7 @@ public class EditorFoldingInfo { private final Map> myFoldRegionToSmartPointerMap = new THashMap>(); + @NotNull public static EditorFoldingInfo get(@NotNull Editor editor) { EditorFoldingInfo info = editor.getUserData(KEY); if (info == null){ @@ -82,15 +84,18 @@ public class EditorFoldingInfo { } public void dispose() { + for(FoldRegion region:myFoldRegionToSmartPointerMap.keySet()) { + SmartPsiElementPointer pointer = myFoldRegionToSmartPointerMap.get(region); + ((SmartPointerEx)pointer).dispose(); + region.dispose(); + } myFoldRegionToSmartPointerMap.clear(); } public static void resetInfo(final Editor editor) { EditorFoldingInfo info = editor.getUserData(KEY); if (info != null) { - for(FoldRegion region:info.myFoldRegionToSmartPointerMap.keySet()) { - region.dispose(); - } + info.dispose(); } editor.putUserData(KEY, null); } 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 52ffb45c8a74..b9e746fa4d4e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java @@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.pom.Navigatable; import com.intellij.psi.*; +import com.intellij.psi.impl.smartPointers.SmartPointerEx; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; @@ -40,7 +41,6 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement @NotNull private final SmartPsiElementPointer myStartSmartPointer; @Nullable private final SmartPsiElementPointer myEndSmartPointer; - private final ProblemHighlightType myHighlightType; private Navigatable myNavigatable; private final boolean myAfterEndOfLine; @@ -66,7 +66,10 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement this(startElement, endElement, descriptionTemplate, fixes, highlightType, isAfterEndOfLine, rangeInElement, true, hintAction, onTheFly); } - public ProblemDescriptorImpl(@NotNull PsiElement startElement, @NotNull PsiElement endElement, String descriptionTemplate, LocalQuickFix[] fixes, + public ProblemDescriptorImpl(@NotNull PsiElement startElement, + @NotNull PsiElement endElement, + String descriptionTemplate, + LocalQuickFix[] fixes, ProblemHighlightType highlightType, boolean isAfterEndOfLine, final TextRange rangeInElement, @@ -191,4 +194,9 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement public boolean showTooltip() { return myShowTooltip; } + + public void dispose() { + ((SmartPointerEx)myStartSmartPointer).dispose(); + if (myEndSmartPointer != null) ((SmartPointerEx)myEndSmartPointer).dispose(); + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java b/platform/lang-impl/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java index 88cbc3339233..15897a46b278 100644 --- a/platform/lang-impl/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java +++ b/platform/lang-impl/src/com/intellij/openapi/editor/ex/util/LayeredLexerEditorHighlighter.java @@ -350,13 +350,13 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter { final int newEnd = start + tokenText.length(); if (oldMapping.range.getStartOffset() != start || - oldMapping.range.getEndOffset() != newEnd - ) { + oldMapping.range.getEndOffset() != newEnd) { + oldMapping.range.dispose(); oldMapping.range = doc.createRangeMarker(start, newEnd); } } - public MappedRange insertMapping(int tokenIndex, IElementType outerToken) { + private MappedRange insertMapping(int tokenIndex, IElementType outerToken) { CharSequence tokenText = getTokenText(tokenIndex); final int length = tokenText.length(); @@ -367,7 +367,8 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter { doc.insertString(insertOffset, new MergingCharSequence(mySeparator, tokenText)); insertOffset += mySeparator.length(); - return new MappedRange(this, doc.createRangeMarker(insertOffset, insertOffset + length), outerToken); + RangeMarker marker = doc.createRangeMarker(insertOffset, insertOffset + length); + return new MappedRange(this, marker, outerToken); } private CharSequence getTokenText(final int tokenIndex) { @@ -386,12 +387,13 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter { return null; } - public void removeMapping(MappedRange mapping) { + private void removeMapping(MappedRange mapping) { RangeMarker rangeMarker = mapping.range; if (rangeMarker.isValid()) { final int start = rangeMarker.getStartOffset(); final int end = rangeMarker.getEndOffset(); doc.deleteString(start - mySeparator.length(), end); + rangeMarker.dispose(); } } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/FileElementInfo.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/FileElementInfo.java index 0047cd5683da..c825b9ec7302 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/FileElementInfo.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/FileElementInfo.java @@ -18,10 +18,8 @@ package com.intellij.psi.impl.smartPointers; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import org.jetbrains.annotations.NotNull; /** @@ -50,4 +48,8 @@ class FileElementInfo implements SmartPointerElementInfo { myFile = SelfElementInfo.restoreFile(myFile, myProject); return myFile; } + + @Override + public void dispose() { + } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/LazyPointerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/LazyPointerImpl.java index 95f0c04401b8..b091bc7de1b2 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/LazyPointerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/LazyPointerImpl.java @@ -110,4 +110,8 @@ public class LazyPointerImpl implements SmartPointerEx return null; } + @Override + public void dispose() { + if (myPointer != null) ((SmartPointerEx)myPointer).dispose(); + } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java index 03cb478976a2..8f338691024f 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java @@ -113,6 +113,13 @@ class SelfElementInfo implements SmartPointerElementInfo { return null; } + @Override + public void dispose() { + if (myMarker != null) { + myMarker.dispose(); + } + } + @Nullable public static PsiFile restoreFile(PsiFile file,@NotNull Project project) { if (file == null) return null; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java index 9c85e8082473..98435ed3f3ca 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java @@ -28,4 +28,6 @@ interface SmartPointerElementInfo { @Nullable PsiElement restoreElement(); + + void dispose(); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java index 8133f292798a..4ab980b7ef08 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java @@ -21,4 +21,5 @@ import com.intellij.psi.SmartPsiElementPointer; public interface SmartPointerEx extends SmartPsiElementPointer { void fastenBelt(); void documentAndPsiInSync(); + void dispose(); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java index 507b4fe0856f..da8b80f07d38 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java @@ -149,6 +149,15 @@ class SmartPsiElementPointerImpl implements SmartPointerEx } } + @Override + public void dispose() { + if (myElementInfo != null) { + myElementInfo.dispose(); + myElementInfo = null; + myElement = null; + } + } + public void fastenBelt() { if (myElementInfo != null && myElement != null && myElement.isValid()) return; @@ -156,5 +165,4 @@ class SmartPsiElementPointerImpl implements SmartPointerEx myElementInfo = createElementInfo(); } } - }