Search in sources :

Example 1 with StubBasedPsiElementBase

use of com.intellij.extapi.psi.StubBasedPsiElementBase in project intellij-community by JetBrains.

the class ClassPresentationUtil method getFunctionalExpressionPresentation.

public static String getFunctionalExpressionPresentation(PsiFunctionalExpression functionalExpression, boolean qualified) {
    final StubElement stub = ((StubBasedPsiElementBase<?>) functionalExpression).getGreenStub();
    final String lambdaText = stub instanceof FunctionalExpressionStub ? ((FunctionalExpressionStub) stub).getPresentableText() : PsiExpressionTrimRenderer.render(functionalExpression);
    return PsiBundle.message("class.context.display", lambdaText, getContextName(functionalExpression, qualified));
}
Also used : FunctionalExpressionStub(com.intellij.psi.impl.java.stubs.FunctionalExpressionStub) StubElement(com.intellij.psi.stubs.StubElement) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase)

Example 2 with StubBasedPsiElementBase

use of com.intellij.extapi.psi.StubBasedPsiElementBase in project intellij-community by JetBrains.

the class JavaStubPsiElement method cloneImpl.

protected StubBasedPsiElementBase cloneImpl(@NotNull CompositeElement treeElementClone) {
    StubBasedPsiElementBase clone = (StubBasedPsiElementBase) super.clone();
    clone.setNode(treeElementClone);
    treeElementClone.setPsi(clone);
    return clone;
}
Also used : StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase)

Example 3 with StubBasedPsiElementBase

use of com.intellij.extapi.psi.StubBasedPsiElementBase 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 4 with StubBasedPsiElementBase

use of com.intellij.extapi.psi.StubBasedPsiElementBase 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;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with StubBasedPsiElementBase

use of com.intellij.extapi.psi.StubBasedPsiElementBase in project intellij-community by JetBrains.

the class PsiFileImpl method switchFromStubToAst.

private void switchFromStubToAst(List<Pair<StubBasedPsiElementBase, AstPath>> bindings, FileTrees trees) {
    if (!bindings.isEmpty() && trees.useStrongRefs) {
        List<String> psiStrings = ContainerUtil.map(bindings, pair -> pair.first.getClass().getName());
        LOG.error(this + " of " + getClass() + "; " + psiStrings);
    }
    for (int i = 0; i < bindings.size(); i++) {
        Pair<StubBasedPsiElementBase, AstPath> pair = bindings.get(i);
        StubBasedPsiElementBase psi = pair.first;
        AstPath path = pair.second;
        path.getNode().setPsi(psi);
        myRefToPsi.cachePsi(path, psi);
        psi.setStubIndex(i + 1);
    }
}
Also used : StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase)

Aggregations

StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)5 StubElement (com.intellij.psi.stubs.StubElement)3 StubBuilder (com.intellij.psi.StubBuilder)1 FunctionalExpressionStub (com.intellij.psi.impl.java.stubs.FunctionalExpressionStub)1 PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)1 IStubElementType (com.intellij.psi.stubs.IStubElementType)1 IElementType (com.intellij.psi.tree.IElementType)1 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)1 Nullable (org.jetbrains.annotations.Nullable)1