use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class TreeUtil method bindStubsToTree.
public static void bindStubsToTree(@NotNull PsiFileImpl file, @NotNull StubTree stubTree, @NotNull FileElement tree) throws StubBindingException {
final ListIterator<StubElement<?>> stubs = stubTree.getPlainList().listIterator();
// skip file root stub
stubs.next();
final IStubFileElementType type = file.getElementTypeForStubBuilder();
assert type != null;
final StubBuilder builder = type.getBuilder();
tree.acceptTree(new RecursiveTreeElementWalkingVisitor() {
@Override
protected void visitNode(TreeElement node) {
CompositeElement parent = node.getTreeParent();
if (parent != null && builder.skipChildProcessingWhenBuildingStubs(parent, node)) {
return;
}
IElementType type = node.getElementType();
if (type instanceof IStubElementType && ((IStubElementType) type).shouldCreateStub(node)) {
final StubElement stub = stubs.hasNext() ? stubs.next() : null;
if (stub == null || stub.getStubType() != type) {
throw new StubBindingException("stub:" + stub + ", AST:" + type);
}
StubBasedPsiElementBase psi = (StubBasedPsiElementBase) node.getPsi();
//noinspection unchecked
((StubBase) stub).setPsi(psi);
psi.setStubIndex(stubs.previousIndex());
}
super.visitNode(node);
}
});
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class TypeInfo method applyAnnotations.
@NotNull
public TypeInfo applyAnnotations(@NotNull StubBase<?> owner) {
PsiModifierListStub modifierList = (PsiModifierListStub) owner.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
if (modifierList == null)
return this;
List<PsiAnnotationStub> annotationStubs = null;
for (StubElement child : modifierList.getChildrenStubs()) {
if (!(child instanceof PsiAnnotationStub))
continue;
PsiAnnotationStub annotationStub = (PsiAnnotationStub) child;
if (PsiImplUtil.isTypeAnnotation(annotationStub.getPsiElement())) {
if (annotationStubs == null)
annotationStubs = new SmartList<>();
annotationStubs.add(annotationStub);
}
}
PsiAnnotationStub[] stubArray = PsiAnnotationStub.EMPTY_ARRAY;
if (annotationStubs != null)
stubArray = annotationStubs.toArray(new PsiAnnotationStub[annotationStubs.size()]);
return new TypeInfo(text, arrayCount, isEllipsis, stubArray);
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class GroovyFileImpl method getPackageDefinition.
@Override
public GrPackageDefinition getPackageDefinition() {
final StubElement<?> stub = getStub();
if (stub != null) {
for (StubElement element : stub.getChildrenStubs()) {
if (element instanceof GrPackageDefinitionStub)
return (GrPackageDefinition) element.getPsi();
}
return null;
}
ASTNode node = calcTreeElement().findChildByType(GroovyElementTypes.PACKAGE_DEFINITION);
return node != null ? (GrPackageDefinition) node.getPsi() : null;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class GrTraitUtil method doCollectCompiledTraitMethods.
private static void doCollectCompiledTraitMethods(final ClsClassImpl trait, final Collection<PsiMethod> result) {
for (PsiMethod method : trait.getMethods()) {
if (AnnotationUtil.isAnnotated(method, GROOVY_TRAIT_IMPLEMENTED, false)) {
result.add(method);
}
}
VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
if (traitFile == null)
return;
VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitMethodsFileIndex.HELPER_SUFFIX);
if (helperFile == null)
return;
int key = FileBasedIndex.getFileId(helperFile);
List<PsiJavaFileStub> values = FileBasedIndex.getInstance().getValues(GroovyTraitMethodsFileIndex.INDEX_ID, key, trait.getResolveScope());
values.forEach(root -> ((PsiJavaFileStubImpl) root).setPsi((PsiJavaFile) trait.getContainingFile()));
values.stream().map(root -> root.getChildrenStubs().get(0).getChildrenStubs()).<StubElement>flatMap(Collection::stream).filter(stub -> stub instanceof PsiMethodStub).forEach(stub -> result.add(createTraitMethodFromCompiledHelperMethod(((PsiMethodStub) stub).getPsi(), trait)));
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class GrStubIndexer method processClassDecl.
@Nullable
private static ClassDecl processClassDecl(GrTypeDefinitionStub classStub, Set<String> namesCache, boolean inner) {
ArrayList<String> superList = new ArrayList<>();
ArrayList<Decl> innerList = new ArrayList<>();
if (classStub.isAnonymous()) {
String name = classStub.getBaseClassName();
if (name != null) {
superList.add(id(name, true, namesCache));
}
}
for (StubElement el : classStub.getChildrenStubs()) {
if (el instanceof GrReferenceListStub) {
GrReferenceListStub refList = (GrReferenceListStub) el;
if (el.getStubType() == GroovyElementTypes.IMPLEMENTS_CLAUSE || el.getStubType() == GroovyElementTypes.EXTENDS_CLAUSE) {
for (String extName : refList.getBaseClasses()) {
superList.add(id(extName, true, namesCache));
}
}
}
Decl member = processMember(el, namesCache);
if (member != null) {
innerList.add(member);
}
}
int flags = translateFlags(classStub);
if (inner && !superList.isEmpty()) {
// 'extends' list resolves to classes from the current package first, and those can be in a language unknown to this hierarchy
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);
}
Aggregations