optimize PsiTreeUtil.getStubOrPsiParent() pycharm/96.1163
authorDmitry Jemerov <yole@jetbrains.com>
Mon, 13 Sep 2010 12:57:36 +0000 (16:57 +0400)
committerDmitry Jemerov <yole@jetbrains.com>
Mon, 13 Sep 2010 18:00:09 +0000 (22:00 +0400)
platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java

index 35fa915d585ed727bcd3ace83692adb342aee577..01e6a35be7ebdb61093e47d5b3b2d90ecb983c5d 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.psi.*;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.search.PsiElementProcessor;
 import com.intellij.psi.stubs.StubBase;
+import com.intellij.psi.stubs.StubElement;
 import com.intellij.psi.templateLanguages.OuterLanguageElement;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.SmartList;
@@ -352,7 +353,16 @@ public class PsiTreeUtil {
 
   @Nullable
   public static PsiElement getStubOrPsiParent(@Nullable PsiElement element) {
-    return getStubOrPsiParentOfType(element, PsiElement.class);
+    if (element instanceof StubBasedPsiElement) {
+      StubBase stub = (StubBase)((StubBasedPsiElement)element).getStub();
+      if (stub != null) {
+        //noinspection unchecked
+        final StubElement parentStub = stub.getParentStub();
+        return parentStub != null ? parentStub.getPsi() : null;
+      }
+
+    }
+    return element != null ? element.getParent() : null;
   }
 
   @Nullable