Search in sources :

Example 1 with IStubElementType

use of com.intellij.psi.stubs.IStubElementType in project kotlin by JetBrains.

the class KtStubElementType method createStubDependingOnParent.

private static boolean createStubDependingOnParent(ASTNode node) {
    ASTNode parent = node.getTreeParent();
    IElementType parentType = parent.getElementType();
    if (parentType instanceof IStubElementType) {
        return ((IStubElementType) parentType).shouldCreateStub(parent);
    }
    if (parentType instanceof IStubFileElementType) {
        return true;
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) ASTNode(com.intellij.lang.ASTNode) IStubElementType(com.intellij.psi.stubs.IStubElementType)

Example 2 with IStubElementType

use of com.intellij.psi.stubs.IStubElementType 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);
        }
    });
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) StubElement(com.intellij.psi.stubs.StubElement) IStubElementType(com.intellij.psi.stubs.IStubElementType) StubBuilder(com.intellij.psi.StubBuilder) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase)

Example 3 with IStubElementType

use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.

the class SmartPsiElementPointerImpl method createAnchorInfo.

@Nullable
private static SmartPointerElementInfo createAnchorInfo(@NotNull PsiElement element, @NotNull PsiFile containingFile) {
    if (element instanceof StubBasedPsiElement && containingFile instanceof PsiFileWithStubSupport) {
        PsiFileWithStubSupport stubFile = (PsiFileWithStubSupport) containingFile;
        StubTree stubTree = stubFile.getStubTree();
        if (stubTree != null) {
            // use stubs when tree is not loaded
            StubBasedPsiElement stubPsi = (StubBasedPsiElement) element;
            int stubId = PsiAnchor.calcStubIndex(stubPsi);
            IStubElementType myStubElementType = stubPsi.getElementType();
            IStubFileElementType elementTypeForStubBuilder = ((PsiFileImpl) containingFile).getElementTypeForStubBuilder();
            if (stubId != -1 && elementTypeForStubBuilder != null) {
                // TemplateDataElementType is not IStubFileElementType
                return new AnchorElementInfo(element, stubFile, stubId, myStubElementType);
            }
        }
    }
    Pair<Identikit.ByAnchor, PsiElement> pair = Identikit.withAnchor(element, LanguageUtil.getRootLanguage(containingFile));
    if (pair != null) {
        return new AnchorElementInfo(pair.second, containingFile, pair.first);
    }
    return null;
}
Also used : PsiFileWithStubSupport(com.intellij.psi.impl.source.PsiFileWithStubSupport) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) StubTree(com.intellij.psi.stubs.StubTree) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) IStubElementType(com.intellij.psi.stubs.IStubElementType) ForeignLeafPsiElement(com.intellij.psi.impl.source.tree.ForeignLeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with IStubElementType

use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.

the class AnchorElementInfo method restoreElement.

@Override
@Nullable
public PsiElement restoreElement() {
    long typeAndId = myStubElementTypeAndId;
    int stubId = (int) typeAndId;
    if (stubId != -1) {
        PsiFile file = restoreFile();
        if (!(file instanceof PsiFileWithStubSupport))
            return null;
        short index = (short) (typeAndId >> 32);
        IStubElementType stubElementType = (IStubElementType) IElementType.find(index);
        return PsiAnchor.restoreFromStubIndex((PsiFileWithStubSupport) file, stubId, stubElementType, false);
    }
    return super.restoreElement();
}
Also used : PsiFileWithStubSupport(com.intellij.psi.impl.source.PsiFileWithStubSupport) PsiFile(com.intellij.psi.PsiFile) IStubElementType(com.intellij.psi.stubs.IStubElementType) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with IStubElementType

use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.

the class GrTypeDefinitionImpl method getScope.

@Nullable
@Override
public PsiElement getScope() {
    final GrTypeDefinitionStub stub = getStub();
    if (stub != null) {
        return stub.getParentStub().getPsi();
    }
    ASTNode treeElement = getNode();
    ASTNode parent = treeElement.getTreeParent();
    while (parent != null) {
        if (parent.getElementType() instanceof IStubElementType && !(parent.getElementType() == GroovyElementTypes.CLASS_BODY)) {
            return parent.getPsi();
        }
        parent = parent.getTreeParent();
    }
    return getContainingFile();
}
Also used : GrTypeDefinitionStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub) ASTNode(com.intellij.lang.ASTNode) IStubElementType(com.intellij.psi.stubs.IStubElementType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IStubElementType (com.intellij.psi.stubs.IStubElementType)7 Nullable (org.jetbrains.annotations.Nullable)4 ASTNode (com.intellij.lang.ASTNode)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 PsiFileWithStubSupport (com.intellij.psi.impl.source.PsiFileWithStubSupport)2 IElementType (com.intellij.psi.tree.IElementType)2 StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)1 PsiFile (com.intellij.psi.PsiFile)1 StubBuilder (com.intellij.psi.StubBuilder)1 PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)1 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)1 ForeignLeafPsiElement (com.intellij.psi.impl.source.tree.ForeignLeafPsiElement)1 StubElement (com.intellij.psi.stubs.StubElement)1 StubTree (com.intellij.psi.stubs.StubTree)1 GrTypeDefinitionStub (org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub)1