use of com.intellij.util.ThrowableRunnable in project intellij-plugins by JetBrains.
the class ActionScriptStubsTest method doTest.
private void doTest(@Nullable final ThrowableRunnable<Exception> runnable, String... files) throws Exception {
Runnable r = runnable != null ? () -> {
try {
runnable.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
} : null;
doTestFor(true, r, files);
// the first one was parsed during highlighting
assertNotParsed(myPsiFiles.subList(1, myPsiFiles.size()));
// we need to go though files open in editors
assertNotParsed(ContainerUtil.mapNotNull(FileEditorManager.getInstance(myProject).getOpenFiles(), virtualFile -> {
if (Comparing.equal(virtualFile, myFile.getVirtualFile())) {
return null;
}
Document document = ((TextEditor) FileEditorManager.getInstance(myProject).getSelectedEditor(virtualFile)).getEditor().getDocument();
return PsiDocumentManager.getInstance(myProject).getPsiFile(document);
}));
}
use of com.intellij.util.ThrowableRunnable in project intellij-plugins by JetBrains.
the class FlexScopeTest method testTransitiveDependency.
public void testTransitiveDependency() throws Exception {
final Module module2 = FlexTestUtils.createModule(myProject, "module2", getVirtualFile(getBasePath() + "m2"));
final Module module3 = FlexTestUtils.createModule(myProject, "module3", getVirtualFile(getBasePath() + "m3"));
FlexTestUtils.modifyConfigs(myProject, editor -> {
final ModifiableFlexBuildConfiguration bc1 = editor.getConfigurations(myModule)[0];
final ModifiableFlexBuildConfiguration bc2 = editor.getConfigurations(module2)[0];
bc2.setOutputType(OutputType.Library);
final ModifiableFlexBuildConfiguration bc3 = editor.getConfigurations(module3)[0];
bc3.setOutputType(OutputType.Library);
final ModifiableFlexBuildConfiguration bc3a = editor.createConfiguration(module3);
bc3a.setOutputType(OutputType.Library);
bc3a.setName("bc3a");
bc1.getDependencies().getModifiableEntries().add(editor.createBcEntry(bc1.getDependencies(), bc2, null));
bc2.getDependencies().getModifiableEntries().add(editor.createBcEntry(bc2.getDependencies(), bc3, null));
bc2.getDependencies().getModifiableEntries().add(editor.createBcEntry(bc2.getDependencies(), bc3a, null));
});
FlexTestUtils.addFlexLibrary(false, module2, "Flex Lib", true, FlexTestUtils.getTestDataPath("flexlib/"), "flexlib.swc", null, null);
doHighlightingTest("_1");
class Test implements ThrowableRunnable<Exception> {
private final LinkageType myLinkageType1;
private final LinkageType myLinkageType2;
private final String mySuffix;
Test(LinkageType linkageType1, LinkageType linkageType2, String suffix) {
myLinkageType1 = linkageType1;
myLinkageType2 = linkageType2;
mySuffix = suffix;
}
public void run() throws Exception {
FlexTestUtils.modifyConfigs(myProject, editor -> {
final ModifiableFlexBuildConfiguration bc = editor.getConfigurations(module2)[0];
final ModifiableDependencyEntry e1 = bc.getDependencies().getModifiableEntries().get(0);
e1.getDependencyType().setLinkageType(myLinkageType1);
final ModifiableDependencyEntry e2 = bc.getDependencies().getModifiableEntries().get(1);
e2.getDependencyType().setLinkageType(myLinkageType2);
});
doHighlightingTest(mySuffix);
}
}
new Test(LinkageType.Default, LinkageType.Default, "_1").run();
new Test(LinkageType.External, LinkageType.Default, "_1").run();
new Test(LinkageType.Include, LinkageType.Default, "_2").run();
new Test(LinkageType.LoadInRuntime, LinkageType.Default, "_1").run();
new Test(LinkageType.Merged, LinkageType.Default, "_1").run();
new Test(LinkageType.RSL, LinkageType.Default, "_1").run();
new Test(LinkageType.RSL, LinkageType.Include, "_2").run();
new Test(LinkageType.Include, LinkageType.Include, "_2").run();
FlexTestUtils.modifyConfigs(myProject, editor -> {
final ModifiableFlexBuildConfiguration bc2 = editor.getConfigurations(module2)[0];
final ModifiableDependencyEntry entry = bc2.getDependencies().getModifiableEntries().get(2);
assert entry instanceof ModifiableModuleLibraryEntry;
entry.getDependencyType().setLinkageType(LinkageType.Include);
});
new Test(LinkageType.Include, LinkageType.Include, "_3").run();
}
use of com.intellij.util.ThrowableRunnable in project intellij-community by JetBrains.
the class VfsUtilPerformanceTest method testGetParentPerformance.
@Test
public void testGetParentPerformance() throws IOException {
File tempDir = myTempDir.newFolder();
VirtualFile vDir = LocalFileSystem.getInstance().findFileByIoFile(tempDir);
assertNotNull(vDir);
assertTrue(vDir.isDirectory());
int depth = 10;
new WriteCommandAction.Simple(null) {
@Override
protected void run() throws Throwable {
VirtualFile dir = vDir;
for (int i = 0; i < depth; i++) {
dir = dir.createChildDirectory(this, "foo");
}
VirtualFile leafDir = dir;
ThrowableRunnable checkPerformance = new ThrowableRunnable() {
private VirtualFile findRoot(VirtualFile file) {
while (true) {
VirtualFile parent = file.getParent();
if (parent == null) {
return file;
}
file = parent;
}
}
@Override
public void run() throws Throwable {
for (int i = 0; i < 5000000; i++) {
checkRootsEqual();
}
}
private void checkRootsEqual() {
assertEquals(findRoot(vDir), findRoot(leafDir));
}
};
int time = 1200;
PlatformTestUtil.startPerformanceTest("getParent is slow before movement", time, checkPerformance).useLegacyScaling().assertTiming();
VirtualFile dir1 = vDir.createChildDirectory(this, "dir1");
VirtualFile dir2 = vDir.createChildDirectory(this, "dir2");
for (int i = 0; i < 13; i++) {
/*13 is max length with THashMap capacity of 17, we get plenty collisions then*/
dir1.createChildData(this, "a" + i + ".txt").move(this, dir2);
}
PlatformTestUtil.startPerformanceTest("getParent is slow after movement", time, checkPerformance).useLegacyScaling().assertTiming();
}
}.execute();
}
use of com.intellij.util.ThrowableRunnable in project intellij-community by JetBrains.
the class VcsSynchronousProgressWrapper method wrap.
public static boolean wrap(final ThrowableRunnable<VcsException> runnable, final Project project, final String title) {
final VcsException[] exc = new VcsException[1];
final Runnable process = new Runnable() {
@Override
public void run() {
try {
runnable.run();
} catch (VcsException e) {
exc[0] = e;
}
}
};
final boolean notCanceled;
if (ApplicationManager.getApplication().isDispatchThread()) {
notCanceled = ProgressManager.getInstance().runProcessWithProgressSynchronously(process, title, true, project);
} else {
process.run();
notCanceled = true;
}
if (exc[0] != null) {
AbstractVcsHelper.getInstance(project).showError(exc[0], title);
return false;
}
return notCanceled;
}
Aggregations