Search in sources :

Example 1 with Function

use of com.intellij.util.Function in project intellij-elixir by KronicDeth.

the class CallDefinitionClause method execute.

/*
     * Private Instance Methods
     */
private boolean execute(@NotNull Call element, @NotNull final ResolveState state) {
    boolean keepProcessing = true;
    if (org.elixir_lang.structure_view.element.CallDefinitionClause.is(element)) {
        keepProcessing = executeOnCallDefinitionClause(element, state);
    } else if (Import.is(element)) {
        final ResolveState importState = state.put(IMPORT_CALL, element);
        try {
            Import.callDefinitionClauseCallWhile(element, new Function<Call, Boolean>() {

                @Override
                public Boolean fun(Call callDefinitionClause) {
                    return executeOnCallDefinitionClause(callDefinitionClause, importState);
                }
            });
        } catch (StackOverflowError stackOverflowError) {
            Logger.error(CallDefinitionClause.class, "StackOverflowError while processing import", element);
        }
    } else if (Module.is(element)) {
        Call[] childCalls = macroChildCalls(element);
        if (childCalls != null) {
            for (Call childCall : childCalls) {
                if (!execute(childCall, state)) {
                    break;
                }
            }
        }
        // Only check MultiResolve.keepProcessing at the end of a Module to all multiple arities
        keepProcessing = keepProcessing();
        if (keepProcessing) {
            // the implicit `import Kernel` and `import Kernel.SpecialForms`
            keepProcessing = implicitImports(element, state);
        }
    }
    return keepProcessing;
}
Also used : Function(com.intellij.util.Function) Call(org.elixir_lang.psi.call.Call) ResolveState(com.intellij.psi.ResolveState)

Example 2 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class HgVFSListener method performAdding.

@Override
protected void performAdding(final Collection<VirtualFile> addedFiles, final Map<VirtualFile, VirtualFile> copyFromMap) {
    (new Task.ConditionalModal(myProject, HgVcsMessages.message("hg4idea.add.progress"), false, VcsConfiguration.getInstance(myProject).getAddRemoveOption()) {

        @Override
        public void run(@NotNull ProgressIndicator aProgressIndicator) {
            final ArrayList<VirtualFile> adds = new ArrayList<>();
            // from -> to
            final HashMap<VirtualFile, VirtualFile> copies = new HashMap<>();
            //delete unversioned and ignored files from copy source
            LOG.assertTrue(myProject != null, "Project is null");
            Collection<VirtualFile> unversionedAndIgnoredFiles = new ArrayList<>();
            final Map<VirtualFile, Collection<VirtualFile>> sortedSourceFilesByRepos = HgUtil.sortByHgRoots(myProject, copyFromMap.values());
            HgStatusCommand statusCommand = new HgStatusCommand.Builder(false).unknown(true).ignored(true).build(myProject);
            for (Map.Entry<VirtualFile, Collection<VirtualFile>> entry : sortedSourceFilesByRepos.entrySet()) {
                Set<HgChange> changes = statusCommand.executeInCurrentThread(entry.getKey(), ContainerUtil.map(entry.getValue(), new Function<VirtualFile, FilePath>() {

                    @Override
                    public FilePath fun(VirtualFile virtualFile) {
                        return VcsUtil.getFilePath(virtualFile);
                    }
                }));
                for (HgChange change : changes) {
                    unversionedAndIgnoredFiles.add(change.afterFile().toFilePath().getVirtualFile());
                }
            }
            copyFromMap.values().removeAll(unversionedAndIgnoredFiles);
            // separate adds from copies
            for (VirtualFile file : addedFiles) {
                if (file.isDirectory()) {
                    continue;
                }
                final VirtualFile copyFrom = copyFromMap.get(file);
                if (copyFrom != null) {
                    copies.put(copyFrom, file);
                } else {
                    adds.add(file);
                }
            }
            // add for all files at once
            if (!adds.isEmpty()) {
                new HgAddCommand(myProject).executeInCurrentThread(adds);
            }
            // copy needs to be run for each file separately
            if (!copies.isEmpty()) {
                for (Map.Entry<VirtualFile, VirtualFile> copy : copies.entrySet()) {
                    new HgCopyCommand(myProject).executeInCurrentThread(copy.getKey(), copy.getValue());
                }
            }
            for (VirtualFile file : addedFiles) {
                dirtyScopeManager.fileDirty(file);
            }
        }
    }).queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) Function(com.intellij.util.Function) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 3 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class YouTrackCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull CompletionResultSet result) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(DebugUtil.psiToString(parameters.getOriginalFile(), true));
    }
    super.fillCompletionVariants(parameters, result);
    PsiFile file = parameters.getOriginalFile();
    final YouTrackIntellisense intellisense = file.getUserData(YouTrackIntellisense.INTELLISENSE_KEY);
    if (intellisense == null) {
        return;
    }
    final Application application = ApplicationManager.getApplication();
    Future<List<CompletionItem>> future = application.executeOnPooledThread(() -> intellisense.fetchCompletion(parameters.getOriginalFile().getText(), parameters.getOffset()));
    try {
        final List<CompletionItem> suggestions = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
        // actually backed by original CompletionResultSet
        result = result.withPrefixMatcher(extractPrefix(parameters)).caseInsensitive();
        result.addAllElements(ContainerUtil.map(suggestions, (Function<CompletionItem, LookupElement>) item -> LookupElementBuilder.create(item, item.getOption()).withTypeText(item.getDescription(), true).withInsertHandler(INSERT_HANDLER).withBoldness(item.getStyleClass().equals("keyword"))));
    } catch (Exception ignored) {
        //noinspection InstanceofCatchParameter
        if (ignored instanceof TimeoutException) {
            LOG.debug(String.format("YouTrack request took more than %d ms to complete", TIMEOUT));
        }
        LOG.debug(ignored);
    }
}
Also used : Function(com.intellij.util.Function) YouTrackIntellisense(com.intellij.tasks.youtrack.YouTrackIntellisense) CompletionItem(com.intellij.tasks.youtrack.YouTrackIntellisense.CompletionItem) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) Application(com.intellij.openapi.application.Application) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class TestsPattern method createSearchingForTestsTask.

