Search in sources :

Example 1 with StubElement

use of com.intellij.psi.stubs.StubElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoMethodDeclarationStubElementType method indexStub.

@Override
public void indexStub(@NotNull GoMethodDeclarationStub stub, @NotNull IndexSink sink) {
    super.indexStub(stub, sink);
    String typeName = stub.getTypeName();
    if (!StringUtil.isEmpty(typeName)) {
        StubElement parent = stub.getParentStub();
        if (parent instanceof GoFileStub) {
            String packageName = ((GoFileStub) parent).getPackageName();
            if (!StringUtil.isEmpty(typeName)) {
                sink.occurrence(GoMethodIndex.KEY, packageName + "." + typeName);
            }
        }
    }
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) GoFileStub(com.goide.stubs.GoFileStub)

Example 2 with StubElement

use of com.intellij.psi.stubs.StubElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoNamedStubElementType method indexStub.

@Override
public void indexStub(@NotNull S stub, @NotNull IndexSink sink) {
    String name = stub.getName();
    if (shouldIndex() && StringUtil.isNotEmpty(name)) {
        String packageName = null;
        StubElement parent = stub.getParentStub();
        while (parent != null) {
            if (parent instanceof GoFileStub) {
                packageName = ((GoFileStub) parent).getPackageName();
                break;
            }
            parent = parent.getParentStub();
        }
        String indexingName = StringUtil.isNotEmpty(packageName) ? packageName + "." + name : name;
        if (stub.isPublic()) {
            sink.occurrence(GoAllPublicNamesIndex.ALL_PUBLIC_NAMES, indexingName);
        } else {
            sink.occurrence(GoAllPrivateNamesIndex.ALL_PRIVATE_NAMES, indexingName);
        }
        for (StubIndexKey<String, ? extends GoNamedElement> key : getExtraIndexKeys()) {
            sink.occurrence(key, name);
        }
    }
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) GoFileStub(com.goide.stubs.GoFileStub)

Example 3 with StubElement

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

the class StubsTest method doTest.

public void doTest() throws Exception {
    final List<String> data = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
    String fileText = data.get(0);
    PsiFile psiFile = TestUtils.createPseudoPhysicalGroovyFile(getProject(), fileText);
    ASTNode node = psiFile.getNode();
    Assert.assertNotNull(node);
    IElementType type = node.getElementType();
    Assert.assertTrue(type instanceof IStubFileElementType);
    IStubFileElementType stubFileType = (IStubFileElementType) type;
    StubBuilder builder = stubFileType.getBuilder();
    StubElement element = builder.buildStubTree(psiFile);
    StringBuffer buffer = new StringBuffer();
    getStubsTreeImpl(element, buffer, "");
    String stubTree = buffer.toString().trim();
    assertEquals(data.get(1), stubTree);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) ASTNode(com.intellij.lang.ASTNode) PsiFile(com.intellij.psi.PsiFile) StubElement(com.intellij.psi.stubs.StubElement) StubBuilder(com.intellij.psi.StubBuilder)

Example 4 with StubElement

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

the class ScopeUtil method getScopeOwner.

/**
   * Return the scope owner for the element.
   *
   * Scope owner is not always the first ScopeOwner parent of the element. Some elements are resolved in outer scopes.
   *
   * This method does not access AST if underlying PSI is stub based.
   */
@Nullable
public static ScopeOwner getScopeOwner(@Nullable final PsiElement element) {
    if (element == null) {
        return null;
    }
    if (element instanceof StubBasedPsiElement) {
        final StubElement stub = ((StubBasedPsiElement) element).getStub();
        if (stub != null) {
            StubElement parentStub = stub.getParentStub();
            while (parentStub != null) {
                final PsiElement parent = parentStub.getPsi();
                if (parent instanceof ScopeOwner) {
                    return (ScopeOwner) parent;
                }
                parentStub = parentStub.getParentStub();
            }
            return null;
        }
    }
    return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result.create(calculateScopeOwnerByAST(element), PsiModificationTracker.MODIFICATION_COUNT));
}
Also used : ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) StubElement(com.intellij.psi.stubs.StubElement) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with StubElement

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

the class PyFileImpl method getDunderAll.

@Override
public List<String> getDunderAll() {
    final StubElement stubElement = getStub();
    if (stubElement instanceof PyFileStub) {
        return ((PyFileStub) stubElement).getDunderAll();
    }
    if (!myDunderAllCalculated) {
        final List<String> dunderAll = calculateDunderAll();
        myDunderAll = dunderAll == null ? null : Collections.unmodifiableList(dunderAll);
        myDunderAllCalculated = true;
    }
    return myDunderAll;
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) PyFileStub(com.jetbrains.python.psi.stubs.PyFileStub)

Aggregations

StubElement (com.intellij.psi.stubs.StubElement)38 Nullable (org.jetbrains.annotations.Nullable)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)7 StubBasedPsiElement (com.intellij.psi.StubBasedPsiElement)4 PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)4 StubTree (com.intellij.psi.stubs.StubTree)4 StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)3 SmartList (com.intellij.util.SmartList)3 PyClassStub (com.jetbrains.python.psi.stubs.PyClassStub)3 GoFileStub (com.goide.stubs.GoFileStub)2 ASTNode (com.intellij.lang.ASTNode)2 FileASTNode (com.intellij.lang.FileASTNode)2 PsiFile (com.intellij.psi.PsiFile)2 StubBuilder (com.intellij.psi.StubBuilder)2 PsiMethodStub (com.intellij.psi.impl.java.stubs.PsiMethodStub)2 IElementType (com.intellij.psi.tree.IElementType)2