use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiClassImpl method getContainingClass.
@Override
@Nullable
public PsiClass getContainingClass() {
final PsiClassStub stub = getGreenStub();
if (stub != null) {
StubElement parent = stub.getParentStub();
return parent instanceof PsiClassStub ? ((PsiClassStub<?>) parent).getPsi() : null;
}
PsiElement parent = getParent();
if (parent instanceof PsiClassLevelDeclarationStatement) {
return PsiTreeUtil.getParentOfType(this, PsiSyntheticClass.class);
}
return parent instanceof PsiClass ? (PsiClass) parent : null;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiClassImpl method isAnonymousOrLocal.
private static boolean isAnonymousOrLocal(PsiClass aClass) {
if (aClass instanceof PsiAnonymousClass)
return true;
final PsiClassStub stub = ((PsiClassImpl) aClass).getGreenStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
return !(parentStub instanceof PsiClassStub || parentStub instanceof PsiFileStub);
}
PsiElement parent = aClass.getParent();
while (parent != null) {
if (parent instanceof PsiMethod || parent instanceof PsiField || parent instanceof PsiClassInitializer)
return true;
if (parent instanceof PsiClass || parent instanceof PsiFile)
return false;
parent = parent.getParent();
}
return false;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiAnchor method calcStubIndex.
public static int calcStubIndex(@NotNull StubBasedPsiElement psi) {
if (psi instanceof PsiFile) {
return 0;
}
final StubElement liveStub = psi.getStub();
if (liveStub != null) {
return ((StubBase) liveStub).id;
}
PsiFileImpl file = (PsiFileImpl) psi.getContainingFile();
final StubTree stubTree = file.calcStubTree();
for (StubElement<?> stb : stubTree.getPlainList()) {
if (stb.getPsi() == psi) {
return ((StubBase) stb).id;
}
}
// it is possible via custom stub builder intentionally not producing stubs for stubbed elements
return -1;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiAnchor method restoreFromStubIndex.
@Nullable
public static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl, int index, @NotNull IStubElementType elementType, boolean throwIfNull) {
if (fileImpl == null) {
if (throwIfNull)
throw new AssertionError("Null file");
return null;
}
StubTree tree = fileImpl.getStubTree();
if (tree == null) {
if (fileImpl instanceof PsiFileImpl) {
// Note: as far as this is a realization of StubIndexReference fileImpl#getContentElementType() must be instance of IStubFileElementType
tree = ((PsiFileImpl) fileImpl).calcStubTree();
} else {
if (throwIfNull)
throw new AssertionError("Not PsiFileImpl: " + fileImpl.getClass());
return null;
}
}
List<StubElement<?>> list = tree.getPlainList();
if (index >= list.size()) {
if (throwIfNull)
throw new AssertionError("Too large index: " + index + ">=" + list.size());
return null;
}
StubElement stub = list.get(index);
if (stub.getStubType() != elementType) {
if (throwIfNull)
throw new AssertionError("Element type mismatch: " + stub.getStubType() + "!=" + elementType);
return null;
}
return stub.getPsi();
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PyFunctionImpl method getContainingClass.
public PyClass getContainingClass() {
final PyFunctionStub stub = getStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PyClassStub) {
return ((PyClassStub) parentStub).getPsi();
}
return null;
}
final PsiElement parent = PsiTreeUtil.getParentOfType(this, StubBasedPsiElement.class);
if (parent instanceof PyClass) {
return (PyClass) parent;
}
return null;
}
Aggregations