Search in sources :

Example 1 with Computable

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"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaCommitHandler(org.jetbrains.idea.svn.checkin.IdeaCommitHandler) ISVNCommitHandler(org.tmatesoft.svn.core.wc.ISVNCommitHandler) CommitEventHandler(org.jetbrains.idea.svn.checkin.CommitEventHandler) SvnVcs(org.jetbrains.idea.svn.SvnVcs) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SvnExcludingIgnoredOperation(org.jetbrains.idea.svn.actions.SvnExcludingIgnoredOperation) VcsException(com.intellij.openapi.vcs.VcsException) Computable(com.intellij.openapi.util.Computable) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 2 with Computable

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);
                        }
                    }
                }
            });
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) Computable(com.intellij.openapi.util.Computable)

Example 3 with Computable

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());
        });
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) YAMLScalar(org.jetbrains.yaml.psi.YAMLScalar) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Computable(com.intellij.openapi.util.Computable)

Example 4 with Computable

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()]);
}
Also used : Task(com.intellij.tasks.Task) Matcher(java.util.regex.Matcher) XmlElementFactory(com.intellij.psi.XmlElementFactory) ArrayList(java.util.ArrayList) Computable(com.intellij.openapi.util.Computable) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Computable

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;
    });
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor) Computable(com.intellij.openapi.util.Computable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Computable (com.intellij.openapi.util.Computable)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 NotNull (org.jetbrains.annotations.NotNull)12 Nullable (org.jetbrains.annotations.Nullable)12 Project (com.intellij.openapi.project.Project)11 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 Task (com.intellij.openapi.progress.Task)6 PsiFile (com.intellij.psi.PsiFile)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 IncorrectOperationException (com.intellij.util.IncorrectOperationException)6 IOException (java.io.IOException)5 Application (com.intellij.openapi.application.Application)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 Editor (com.intellij.openapi.editor.Editor)4 Module (com.intellij.openapi.module.Module)4 File (java.io.File)4 Ref (com.intellij.openapi.util.Ref)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 PsiElement (com.intellij.psi.PsiElement)3 UsageInfo (com.intellij.usageView.UsageInfo)3