consulo.application.AccessRule Java Examples

The following examples show how to use consulo.application.AccessRule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArtifactCompilerUtil.java    From consulo with Apache License 2.0 8 votes vote down vote up
public static MultiMap<String, Artifact> createOutputToArtifactMap(final Project project) {
  final MultiMap<String, Artifact> result = new MultiMap<String, Artifact>() {
    @Nonnull
    @Override
    protected Map<String, Collection<Artifact>> createMap() {
      return new THashMap<String, Collection<Artifact>>(FileUtil.PATH_HASHING_STRATEGY);
    }
  };
  AccessRule.read(() -> {
    for (Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) {
      String outputPath = artifact.getOutputFilePath();
      if (!StringUtil.isEmpty(outputPath)) {
        result.putValue(outputPath, artifact);
      }
    }
  });
  return result;
}
 
Example #2
Source File: ModuleManagerComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void loadModules(@Nonnull ProgressIndicator indicator, AsyncResult<Void> result) {
  StatCollector stat = new StatCollector();

  stat.markWith("load modules", () -> loadModules(myModuleModel, indicator, true));

  indicator.setIndeterminate(true);

  AccessRule.writeAsync(() -> {
    stat.markWith("fire modules add", () -> {
      for (Module module : myModuleModel.myModules) {
        fireModuleAdded(module);
      }
    });

    stat.dump("ModulesManager", LOG::info);
  }).doWhenDone((Runnable)result::setDone);
}
 
Example #3
Source File: TreeStructureWrappenModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchChildren(@Nonnull Function<T, TreeNode<T>> nodeFactory, @Nullable T parentValue) {
  ThrowableComputable<Object[],RuntimeException> action = () -> myStructure.getChildElements(parentValue);
  for (Object o : AccessRule.read(action)) {
    T element = (T)o;
    TreeNode<T> apply = nodeFactory.apply(element);

    apply.setLeaf(o instanceof AbstractTreeNode && !((AbstractTreeNode)o).isAlwaysShowPlus());


    apply.setRender((fileElement, itemPresentation) -> {
      NodeDescriptor descriptor = myStructure.createDescriptor(element, null);

      descriptor.update();

      itemPresentation.append(descriptor.toString());
      try {
        AccessRule.read(() -> itemPresentation.setIcon(descriptor.getIcon()));
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    });
  }
}
 
Example #4
Source File: ExtractMethodHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Finds duplicates of the code fragment specified in the finder in given scopes.
 * Note that in contrast to {@link #processDuplicates} the search is performed synchronously because normally you need the results in
 * order to complete the refactoring. If user cancels it, empty list will be returned.
 *
 * @param finder          finder object to seek for duplicates
 * @param searchScopes    scopes where to look them in
 * @param generatedMethod new method that should be excluded from the search
 * @return list of discovered duplicate code fragments or empty list if user interrupted the search
 * @see #replaceDuplicates(PsiElement, Editor, Consumer, List)
 */
@Nonnull
public static List<SimpleMatch> collectDuplicates(@Nonnull SimpleDuplicatesFinder finder,
                                                  @Nonnull List<PsiElement> searchScopes,
                                                  @Nonnull PsiElement generatedMethod) {
  final Project project = generatedMethod.getProject();
  try {
    //noinspection RedundantCast
    return ProgressManager.getInstance().runProcessWithProgressSynchronously(
            (ThrowableComputable<List<SimpleMatch>, RuntimeException>)() -> {
              ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
              ThrowableComputable<List<SimpleMatch>, RuntimeException> action = () -> finder.findDuplicates(searchScopes, generatedMethod);
              return AccessRule.read(action);
            }, RefactoringBundle.message("searching.for.duplicates"), true, project);
  }
  catch (ProcessCanceledException e) {
    return Collections.emptyList();
  }
}
 
Example #5
Source File: NavBarPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("MethodMayBeStatic")
@Nullable
public Icon getIcon(final Object object) {
  if (!NavBarModel.isValid(object)) return null;
  if (object instanceof Project) return AllIcons.Nodes.ProjectTab;
  if (object instanceof Module) return AllIcons.Nodes.Module;
  try {
    if (object instanceof PsiElement) {
      Icon icon = TargetAWT.to(AccessRule.read(() -> ((PsiElement)object).isValid() ? IconDescriptorUpdaters.getIcon(((PsiElement)object), 0) : null));

      if (icon != null && (icon.getIconHeight() > JBUI.scale(16) || icon.getIconWidth() > JBUI.scale(16))) {
        icon = IconUtil.cropIcon(icon, JBUI.scale(16), JBUI.scale(16));
      }
      return icon;
    }
  }
  catch (IndexNotReadyException e) {
    return null;
  }
  if (object instanceof ModuleExtensionWithSdkOrderEntry) {
    return TargetAWT.to(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)object).getSdk()));
  }
  if (object instanceof LibraryOrderEntry) return AllIcons.Nodes.PpLibFolder;
  if (object instanceof ModuleOrderEntry) return AllIcons.Nodes.Module;
  return null;
}
 
