mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
performance
This commit is contained in:
+12
-3
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.source.tree.java;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.LogUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -313,16 +314,24 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final PsiManagerEx manager = getManager();
|
||||
FileElement fileElement = SharedImplUtil.findFileElement(this);
|
||||
if (fileElement == null) {
|
||||
LOG.error("fileElement == null!");
|
||||
return JavaResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
final PsiManagerEx manager = fileElement.getManager();
|
||||
if (manager == null) {
|
||||
LOG.error("getManager() == null!");
|
||||
return JavaResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
if (!isValid()) {
|
||||
PsiFile file = SharedImplUtil.getContainingFile(fileElement);
|
||||
boolean valid = file != null && file.isValid();
|
||||
if (!valid) {
|
||||
LOG.error("invalid!");
|
||||
return JavaResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
ResolveResult[] results = ResolveCache.getInstance(getProject()).resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode);
|
||||
Project project = manager.getProject();
|
||||
ResolveResult[] results = ResolveCache.getInstance(project).resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode);
|
||||
return results.length == 0 ? JavaResolveResult.EMPTY_ARRAY : (JavaResolveResult[])results;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ public class FileElement extends LazyParseableElement implements FileASTNode {
|
||||
|
||||
@Override
|
||||
public PsiManagerEx getManager() {
|
||||
if (getTreeParent() != null) return getTreeParent().getManager();
|
||||
CompositeElement treeParent = getTreeParent();
|
||||
if (treeParent != null) return treeParent.getManager();
|
||||
return (PsiManagerEx)getPsi().getManager(); //TODO: cache?
|
||||
}
|
||||
|
||||
|
||||
@@ -58,12 +58,9 @@ public class SharedImplUtil {
|
||||
}
|
||||
|
||||
public static PsiFile getContainingFile(ASTNode thisElement) {
|
||||
TreeElement element;
|
||||
for (element = (TreeElement)thisElement; element.getTreeParent() != null; element = element.getTreeParent()) {
|
||||
}
|
||||
|
||||
PsiElement psiElement = element.getPsi();
|
||||
if (!(psiElement instanceof PsiFile)) return null;
|
||||
TreeElement element = findFileElement(thisElement);
|
||||
PsiElement psiElement = element == null ? null : element.getPsi();
|
||||
if (psiElement == null) return null;
|
||||
return psiElement.getContainingFile();
|
||||
}
|
||||
|
||||
@@ -74,10 +71,23 @@ public class SharedImplUtil {
|
||||
}
|
||||
|
||||
public static boolean isWritable(ASTNode thisElement) {
|
||||
PsiFile file = SourceTreeToPsiMap.treeElementToPsi(thisElement).getContainingFile();
|
||||
PsiFile file = getContainingFile(thisElement);
|
||||
return file == null || file.isWritable();
|
||||
}
|
||||
|
||||
public static FileElement findFileElement(@NotNull ASTNode element) {
|
||||
ASTNode parent = element.getTreeParent();
|
||||
while (parent != null) {
|
||||
element = parent;
|
||||
parent = parent.getTreeParent();
|
||||
}
|
||||
|
||||
if (element instanceof FileElement) {
|
||||
return (FileElement)element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CharTable findCharTableByTree(ASTNode tree) {
|
||||
while (tree != null) {
|
||||
final CharTable userData = tree.getUserData(CharTable.CHAR_TABLE_KEY);
|
||||
|
||||
Reference in New Issue
Block a user