Java 类com.intellij.psi.stubs.BinaryFileStubBuilder 实例源码

项目:buck    文件:BuckFileUtil.java   
public static void setBuckFileType() {
  ApplicationManager.getApplication()
      .runWriteAction(
          new Runnable() {
            @Override
            public void run() {
              FileTypeManager fileTypeManager = FileTypeManagerImpl.getInstance();

              FileType fileType =
                  fileTypeManager.getFileTypeByFileName(
                      BuckFileType.INSTANCE.getDefaultExtension());

              // Remove all FileType associations for BUCK files that are not BuckFileType
              while (!(fileType instanceof BuckFileType || fileType instanceof UnknownFileType)) {
                List<FileNameMatcher> fileNameMatchers =
                    fileTypeManager.getAssociations(fileType);

                for (FileNameMatcher fileNameMatcher : fileNameMatchers) {
                  if (fileNameMatcher.accept(BuckFileType.INSTANCE.getDefaultExtension())) {
                    fileTypeManager.removeAssociation(fileType, fileNameMatcher);
                  }
                }

                fileType =
                    fileTypeManager.getFileTypeByFileName(
                        BuckFileType.INSTANCE.getDefaultExtension());
              }

              // Use a simple BinaryFileStubBuilder, that doesn't offer stubbing
              BinaryFileStubBuilders.INSTANCE.addExplicitExtension(
                  fileType,
                  new BinaryFileStubBuilder() {
                    @Override
                    public boolean acceptsFile(VirtualFile virtualFile) {
                      return false;
                    }

                    @Nullable
                    @Override
                    public Stub buildStubTree(FileContent fileContent) {
                      return null;
                    }

                    @Override
                    public int getStubVersion() {
                      return 0;
                    }
                  });
            }
          });
}