@Override public StubElement buildStubTree(@NotNull PsiFile file) { LighterAST tree = FORCED_AST.get(); if (tree == null) { FileType fileType = file.getFileType(); if (!(fileType instanceof LanguageFileType)) { LOG.error("File is not of LanguageFileType: " + fileType + ", " + file); return null; } Language language = ((LanguageFileType)fileType).getLanguage(); final IFileElementType contentType = LanguageParserDefinitions.INSTANCE.forLanguage(language).getFileNodeType(); if (!(contentType instanceof IStubFileElementType)) { LOG.error("File is not of IStubFileElementType: " + contentType + ", " + file); return null; } final FileASTNode node = file.getNode(); if (contentType instanceof ILightStubFileElementType) { tree = node.getLighterAST(); } else { tree = new TreeBackedLighterAST(node); } } else { FORCED_AST.set(null); } if (tree == null) return null; final StubElement rootStub = createStubForFile(file, tree); buildStubTree(tree, tree.getRoot(), rootStub); return rootStub; }
@RequiredReadAction @Override public StubElement buildStubTree(@Nonnull PsiFile file) { LighterAST tree = FORCED_AST.get(); if (tree == null) { FileType fileType = file.getFileType(); if (!(fileType instanceof LanguageFileType)) { LOG.error("File is not of LanguageFileType: " + file + ", " + fileType); return null; } if (!(file instanceof PsiFileImpl)) { LOG.error("Unexpected PsiFile instance: " + file + ", " + file.getClass()); return null; } if (((PsiFileImpl)file).getElementTypeForStubBuilder() == null) { LOG.error("File is not of IStubFileElementType: " + file); return null; } FileASTNode node = file.getNode(); tree = node.getElementType() instanceof ILightStubFileElementType ? node.getLighterAST() : new TreeBackedLighterAST(node); } else { FORCED_AST.set(null); } StubElement rootStub = createStubForFile(file, tree); buildStubTree(tree, tree.getRoot(), rootStub); return rootStub; }
@Nonnull @Override public LighterAST getLighterAST() { IElementType contentType = getElementType(); if (!isParsed() && contentType instanceof ILightStubFileElementType) { return new FCTSBackedLighterAST(getCharTable(), ((ILightStubFileElementType<?>)contentType).parseContentsLight(this)); } return new TreeBackedLighterAST(this); }