This commit is contained in:
Alexey Kudravtsev
2010-11-23 18:49:25 +03:00
parent dec5afbfd5
commit a79b28fa1a
13 changed files with 113 additions and 23 deletions
@@ -115,4 +115,11 @@ class AnchorElementInfo implements SmartPointerElementInfo {
return null;
}
}
@Override
public void dispose() {
if (myMarker != null) {
myMarker.dispose();
}
}
}
@@ -43,6 +43,10 @@ public class ImplicitVariableElementInfoFactory implements SmartPointerElementIn
return null;
}
@Override
public void dispose() {
}
@Nullable
public Document getDocumentToSynchronize() {
return null;
@@ -42,6 +42,10 @@ public class ImportListElementInfoFactory implements SmartPointerElementInfoFact
return myFile.getImportList();
}
@Override
public void dispose() {
}
public Document getDocumentToSynchronize() {
return null;
}
@@ -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<LocalInspectionTool> 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<LocalInspectionTool> tools = DumbService.getInstance(myProject).filterByDumbAwareness(getInspectionTools(profile));
inspect(tools, iManager, true, true, true, progress);
}
finally {
disposeDescriptors();
}
}
private void disposeDescriptors() {
for (List<InspectionResult> list : result.values()) {
for (InspectionResult inspectionResult : list) {
for (ProblemDescriptor pd: inspectionResult.foundProblems) {
((ProblemDescriptorImpl)pd).dispose();
}
}
}
result.clear();
}
public void doInspectInBatch(final InspectionManagerEx iManager, List<InspectionProfileEntry> toolWrappers, boolean ignoreSuppressed) {
@@ -202,8 +218,26 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
final LocalInspectionToolSession session = new LocalInspectionToolSession(myFile, myStartOffset, myEndOffset);
List<Trinity<LocalInspectionTool, ProblemsHolder, PsiElementVisitor>> init = new ArrayList<Trinity<LocalInspectionTool, ProblemsHolder, PsiElementVisitor>>();
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<LocalInspectionTool, ProblemsHolder, PsiElementVisitor> trinity : init) {
List<ProblemDescriptor> 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<TextRange> emptyActionRegistered) {
private static void registerQuickFixes(final LocalInspectionTool tool,
final ProblemDescriptor descriptor,
final HighlightInfo highlightInfo,
final Set<TextRange> 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());
@@ -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<FoldRegion, SmartPsiElementPointer<?>> myFoldRegionToSmartPointerMap
= new THashMap<FoldRegion, SmartPsiElementPointer<?>>();
@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);
}
@@ -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();
}
}
@@ -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();
}
}
}
@@ -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() {
}
}
@@ -110,4 +110,8 @@ public class LazyPointerImpl<E extends PsiElement> implements SmartPointerEx<E>
return null;
}
@Override
public void dispose() {
if (myPointer != null) ((SmartPointerEx)myPointer).dispose();
}
}
@@ -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;
@@ -28,4 +28,6 @@ interface SmartPointerElementInfo {
@Nullable
PsiElement restoreElement();
void dispose();
}
@@ -21,4 +21,5 @@ import com.intellij.psi.SmartPsiElementPointer;
public interface SmartPointerEx<E extends PsiElement> extends SmartPsiElementPointer<E> {
void fastenBelt();
void documentAndPsiInSync();
void dispose();
}
@@ -149,6 +149,15 @@ class SmartPsiElementPointerImpl<E extends PsiElement> 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<E extends PsiElement> implements SmartPointerEx
myElementInfo = createElementInfo();
}
}
}