Example #6
Source File: ProjectStructureDaemonAnalyzer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void doCollectUsages(final ProjectStructureElement element) {
  ThrowableComputable<List<ProjectStructureElementUsage>,RuntimeException> action = () -> {
    if (myStopped.get()) return null;

    if (LOG.isDebugEnabled()) {
      LOG.debug("collecting usages in " + element);
    }
    return getUsagesInElement(element);
  };
  final List<ProjectStructureElementUsage> usages = AccessRule.read(action);

  invokeLater(new Runnable() {
    @Override
    public void run() {
      if (myStopped.get() || usages == null) return;

      if (LOG.isDebugEnabled()) {
        LOG.debug("updating usages for " + element);
      }
      updateUsages(element, usages);
    }
  });
}
 
Example #7
Source File: ProjectStructureDaemonAnalyzer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void doCheck(final ProjectStructureElement element) {
  final ProjectStructureProblemsHolderImpl problemsHolder = new ProjectStructureProblemsHolderImpl();
  AccessRule.read(() -> {
    if (myStopped.get()) return;

    if (LOG.isDebugEnabled()) {
      LOG.debug("checking " + element);
    }
    ProjectStructureValidator.check(element, problemsHolder);
  });

  invokeLater(new Runnable() {
    @Override
    public void run() {
      if (myStopped.get()) return;

      if (LOG.isDebugEnabled()) {
        LOG.debug("updating problems for " + element);
      }
      final ProjectStructureProblemDescription warning = myWarningsAboutUnused.get(element);
      if (warning != null) problemsHolder.registerProblem(warning);
      myProblemHolders.put(element, problemsHolder);
      myDispatcher.getMulticaster().problemsChanged(element);
    }
  });
}
 
Example #8
Source File: FormatChangedTextUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Allows to answer if any file that belongs to the given project has changes in comparison with VCS.
 *
 * @param project target project to check
 * @return <code>true</code> if any file that belongs to the given project has changes in comparison with VCS
 * <code>false</code> otherwise
 */
public static boolean hasChanges(@Nonnull final Project project) {
  ThrowableComputable<ModifiableModuleModel,RuntimeException> action = () -> ModuleManager.getInstance(project).getModifiableModel();
  final ModifiableModuleModel moduleModel = AccessRule.read(action);

  try {
    for (Module module : moduleModel.getModules()) {
      if (hasChanges(module)) {
        return true;
      }
    }
    return false;
  }
  finally {
    moduleModel.dispose();
  }
}
 
Example #9
Source File: ShowImplementationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
static PsiElement[] getSelfAndImplementations(Editor editor, @Nonnull PsiElement element, @Nonnull ImplementationSearcher handler, final boolean includeSelfAlways) {
  final PsiElement[] handlerImplementations = handler.searchImplementations(element, editor, includeSelfAlways, true);
  if (handlerImplementations.length > 0) return handlerImplementations;

  ThrowableComputable<PsiElement[], RuntimeException> action = () -> {
    PsiElement psiElement = element;
    PsiFile psiFile = psiElement.getContainingFile();
    if (psiFile == null) {
      // Magically, it's null for ant property declarations.
      psiElement = psiElement.getNavigationElement();
      psiFile = psiElement.getContainingFile();
      if (psiFile == null) {
        return PsiElement.EMPTY_ARRAY;
      }
    }
    if (psiFile.getVirtualFile() != null && (psiElement.getTextRange() != null || psiElement instanceof PsiFile)) {
      return new PsiElement[]{psiElement};
    }
    return PsiElement.EMPTY_ARRAY;
  };
  return AccessRule.read(action);
}
 
Example #10
Source File: LazyPatchContentRevision.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String getContent() {
  if (myContent == null) {
    String localContext = AccessRule.read(() -> {
      final Document doc = FileDocumentManager.getInstance().getDocument(myVf);
      if(doc == null) {
        return null;
      }

      return doc.getText();
    });

    if (localContext == null) {
      myPatchApplyFailed = true;
      return null;
    }

    final GenericPatchApplier applier = new GenericPatchApplier(localContext, myPatch.getHunks());
    if (applier.execute()) {
      myContent = applier.getAfter();
    } else {
      myPatchApplyFailed = true;
    }
  }
  return myContent;
}
 
