use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class InjectedPsiCachedValueProvider method compute.
@Override
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) {
PsiFile hostPsiFile = element.getContainingFile();
if (hostPsiFile == null)
return null;
FileViewProvider viewProvider = hostPsiFile.getViewProvider();
final DocumentEx hostDocument = (DocumentEx) viewProvider.getDocument();
if (hostDocument == null)
return null;
PsiManager psiManager = viewProvider.getManager();
final Project project = psiManager.getProject();
InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project);
final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile);
return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument);
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class PersistentRangeHighlighterImpl method translatedViaDiff.
private boolean translatedViaDiff(DocumentEvent e, DocumentEventImpl event) {
try {
myLine = event.translateLineViaDiff(myLine);
} catch (FilesTooBigForDiffException ignored) {
return false;
}
if (myLine < 0 || myLine >= getDocument().getLineCount()) {
invalidate(e);
} else {
DocumentEx document = getDocument();
setIntervalStart(document.getLineStartOffset(myLine));
setIntervalEnd(document.getLineEndOffset(myLine));
}
return true;
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class FoldingModelSupport method getFoldedRanges.
@NotNull
private List<FoldedRangeState> getFoldedRanges(int index, @NotNull Settings settings) {
ApplicationManager.getApplication().assertReadAccessAllowed();
List<FoldedRangeState> ranges = new ArrayList<>();
DocumentEx document = myEditors[index].getDocument();
for (FoldedBlock[] blocks : myFoldings) {
LineRange expanded = null;
LineRange collapsed = null;
for (FoldedBlock folding : blocks) {
FoldRegion region = folding.getRegion(index);
if (region == null || !region.isValid())
continue;
if (region.isExpanded()) {
if (expanded == null) {
int line1 = document.getLineNumber(region.getStartOffset());
int line2 = document.getLineNumber(region.getEndOffset()) + 1;
expanded = new LineRange(line1, line2);
}
} else {
int line1 = document.getLineNumber(region.getStartOffset());
int line2 = document.getLineNumber(region.getEndOffset()) + 1;
collapsed = new LineRange(line1, line2);
break;
}
}
if (expanded != null || collapsed != null) {
ranges.add(new FoldedRangeState(expanded, collapsed));
}
}
return ranges;
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method testMoveText.
public void testMoveText() {
PsiJavaFile file = (PsiJavaFile) configureByText(JavaFileType.INSTANCE, "class C1{}\nclass C2 {}");
DocumentEx document = (DocumentEx) file.getViewProvider().getDocument();
SmartPsiElementPointer<PsiClass> pointer1 = createPointer(file.getClasses()[0]);
SmartPsiElementPointer<PsiClass> pointer2 = createPointer(file.getClasses()[1]);
assertEquals("C1", pointer1.getElement().getName());
assertEquals("C2", pointer2.getElement().getName());
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertNull(((SmartPointerEx) pointer1).getCachedElement());
assertNull(((SmartPointerEx) pointer2).getCachedElement());
TextRange range = file.getClasses()[1].getTextRange();
ApplicationManager.getApplication().runWriteAction(() -> document.moveText(range.getStartOffset(), range.getEndOffset(), 0));
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
assertEquals("C1", pointer1.getElement().getName());
assertEquals("C2", pointer2.getElement().getName());
}
use of com.intellij.openapi.editor.ex.DocumentEx 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();
}
Aggregations