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);
}
}
}
}
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);
}
}
}
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);
}
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));
}
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;
}
Aggregations