Example #11
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private <B extends XBreakpoint<?>> void handleBreakpoint(final XBreakpointHandler<B> handler, final B b, final boolean register,
                                                         final boolean temporary) {
  if (register) {
    ThrowableComputable<Boolean,RuntimeException> action = () -> isBreakpointActive(b);
    boolean active = AccessRule.read(action);
    if (active) {
      synchronized (myRegisteredBreakpoints) {
        myRegisteredBreakpoints.put(b, new CustomizedBreakpointPresentation());
      }
      handler.registerBreakpoint(b);
    }
  }
  else {
    boolean removed;
    synchronized (myRegisteredBreakpoints) {
      removed = myRegisteredBreakpoints.remove(b) != null;
    }
    if (removed) {
      handler.unregisterBreakpoint(b, temporary);
    }
  }
}
 
Example #12
Source File: ChangesUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private static VirtualFile getValidParentUnderReadAction(@Nonnull FilePath filePath) {
  ThrowableComputable<VirtualFile,RuntimeException> action = () -> {
    VirtualFile result = null;
    FilePath parent = filePath;
    LocalFileSystem lfs = LocalFileSystem.getInstance();

    while (result == null && parent != null) {
      result = lfs.findFileByPath(parent.getPath());
      parent = parent.getParentPath();
    }

    return result;
  };
  return AccessRule.read(action);
}
 
Example #13
Source File: ChangesUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static FilePath getLocalPath(@Nonnull Project project, FilePath filePath) {
  // check if the file has just been renamed (IDEADEV-15494)
  ThrowableComputable<Change, RuntimeException> action = () -> {
    if (project.isDisposed()) throw new ProcessCanceledException();
    return ChangeListManager.getInstance(project).getChange(filePath);
  };
  Change change = AccessRule.read(action);
  if (change != null) {
    ContentRevision beforeRevision = change.getBeforeRevision();
    ContentRevision afterRevision = change.getAfterRevision();
    if (beforeRevision != null && afterRevision != null && !beforeRevision.getFile().equals(afterRevision.getFile()) &&
        beforeRevision.getFile().equals(filePath)) {
      return afterRevision.getFile();
    }
  }
  return filePath;
}
 
Example #14
Source File: CompilerConfigurationImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void loadState(Element element) {
  String url = element.getAttributeValue(URL);
  if (url != null) {
    setCompilerOutputUrl(url);
  }

  for (Element moduleElement : element.getChildren("module")) {
    String name = moduleElement.getAttributeValue("name");
    if (name == null) {
      continue;
    }
    Module module = AccessRule.read(() -> myModuleManager.findModuleByName(name));
    if (module != null) {
      ModuleCompilerPathsManagerImpl moduleCompilerPathsManager = (ModuleCompilerPathsManagerImpl)ModuleCompilerPathsManager.getInstance(module);
      moduleCompilerPathsManager.loadState(moduleElement);
    }
  }
}
 
Example #15
Source File: DiffContentFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Document createPsiDocument(@Nonnull Project project,
                                          @Nonnull String content,
                                          @Nonnull FileType fileType,
                                          @Nonnull String fileName,
                                          boolean readOnly) {
  ThrowableComputable<Document,RuntimeException> action = () -> {
    LightVirtualFile file = new LightVirtualFile(fileName, fileType, content);
    file.setWritable(!readOnly);

    file.putUserData(DiffPsiFileSupport.KEY, true);

    Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document == null) return null;

    PsiDocumentManager.getInstance(project).getPsiFile(document);

    return document;
  };
  return AccessRule.read(action);
}
 
Example #16
Source File: ProjectFileIndexImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Set<VirtualFile> getRootsToIterate(final Module module) {
  return AccessRule.read(() -> {
    if (module.isDisposed()) return Collections.emptySet();

    Set<VirtualFile> result = new LinkedHashSet<>();
    for (VirtualFile[] roots : getModuleContentAndSourceRoots(module)) {
      for (VirtualFile root : roots) {
        DirectoryInfo info = getInfoForFileOrDirectory(root);
        if (!info.isInProject(root)) continue; // is excluded or ignored
        if (!module.equals(info.getModule())) continue; // maybe 2 modules have the same content root?

        VirtualFile parent = root.getParent();
        if (parent != null) {
          DirectoryInfo parentInfo = getInfoForFileOrDirectory(parent);
          if (isFileInContent(parent, parentInfo)) continue;
        }
        result.add(root);
      }
    }

    return result;
  });
}
 
