use of com.intellij.openapi.editor.impl.DocumentImpl in project kotlin by JetBrains.
the class AbstractFormatterTest method doTextTest.
public void doTextTest(final Action action, final String text, File fileAfter, String extension) throws IncorrectOperationException {
final PsiFile file = createFile("A" + extension, text);
if (myLineRange != null) {
DocumentImpl document = new DocumentImpl(text);
myTextRange = new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset()));
}
final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
final Document document = manager.getDocument(file);
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
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);
}
}
});
}
}, "", "");
if (document == null) {
fail("Don't expect the document to be null");
return;
}
KotlinTestUtils.assertEqualsToFile(fileAfter, document.getText());
manager.commitDocument(document);
KotlinTestUtils.assertEqualsToFile(fileAfter, file.getText());
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class EduAnswerPlaceholderPainter method createGuardedBlocks.
public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder) {
Document document = editor.getDocument();
if (document instanceof DocumentImpl) {
DocumentImpl documentImpl = (DocumentImpl) document;
List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
Integer start = offsets.first;
Integer end = offsets.second;
if (start != 0) {
createGuardedBlock(editor, blocks, start - 1, start);
}
if (end != document.getTextLength()) {
createGuardedBlock(editor, blocks, end, end + 1);
}
}
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class SvnPropertiesDiffViewer method convertRequest.
//
// Initial step
//
@NotNull
private static Pair<WrapperRequest, List<DiffChange>> convertRequest(@NotNull SvnPropertiesDiffRequest request, boolean embedded) {
List<PropertyRecord> records = collectRecords(request);
StringBuilder builder1 = new StringBuilder();
StringBuilder builder2 = new StringBuilder();
List<DiffChange> diffChanges = new ArrayList<>();
int totalLines = 0;
for (PropertyRecord record : records) {
int start = totalLines;
String before = StringUtil.notNullize(record.getBefore());
String after = StringUtil.notNullize(record.getAfter());
builder1.append(before);
builder2.append(after);
int lines1 = StringUtil.countNewLines(before);
int lines2 = StringUtil.countNewLines(after);
int appendedLines = Math.max(lines1, lines2) + 1;
totalLines += appendedLines;
for (int i = lines1; i < appendedLines; i++) {
builder1.append('\n');
}
for (int i = lines2; i < appendedLines; i++) {
builder2.append('\n');
}
diffChanges.add(new DiffChange(record, start, totalLines, start, totalLines));
}
Document document1 = new DocumentImpl(builder1);
Document document2 = new DocumentImpl(builder2);
return Pair.create(new WrapperRequest(request, document1, document2, embedded), diffChanges);
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method getLastCommittedDocument.
@NotNull
public DocumentEx getLastCommittedDocument(@NotNull Document document) {
if (document instanceof FrozenDocument)
return (DocumentEx) document;
if (document instanceof DocumentWindow) {
DocumentWindow window = (DocumentWindow) document;
Document delegate = window.getDelegate();
if (delegate instanceof FrozenDocument)
return (DocumentEx) window;
if (!window.isValid()) {
throw new AssertionError("host committed: " + isCommitted(delegate) + ", window=" + window);
}
UncommittedInfo info = myUncommittedInfos.get(delegate);
DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document);
if (answer == null)
answer = freezeWindow(window);
if (info != null)
answer = ConcurrencyUtil.cacheOrGet(info.myFrozenWindows, window, answer);
return (DocumentEx) answer;
}
assert document instanceof DocumentImpl;
UncommittedInfo info = myUncommittedInfos.get(document);
return info != null ? info.myFrozen : ((DocumentImpl) document).freeze();
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method beforeDocumentChange.
@Override
public void beforeDocumentChange(@NotNull DocumentEvent event) {
if (myStopTrackingDocuments || myProject.isDisposed())
return;
final Document document = event.getDocument();
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
boolean isRelevant = virtualFile != null && isRelevant(virtualFile);
if (document instanceof DocumentImpl && !myUncommittedInfos.containsKey(document)) {
myUncommittedInfos.put(document, new UncommittedInfo((DocumentImpl) document));
}
final FileViewProvider viewProvider = getCachedViewProvider(document);
boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
if (!isRelevant || !inMyProject) {
return;
}
final List<PsiFile> files = viewProvider.getAllFiles();
PsiFile psiCause = null;
for (PsiFile file : files) {
if (file == null) {
throw new AssertionError("View provider " + viewProvider + " (" + viewProvider.getClass() + ") returned null in its files array: " + files + " for file " + viewProvider.getVirtualFile());
}
if (PsiToDocumentSynchronizer.isInsideAtomicChange(file)) {
psiCause = file;
}
}
if (psiCause == null) {
beforeDocumentChangeOnUnlockedDocument(viewProvider);
}
((SingleRootFileViewProvider) viewProvider).beforeDocumentChanged(psiCause);
}
Aggregations