@Override
public SearchForTestsTask createSearchingForTestsTask() {
    final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
    final Project project = getConfiguration().getProject();
    final Set<String> classNames = new LinkedHashSet<>();
    for (String className : data.getPatterns()) {
        final PsiClass psiClass = getTestClass(project, className);
        if (psiClass != null && JUnitUtil.isTestClass(psiClass)) {
            classNames.add(className);
        }
    }
    if (classNames.size() == data.getPatterns().size()) {
        return new SearchForTestsTask(project, myServerSocket) {

            @Override
            protected void search() throws ExecutionException {
                final Function<String, String> nameFunction = StringUtil.isEmpty(data.METHOD_NAME) ? FunctionUtil.<String>id() : (Function<String, String>) className -> className;
                addClassesListToJavaParameters(classNames, nameFunction, "", false, getJavaParameters());
            }

            @Override
            protected void onFound() {
            }
        };
    }
    return super.createSearchingForTestsTask();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) ExecutionException(com.intellij.execution.ExecutionException) StringUtil(com.intellij.openapi.util.text.StringUtil) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) JavaExecutionUtil(com.intellij.execution.JavaExecutionUtil) Nullable(org.jetbrains.annotations.Nullable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RefactoringElementListenerComposite(com.intellij.refactoring.listeners.RefactoringElementListenerComposite) Function(com.intellij.util.Function) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) Project(com.intellij.openapi.project.Project) com.intellij.psi(com.intellij.psi) FunctionUtil(com.intellij.util.FunctionUtil) CantRunException(com.intellij.execution.CantRunException) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) Module(com.intellij.openapi.module.Module) LinkedHashSet(java.util.LinkedHashSet) Project(com.intellij.openapi.project.Project) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask)

Example 5 with Function

use of com.intellij.util.Function in project kotlin by JetBrains.

the class ExpressionCodegen method generateBlock.

private StackValueWithLeaveTask generateBlock(@NotNull List<KtExpression> statements, boolean isStatement, @Nullable Label labelBeforeLastExpression, @Nullable final Label labelBlockEnd) {
    final Label blockEnd = labelBlockEnd != null ? labelBlockEnd : new Label();
    final List<Function<StackValue, Void>> leaveTasks = Lists.newArrayList();
    @Nullable StackValue blockResult = null;
    for (Iterator<KtExpression> iterator = statements.iterator(); iterator.hasNext(); ) {
        KtExpression possiblyLabeledStatement = iterator.next();
        KtElement statement = KtPsiUtil.safeDeparenthesize(possiblyLabeledStatement);
        if (statement instanceof KtNamedDeclaration) {
            KtNamedDeclaration declaration = (KtNamedDeclaration) statement;
            if (KtPsiUtil.isScriptDeclaration(declaration)) {
                continue;
            }
        }
        putDescriptorIntoFrameMap(statement);
        boolean isExpression = !iterator.hasNext() && !isStatement;
        if (isExpression && labelBeforeLastExpression != null) {
            v.mark(labelBeforeLastExpression);
        }
        // Note that this statementResult value is potentially unused (in case of handleResult coroutine call)
        // It's supposed here that no bytecode is emitted until 'put' call on relevant StackValue object
        StackValue statementResult = isExpression ? gen(possiblyLabeledStatement) : genStatement(possiblyLabeledStatement);
        if (!iterator.hasNext()) {
            blockResult = statementResult;
        } else {
            statementResult.put(Type.VOID_TYPE, v);
        }
        addLeaveTaskToRemoveDescriptorFromFrameMap(statement, blockEnd, leaveTasks);
    }
    if (statements.isEmpty()) {
        blockResult = StackValue.none();
    }
    assert blockResult != null : "Block result should be initialized in the loop or the condition above";
    return new StackValueWithLeaveTask(blockResult, new Function1<StackValue, Unit>() {

        @Override
        public Unit invoke(StackValue value) {
            if (labelBlockEnd == null) {
                v.mark(blockEnd);
            }
            for (Function<StackValue, Void> task : Lists.reverse(leaveTasks)) {
                task.fun(value);
            }
            return Unit.INSTANCE;
        }
    });
}
Also used : Label(org.jetbrains.org.objectweb.asm.Label) Unit(kotlin.Unit) Function(com.intellij.util.Function) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Function (com.intellij.util.Function)53 NotNull (org.jetbrains.annotations.NotNull)32 Nullable (org.jetbrains.annotations.Nullable)24 Project (com.intellij.openapi.project.Project)23 Logger (com.intellij.openapi.diagnostic.Logger)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 List (java.util.List)15 StringUtil (com.intellij.openapi.util.text.StringUtil)12 Module (com.intellij.openapi.module.Module)11 com.intellij.psi (com.intellij.psi)11 java.util (java.util)10 ArrayList (java.util.ArrayList)10 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 ApplicationManager (com.intellij.openapi.application.ApplicationManager)8 PsiElement (com.intellij.psi.PsiElement)7 File (java.io.File)7 Messages (com.intellij.openapi.ui.Messages)6 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)6 IOException (java.io.IOException)6