public @NotNull LighterAST getLighterASTForPsiDependentIndex() { LighterAST lighterAST = getUserData(IndexingDataKeys.LIGHTER_AST_NODE_KEY); if (lighterAST == null) { FileASTNode node = getPsiFileForPsiDependentIndex().getNode(); lighterAST = myLighterASTShouldBeThreadSafe ? new TreeBackedLighterAST(node) : node.getLighterAST(); putUserData(IndexingDataKeys.LIGHTER_AST_NODE_KEY, lighterAST); } return lighterAST; }
public static void cacheSingleFile(Project project, VirtualFile openFile) { if (openFile.exists()) { // cache attributes PsiManager psiManager = PsiManager.getInstance(project); if (psiManager == null) return; PsiFile psiFile = psiManager.findFile(openFile); if (psiFile == null) return; FileASTNode astNode = psiFile.getNode(); if (astNode == null) return; HashSet<String> rs = findAllVariables(astNode.getChildren(null), PerlTypes.VARIABLE, false); if (rs == null) return; for (String str : rs) { addCachedVariables(null, str); } // cache subs ArrayList<Package> packages = ModulesContainer.getPackageListFromFile(openFile.getPath()); for (int i = 0; i < packages.size(); i++) { ArrayList<Sub> subs = packages.get(i).getAllSubs(); for (int j = 0; j < subs.size(); j++) { addCachedSub(null, subs.get(j)); } } } }
private static void doTest(@NonNls final String source, @NonNls @Nullable final String tree) { final PsiJavaFile file = (PsiJavaFile) createLightFile("test.java", source); final FileASTNode fileNode = file.getNode(); assertNotNull(fileNode); assertFalse(fileNode.isParsed()); long t1 = System.nanoTime(); final StubElement lighterTree = NEW_BUILDER.buildStubTree(file); t1 = Math.max((System.nanoTime() - t1) / 1000, 1); assertFalse(fileNode.isParsed()); file.getNode().getChildren(null); // force switch to AST long t2 = System.nanoTime(); final StubElement lighterTree2 = NEW_BUILDER.buildStubTree(file); // build over AST t2 = Math.max((System.nanoTime() - t2) / 1000, 1); file.accept( new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { assert !(element instanceof PsiErrorElement) : element; super.visitElement(element); } }); final String lightStr = DebugUtil.stubTreeToString(lighterTree); final String lightStr2 = DebugUtil.stubTreeToString(lighterTree2); if (tree != null) { System.out.println("light=" + t1 + "mks, heavy=" + t2 + "mks"); if (!tree.isEmpty()) { assertEquals("light tree differs", tree, lightStr); assertEquals("light tree (2nd) differs", tree, lightStr2); } } }