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); } } }
protected JComponent createCenterPanel() { final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true); ((DocumentImpl)document).setAcceptSlashR(true); myTextArea = EditorFactory.getInstance().createEditor(document, myProject, FileTypes.PLAIN_TEXT, true); final EditorSettings settings = myTextArea.getSettings(); settings.setLineNumbersShown(false); settings.setLineMarkerAreaShown(false); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setAdditionalLinesCount(0); settings.setAdditionalColumnsCount(0); settings.setAdditionalPageAtBottom(false); ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor()); myTextArea.getComponent().setPreferredSize(new Dimension(700, 400)); return myTextArea.getComponent(); }
public void testStress8() throws Exception { DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789"); Editor editor = EditorFactory.getInstance().createEditor(doc); try { final FoldingModel model = editor.getFoldingModel(); model.runBatchFoldingOperation(new Runnable() { @Override public void run() { addAndCollapseFoldRegion(model, 0, 8, "/*...*/"); addAndCollapseFoldRegion(model, 10, 12, "/*...*/"); } }); assertEquals(10, editor.logicalPositionToOffset(new LogicalPosition(0, 10))); for (int line = 0; line <= 3; line++) { for (int column = 0; column <= 100; column++) { LogicalPosition log = new LogicalPosition(line, column); editor.logicalToVisualPosition(log); } } } finally { EditorFactory.getInstance().releaseEditor(editor); } }
private static void stress(final int len) { DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789"); Editor editor = EditorFactory.getInstance().createEditor(doc); try { final FoldingModel model = editor.getFoldingModel(); model.runBatchFoldingOperation(new Runnable() { @Override public void run() { addAndCollapseFoldRegion(model, 0, len, "/*...*/"); addAndCollapseFoldRegion(model, len + 2, len + 4, "/*...*/"); } }); for (int line = 0; line <= 3; line++) { for (int column = 0; column <= 100; column++) { LogicalPosition log = new LogicalPosition(line, column); editor.logicalToVisualPosition(log); } } } finally { EditorFactory.getInstance().releaseEditor(editor); } }
public static FormattingDocumentModelImpl createOn(PsiFile file) { Document document = getDocumentToBeUsedFor(file); if (document != null) { if (PsiDocumentManager.getInstance(file.getProject()).isUncommited(document)) { LOG.error("Document is uncommitted"); } if (file.getTextLength() != document.getTextLength()) { LOG.error("Document and psi file texts should be equal: " + file + " file length = " + file.getTextLength() + ", document length = " + document.getTextLength()); } return new FormattingDocumentModelImpl(document, file); } else { return new FormattingDocumentModelImpl(new DocumentImpl(file.getViewProvider().getContents(), true), file); } }
public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder, boolean useLength) { Document document = editor.getDocument(); if (document instanceof DocumentImpl) { DocumentImpl documentImpl = (DocumentImpl)document; List<RangeMarker> blocks = documentImpl.getGuardedBlocks(); if (useLength && !placeholder.isValid(document)) return; int start = placeholder.getRealStartOffset(document); final int length = useLength ? placeholder.getLength() : placeholder.getPossibleAnswerLength(); int end = start + length; if (start != 0) { createGuardedBlock(editor, blocks, start - 1, start); } if (end != document.getTextLength()) { createGuardedBlock(editor, blocks, end, end + 1); } } }
public static void deleteGuardedBlocks(@NotNull final Document document) { if (document instanceof DocumentImpl) { final DocumentImpl documentImpl = (DocumentImpl)document; List<RangeMarker> blocks = documentImpl.getGuardedBlocks(); for (final RangeMarker block : blocks) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { document.removeGuardedBlock(block); } }); } }); } } }
protected JComponent createCenterPanel() { final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true); ((DocumentImpl)document).setAcceptSlashR(true); myTextArea = EditorFactory.getInstance().createEditor(document, myProject, StdFileTypes.PLAIN_TEXT, true); final EditorSettings settings = myTextArea.getSettings(); settings.setLineNumbersShown(false); settings.setLineMarkerAreaShown(false); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setAdditionalLinesCount(0); settings.setAdditionalColumnsCount(0); settings.setAdditionalPageAtBottom(false); ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor()); return myTextArea.getComponent(); }
public void testStress8() throws Exception { DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789"); Editor editor = EditorFactory.getInstance().createEditor(doc); try { final FoldingModel model = editor.getFoldingModel(); model.runBatchFoldingOperation(new Runnable() { @Override public void run() { model.addFoldRegion(0, 8, "/*...*/").setExpanded(false); model.addFoldRegion(10, 12, "/*...*/").setExpanded(false); } }); assertEquals(10, editor.logicalPositionToOffset(new LogicalPosition(0, 10))); for (int line = 0; line <= 3; line++) { for (int column = 0; column <= 100; column++) { LogicalPosition log = new LogicalPosition(line, column); editor.logicalToVisualPosition(log); } } } finally { EditorFactory.getInstance().releaseEditor(editor); } }
private static void stress(final int len) { DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789"); Editor editor = EditorFactory.getInstance().createEditor(doc); try { final FoldingModel model = editor.getFoldingModel(); model.runBatchFoldingOperation(new Runnable() { @Override public void run() { model.addFoldRegion(0, len, "/*...*/").setExpanded(false); model.addFoldRegion(len + 2, len + 4, "/*...*/").setExpanded(false); } }); for (int line = 0; line <= 3; line++) { for (int column = 0; column <= 100; column++) { LogicalPosition log = new LogicalPosition(line, column); editor.logicalToVisualPosition(log); } } } finally { EditorFactory.getInstance().releaseEditor(editor); } }
public static FormattingDocumentModelImpl createOn(PsiFile file) { Document document = getDocumentToBeUsedFor(file); if (document != null) { if (PsiDocumentManager.getInstance(file.getProject()).isUncommited(document)) { LOG.error("Document is uncommitted"); } if (!document.getText().equals(file.getText())) { LOG.error("Document and psi file texts should be equal: file " + file); } return new FormattingDocumentModelImpl(document, file); } else { return new FormattingDocumentModelImpl(new DocumentImpl(file.getText()), file); } }
public LineStatusTrackerBase(@javax.annotation.Nullable final Project project, @Nonnull final Document document) { myDocument = document; myProject = project; myApplication = ApplicationManager.getApplication(); myDocumentListener = new MyDocumentListener(); myDocument.addDocumentListener(myDocumentListener); myApplicationListener = new MyApplicationListener(); myApplication.addApplicationListener(myApplicationListener); myVcsDocument = new DocumentImpl("", true); myVcsDocument.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE); }
@Override protected JComponent createCenterPanel() { final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true); ((DocumentImpl)document).setAcceptSlashR(true); myTextArea = EditorFactory.getInstance().createEditor(document, myProject, PlainTextFileType.INSTANCE, true); final EditorSettings settings = myTextArea.getSettings(); settings.setLineNumbersShown(false); settings.setLineMarkerAreaShown(false); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setAdditionalLinesCount(0); settings.setAdditionalColumnsCount(0); settings.setAdditionalPageAtBottom(false); ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor()); return myTextArea.getComponent(); }
@Nonnull public static CharSequence getPatchedContent(@Nonnull AppliedTextPatch patch, @Nonnull String localContent) { PatchChangeBuilder builder = new PatchChangeBuilder(); builder.exec(patch.getHunks()); DocumentImpl document = new DocumentImpl(localContent, true); List<Hunk> appliedHunks = ContainerUtil.filter(builder.getHunks(), (h) -> h.getStatus() == HunkStatus.EXACTLY_APPLIED); ContainerUtil.sort(appliedHunks, Comparator.comparingInt(h -> h.getAppliedToLines().start)); for (int i = appliedHunks.size() - 1; i >= 0; i--) { Hunk hunk = appliedHunks.get(i); LineRange appliedTo = hunk.getAppliedToLines(); List<String> inserted = hunk.getInsertedLines(); DiffUtil.applyModification(document, appliedTo.start, appliedTo.end, inserted); } return document.getText(); }
public static FormattingDocumentModelImpl createOn(PsiFile file) { Document document = getDocumentToBeUsedFor(file); if (document != null) { if (PsiDocumentManager.getInstance(file.getProject()).isUncommited(document)) { LOG.error("Document is uncommitted"); } if (!file.textMatches(document.getImmutableCharSequence())) { LOG.error("Document and psi file texts should be equal: file " + file); } return new FormattingDocumentModelImpl(document, file); } else { return new FormattingDocumentModelImpl(new DocumentImpl(file.getText()), file); } }
public void testFindParents() throws Exception { List<VirtualFile> virtualFiles = prepareScenarioWithTestFiles("child.js", "parent.js", "grandpa.js"); HierarchyFinder hierarchyFinder = new HierarchyFinder(getProject(), getDocument(virtualFiles.get(0))) { @Override protected Document getDocument(VirtualFile virtualFile) { try { String s = new String(virtualFile.contentsToByteArray()); return new DocumentImpl(s); } catch (IOException e) { throw new RuntimeException(e); } } }; HierarchyResults results = hierarchyFinder.findParents(); List<Document> hierarchy = results.getHierarchy(); assertEquals(2, hierarchy.size()); assertEquals("Yo.child", results.getCurrentClass()); assertEquals("Yo.parent", results.getParentClass()); }
public static void deleteGuardedBlocks(@NotNull final Document document) { if (document instanceof DocumentImpl) { final DocumentImpl documentImpl = (DocumentImpl)document; List<RangeMarker> blocks = documentImpl.getGuardedBlocks(); for (final RangeMarker block : blocks) { ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> document.removeGuardedBlock(block))); } } }
public TextAttributes getAttributes(DocumentImpl document, int offset, char c) { int startOffset = 0; if (mySegments.getSegmentCount() > 0) { final int segmentIndex; try { segmentIndex = mySegments.findSegmentIndex(offset) - 2; } catch (IndexOutOfBoundsException ex) { throw new IndexOutOfBoundsException(ex.getMessage() + " Lexer: " + myLexer); } int startIndex = Math.max(0, segmentIndex); int data; do { data = mySegments.getSegmentData(startIndex); if (isInitialState(data)|| startIndex == 0) break; startIndex--; } while (true); startOffset = mySegments.getSegmentStart(startIndex); } ImmutableText newText = document.getImmutableText().insert(offset, Character.toString(c)); myLexer.start(newText, startOffset, newText.length(), myInitialState); IElementType tokenType = null; while (myLexer.getTokenType() != null) { if (myLexer.getTokenEnd() >= offset + 1) { tokenType = myLexer.getTokenType(); break; } myLexer.advance(); } return getAttributes(tokenType); }
private Mapper(LayerDescriptor descriptor) { doc = new DocumentImpl("",true); mySyntaxHighlighter = descriptor.getLayerHighlighter(); myBackground = descriptor.getBackgroundKey(); highlighter = new LexerEditorHighlighter(mySyntaxHighlighter, getScheme()); mySeparator = descriptor.getTokenSeparator(); highlighter.setEditor(this); doc.addDocumentListener(highlighter); }
@NotNull private String stripTrailingSpaces(@NotNull String actualText) { final Document document = EditorFactory.getInstance().createDocument(actualText); ((DocumentImpl)document).stripTrailingSpaces(getProject()); actualText = document.getText(); return actualText; }
@Override @NotNull public Editor getEditor() { TextEditor fileEditor = getTextEditor(); if (fileEditor != null) { return fileEditor.getEditor(); } else if (myMockTextEditor == null) { myMockTextEditor = EditorFactory.getInstance().createViewer(new DocumentImpl(""), myProject); } return myMockTextEditor; }
private static void indentNewLines(DocumentImpl logDoc, List<RangeMarker> lineSeparators, RangeMarker afterTitle, boolean hasHtml, String indent) { if (!hasHtml) { int i = -1; while (true) { i = StringUtil.indexOf(logDoc.getText(), '\n', i + 1); if (i < 0) { break; } lineSeparators.add(logDoc.createRangeMarker(i, i + 1)); } } if (!lineSeparators.isEmpty() && afterTitle != null && afterTitle.isValid()) { lineSeparators.add(afterTitle); } int nextLineStart = -1; for (RangeMarker separator : lineSeparators) { if (separator.isValid()) { int start = separator.getStartOffset(); if (start == nextLineStart) { continue; } logDoc.replaceString(start, separator.getEndOffset(), "\n" + indent); nextLineStart = start + 1 + indent.length(); while (nextLineStart < logDoc.getTextLength() && Character.isWhitespace(logDoc.getCharsSequence().charAt(nextLineStart))) { logDoc.deleteString(nextLineStart, nextLineStart + 1); } } } }
private static String getStatusText(DocumentImpl logDoc, AtomicBoolean showMore, List<RangeMarker> lineSeparators, boolean hasHtml) { DocumentImpl statusDoc = new DocumentImpl(logDoc.getImmutableCharSequence(),true); List<RangeMarker> statusSeparators = new ArrayList<RangeMarker>(); for (RangeMarker separator : lineSeparators) { if (separator.isValid()) { statusSeparators.add(statusDoc.createRangeMarker(separator.getStartOffset(), separator.getEndOffset())); } } removeJavaNewLines(statusDoc, statusSeparators, hasHtml); insertNewLineSubstitutors(statusDoc, showMore, statusSeparators); return statusDoc.getText(); }
private void initWithCustomLineSeparators(final String text) { myFixture.configureByText(getTestName(true) + ".java", ""); final DocumentImpl document = (DocumentImpl)myFixture.getEditor().getDocument(); document.setAcceptSlashR(true); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { document.setText(text); } }); myFixture.doHighlighting(); }
public void testEmptyDocumentLineCount() { WriteCommandAction.runWriteCommandAction(ourProject, new Runnable() { @Override public void run() { DocumentImpl document = new DocumentImpl(""); assertEquals(0, document.getLineCount()); document.insertString(0, "a"); assertEquals(1, document.getLineCount()); document.deleteString(0, 1); assertEquals(0, document.getLineCount()); } }); }
public void testDocumentGced() throws Exception { VirtualFile vFile = getVirtualFile(createTempFile("txt", "abc")); PsiDocumentManagerImpl documentManager = getPsiDocumentManager(); long id = System.identityHashCode(documentManager.getDocument(getPsiManager().findFile(vFile))); documentManager.commitAllDocuments(); UIUtil.dispatchAllInvocationEvents(); UIUtil.dispatchAllInvocationEvents(); assertEmpty(documentManager.getUncommittedDocuments()); LeakHunter.checkLeak(documentManager, DocumentImpl.class); LeakHunter.checkLeak(documentManager, PsiFileImpl.class, new Processor<PsiFileImpl>() { @Override public boolean process(PsiFileImpl psiFile) { return psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem; } }); //Class.forName("com.intellij.util.ProfilingUtil").getDeclaredMethod("forceCaptureMemorySnapshot").invoke(null); for (int i = 0; i < 1000; i++) { PlatformTestUtil.tryGcSoftlyReachableObjects(); UIUtil.dispatchAllInvocationEvents(); if (documentManager.getCachedDocument(getPsiManager().findFile(vFile)) == null) break; System.gc(); } assertNull(documentManager.getCachedDocument(getPsiManager().findFile(vFile))); Document newDoc = documentManager.getDocument(getPsiManager().findFile(vFile)); assertTrue(id != System.identityHashCode(newDoc)); }
@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 (mySynchronizer.isInsideAtomicChange(file)) { psiCause = file; } } if (psiCause == null) { beforeDocumentChangeOnUnlockedDocument(viewProvider); } ((SingleRootFileViewProvider)viewProvider).beforeDocumentChanged(psiCause); }
private static Document documentFromRevision(final ContentRevision cr) throws VcsException { final Document oldDocument = new DocumentImpl(StringUtil.convertLineSeparators(notNullContentRevision(cr)),true); // todo !!! a question how to show line separators in diff etc // todo currently document doesn't allow to put \r as separator oldDocument.setReadOnly(true); return oldDocument; }
@NotNull private static DocumentEx createDocument(@NotNull LightVirtualFile virtualFile) { CharSequence content = virtualFile.getContent(); DocumentImpl document = new DocumentImpl(content, StringUtil.indexOf(content, '\r') >= 0, false); FileDocumentManagerImpl.registerDocument(document, virtualFile); return document; }
@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<DiffChange>(); 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); }
public static Document createDocument(final String s, final Project project) { if (ApplicationManager.getApplication().isUnitTestMode() || project.isDefault()) { return new DocumentImpl(s); } else { return JavaReferenceEditorUtil.createTypeDocument(s, project); } }
private static EditorEx createEditor(String tooltip) { Project project = getProject(); LightVirtualFile virtualFile = new LightVirtualFile("mockProjectViewFile", ProjectViewLanguage.INSTANCE, ""); final Document document = ((EditorFactoryImpl) EditorFactory.getInstance()).createDocument(true); ((DocumentImpl) document).setAcceptSlashR(true); FileDocumentManagerImpl.registerDocument(document, virtualFile); FileManager fileManager = ((PsiManagerEx) PsiManager.getInstance(project)).getFileManager(); fileManager.setViewProvider(virtualFile, fileManager.createFileViewProvider(virtualFile, true)); if (project.isDefault()) { // Undo-redo doesn't work with the default project. // Explicitly turn it off to avoid error dialogs. UndoUtil.disableUndoFor(document); } EditorEx editor = (EditorEx) EditorFactory.getInstance() .createEditor(document, project, ProjectViewFileType.INSTANCE, false); final EditorSettings settings = editor.getSettings(); settings.setLineNumbersShown(false); settings.setLineMarkerAreaShown(false); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setAdditionalPageAtBottom(false); editor.getComponent().setMinimumSize(getEditorSize()); editor.getComponent().setPreferredSize(getEditorSize()); editor.getComponent().setToolTipText(tooltip); editor.getComponent().setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); editor.getComponent().setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); return editor; }
private static void indentNewLines(DocumentImpl logDoc, List<RangeMarker> lineSeparators, RangeMarker afterTitle, boolean hasHtml, String indent) { if(!hasHtml) { int i = -1; while(true) { i = StringUtil.indexOf(logDoc.getText(), '\n', i + 1); if(i < 0) { break; } lineSeparators.add(logDoc.createRangeMarker(i, i + 1)); } } if(!lineSeparators.isEmpty() && afterTitle != null && afterTitle.isValid()) { lineSeparators.add(afterTitle); } int nextLineStart = -1; for(RangeMarker separator : lineSeparators) { if(separator.isValid()) { int start = separator.getStartOffset(); if(start == nextLineStart) { continue; } logDoc.replaceString(start, separator.getEndOffset(), "\n" + indent); nextLineStart = start + 1 + indent.length(); while(nextLineStart < logDoc.getTextLength() && Character.isWhitespace(logDoc.getCharsSequence().charAt(nextLineStart))) { logDoc.deleteString(nextLineStart, nextLineStart + 1); } } } }
private static String getStatusText(DocumentImpl logDoc, AtomicBoolean showMore, List<RangeMarker> lineSeparators, boolean hasHtml) { DocumentImpl statusDoc = new DocumentImpl(logDoc.getImmutableCharSequence(), true); List<RangeMarker> statusSeparators = new ArrayList<RangeMarker>(); for(RangeMarker separator : lineSeparators) { if(separator.isValid()) { statusSeparators.add(statusDoc.createRangeMarker(separator.getStartOffset(), separator.getEndOffset())); } } removeJavaNewLines(statusDoc, statusSeparators, hasHtml); insertNewLineSubstitutors(statusDoc, showMore, statusSeparators); return statusDoc.getText(); }
private static Document createDocument() { final Document document = EditorFactory.getInstance().createDocument(""); if (document instanceof DocumentImpl) { ((DocumentImpl)document).setAcceptSlashR(true); } return document; }
public void testDocumentGced() throws Exception { VirtualFile vFile = createFile(); PsiDocumentManagerImpl documentManager = getPsiDocumentManager(); long id = System.identityHashCode(documentManager.getDocument(getPsiManager().findFile(vFile))); documentManager.commitAllDocuments(); UIUtil.dispatchAllInvocationEvents(); UIUtil.dispatchAllInvocationEvents(); assertEmpty(documentManager.getUncommittedDocuments()); LeakHunter.checkLeak(documentManager, DocumentImpl.class); LeakHunter.checkLeak(documentManager, PsiFileImpl.class, new Processor<PsiFileImpl>() { @Override public boolean process(PsiFileImpl psiFile) { return psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem; } }); //Class.forName("com.intellij.util.ProfilingUtil").getDeclaredMethod("forceCaptureMemorySnapshot").invoke(null); Reference<Document> reference = vFile.getUserData(FileDocumentManagerImpl.DOCUMENT_KEY); assertNotNull(reference); for (int i=0;i<1000;i++) { UIUtil.dispatchAllInvocationEvents(); if (reference.get() == null) break; System.gc(); } assertNull(documentManager.getCachedDocument(getPsiManager().findFile(vFile))); Document newDoc = documentManager.getDocument(getPsiManager().findFile(vFile)); assertTrue(id != System.identityHashCode(newDoc)); }
@Override protected void setUp() throws Exception { super.setUp(); if (shouldContainTempFiles()) { String testName = getTestName(true); if (StringUtil.isEmptyOrSpaces(testName)) testName = ""; testName = new File(testName).getName(); // in case the test name contains file separators myTempDir = ORIGINAL_TEMP_DIR + "/unitTest_" + testName + "_"+ PRNG.nextInt(1000); FileUtil.resetCanonicalTempPathCache(myTempDir); } DocumentImpl.CHECK_DOCUMENT_CONSISTENCY = !isPerformanceTest(); }
public void clearLineModificationFlags(@NotNull Document document) { if (document instanceof DocumentWindow) { document = ((DocumentWindow)document).getDelegate(); } if (!(document instanceof DocumentImpl)) { return; } Component focusOwner = IdeFocusManager.getGlobalInstance().getFocusOwner(); DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner); boolean isDisposeInProgress = ApplicationManager.getApplication().isDisposeInProgress(); // ignore caret placing when exiting Editor activeEditor = isDisposeInProgress ? null : PlatformDataKeys.EDITOR.getData(dataContext); // when virtual space enabled, we can strip whitespace anywhere boolean isVirtualSpaceEnabled = activeEditor == null || activeEditor.getSettings().isVirtualSpace(); int caretLine = activeEditor == null ? -1 : activeEditor.getCaretModel().getLogicalPosition().line; final EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance(); if (settings == null) return; String stripTrailingSpaces = settings.getStripTrailingSpaces(); final boolean doStrip = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE); final boolean inChangedLinesOnly = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE); if (!inChangedLinesOnly || !doStrip || isVirtualSpaceEnabled) caretLine = -1; ((DocumentImpl)document).clearLineModificationFlagsExcept(caretLine); }
public static boolean stripIfNotCurrentLine(Document document, boolean inChangedLinesOnly) { if (document instanceof DocumentWindow) { document = ((DocumentWindow)document).getDelegate(); } if (!(document instanceof DocumentImpl)) { return true; } DataContext dataContext = DataManager.getInstance().getDataContext(IdeFocusManager.getGlobalInstance().getFocusOwner()); boolean isDisposeInProgress = ApplicationManager.getApplication().isDisposeInProgress(); // ignore caret placing when exiting Editor activeEditor = isDisposeInProgress ? null : PlatformDataKeys.EDITOR.getData(dataContext); // when virtual space enabled, we can strip whitespace anywhere boolean isVirtualSpaceEnabled = activeEditor == null || activeEditor.getSettings().isVirtualSpace(); VisualPosition visualCaret = activeEditor == null ? null : activeEditor.getCaretModel().getVisualPosition(); int caretLine = activeEditor == null ? -1 : activeEditor.getCaretModel().getLogicalPosition().line; int caretOffset = activeEditor == null ? -1 : activeEditor.getCaretModel().getOffset(); final Project project = activeEditor == null ? null : activeEditor.getProject(); boolean markAsNeedsStrippingLater = ((DocumentImpl)document).stripTrailingSpaces(project, inChangedLinesOnly, isVirtualSpaceEnabled, caretLine, caretOffset); if (!ShutDownTracker.isShutdownHookRunning() && activeEditor != null) { activeEditor.getCaretModel().moveToVisualPosition(visualCaret); } return !markAsNeedsStrippingLater; }
@NotNull public Editor getEditor() { final TextEditor fileEditor = myPanel.getFileEditor(); if (fileEditor != null) { return fileEditor.getEditor(); } if (myMockTextEditor == null) { myMockTextEditor = EditorFactory.getInstance().createViewer(new DocumentImpl(""), myProject); } return myMockTextEditor; }