Stub (Project project, PsiElement rootElement, @NotNull String textToParse) { Stub stub = null; PsiFileWithStubSupport psiFile = (PsiFileWithStubSupport)rootElement; StubTree tree = psiFile.getStubTree(); if (tree != null) { stub = tree.getRoot(); } else if (rootElement instanceof PsiFileImpl) { StubBuilder stubBuilder = getStubBuilder((PsiFileImpl)rootElement); stub = stubBuilder == null ? null : stubBuilder.buildStubTree((PsiFile)rootElement); } if (stub == null) { LightVirtualFile file = new LightVirtualFile("stub", rootElement.getLanguage(), textToParse); final FileContent fc; try { fc = FileContentImpl.createByFile(file, project); fc.putUserData(IndexingDataKeys.PSI_FILE, psiFile); stub = StubTreeBuilder.buildStubTree(fc); } catch (IOException e) { LOG.warn(e.getMessage(), e); } } return stub; }