use of com.intellij.psi.StubBasedPsiElement in project intellij-community by JetBrains.
the class ScopeUtil method getScopeOwner.
/**
* Return the scope owner for the element.
*
* Scope owner is not always the first ScopeOwner parent of the element. Some elements are resolved in outer scopes.
*
* This method does not access AST if underlying PSI is stub based.
*/
@Nullable
public static ScopeOwner getScopeOwner(@Nullable final PsiElement element) {
if (element == null) {
return null;
}
if (element instanceof StubBasedPsiElement) {
final StubElement stub = ((StubBasedPsiElement) element).getStub();
if (stub != null) {
StubElement parentStub = stub.getParentStub();
while (parentStub != null) {
final PsiElement parent = parentStub.getPsi();
if (parent instanceof ScopeOwner) {
return (ScopeOwner) parent;
}
parentStub = parentStub.getParentStub();
}
return null;
}
}
return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result.create(calculateScopeOwnerByAST(element), PsiModificationTracker.MODIFICATION_COUNT));
}
use of com.intellij.psi.StubBasedPsiElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPsiTreeUtil method getStubChildrenOfTypeAsList.
@NotNull
public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @NotNull Class<T> aClass) {
if (element == null)
return Collections.emptyList();
StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement) element).getStub() : null;
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;
}
Aggregations