mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify smart pointer equals (IDEA-CR-19433)
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
package com.intellij.psi.impl.smartPointers;
|
||||
|
||||
import com.intellij.lang.LanguageUtil;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import com.intellij.openapi.util.Segment;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -88,7 +90,7 @@ class AnchorElementInfo extends SelfElementInfo {
|
||||
return packed1 == packed2;
|
||||
}
|
||||
if (packed1 != -1 || packed2 != -1) {
|
||||
return areRestoredElementsEqual(other);
|
||||
return ReadAction.compute(() -> Comparing.equal(restoreElement(), other.restoreElement()));
|
||||
}
|
||||
}
|
||||
return super.pointsToTheSameElementAs(other);
|
||||
|
||||
@@ -55,10 +55,7 @@ class DirElementInfo extends SmartPointerElementInfo {
|
||||
|
||||
@Override
|
||||
public boolean pointsToTheSameElementAs(@NotNull SmartPointerElementInfo other) {
|
||||
if (other instanceof DirElementInfo) {
|
||||
return Comparing.equal(myVirtualFile, ((DirElementInfo)other).myVirtualFile);
|
||||
}
|
||||
return Comparing.equal(restoreElement(), other.restoreElement());
|
||||
return other instanceof DirElementInfo && Comparing.equal(myVirtualFile, ((DirElementInfo)other).myVirtualFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -66,14 +66,7 @@ class FileElementInfo extends SmartPointerElementInfo {
|
||||
|
||||
@Override
|
||||
public boolean pointsToTheSameElementAs(@NotNull SmartPointerElementInfo other) {
|
||||
if (other instanceof FileElementInfo) {
|
||||
return Comparing.equal(myVirtualFile, ((FileElementInfo)other).myVirtualFile);
|
||||
}
|
||||
if (other instanceof SelfElementInfo || other instanceof ClsElementInfo) {
|
||||
// optimisation: SelfElementInfo need psi (parsing) for element restoration and apriori could not reference psi file
|
||||
return false;
|
||||
}
|
||||
return Comparing.equal(restoreElement(), other.restoreElement());
|
||||
return other instanceof FileElementInfo && Comparing.equal(myVirtualFile, ((FileElementInfo)other).myVirtualFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.smartPointers;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Segment;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -57,12 +54,7 @@ class HardElementInfo extends SmartPointerElementInfo {
|
||||
|
||||
@Override
|
||||
public boolean pointsToTheSameElementAs(@NotNull final SmartPointerElementInfo other) {
|
||||
return Comparing.equal(myElement, ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
|
||||
@Override
|
||||
public PsiElement compute() {
|
||||
return other.restoreElement();
|
||||
}
|
||||
}));
|
||||
return other instanceof HardElementInfo && myElement.equals(((HardElementInfo)other).myElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -192,13 +192,7 @@ public class SelfElementInfo extends SmartPointerElementInfo {
|
||||
&& range1.getEndOffset() == range2.getEndOffset();
|
||||
});
|
||||
}
|
||||
return areRestoredElementsEqual(other);
|
||||
}
|
||||
|
||||
boolean areRestoredElementsEqual(@NotNull final SmartPointerElementInfo other) {
|
||||
return ApplicationManager.getApplication().runReadAction(
|
||||
(Computable<Boolean>)() -> Comparing.equal(getVirtualFile(), other.getVirtualFile())
|
||||
&& Comparing.equal(restoreElement(), other.restoreElement()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user