public void doTest() throws Exception { final List<String> data = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test"); String fileText = data.get(0); PsiFile psiFile = TestUtils.createPseudoPhysicalGroovyFile(getProject(), fileText); ASTNode node = psiFile.getNode(); Assert.assertNotNull(node); IElementType type = node.getElementType(); Assert.assertTrue(type instanceof IStubFileElementType); IStubFileElementType stubFileType = (IStubFileElementType) type; StubBuilder builder = stubFileType.getBuilder(); StubElement element = builder.buildStubTree(psiFile); StringBuffer buffer = new StringBuffer(); getStubsTreeImpl(element, buffer, ""); String stubTree = buffer.toString().trim(); assertEquals(data.get(1), stubTree); }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { if(file instanceof CSharpFileImpl) { return new CSharpFileStub((CSharpFileImpl) file); } return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { if(file instanceof MsilFile) { return new MsilFileStub((MsilFile) file); } return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { if(file instanceof JSFile) { return new JSFileStubImpl((JSFile) file, file.getName()); } return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { if (file instanceof RmlFile) { return new RmlFileStub((RmlFile) file); } return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @Override protected StubElement createStubForFile(@NotNull PsiFile file) { return new FileStub((SoyFile) file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { return new FusionFileStub((FusionFile) file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @Override protected StubElement createStubForFile(@NotNull PsiFile file) { return new FileStub((ProtoPsiFileRoot) file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull final PsiFile file) { if (file instanceof GroovyFile) { return new GrFileStub((GroovyFile)file); } return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { if (file instanceof SchemaFile) { SchemaFile schemaFile = (SchemaFile) file; Qn namespace = NamespaceManager.getNamespace(schemaFile); return new SchemaFileStubImpl(schemaFile, StringRef.fromNullableString(namespace == null ? null : namespace.toString())); } else return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new DefaultStubBuilder() { @NotNull @Override protected StubElement createStubForFile(@NotNull PsiFile file) { if (file instanceof HaskellFile) { return new HaskellFileStub((HaskellFile)file); } return super.createStubForFile(file); } }; }
@SuppressWarnings("deprecation") public static boolean skipNode(@NotNull StubBuilder builder, @NotNull ASTNode parent, @NotNull ASTNode node) { if (builder instanceof DefaultStubBuilder) { return ((DefaultStubBuilder)builder).skipChildProcessingWhenBuildingStubs(parent, node); } else if (builder instanceof LightStubBuilder) { return ((LightStubBuilder)builder).skipChildProcessingWhenBuildingStubs(parent, node); } else { return builder.skipChildProcessingWhenBuildingStubs(parent, node.getElementType()); } }
public StubBuilder getBuilder() { return new DefaultStubBuilder() { protected StubElement createStubForFile(@NotNull final PsiFile file) { if (file instanceof GroovyFile) { return new GrFileStub((GroovyFile)file); } return super.createStubForFile(file); } }; }
@Override public StubBuilder getBuilder() { return new LuaFileStubBuilder(); }
public StubBuilder getBuilder() { return new DefaultStubBuilder(); }
@Nullable public static Stub buildStubTree(final FileContent inputData) { Stub data = inputData.getUserData(stubElementKey); if (data != null) return data; //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (inputData) { data = inputData.getUserData(stubElementKey); if (data != null) return data; final FileType fileType = inputData.getFileType(); final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); if (builder != null) { data = builder.buildStubTree(inputData); if (data instanceof PsiFileStubImpl && !((PsiFileStubImpl)data).rootsAreSet()) { ((PsiFileStubImpl)data).setStubRoots(new PsiFileStub[]{(PsiFileStubImpl)data}); } } else { CharSequence contentAsText = inputData.getContentAsText(); FileContentImpl fileContent = (FileContentImpl)inputData; PsiFile psi = fileContent.getPsiFileForPsiDependentIndex(); final FileViewProvider viewProvider = psi.getViewProvider(); psi = viewProvider.getStubBindingRoot(); psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText); // if we load AST, it should be easily gc-able. See PsiFileImpl.createTreeElementPointer() psi.getManager().startBatchFilesProcessingMode(); try { IStubFileElementType stubFileElementType = ((PsiFileImpl)psi).getElementTypeForStubBuilder(); if (stubFileElementType != null) { final StubBuilder stubBuilder = stubFileElementType.getBuilder(); if (stubBuilder instanceof LightStubBuilder) { LightStubBuilder.FORCED_AST.set(fileContent.getLighterASTForPsiDependentIndex()); } data = stubBuilder.buildStubTree(psi); final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = getStubbedRoots(viewProvider); final List<PsiFileStub> stubs = new ArrayList<PsiFileStub>(stubbedRoots.size()); stubs.add((PsiFileStub)data); for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) { final PsiFile secondaryPsi = stubbedRoot.second; if (psi == secondaryPsi) continue; final StubBuilder stubbedRootBuilder = stubbedRoot.first.getBuilder(); if (stubbedRootBuilder instanceof LightStubBuilder) { LightStubBuilder.FORCED_AST.set(new TreeBackedLighterAST(secondaryPsi.getNode())); } final StubElement element = stubbedRootBuilder.buildStubTree(secondaryPsi); if (element instanceof PsiFileStub) { stubs.add((PsiFileStub)element); } } final PsiFileStub[] stubsArray = stubs.toArray(new PsiFileStub[stubs.size()]); for (PsiFileStub stub : stubsArray) { if (stub instanceof PsiFileStubImpl) { ((PsiFileStubImpl)stub).setStubRoots(stubsArray); } } } } finally { psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null); psi.getManager().finishBatchFilesProcessingMode(); } } inputData.putUserData(stubElementKey, data); return data; } }
@Override public StubBuilder getBuilder() { return new PyFileStubBuilder(); }
@Nullable @RequiredReadAction public static Stub buildStubTree(final FileContent inputData) { Stub data = inputData.getUserData(stubElementKey); if (data != null) return data; //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (inputData) { data = inputData.getUserData(stubElementKey); if (data != null) return data; final FileType fileType = inputData.getFileType(); final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); if (builder != null) { data = builder.buildStubTree(inputData); if (data instanceof PsiFileStubImpl && !((PsiFileStubImpl)data).rootsAreSet()) { ((PsiFileStubImpl)data).setStubRoots(new PsiFileStub[]{(PsiFileStubImpl)data}); } } else { CharSequence contentAsText = inputData.getContentAsText(); FileContentImpl fileContent = (FileContentImpl)inputData; PsiFile psi = fileContent.getPsiFileForPsiDependentIndex(); final FileViewProvider viewProvider = psi.getViewProvider(); psi = viewProvider.getStubBindingRoot(); psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText); // if we load AST, it should be easily gc-able. See PsiFileImpl.createTreeElementPointer() psi.getManager().startBatchFilesProcessingMode(); try { IStubFileElementType stubFileElementType = ((PsiFileImpl)psi).getElementTypeForStubBuilder(); if (stubFileElementType != null) { final StubBuilder stubBuilder = stubFileElementType.getBuilder(); if (stubBuilder instanceof LightStubBuilder) { LightStubBuilder.FORCED_AST.set(fileContent.getLighterASTForPsiDependentIndex()); } data = stubBuilder.buildStubTree(psi); final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = getStubbedRoots(viewProvider); final List<PsiFileStub> stubs = new ArrayList<PsiFileStub>(stubbedRoots.size()); stubs.add((PsiFileStub)data); for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) { final PsiFile secondaryPsi = stubbedRoot.second; if (psi == secondaryPsi) continue; final StubBuilder stubbedRootBuilder = stubbedRoot.first.getBuilder(); if (stubbedRootBuilder instanceof LightStubBuilder) { LightStubBuilder.FORCED_AST.set(new TreeBackedLighterAST(secondaryPsi.getNode())); } final StubElement element = stubbedRootBuilder.buildStubTree(secondaryPsi); if (element instanceof PsiFileStub) { stubs.add((PsiFileStub)element); } } final PsiFileStub[] stubsArray = stubs.toArray(new PsiFileStub[stubs.size()]); for (PsiFileStub stub : stubsArray) { if (stub instanceof PsiFileStubImpl) { ((PsiFileStubImpl)stub).setStubRoots(stubsArray); } } } } finally { psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null); psi.getManager().finishBatchFilesProcessingMode(); } } inputData.putUserData(stubElementKey, data); return data; } }