@NotNull public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList( @Nullable PsiElement element, @NotNull Class<T> aClass) { if (element == null) return Collections.emptyList(); StubElement<?> stub = null; if (element instanceof PsiFileImpl) stub = ((PsiFileImpl) element).getStub(); else if (element instanceof StubBasedPsiElement) stub = ((StubBasedPsiElement) element).getStub(); if (stub == null) { return getChildrenOfTypeAsList(element, aClass); } List<T> result = new SmartList<T>(); for (StubElement childStub : stub.getChildrenStubs()) { PsiElement child = childStub.getPsi(); if (aClass.isInstance(child)) { //noinspection unchecked result.add((T) child); } } return result; }
private static PsiClass findClass(String fqn, StubElement<?> stub) { if (stub instanceof PsiClassStub && Comparing.equal(fqn, ((PsiClassStub) stub).getQualifiedName())) { return (PsiClass) stub.getPsi(); } for (StubElement child : stub.getChildrenStubs()) { PsiClass answer = findClass(fqn, child); if (answer != null) return answer; } return null; }
@Nullable public static <T extends PsiElement> T getStubChildOfType( @Nullable PsiElement element, @NotNull Class<T> aClass) { if (element == null) return null; StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement) element).getStub() : null; if (stub == null) { return getChildOfType(element, aClass); } for (StubElement childStub : stub.getChildrenStubs()) { PsiElement child = childStub.getPsi(); if (aClass.isInstance(child)) { //noinspection unchecked return (T) child; } } return null; }
@Nullable private Modifier getWrappersFromStub() { final StubElement parentStub = getStub().getParentStub(); final List childrenStubs = parentStub.getChildrenStubs(); int index = childrenStubs.indexOf(getStub()); if (index >= 0 && index < childrenStubs.size() - 1) { StubElement nextStub = (StubElement) childrenStubs.get(index + 1); if (nextStub instanceof PyTargetExpressionStub) { final PyTargetExpressionStub targetExpressionStub = (PyTargetExpressionStub) nextStub; if (targetExpressionStub.getInitializerType() == PyTargetExpressionStub.InitializerType.CallExpression) { final QualifiedName qualifiedName = targetExpressionStub.getInitializer(); if (QualifiedName.fromComponents(PyNames.CLASSMETHOD).equals(qualifiedName)) { return CLASSMETHOD; } if (QualifiedName.fromComponents(PyNames.STATICMETHOD).equals(qualifiedName)) { return STATICMETHOD; } } } } return null; }