Search in sources :

Example 1 with StubBase

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

the class StubClassBuilder method markLastChild.

private void markLastChild(@NotNull JvmDeclarationOrigin origin) {
    List children = v.getResult().getChildrenStubs();
    StubBase last = (StubBase) children.get(children.size() - 1);
    LightElementOrigin oldOrigin = last.getUserData(ClsWrapperStubPsiFactory.ORIGIN);
    if (oldOrigin != null) {
        PsiElement originalElement = oldOrigin.getOriginalElement();
        throw new IllegalStateException("Rewriting origin element: " + (originalElement != null ? originalElement.getText() : null) + " for stub " + last.toString());
    }
    last.putUserData(ClsWrapperStubPsiFactory.ORIGIN, LightElementOriginKt.toLightMemberOrigin(origin));
    last.putUserData(MemberIndex.KEY, new MemberIndex(memberIndex++));
}
Also used : StubBase(com.intellij.psi.stubs.StubBase) List(java.util.List) PsiElement(com.intellij.psi.PsiElement)

Example 2 with StubBase

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

the class StubClassBuilder method defineClass.

@Override
public void defineClass(PsiElement origin, int version, int access, @NotNull String name, @Nullable String signature, @NotNull String superName, @NotNull String[] interfaces) {
    assert v == null : "defineClass() called twice?";
    v = new StubBuildingVisitor<Object>(null, EMPTY_STRATEGY, parent, access, calculateShortName(name));
    super.defineClass(origin, version, access, name, signature, superName, interfaces);
    if (origin instanceof KtFile) {
        FqName packageName = ((KtFile) origin).getPackageFqName();
        String packageClassName = OldPackageFacadeClassUtils.getPackageClassName(packageName);
        if (name.equals(packageClassName) || name.endsWith("/" + packageClassName)) {
            isPackageClass = true;
        }
    }
    if (!isPackageClass) {
        parentStack.push(v.getResult());
    }
    ((StubBase) v.getResult()).putUserData(ClsWrapperStubPsiFactory.ORIGIN, LightElementOriginKt.toLightClassOrigin(origin));
}
Also used : StubBase(com.intellij.psi.stubs.StubBase) FqName(org.jetbrains.kotlin.name.FqName) KtFile(org.jetbrains.kotlin.psi.KtFile)

Example 3 with StubBase

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

the class PsiAnchor method calcStubIndex.

public static int calcStubIndex(@NotNull StubBasedPsiElement psi) {
    if (psi instanceof PsiFile) {
        return 0;
    }
    final StubElement liveStub = psi.getStub();
    if (liveStub != null) {
        return ((StubBase) liveStub).id;
    }
    PsiFileImpl file = (PsiFileImpl) psi.getContainingFile();
    final StubTree stubTree = file.calcStubTree();
    for (StubElement<?> stb : stubTree.getPlainList()) {
        if (stb.getPsi() == psi) {
            return ((StubBase) stb).id;
        }
    }
    // it is possible via custom stub builder intentionally not producing stubs for stubbed elements
    return -1;
}
Also used : StubBase(com.intellij.psi.stubs.StubBase) StubTree(com.intellij.psi.stubs.StubTree) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) StubElement(com.intellij.psi.stubs.StubElement)

Aggregations

StubBase (com.intellij.psi.stubs.StubBase)3 PsiElement (com.intellij.psi.PsiElement)1 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)1 StubElement (com.intellij.psi.stubs.StubElement)1 StubTree (com.intellij.psi.stubs.StubTree)1 List (java.util.List)1 FqName (org.jetbrains.kotlin.name.FqName)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1