IDEA-67711

This commit is contained in:
Alexey Kudravtsev
2011-04-22 18:49:35 +04:00
parent dde16226d5
commit 3669d89e46
15 changed files with 44 additions and 260 deletions
@@ -35,14 +35,14 @@ class AnchorElementInfo extends SelfElementInfo {
private IStubElementType myStubElementType;
AnchorElementInfo(@NotNull PsiElement anchor, @NotNull PsiFile containingFile) {
super(containingFile.getProject(), anchor.getTextRange(), anchor.getClass(), containingFile);
super(containingFile.getProject(), anchor.getTextRange(), anchor.getClass(), containingFile, anchor.getLanguage());
}
// will restore by stub index until file tree get loaded
AnchorElementInfo(@NotNull PsiElement anchor,
@NotNull PsiFileWithStubSupport containingFile,
int stubId,
@NotNull IStubElementType stubElementType) {
super(containingFile.getProject(), new TextRange(0,0), anchor.getClass(), containingFile);
super(containingFile.getProject(), new TextRange(0,0), anchor.getClass(), containingFile, anchor.getLanguage());
this.stubId = stubId;
myStubElementType = stubElementType;
IElementType contentElementType = ((PsiFileImpl)containingFile).getContentElementType();
@@ -15,7 +15,6 @@
*/
package com.intellij.usageView;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
@@ -208,13 +207,6 @@ public class UsageInfo {
return mySmartPointer.getVirtualFile();
}
public void dispose() {
((Disposable)mySmartPointer).dispose();
if (myPsiFileRange != null) {
((Disposable)myPsiFileRange).dispose();
}
}
public boolean isDynamicUsage() {
return myDynamicUsage;
}
@@ -138,13 +138,6 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
}
private void disposeDescriptors() {
for (List<InspectionResult> list : result.values()) {
for (InspectionResult inspectionResult : list) {
for (ProblemDescriptor pd: inspectionResult.foundProblems) {
((ProblemDescriptorImpl)pd).dispose();
}
}
}
result.clear();
}
@@ -231,26 +224,8 @@ 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>>();
boolean finished = false;
try {
visitPriorityElementsAndInit(tools, iManager, isOnTheFly, indicator, inside, session, init);
visitRestElementsAndCleanup(tools,iManager,isOnTheFly, 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();
}
}
}
}
}
}
visitPriorityElementsAndInit(tools, iManager, isOnTheFly, indicator, inside, session, init);
visitRestElementsAndCleanup(tools,iManager,isOnTheFly, indicator, outside, session, init);
indicator.checkCanceled();
@@ -26,7 +26,6 @@ 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;
@@ -86,9 +85,7 @@ public class EditorFoldingInfo {
}
public void dispose() {
for(FoldRegion region:myFoldRegionToSmartPointerMap.keySet()) {
SmartPsiElementPointer<?> pointer = myFoldRegionToSmartPointerMap.get(region);
((SmartPointerEx)pointer).dispose();
for (FoldRegion region : myFoldRegionToSmartPointerMap.keySet()) {
region.dispose();
}
myFoldRegionToSmartPointerMap.clear();
@@ -26,7 +26,6 @@ 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;
@@ -205,13 +204,6 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement
return myShowTooltip;
}
public void dispose() {
QuickFix[] fixes = getFixes();
if (fixes != null && fixes.length != 0) return;
((SmartPointerEx)myStartSmartPointer).dispose();
if (myEndSmartPointer != null) ((SmartPointerEx)myEndSmartPointer).dispose();
}
@Override
public String toString() {
PsiElement element = getPsiElement();
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.smartPointers;
import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
@@ -31,17 +32,17 @@ import java.util.List;
* User: cdr
*/
class InjectedSelfElementInfo extends SelfElementInfo {
private final SmartPsiFileRange myPsiFileRangeInHostElement;
private final Class<? extends PsiElement> myClass;
private final SmartPsiFileRange myInjectedFileRangeInHostElement;
private final Class<? extends PsiElement> anchorClass;
private final Language anchorLanguage;
InjectedSelfElementInfo(@NotNull Project project,
@NotNull PsiElement anchor,
@NotNull PsiElement context) {
InjectedSelfElementInfo(@NotNull Project project, @NotNull PsiElement anchor, @NotNull PsiElement context) {
super(project, context);
SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project);
myPsiFileRangeInHostElement = smartPointerManager.createSmartPsiFileRangePointer(context.getContainingFile(), InjectedLanguageManager.getInstance(
project).injectedToHost(anchor, anchor.getTextRange()));
myClass = anchor.getClass();
TextRange range = InjectedLanguageManager.getInstance(project).injectedToHost(anchor, anchor.getTextRange());
myInjectedFileRangeInHostElement = smartPointerManager.createSmartPsiFileRangePointer(context.getContainingFile(), range);
anchorClass = anchor.getClass();
anchorLanguage = anchor.getLanguage();
}
@Override
@@ -56,7 +57,7 @@ class InjectedSelfElementInfo extends SelfElementInfo {
PsiElement host = super.restoreElement();
if (host == null) return null;
Segment segment = myPsiFileRangeInHostElement.getRange();
Segment segment = myInjectedFileRangeInHostElement.getRange();
if (segment == null) return null;
final TextRange rangeInHostElement = TextRange.create(segment);
final Ref<PsiElement> result = new Ref<PsiElement>();
@@ -69,7 +70,8 @@ class InjectedSelfElementInfo extends SelfElementInfo {
InjectedLanguageManager.getInstance(getProject()).injectedToHost(injectedPsi, new TextRange(0, injectedPsi.getTextLength()));
if (hostRange.contains(rangeInHostElement)) {
TextRange rangeInside = rangeInHostElement.shiftRight(-hostRange.getStartOffset());
PsiElement element = findElementInside(injectedPsi, rangeInside.getStartOffset(), rangeInside.getEndOffset(), myClass);
PsiElement element = findElementInside(injectedPsi, rangeInside.getStartOffset(), rangeInside.getEndOffset(), anchorClass,
anchorLanguage);
result.set(element);
}
}
@@ -82,8 +84,8 @@ class InjectedSelfElementInfo extends SelfElementInfo {
public boolean pointsToTheSameElementAs(@NotNull SmartPointerElementInfo other) {
if (getClass() != other.getClass()) return false;
if (!super.pointsToTheSameElementAs(other)) return false;
SmartPointerElementInfo myElementInfo = ((SmartPsiElementPointerImpl)myPsiFileRangeInHostElement).getElementInfo();
SmartPointerElementInfo oElementInfo = ((SmartPsiElementPointerImpl)((InjectedSelfElementInfo)other).myPsiFileRangeInHostElement).getElementInfo();
SmartPointerElementInfo myElementInfo = ((SmartPsiElementPointerImpl)myInjectedFileRangeInHostElement).getElementInfo();
SmartPointerElementInfo oElementInfo = ((SmartPsiElementPointerImpl)((InjectedSelfElementInfo)other).myInjectedFileRangeInHostElement).getElementInfo();
return myElementInfo.pointsToTheSameElementAs(oElementInfo);
}
}
@@ -1,159 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.impl.smartPointers;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.util.ReflectionCache;
import org.jetbrains.annotations.NotNull;
public class LazyPointerImpl<E extends PsiElement> implements SmartPointerEx<E> {
private E myElement = null;
private PsiAnchor myAnchor = null;
private SmartPsiElementPointer myPointer = null;
private final Class<? extends PsiElement> myElementClass;
private final Project myProject;
LazyPointerImpl(@NotNull E element) {
myElementClass = element.getClass();
if (element instanceof PsiCompiledElement) {
myElement = element;
}
else {
myAnchor = PsiAnchor.create(element);
}
myProject = element.getProject();
}
public boolean pointsToTheSameElementAs(LazyPointerImpl pointer) {
if (myElementClass != pointer.myElementClass) return false;
if (myElement != null) return pointer.myElement == myElement;
if (myAnchor != null && pointer.myAnchor != null) {
return myAnchor.pointsToTheSameElementAs(pointer.myAnchor);
}
if (myPointer != null && pointer.myPointer != null) {
return SmartPointerManager.getInstance(myProject).pointToTheSameElement(myPointer, pointer.myPointer);
}
return Comparing.equal(getElement(), pointer.getElement());
}
private static SmartPsiElementPointer setupPointer(PsiElement element) {
return SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
}
public void fastenBelt(int offset) {
if (myAnchor != null) {
final PsiElement element = myAnchor.retrieve();
if (element != null) {
myPointer = setupPointer(element);
//((SmartPointerEx)myPointer).fastenBelt(offset);
myAnchor = null;
}
}
}
@Override
public void unfastenBelt(int offset) {
}
public void documentAndPsiInSync() {
}
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof LazyPointerImpl)) return false;
final LazyPointerImpl that = (LazyPointerImpl)o;
return pointsToTheSameElementAs(that);
}
public int hashCode() {
int result = myElement != null ? myElement.hashCode() : 0;
result = 31 * result + (myAnchor != null ? myAnchor.hashCode() : 0);
result = 31 * result + (myPointer != null ? myPointer.hashCode() : 0);
result = 31 * result + (myElementClass != null ? myElementClass.hashCode() : 0);
return result;
}
@NotNull
public Project getProject() {
return myProject;
}
@Override
public VirtualFile getVirtualFile() {
PsiFile psiFile = getContainingFile();
return psiFile == null ? null : psiFile.getVirtualFile();
}
public E getElement() {
E element = myElement;
if (element != null) return element.isValid() ? element : null;
SmartPsiElementPointer pointer = myPointer;
if (pointer != null) return (E) pointer.getElement();
PsiAnchor anchor = myAnchor;
if (anchor != null) {
final PsiElement psiElement = anchor.retrieve();
if (psiElement != null) {
return ReflectionCache.isAssignable(myElementClass, psiElement.getClass()) ? (E) psiElement : null;
}
}
return null;
}
public PsiFile getContainingFile() {
E element = myElement;
if (element != null) {
return element.getContainingFile();
}
PsiAnchor anchor = myAnchor;
if (anchor != null) {
return anchor.getFile();
}
SmartPsiElementPointer pointer = myPointer;
if (pointer != null) {
return pointer.getContainingFile();
}
return null;
}
@Override
public void dispose() {
if (myPointer != null) ((SmartPointerEx)myPointer).dispose();
}
@Override
public Segment getRange() {
E element = myElement;
if (element != null && element.isValid()) return element.getTextRange();
SmartPsiElementPointer pointer = myPointer;
if (pointer != null) return pointer.getRange();
PsiAnchor anchor = myAnchor;
if (anchor != null) {
final PsiElement psiElement = anchor.retrieve();
if (psiElement != null) {
return psiElement.getTextRange();
}
}
return null;
}
}
@@ -25,15 +25,12 @@ import org.jetbrains.annotations.NotNull;
* User: cdr
*/
public class MultiRootSelfElementInfo extends SelfElementInfo {
private final Language myLanguage;
public MultiRootSelfElementInfo(@NotNull Project project,
@NotNull TextRange anchor,
@NotNull Class anchorClass,
@NotNull PsiFile containingFile,
@NotNull Language language) {
super(project, anchor, anchorClass, containingFile);
myLanguage = language;
super(project, anchor, anchorClass, containingFile, language);
}
@Override
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.smartPointers;
import com.intellij.lang.Language;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.RangeMarker;
@@ -45,11 +46,17 @@ public class SelfElementInfo implements SmartPointerElementInfo {
protected final Project myProject;
@SuppressWarnings({"UnusedDeclaration"})
private RangeMarker myRangeMarker; //maintain hard reference during modification
protected final Language myLanguage;
protected SelfElementInfo(@NotNull Project project, @NotNull PsiElement anchor) {
this(project, anchor.getTextRange(), anchor.getClass(), anchor.getContainingFile());
this(project, anchor.getTextRange(), anchor.getClass(), anchor.getContainingFile(), anchor.getLanguage());
}
public SelfElementInfo(@NotNull Project project, @NotNull TextRange anchor, @NotNull Class anchorClass, @NotNull PsiFile containingFile) {
public SelfElementInfo(@NotNull Project project,
@NotNull TextRange anchor,
@NotNull Class anchorClass,
@NotNull PsiFile containingFile,
@NotNull Language language) {
myLanguage = language;
myVirtualFile = containingFile.getVirtualFile();
myType = anchorClass;
@@ -159,15 +166,15 @@ public class SelfElementInfo implements SmartPointerElementInfo {
final int syncStartOffset = getSyncStartOffset();
final int syncEndOffset = getSyncEndOffset();
return findElementInside(file, syncStartOffset, syncEndOffset, myType);
return findElementInside(file, syncStartOffset, syncEndOffset, myType, myLanguage);
}
protected PsiFile restoreFile() {
return restoreFileFromVirtual(myVirtualFile, myProject);
}
protected static PsiElement findElementInside(PsiFile file, int syncStartOffset, int syncEndOffset, Class type) {
PsiElement anchor = file.getViewProvider().findElementAt(syncStartOffset, file.getLanguage());
protected static PsiElement findElementInside(@NotNull PsiFile file, int syncStartOffset, int syncEndOffset, @NotNull Class type, @NotNull Language language) {
PsiElement anchor = file.getViewProvider().findElementAt(syncStartOffset, language);
if (anchor == null) return null;
TextRange range = anchor.getTextRange();
@@ -15,14 +15,12 @@
*/
package com.intellij.psi.impl.smartPointers;
import com.intellij.openapi.Disposable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.SmartPsiElementPointer;
public interface SmartPointerEx<E extends PsiElement> extends SmartPsiElementPointer<E>, Disposable {
public interface SmartPointerEx<E extends PsiElement> extends SmartPsiElementPointer<E> {
void fastenBelt(int offset);
void documentAndPsiInSync();
void dispose();
void unfastenBelt(int offset);
}
@@ -74,7 +74,6 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
for (int i = size - 1; i >= index; i--) {
pointers.remove(i);
}
int i = 0;
}
}
@@ -148,15 +147,21 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
}
}
//private static final Key<SmartPsiElementPointer> CACHED_SMART_POINTER_KEY = Key.create("CACHED_SMART_POINTER_KEY");
@NotNull
public <E extends PsiElement> SmartPsiElementPointer<E> createSmartPsiElementPointer(@NotNull E element) {
if (!element.isValid()) {
LOG.error("Invalid element:" + element);
}
//final SmartPsiElementPointer cachedPointer = element.getUserData(CACHED_SMART_POINTER_KEY);
//if (cachedPointer != null) {
// return cachedPointer;
//}
PsiFile containingFile = element.getContainingFile();
SmartPointerEx<E> pointer = new SmartPsiElementPointerImpl<E>(myProject, element, containingFile);
initPointer(pointer, containingFile);
//element.putUserData(CACHED_SMART_POINTER_KEY, pointer);
return pointer;
}
@@ -173,7 +178,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
return pointer;
}
private <E extends PsiElement> void initPointer(SmartPointerEx<E> pointer, PsiFile containingFile) {
private static <E extends PsiElement> void initPointer(SmartPointerEx<E> pointer, PsiFile containingFile) {
if (containingFile == null) return;
synchronized (containingFile) {
//Document document = PsiDocumentManager.getInstance(myProject).getCachedDocument(containingFile);
@@ -210,11 +215,9 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
@NotNull
@Deprecated
public <E extends PsiElement> SmartPsiElementPointer<E> createLazyPointer(@NotNull E element) {
return createSmartPsiElementPointer(element);
//LazyPointerImpl<E> pointer = new LazyPointerImpl<E>(element);
//initPointer(element, pointer, element.getContainingFile());
//return pointer;
}
@Override
@@ -224,9 +227,6 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
SmartPointerElementInfo elementInfo2 = ((SmartPsiElementPointerImpl)pointer2).getElementInfo();
return elementInfo1.pointsToTheSameElementAs(elementInfo2);
}
if (pointer1 instanceof LazyPointerImpl && pointer2 instanceof LazyPointerImpl) {
return ((LazyPointerImpl)pointer1).pointsToTheSameElementAs((LazyPointerImpl)pointer2);
}
return Comparing.equal(pointer1.getElement(), pointer2.getElement());
}
}
@@ -179,19 +179,13 @@ class SmartPsiElementPointerImpl<E extends PsiElement> implements SmartPointerEx
if (isMultiRoot && !isElementInMainRoot) {
return new MultiRootSelfElementInfo(project, element.getTextRange(), element.getClass(), containingFile, containingFile.getLanguage());
}
return new SelfElementInfo(project, element.getTextRange(), element.getClass(), containingFile);
return new SelfElementInfo(project, element.getTextRange(), element.getClass(), containingFile, element.getLanguage());
}
public void documentAndPsiInSync() {
myElementInfo.documentAndPsiInSync();
}
@Override
public void dispose() {
//myElementInfo.dispose();
//myElement = null;
}
@Override
public void unfastenBelt(int offset) {
myElementInfo.unfastenBelt(offset);
@@ -30,7 +30,7 @@ public class SmartPsiFileRangePointerImpl extends SmartPsiElementPointerImpl<Psi
@NotNull
private static SmartPointerElementInfo createElementInfo(@NotNull PsiFile containingFile, @NotNull TextRange range) {
return new SelfElementInfo(containingFile.getProject(), range, PsiFile.class, containingFile);
return new SelfElementInfo(containingFile.getProject(), range, PsiFile.class, containingFile, containingFile.getLanguage());
}
@Override
@@ -383,12 +383,6 @@ public class UsageInfo2UsageAdapter implements UsageInModule,
return myMergedUsageInfos;
}
public void dispose() {
for (UsageInfo usageInfo : myMergedUsageInfos) {
usageInfo.dispose();
}
}
private long myModificationStamp;
private long getCurrentModificationStamp() {
final PsiFile containingFile = getPsiFile();
@@ -805,11 +805,6 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS = ((Splitter)myUsagePreviewPanel.getParent()).getProportion();
myUsagePreviewPanel = null;
}
for (Usage usage : getUsages()) {
if (usage instanceof UsageInfo2UsageAdapter) {
((UsageInfo2UsageAdapter)usage).dispose();
}
}
}
}