Java 类com.intellij.psi.StubBuilder 实例源码

项目:intellij-ce-playground    文件:StubsTest.java   
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);
}
项目:tools-idea    文件:StubsTest.java   
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);
}
项目:consulo-csharp    文件:CSharpFileStubElementType.java   
@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);
        }
    };
}
项目:consulo-dotnet    文件:MsilFileStubElementType.java   
@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);
        }
    };
}
项目:consulo-javascript    文件:JSFileElementType.java   
@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);
        }
    };
}
项目:reasonml-idea-plugin    文件:RmlFileStubElementType.java   
@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);
        }
    };
}
项目:bamboo-soy    文件:FileStub.java   
@Override
public StubBuilder getBuilder() {
  return new DefaultStubBuilder() {
    @Override
    protected StubElement createStubForFile(@NotNull PsiFile file) {
      return new FileStub((SoyFile) file);
    }
  };
}
项目:intellij-neos    文件:FusionFileStub.java   
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            return new FusionFileStub((FusionFile) file);
        }
    };
}
项目:protobuf-jetbrains-plugin    文件:FileStub.java   
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            return new FileStub((ProtoPsiFileRoot) file);
        }
    };
}
项目:intellij-ce-playground    文件:GrStubFileElementType.java   
@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);
    }
  };
}
项目:epigraph    文件:SchemaFileElementType.java   
@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);
    }
  };
}
项目:intellij-haskforce    文件:HaskellFileStubElementType.java   
@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);
        }
    };
}
项目:tools-idea    文件:TreeUtil.java   
@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());
  }
}
项目:tools-idea    文件:GrStubFileElementType.java   
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);
    }
  };
}
项目:lua-for-idea    文件:LuaStubFileElementType.java   
@Override
public StubBuilder getBuilder() {
    return new LuaFileStubBuilder();
}
项目:intellij-ce-playground    文件:IStubFileElementType.java   
public StubBuilder getBuilder() {
  return new DefaultStubBuilder();
}
项目:intellij-ce-playground    文件:StubTreeBuilder.java   
@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;
  }
}
项目:intellij-ce-playground    文件:PyFileElementType.java   
@Override
public StubBuilder getBuilder() {
  return new PyFileStubBuilder();
}
项目:tools-idea    文件:IStubFileElementType.java   
public StubBuilder getBuilder() {
  return new DefaultStubBuilder();
}
项目:consulo-lua    文件:LuaStubFileElementType.java   
@Override
public StubBuilder getBuilder() {
    return new LuaFileStubBuilder();
}
项目:consulo    文件:IStubFileElementType.java   
public StubBuilder getBuilder() {
  return new DefaultStubBuilder();
}
项目:consulo    文件:StubTreeBuilder.java   
@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;
  }
}