Example #17
Source File: ModuleFileIndexImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean iterateContent(@Nonnull ContentIterator processor, @Nullable VirtualFileFilter filter) {
  final Set<VirtualFile> contentRoots = AccessRule.read(() -> {
    if (myModule.isDisposed()) return Collections.emptySet();

    Set<VirtualFile> result = new LinkedHashSet<>();
    VirtualFile[][] allRoots = getModuleContentAndSourceRoots(myModule);
    for (VirtualFile[] roots : allRoots) {
      for (VirtualFile root : roots) {
        DirectoryInfo info = getInfoForFileOrDirectory(root);
        if (!info.isInProject(root)) continue;

        VirtualFile parent = root.getParent();
        if (parent != null) {
          DirectoryInfo parentInfo = myDirectoryIndex.getInfoForFile(parent);
          if (parentInfo.isInProject(parent) && myModule.equals(parentInfo.getModule())) continue; // inner content - skip it
        }
        result.add(root);
      }
    }

    return result;
  });
  for (VirtualFile contentRoot : contentRoots) {
    if (!iterateContentUnderDirectory(contentRoot, processor, filter)) {
      return false;
    }
  }
  return true;
}
 
Example #18
Source File: AbstractRepositoryManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private T validateAndGetRepository(@javax.annotation.Nullable Repository repository) {
  if (repository == null || !myVcs.equals(repository.getVcs())) return null;
  ThrowableComputable<T,RuntimeException> action = () -> {
    VirtualFile root = repository.getRoot();
    if (root.isValid()) {
      VirtualFile vcsDir = root.findChild(myRepoDirName);
      //noinspection unchecked
      return vcsDir != null && vcsDir.exists() ? (T)repository : null;
    }
    return null;
  };
  return AccessRule.read(action);
}
 
Example #19
Source File: UsageInfo2UsageAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public UsageInfo2UsageAdapter(@Nonnull final UsageInfo usageInfo) {
  myUsageInfo = usageInfo;
  myMergedUsageInfos = usageInfo;

  ThrowableComputable<Point, RuntimeException> action = () -> {
    PsiElement element = getElement();
    PsiFile psiFile = usageInfo.getFile();
    Document document = psiFile == null ? null : PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);

    int offset;
    int lineNumber;
    if (document == null) {
      // element over light virtual file
      offset = element == null ? 0 : element.getTextOffset();
      lineNumber = -1;
    }
    else {
      int startOffset = myUsageInfo.getNavigationOffset();
      if (startOffset == -1) {
        offset = element == null ? 0 : element.getTextOffset();
        lineNumber = -1;
      }
      else {
        offset = -1;
        lineNumber = getLineNumber(document, startOffset);
      }
    }
    return new Point(offset, lineNumber);
  };
  Point data = AccessRule.read(action);
  myOffset = data.x;
  myLineNumber = data.y;
  myModificationStamp = getCurrentModificationStamp();
}
 
Example #20
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void enableBreakpoints() {
  if (myBreakpointsDisabled) {
    myBreakpointsDisabled = false;
    AccessRule.read(() -> {
      processAllBreakpoints(true, false);
    });
  }
}
 
Example #21
Source File: ModuleDefaultVcsRootPolicy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Collection<VirtualFile> getContentRoots() {
  Module[] modules = AccessRule.read(myModuleManager::getModules);
  return Arrays.stream(modules)
          .map(module -> ModuleRootManager.getInstance(module).getContentRoots())
          .flatMap(Arrays::stream)
          .collect(Collectors.toSet());
}
 
Example #22
Source File: ProjectLevelVcsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public AbstractVcs getVcsFor(final FilePath file) {
  final VirtualFile vFile = ChangesUtil.findValidParentAccurately(file);
  ThrowableComputable<AbstractVcs, RuntimeException> action = () -> {
    if (!ApplicationManager.getApplication().isUnitTestMode() && !myProject.isInitialized()) return null;
    if (myProject.isDisposed()) throw new ProcessCanceledException();
    if (vFile != null) {
      return getVcsFor(vFile);
    }
    return null;
  };
  return AccessRule.read(action);
}
 
Example #23
Source File: ProjectLevelVcsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isFileInContent(@Nullable final VirtualFile vf) {
  ThrowableComputable<Boolean,RuntimeException> action = () ->
                                    vf != null && (myExcludedIndex.isInContent(vf) || isFileInBaseDir(vf) || vf.equals(myProject.getBaseDir()) ||
                                                   hasExplicitMapping(vf) || isInDirectoryBasedRoot(vf)
                                                   || !Registry.is("ide.hide.excluded.files") && myExcludedIndex.isExcludedFile(vf))
                                    && !isIgnored(vf);
  return AccessRule.read(action);
}
 
