use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PyTargetExpressionImpl method getContainingClass.
@Override
public PyClass getContainingClass() {
final PyTargetExpressionStub stub = getStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PyClassStub) {
return ((PyClassStub) parentStub).getPsi();
}
if (parentStub instanceof PyFunctionStub) {
final StubElement functionParent = parentStub.getParentStub();
if (functionParent instanceof PyClassStub) {
return ((PyClassStub) functionParent).getPsi();
}
}
return null;
}
final PsiElement parent = PsiTreeUtil.getParentOfType(this, PyFunction.class, PyClass.class);
if (parent instanceof PyClass) {
return (PyClass) parent;
}
if (parent instanceof PyFunction) {
return ((PyFunction) parent).getContainingClass();
}
return null;
}
use of com.intellij.psi.stubs.StubElement in project smali by JesusFreke.
the class SmaliStubBasedPsiElement method findStubOrPsiAncestorOfType.
@SuppressWarnings("unchecked")
@Nullable
protected <E extends PsiElement> E findStubOrPsiAncestorOfType(@NotNull Class<E> aClass) {
T stub = getStub();
if (stub != null) {
StubElement parent = stub.getParentStub();
while (parent != null) {
PsiElement parentPsi = parent.getPsi();
if (aClass.isInstance(parentPsi)) {
return (E) parentPsi;
}
parent = parent.getParentStub();
}
return null;
}
PsiElement parent = getParent();
while (parent != null) {
if (aClass.isInstance(parent)) {
return (E) parent;
}
parent = parent.getParent();
}
return null;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class JavaStubIndexer method processClassDecl.
@NotNull
private static ClassDecl processClassDecl(PsiClassStubImpl<?> classStub, Set<String> namesCache) {
List<String> superList = new ArrayList<>();
List<Decl> innerList = new ArrayList<>();
if (classStub.isAnonymous()) {
if (classStub.getBaseClassReferenceText() != null) {
superList.add(id(classStub.getBaseClassReferenceText(), namesCache));
}
}
for (StubElement el : classStub.getChildrenStubs()) {
if (el instanceof PsiClassReferenceListStub) {
PsiClassReferenceListStub refList = (PsiClassReferenceListStub) el;
PsiReferenceList.Role role = refList.getRole();
if (role == PsiReferenceList.Role.EXTENDS_LIST || role == PsiReferenceList.Role.IMPLEMENTS_LIST) {
for (String extName : refList.getReferencedNames()) {
superList.add(id(extName, namesCache));
}
}
}
Decl member = processMember(el, namesCache);
if (member != null) {
innerList.add(member);
}
}
int flags = translateFlags(classStub);
if (classStub.isAnonymousInQualifiedNew()) {
flags |= IndexTree.SUPERS_UNRESOLVED;
}
String[] supers = superList.isEmpty() ? ArrayUtil.EMPTY_STRING_ARRAY : ArrayUtil.toStringArray(superList);
Decl[] inners = innerList.isEmpty() ? Decl.EMPTY_ARRAY : innerList.toArray(new Decl[innerList.size()]);
return new ClassDecl(classStub.id, flags, classStub.getName(), supers, inners);
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class ClassPresentationUtil method getFunctionalExpressionPresentation.
public static String getFunctionalExpressionPresentation(PsiFunctionalExpression functionalExpression, boolean qualified) {
final StubElement stub = ((StubBasedPsiElementBase<?>) functionalExpression).getGreenStub();
final String lambdaText = stub instanceof FunctionalExpressionStub ? ((FunctionalExpressionStub) stub).getPresentableText() : PsiExpressionTrimRenderer.render(functionalExpression);
return PsiBundle.message("class.context.display", lambdaText, getContextName(functionalExpression, qualified));
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiClassImpl method getContextStub.
@Nullable
private StubElement getContextStub() {
PsiClassStub<?> stub = getStub();
if (stub == null)
return null;
// if AST is not loaded, then we only can need context to resolve supertype references
// this can be done by stubs unless there are local/anonymous classes referencing other local classes
StubElement parent = stub.getParentStub();
if (parent instanceof PsiClassInitializerStub || parent instanceof PsiMethodStub) {
if (parent.getChildrenByType(JavaStubElementTypes.CLASS, PsiElement.ARRAY_FACTORY).length <= 1) {
parent = parent.getParentStub();
}
}
return parent instanceof PsiClassStub ? parent : null;
}
Aggregations