use of com.intellij.psi.stubs.StubElement 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;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class AnchorRepository method restoreFromStubIndex.
private static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl, int index) {
StubTree tree = fileImpl.getStubTree();
if (tree == null) {
if (fileImpl instanceof PsiFileImpl) {
tree = ((PsiFileImpl) fileImpl).calcStubTree();
} else {
return null;
}
}
List<StubElement<?>> list = tree.getPlainList();
if (index >= list.size()) {
return null;
}
return ((StubElement) list.get(index)).getPsi();
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class JavaMethodElementType method indexStub.
@Override
public void indexStub(@NotNull final PsiMethodStub stub, @NotNull final IndexSink sink) {
final String name = stub.getName();
if (name != null) {
sink.occurrence(JavaStubIndexKeys.METHODS, name);
if (RecordUtil.isStaticNonPrivateMember(stub)) {
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getReturnTypeText(false).getShortTypeText());
}
}
Set<String> methodTypeParams = getVisibleTypeParameters(stub);
for (StubElement stubElement : stub.getChildrenStubs()) {
if (stubElement instanceof PsiParameterListStub) {
for (StubElement paramStub : ((PsiParameterListStub) stubElement).getChildrenStubs()) {
if (paramStub instanceof PsiParameterStub) {
TypeInfo type = ((PsiParameterStub) paramStub).getType(false);
String typeName = PsiNameHelper.getShortClassName(type.text);
if (TypeConversionUtil.isPrimitive(typeName) || TypeConversionUtil.isPrimitiveWrapper(typeName))
continue;
sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, typeName);
if (typeName.equals(type.text) && (type.arrayCount == 0 || type.arrayCount == 1 && type.isEllipsis) && methodTypeParams.contains(typeName)) {
sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, TYPE_PARAMETER_PSEUDO_NAME);
}
}
}
break;
}
}
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiClassImpl method calcBasesResolveContext.
@Nullable
private static PsiElement calcBasesResolveContext(@NotNull PsiElement scope, String baseClassName, boolean isInitialClass, final PsiElement defaultResolveContext) {
final StubElement stub = scope instanceof StubBasedPsiElementBase ? ((StubBasedPsiElementBase<?>) scope).getStub() : null;
if (stub == null || stub instanceof PsiClassStub && ((PsiClassStub) stub).isAnonymousInQualifiedNew()) {
return scope.getParent();
}
if (scope instanceof PsiClass) {
if (!isAnonymousOrLocal((PsiClass) scope)) {
return isInitialClass ? defaultResolveContext : scope;
}
if (!isInitialClass) {
if (((PsiClass) scope).findInnerClassByName(baseClassName, true) != null)
return scope;
}
}
final StubElement parentStub = stub.getParentStub();
PsiElement psi = parentStub.getPsi();
if (!(psi instanceof StubBasedPsiElementBase)) {
LOG.error(stub + " parent is " + parentStub);
return null;
}
if (hasChildClassStub(parentStub, baseClassName, scope)) {
return scope.getParent();
}
if (psi instanceof PsiClass || psi instanceof PsiFunctionalExpression) {
return calcBasesResolveContext(psi, baseClassName, false, defaultResolveContext);
}
if (psi instanceof PsiMember) {
PsiClass containingClass = ((PsiMember) psi).getContainingClass();
return containingClass != null ? calcBasesResolveContext(containingClass, baseClassName, false, defaultResolveContext) : psi;
}
LOG.error(parentStub);
return psi;
}
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;
}
Aggregations