Example #24
Source File: BuildArtifactsBeforeRunTaskProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> executeTaskAsync(UIAccess uiAccess, DataContext context, RunConfiguration configuration, ExecutionEnvironment env, BuildArtifactsBeforeRunTask task) {
  AsyncResult<Void> result = AsyncResult.undefined();

  final List<Artifact> artifacts = new ArrayList<>();
  AccessRule.read(() -> {
    for (ArtifactPointer pointer : task.getArtifactPointers()) {
      ContainerUtil.addIfNotNull(artifacts, pointer.get());
    }
  });

  final CompileStatusNotification callback = (aborted, errors, warnings, compileContext) -> {
    if(!aborted && errors == 0) {
      result.setDone();
    }
    else {
      result.setRejected();
    }
  };

  final Condition<Compiler> compilerFilter = compiler -> compiler instanceof ArtifactsCompiler || compiler instanceof ArtifactAwareCompiler && ((ArtifactAwareCompiler)compiler).shouldRun(artifacts);

  uiAccess.give(() -> {
    final CompilerManager manager = CompilerManager.getInstance(myProject);
    manager.make(ArtifactCompileScope.createArtifactsScope(myProject, artifacts), compilerFilter, callback);
  }).doWhenRejectedWithThrowable(result::rejectWithThrowable);

  return result;
}
 
Example #25
Source File: LocalHistoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Label label(final LabelImpl impl) {
  return new Label() {
    @Override
    public void revert(@Nonnull Project project, @Nonnull VirtualFile file) throws LocalHistoryException {
      revertToLabel(project, file, impl);
    }

    @Override
    public ByteContent getByteContent(final String path) {
      ThrowableComputable<ByteContent, RuntimeException> action = () -> impl.getByteContent(myGateway.createTransientRootEntryForPathOnly(path), path);
      return AccessRule.read(action);
    }
  };
}
 
Example #26
Source File: ProjectFileIndexImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean iterateContent(@Nonnull ContentIterator processor, @Nullable VirtualFileFilter filter) {
  Module[] modules = AccessRule.read(() -> ModuleManager.getInstance(myProject).getModules());
  for (final Module module : modules) {
    for (VirtualFile contentRoot : getRootsToIterate(module)) {
      if (!iterateContentUnderDirectory(contentRoot, processor, filter)) {
        return false;
      }
    }
  }
  return true;
}
 
Example #27
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected ModuleEx createAndLoadModule(@Nonnull final ModuleLoadItem moduleLoadItem, @Nonnull ModuleModelImpl moduleModel, @Nullable final ProgressIndicator progressIndicator) {
  final ModuleEx module = createModule(moduleLoadItem.getName(), moduleLoadItem.getDirUrl(), progressIndicator);
  moduleModel.initModule(module);

  collapseOrExpandMacros(module, moduleLoadItem.getElement(), false);

  final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
  AccessRule.read(() -> moduleRootManager.loadState(moduleLoadItem.getElement(), progressIndicator));

  return module;
}
 
Example #28
Source File: PsiCopyPasteManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public PsiElement[] getElements() {
  return AccessRule.read(() -> {
    List<PsiElement> result = new ArrayList<>();
    for (SmartPsiElementPointer pointer : myPointers) {
      PsiElement element = pointer.getElement();
      if (element != null) {
        result.add(element);
      }
    }
    return result.toArray(PsiElement.EMPTY_ARRAY);
  });
}
 
Example #29
Source File: PsiCopyPasteManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private String getDataAsText() {
  return AccessRule.read(() -> {
    final List<String> names = new ArrayList<>();
    for (PsiElement element : myDataProxy.getElements()) {
      if (element instanceof PsiNamedElement) {
        String name = ((PsiNamedElement)element).getName();
        if (name != null) {
          names.add(name);
        }
      }
    }
    return names.isEmpty() ? null : StringUtil.join(names, "\n");
  });
}
 
Example #30
Source File: DiffContentFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public DocumentContent createDocument(@javax.annotation.Nullable Project project, @Nonnull final VirtualFile file) {
  // TODO: add notification, that file is decompiled ?
  if (file.isDirectory()) return null;
  ThrowableComputable<Document, RuntimeException> action = () -> {
    return FileDocumentManager.getInstance().getDocument(file);
  };
  Document document = AccessRule.read(action);
  if (document == null) return null;
  return new FileDocumentContentImpl(project, document, file);
}