use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class JavaStubIndexer method indexFile.
@Nullable
@Override
public Unit indexFile(@NotNull FileContent content) {
Stub stubTree = StubTreeBuilder.buildStubTree(content);
if (!(stubTree instanceof PsiJavaFileStub))
return null;
PsiJavaFileStub javaFileStub = (PsiJavaFileStub) stubTree;
new StubTree(javaFileStub, false);
List<ClassDecl> classList = new ArrayList<>();
Set<String> usedNames = new HashSet<>();
for (StubElement<?> el : javaFileStub.getChildrenStubs()) {
if (el instanceof PsiClassStubImpl) {
classList.add(processClassDecl((PsiClassStubImpl<?>) el, usedNames));
}
}
List<IndexTree.Import> importList = new ArrayList<>();
for (StubElement<?> el : javaFileStub.getChildrenStubs()) {
if (el instanceof PsiImportListStub) {
processImport((PsiImportListStub) el, importList, usedNames);
}
}
ClassDecl[] classes = classList.isEmpty() ? ClassDecl.EMPTY_ARRAY : classList.toArray(new ClassDecl[classList.size()]);
IndexTree.Import[] imports = importList.isEmpty() ? IndexTree.Import.EMPTY_ARRAY : importList.toArray(new IndexTree.Import[importList.size()]);
byte type = javaFileStub.isCompiled() ? IndexTree.BYTECODE : IndexTree.JAVA;
return new Unit(javaFileStub.getPackageName(), type, imports, classes);
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class SmartPsiElementPointerImpl method createAnchorInfo.
@Nullable
private static SmartPointerElementInfo createAnchorInfo(@NotNull PsiElement element, @NotNull PsiFile containingFile) {
if (element instanceof StubBasedPsiElement && containingFile instanceof PsiFileWithStubSupport) {
PsiFileWithStubSupport stubFile = (PsiFileWithStubSupport) containingFile;
StubTree stubTree = stubFile.getStubTree();
if (stubTree != null) {
// use stubs when tree is not loaded
StubBasedPsiElement stubPsi = (StubBasedPsiElement) element;
int stubId = PsiAnchor.calcStubIndex(stubPsi);
IStubElementType myStubElementType = stubPsi.getElementType();
IStubFileElementType elementTypeForStubBuilder = ((PsiFileImpl) containingFile).getElementTypeForStubBuilder();
if (stubId != -1 && elementTypeForStubBuilder != null) {
// TemplateDataElementType is not IStubFileElementType
return new AnchorElementInfo(element, stubFile, stubId, myStubElementType);
}
}
}
Pair<Identikit.ByAnchor, PsiElement> pair = Identikit.withAnchor(element, LanguageUtil.getRootLanguage(containingFile));
if (pair != null) {
return new AnchorElementInfo(pair.second, containingFile, pair.first);
}
return null;
}
use of com.intellij.psi.stubs.StubTree in project smali by JesusFreke.
the class LightCodeInsightParsingTestCase method doTest.
protected void doTest(boolean checkResult) {
String name = getTestName(false);
try {
String text = loadFile(name + "." + myFileExt);
PsiFile f = createPsiFile(name, text);
if (f instanceof PsiFileImpl) {
// Also want to test stub serialization/deserialization
StubTree stubTree = ((PsiFileImpl) f).calcStubTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SerializationManagerImpl.getInstanceEx().serialize(stubTree.getRoot(), baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
SerializationManagerImpl.getInstanceEx().deserialize(bais);
}
ensureParsed(f);
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) f.getVirtualFile()).getContent().toString());
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(f.getVirtualFile()));
assertEquals("doc text mismatch", text, f.getViewProvider().getDocument().getText());
assertEquals("psi text mismatch", text, f.getText());
if (checkResult) {
checkResult(name, f);
} else {
toParseTreeText(f, skipSpaces(), includeRanges());
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SerializerNotFoundException e) {
throw new RuntimeException(e);
}
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class JavaCompilerElementRetriever method retrieveFunExpressionsByIndices.
@NotNull
static PsiFunctionalExpression[] retrieveFunExpressionsByIndices(@NotNull TIntHashSet indices, @NotNull PsiFileWithStubSupport psiFile) {
StubTree tree = psiFile.getStubTree();
boolean foreign = tree == null;
if (foreign) {
tree = ((PsiFileImpl) psiFile).calcStubTree();
}
PsiFunctionalExpression[] result = new PsiFunctionalExpression[indices.size()];
int resIdx = 0;
int funExprIdx = 0;
for (StubElement<?> element : tree.getPlainList()) {
if (FUN_EXPR.contains(element.getStubType()) && indices.contains(funExprIdx++)) {
result[resIdx++] = (PsiFunctionalExpression) element.getPsi();
}
}
if (result.length != resIdx) {
final CompilerReferenceServiceImpl compilerReferenceService = (CompilerReferenceServiceImpl) CompilerReferenceService.getInstance(psiFile.getProject());
final Set<Module> state = compilerReferenceService.getDirtyScopeHolder().getAllDirtyModules();
final VirtualFile file = psiFile.getVirtualFile();
final Module moduleForFile = ProjectFileIndex.getInstance(psiFile.getProject()).getModuleForFile(file);
LOG.error("Compiler functional expression index doesn't match to stub index.\n" + "Functional expression indices: " + indices + "\n" + "Does the file belong to dirty scope?: " + state.contains(moduleForFile), new Attachment(psiFile.getName(), psiFile.getText()));
return ContainerUtil.filter(result, Objects::nonNull).toArray(PsiFunctionalExpression.EMPTY_ARRAY);
}
return result;
}
use of com.intellij.psi.stubs.StubTree in project intellij-community by JetBrains.
the class JavaCompilerElementRetriever method retrieveMatchedClasses.
private static List<PsiClass> retrieveMatchedClasses(PsiFileWithStubSupport psiFile, Collection<InternalClassMatcher> matchers) {
final List<PsiClass> result = new ArrayList<>(matchers.size());
StubTree tree = psiFile.getStubTree();
boolean foreign = tree == null;
if (foreign) {
tree = ((PsiFileImpl) psiFile).calcStubTree();
}
for (StubElement<?> element : tree.getPlainList()) {
if (element instanceof PsiClassStub && match((PsiClassStub) element, matchers)) {
result.add(((StubBase<PsiClass>) element).getPsi());
}
}
return result;
}
Aggregations