use of com.intellij.openapi.command.impl.UndoManagerImpl in project intellij-community by JetBrains.
the class ImportHelperTest method testAutoImportCaretLocation2.
public void testAutoImportCaretLocation2() throws Throwable {
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
try {
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
configureByText(StdFileTypes.JAVA, "class X { <caret>ArrayList c = new ArrayList(); }");
((UndoManagerImpl) UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
((UndoManagerImpl) UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(getFile().getVirtualFile());
type(" ");
backspace();
assertEquals(2, highlightErrors().size());
UIUtil.dispatchAllInvocationEvents();
int offset = myEditor.getCaretModel().getOffset();
PsiReference ref = myFile.findReferenceAt(offset);
assertTrue(ref instanceof PsiJavaCodeReferenceElement);
ImportClassFixBase.Result result = new ImportClassFix((PsiJavaCodeReferenceElement) ref).doFix(getEditor(), true, false);
assertEquals(ImportClassFixBase.Result.CLASS_AUTO_IMPORTED, result);
UIUtil.dispatchAllInvocationEvents();
assertEmpty(highlightErrors());
} finally {
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
}
}
use of com.intellij.openapi.command.impl.UndoManagerImpl in project intellij-community by JetBrains.
the class RangeMarkerTest method testRandomEdit_NoCommand.
public void testRandomEdit_NoCommand() {
final int N = 100;
final Random gen = new Random();
int N_TRIES = Timings.adjustAccordingToMySpeed(7000, false);
System.out.println("N_TRIES = " + N_TRIES);
DocumentEx document = null;
for (int tryn = 0; tryn < N_TRIES; tryn++) {
((UndoManagerImpl) UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
((UndoManagerImpl) UndoManager.getGlobalInstance()).flushCurrentCommandMerger();
if (document != null) {
((UndoManagerImpl) UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(document);
((UndoManagerImpl) UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(document);
}
if (tryn % 10000 == 0) {
System.out.println(tryn);
}
document = (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', N));
final DocumentEx finalDocument = document;
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Exception {
List<Pair<RangeMarker, TextRange>> adds = new ArrayList<>();
List<Pair<RangeMarker, TextRange>> dels = new ArrayList<>();
List<Trinity<Integer, Integer, Integer>> edits = new ArrayList<>();
try {
for (int i = 0; i < 30; i++) {
int x = gen.nextInt(N);
int y = x + gen.nextInt(N - x);
RangeMarkerEx r = (RangeMarkerEx) finalDocument.createRangeMarker(x, y);
adds.add(Pair.create(r, TextRange.create(r)));
}
for (int i = 0; i < 10; i++) {
int offset = gen.nextInt(finalDocument.getTextLength());
if (gen.nextBoolean()) {
int length = gen.nextInt(5);
edits.add(Trinity.create(offset, 0, length));
finalDocument.insertString(offset, StringUtil.repeatSymbol(' ', length));
} else {
int length = gen.nextInt(finalDocument.getTextLength() - offset);
edits.add(Trinity.create(offset, length, 0));
finalDocument.deleteString(offset, offset + length);
}
}
List<Pair<RangeMarker, TextRange>> candidates = new ArrayList<>(adds);
while (!candidates.isEmpty()) {
int size = candidates.size();
int x = gen.nextInt(size);
Pair<RangeMarker, TextRange> c = candidates.remove(x);
RangeMarkerEx r = (RangeMarkerEx) c.first;
assertEquals(size - 1, candidates.size());
dels.add(c);
r.dispose();
}
} catch (AssertionError e) {
String s = "adds: ";
for (Pair<RangeMarker, TextRange> c : adds) {
TextRange t = c.second;
s += t.getStartOffset() + "," + t.getEndOffset() + ", ";
}
s += "\nedits: ";
for (Trinity<Integer, Integer, Integer> edit : edits) {
s += edit.first + "," + edit.second + "," + edit.third + ", ";
}
s += "\ndels: ";
for (Pair<RangeMarker, TextRange> c : dels) {
int index = adds.indexOf(c);
assertSame(c, adds.get(index));
s += index + ", ";
}
System.err.println(s);
throw e;
}
}
}.execute();
}
}
use of com.intellij.openapi.command.impl.UndoManagerImpl in project intellij-community by JetBrains.
the class PlatformTestCase method cleanupApplicationCaches.
public static void cleanupApplicationCaches(Project project) {
if (project != null && !project.isDisposed()) {
UndoManagerImpl globalInstance = (UndoManagerImpl) UndoManager.getGlobalInstance();
if (globalInstance != null) {
globalInstance.dropHistoryInTests();
}
((UndoManagerImpl) UndoManager.getInstance(project)).dropHistoryInTests();
((DocumentReferenceManagerImpl) DocumentReferenceManager.getInstance()).cleanupForNextTest();
((PsiManagerImpl) PsiManager.getInstance(project)).cleanupForNextTest();
}
final ProjectManager projectManager = ProjectManager.getInstance();
assert projectManager != null : "The ProjectManager is not initialized yet";
ProjectManagerImpl projectManagerImpl = (ProjectManagerImpl) projectManager;
if (projectManagerImpl.isDefaultProjectInitialized()) {
Project defaultProject = projectManager.getDefaultProject();
((PsiManagerImpl) PsiManager.getInstance(defaultProject)).cleanupForNextTest();
}
AsyncHighlighterUpdater.completeAsyncTasks();
((FileBasedIndexImpl) FileBasedIndex.getInstance()).cleanupForNextTest();
LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl) LocalFileSystem.getInstance();
if (localFileSystem != null) {
localFileSystem.cleanupForNextTest();
}
}
use of com.intellij.openapi.command.impl.UndoManagerImpl in project intellij-community by JetBrains.
the class ImportHelperTest method testAutoImportCaretLocation.
public void testAutoImportCaretLocation() throws Throwable {
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
try {
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
configureByText(StdFileTypes.JAVA, "class X { ArrayList<caret> c; }");
((UndoManagerImpl) UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
((UndoManagerImpl) UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(getFile().getVirtualFile());
type(" ");
backspace();
assertOneElement(highlightErrors());
int offset = myEditor.getCaretModel().getOffset();
PsiReference ref = myFile.findReferenceAt(offset - 1);
assertTrue(ref instanceof PsiJavaCodeReferenceElement);
ImportClassFixBase.Result result = new ImportClassFix((PsiJavaCodeReferenceElement) ref).doFix(getEditor(), true, false);
assertEquals(ImportClassFixBase.Result.POPUP_NOT_SHOWN, result);
UIUtil.dispatchAllInvocationEvents();
myEditor.getCaretModel().moveToOffset(offset - 1);
result = new ImportClassFix((PsiJavaCodeReferenceElement) ref).doFix(getEditor(), true, false);
assertEquals(ImportClassFixBase.Result.CLASS_AUTO_IMPORTED, result);
UIUtil.dispatchAllInvocationEvents();
assertEmpty(highlightErrors());
} finally {
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
}
}
use of com.intellij.openapi.command.impl.UndoManagerImpl in project intellij-community by JetBrains.
the class FormatterTestCase method doSanityTestForFile.
private void doSanityTestForFile(final File subFile, final List<File> failedFiles, final boolean formatWithPsi) throws IOException, IncorrectOperationException {
if (subFile.isFile() && subFile.getName().endsWith(getFileExtension())) {
final byte[] bytes = FileUtil.loadFileBytes(subFile);
final String text = new String(bytes);
final String fileName = "before." + getFileExtension();
final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, getFileType(fileName), StringUtil.convertLineSeparators(text), LocalTimeCounter.currentTime(), true);
try {
CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
try {
if (formatWithPsi) {
performFormatting(file);
} else {
performFormattingWithDocument(file);
}
} catch (Throwable e) {
//noinspection CallToPrintStackTrace
e.printStackTrace();
failedFiles.add(subFile);
}
//noinspection UseOfSystemOutOrSystemErr
System.out.println(subFile.getPath() + ": finished");
}), "", null);
} finally {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
((UndoManagerImpl) UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(virtualFile);
((UndoManagerImpl) UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(virtualFile);
}
}
}
}
Aggregations