use of com.intellij.psi.stubs.StubTree in project intellij-plugins by JetBrains.
the class FlexStyleIndex method getIndexer.
@NotNull
@Override
public DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent> getIndexer() {
return new DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent>() {
@Override
@NotNull
public Map<String, Set<FlexStyleIndexInfo>> map(@NotNull FileContent inputData) {
final THashMap<String, Set<FlexStyleIndexInfo>> map = new THashMap<>();
if (JavaScriptSupportLoader.isFlexMxmFile(inputData.getFileName())) {
PsiFile file = inputData.getPsiFile();
VirtualFile virtualFile = inputData.getFile();
if (file instanceof XmlFile) {
indexMxmlFile((XmlFile) file, virtualFile, map);
}
} else {
StubTree tree = JSPackageIndex.getStubTree(inputData);
if (tree != null) {
for (StubElement e : tree.getPlainList()) {
if (e instanceof JSClassStub) {
final PsiElement psiElement = e.getPsi();
if (psiElement instanceof JSClass) {
final String qName = ((JSClass) psiElement).getQualifiedName();
indexAttributes(psiElement, qName, true, map);
}
} else if (e instanceof PsiFileStub) {
PsiElement psiElement = e.getPsi();
if (psiElement instanceof JSFile) {
String name = ((JSFile) psiElement).getName();
indexAttributes(psiElement, name, false, map);
}
}
}
}
}
return map;
}
};
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class GrStubIndexer method indexFile.
@Nullable
@Override
public Unit indexFile(@NotNull FileContent content) {
if (!isNormalGroovyFile(((FileContentImpl) content).getPsiFileForPsiDependentIndex()))
return null;
Stub stubTree = StubTreeBuilder.buildStubTree(content);
if (!(stubTree instanceof GrFileStub))
return null;
GrFileStub grFileStub = (GrFileStub) stubTree;
new StubTree(grFileStub, false);
String pid = "";
ArrayList<ClassDecl> classList = new ArrayList<>();
Set<String> usedNames = new HashSet<>();
for (StubElement<?> el : grFileStub.getChildrenStubs()) {
if (el instanceof GrPackageDefinitionStub) {
GrPackageDefinitionStub packageStub = (GrPackageDefinitionStub) el;
String pkgName = packageStub.getPackageName();
if (pkgName != null) {
pid = id(pkgName, false, null);
}
}
if (el instanceof GrTypeDefinitionStub) {
ClassDecl classDecl = processClassDecl((GrTypeDefinitionStub) el, usedNames, false);
if (classDecl != null) {
classList.add(classDecl);
}
}
}
ArrayList<Import> importList = new ArrayList<>();
for (StubElement<?> el : grFileStub.getChildrenStubs()) {
if (el instanceof GrImportStatementStub) {
processImport((GrImportStatementStub) el, importList, usedNames);
}
}
ClassDecl[] classes = classList.isEmpty() ? ClassDecl.EMPTY_ARRAY : classList.toArray(new ClassDecl[classList.size()]);
Import[] imports = importList.isEmpty() ? Import.EMPTY_ARRAY : importList.toArray(new Import[importList.size()]);
return new Unit(pid, IndexTree.GROOVY, imports, classes);
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class AnchorRepository method restoreFromStubIndex.
private static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl, int index) {
StubTree tree = fileImpl.getStubTree();
if (tree == null) {
if (fileImpl instanceof PsiFileImpl) {
tree = ((PsiFileImpl) fileImpl).calcStubTree();
} else {
return null;
}
}
List<StubElement<?>> list = tree.getPlainList();
if (index >= list.size()) {
return null;
}
return ((StubElement) list.get(index)).getPsi();
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method assertTreeLoaded.
private static void assertTreeLoaded(PsiFileImpl file, boolean loaded) {
FileElement treeElement = file.getTreeElement();
assertEquals(loaded, treeElement != null);
StubTree stubTree = file.getStubTree();
assertEquals(loaded, stubTree == null);
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method testNonAnchoredStubbedElement.
public void testNonAnchoredStubbedElement() {
PsiFile file = configureByText(JavaFileType.INSTANCE, "class Foo { { @NotNull String foo; } }");
StubTree stubTree = ((PsiFileImpl) file).getStubTree();
assertNotNull(stubTree);
PsiElement anno = stubTree.getPlainList().stream().map(StubElement::getPsi).filter(psiElement -> psiElement instanceof PsiAnnotation).findFirst().get();
SmartPsiElementPointer<PsiElement> pointer = createPointer(anno);
assertNotNull(((PsiFileImpl) file).getStubTree());
stubTree = null;
anno = null;
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertNull(((SmartPointerEx) pointer).getCachedElement());
insertString(file.getViewProvider().getDocument(), 0, " ");
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
assertNotNull(pointer.getElement());
}
Aggregations