use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class SvnCheckoutProvider method doImport.
public static void doImport(final Project project, final File target, final SVNURL url, final Depth depth, final boolean includeIgnored, final String message) {
final Ref<String> errorMessage = new Ref<>();
final SvnVcs vcs = SvnVcs.getInstance(project);
final String targetPath = FileUtil.toSystemIndependentName(target.getAbsolutePath());
ExclusiveBackgroundVcsAction.run(project, () -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(project, FileIndexFacade.class);
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
try {
progressIndicator.setText(message("progress.text.import", target.getAbsolutePath()));
final VirtualFile targetVf = SvnUtil.getVirtualFile(targetPath);
if (targetVf == null) {
errorMessage.set("Can not find file: " + targetPath);
} else {
final boolean isInContent = getApplication().runReadAction((Computable<Boolean>) () -> facade.isInContent(targetVf));
CommitEventHandler handler = new IdeaCommitHandler(progressIndicator);
boolean useFileFilter = !project.isDefault() && isInContent;
ISVNCommitHandler commitHandler = useFileFilter ? new MyFilter(LocalFileSystem.getInstance(), new SvnExcludingIgnoredOperation.Filter(project)) : null;
long revision = vcs.getFactoryFromSettings().createImportClient().doImport(target, url, depth, message, includeIgnored, handler, commitHandler);
if (revision > 0) {
StatusBar.Info.set(message("status.text.comitted.revision", revision), project);
}
}
} catch (VcsException e) {
errorMessage.set(e.getMessage());
}
}, message("message.title.import"), true, project));
if (!errorMessage.isNull()) {
showErrorDialog(message("message.text.cannot.import", errorMessage.get()), message("message.title.import"));
}
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class TestNGTestObject method collectDependsOnMethods.
private static void collectDependsOnMethods(final Map<PsiClass, Map<PsiMethod, List<String>>> results, final Set<PsiMember> alreadyMarkedToBeChecked, final Set<PsiMember> membersToCheckNow, final PsiMethod[] methods, final PsiClass... classes) {
final PsiClass[] psiClasses;
if (methods != null && methods.length > 0) {
final Set<PsiClass> containingClasses = new LinkedHashSet<>();
for (final PsiMethod method : methods) {
containingClasses.add(ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
@Override
public PsiClass compute() {
return method.getContainingClass();
}
}));
}
psiClasses = containingClasses.toArray(new PsiClass[containingClasses.size()]);
} else {
psiClasses = classes;
}
for (final PsiClass containingClass : psiClasses) {
final Set<String> testMethodDependencies = new LinkedHashSet<>();
final HashMap<String, Collection<String>> valuesMap = new HashMap<>();
valuesMap.put("dependsOnMethods", testMethodDependencies);
TestNGUtil.collectAnnotationValues(valuesMap, methods, containingClass);
if (!testMethodDependencies.isEmpty()) {
ApplicationManager.getApplication().runReadAction(() -> {
final Project project = containingClass.getProject();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
for (String dependency : testMethodDependencies) {
final String className = StringUtil.getPackageName(dependency);
final String methodName = StringUtil.getShortName(dependency);
if (StringUtil.isEmpty(className)) {
checkClassMethods(methodName, containingClass, alreadyMarkedToBeChecked, membersToCheckNow, results);
} else {
final PsiClass aClass = psiFacade.findClass(className, containingClass.getResolveScope());
if (aClass != null) {
checkClassMethods(methodName, aClass, alreadyMarkedToBeChecked, membersToCheckNow, results);
}
}
}
});
}
}
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class YAMLScalarConversionTest method doTest.
private void doTest(Class<? extends YAMLScalar>... unsupportedClasses) {
final PsiFile file = myFixture.configureByFile("sampleDocument.yml");
Collection<YAMLScalar> scalars = PsiTreeUtil.collectElementsOfType(file, YAMLScalar.class);
assertEquals(5, scalars.size());
final String text;
try {
text = FileUtil.loadFile(new File(getTestDataPath() + getTestName(true) + ".txt"), true);
} catch (IOException e) {
fail(e.toString());
return;
}
for (YAMLScalar scalar : scalars) {
boolean isUnsupported = ((Computable<Boolean>) () -> {
for (Class<? extends YAMLScalar> aClass : unsupportedClasses) {
if (aClass == scalar.getClass()) {
return true;
}
}
return false;
}).compute();
final ElementManipulator<YAMLScalar> manipulator = ElementManipulators.getManipulator(scalar);
assertNotNull(manipulator);
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
final YAMLScalar newElement = manipulator.handleContentChange(scalar, text);
assertEquals(isUnsupported + ";" + newElement.getClass() + ";" + scalar.getClass(), isUnsupported, newElement.getClass() != scalar.getClass());
assertEquals("Failed at " + scalar.getClass() + " (became " + newElement.getClass() + "): ", text, newElement.getTextValue());
});
}
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class RegExResponseHandler method parseIssues.
@NotNull
@Override
public Task[] parseIssues(@NotNull String response, int max) throws Exception {
final List<String> placeholders = getPlaceholders(myTaskRegex);
if (!placeholders.contains(ID_PLACEHOLDER) || !placeholders.contains(SUMMARY_PLACEHOLDER)) {
throw new Exception("Incorrect Task Pattern");
}
final String taskPatternWithoutPlaceholders = myTaskRegex.replaceAll("\\{.+?\\}", "");
Matcher matcher = Pattern.compile(taskPatternWithoutPlaceholders, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE | Pattern.CANON_EQ).matcher(response);
List<Task> tasks = new ArrayList<>();
for (int i = 0; i < max && matcher.find(); i++) {
String id = matcher.group(placeholders.indexOf(ID_PLACEHOLDER) + 1);
String summary = matcher.group(placeholders.indexOf(SUMMARY_PLACEHOLDER) + 1);
// temporary workaround to make AssemblaIntegrationTestPass
final String finalSummary = summary;
summary = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
XmlElementFactory factory = XmlElementFactory.getInstance(ProjectManager.getInstance().getDefaultProject());
XmlTag text = factory.createTagFromText("<a>" + finalSummary + "</a>");
String trimmedText = text.getValue().getTrimmedText();
return XmlUtil.decode(trimmedText);
}
});
tasks.add(new GenericTask(id, summary, myRepository));
}
return tasks.toArray(new Task[tasks.size()]);
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class GroovyTestGenerator method generateTest.
@Nullable
@Override
public PsiElement generateTest(final Project project, final CreateTestDialog d) {
return WriteAction.compute(() -> {
final PsiClass test = (PsiClass) PostprocessReformattingAspect.getInstance(project).postponeFormattingInside((Computable<PsiElement>) () -> {
try {
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
GrTypeDefinition targetClass = CreateClassActionBase.createClassByType(d.getTargetDirectory(), d.getClassName(), PsiManager.getInstance(project), null, GroovyTemplates.GROOVY_CLASS, true);
if (targetClass == null)
return null;
addSuperClass(targetClass, project, d.getSuperClassName());
Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.getContainingFile(), targetClass);
addTestMethods(editor, targetClass, d.getSelectedTestFrameworkDescriptor(), d.getSelectedMethods(), d.shouldGeneratedBefore(), d.shouldGeneratedAfter());
return targetClass;
} catch (IncorrectOperationException e1) {
showErrorLater(project, d.getClassName());
return null;
}
});
if (test == null)
return null;
JavaCodeStyleManager.getInstance(test.getProject()).shortenClassReferences(test);
CodeStyleManager.getInstance(project).reformat(test);
return test;
});
}
Aggregations