use of com.intellij.psi.PsiDocumentManager in project intellij-community by JetBrains.
the class GotoCustomRegionAction method getCustomFoldingDescriptors.
@NotNull
private static Collection<FoldingDescriptor> getCustomFoldingDescriptors(@NotNull Editor editor, @NotNull Project project) {
Set<FoldingDescriptor> foldingDescriptors = new HashSet<>();
final Document document = editor.getDocument();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null;
if (file != null) {
final FileViewProvider viewProvider = file.getViewProvider();
for (final Language language : viewProvider.getLanguages()) {
final PsiFile psi = viewProvider.getPsi(language);
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
if (psi != null) {
for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) {
CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor);
if (customFoldingBuilder != null) {
if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) {
foldingDescriptors.add(descriptor);
}
}
}
}
}
}
return foldingDescriptors;
}
use of com.intellij.psi.PsiDocumentManager in project intellij-community by JetBrains.
the class PsiFileGistImpl method shouldUseMemoryStorage.
private static boolean shouldUseMemoryStorage(PsiFile file) {
if (!(file.getVirtualFile() instanceof NewVirtualFile))
return true;
PsiDocumentManager pdm = PsiDocumentManager.getInstance(file.getProject());
Document document = pdm.getCachedDocument(file);
return document != null && (pdm.isUncommited(document) || FileDocumentManager.getInstance().isDocumentUnsaved(document));
}
use of com.intellij.psi.PsiDocumentManager in project intellij-community by JetBrains.
the class AbstractJavaFormatterTest method formatEveryoneAndCheckIfResultEqual.
public void formatEveryoneAndCheckIfResultEqual(@NotNull final String... before) {
assert before.length > 1;
final PsiFile file = createFile("A.java", "");
final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
final Document document = manager.getDocument(file);
String afterFirst = replaceAndProcessDocument(REFORMAT, before[0], file, document);
for (String nextBefore : before) {
assertEquals(afterFirst, replaceAndProcessDocument(REFORMAT, nextBefore, file, document));
}
}
use of com.intellij.psi.PsiDocumentManager in project intellij-community by JetBrains.
the class AbstractJavaFormatterTest method replaceAndProcessDocument.
@NotNull
private String replaceAndProcessDocument(@NotNull final Action action, @NotNull final String text, @NotNull final PsiFile file, @Nullable final Document document) throws IncorrectOperationException {
if (document == null) {
fail("Don't expect the document to be null");
return null;
}
if (myLineRange != null) {
final DocumentImpl doc = new DocumentImpl(text);
myTextRange = new TextRange(doc.getLineStartOffset(myLineRange.getStartOffset()), doc.getLineEndOffset(myLineRange.getEndOffset()));
}
final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
document.replaceString(0, document.getTextLength(), text);
manager.commitDocument(document);
try {
TextRange rangeToUse = myTextRange;
if (rangeToUse == null) {
rangeToUse = file.getTextRange();
}
ACTIONS.get(action).run(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
} catch (IncorrectOperationException e) {
assertTrue(e.getLocalizedMessage(), false);
}
}), action == REFORMAT ? ReformatCodeProcessor.COMMAND_NAME : "", "");
return document.getText();
}
use of com.intellij.psi.PsiDocumentManager in project intellij-community by JetBrains.
the class AbstractTreeStructure method asyncCommitDocuments.
@NotNull
public static ActionCallback asyncCommitDocuments(@NotNull Project project) {
if (project.isDisposed())
return ActionCallback.DONE;
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
if (!documentManager.hasUncommitedDocuments()) {
return ActionCallback.DONE;
}
final ActionCallback callback = new ActionCallback();
documentManager.performWhenAllCommitted(callback.createSetDoneRunnable());
return callback;
}
Aggregations