Search in sources :

Example 51 with Function

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

the class PySkeletonRefresher method calculateExtraSysPath.

private static String calculateExtraSysPath(@NotNull final Sdk sdk, @Nullable final String skeletonsPath) {
    final File skeletons = skeletonsPath != null ? new File(skeletonsPath) : null;
    final VirtualFile userSkeletonsDir = PyUserSkeletonsUtil.getUserSkeletonsDirectory();
    final File userSkeletons = userSkeletonsDir != null ? new File(userSkeletonsDir.getPath()) : null;
    final VirtualFile remoteSourcesDir = PySdkUtil.findAnyRemoteLibrary(sdk);
    final File remoteSources = remoteSourcesDir != null ? new File(remoteSourcesDir.getPath()) : null;
    final List<VirtualFile> paths = new ArrayList<>();
    paths.addAll(Arrays.asList(sdk.getRootProvider().getFiles(OrderRootType.CLASSES)));
    paths.addAll(BuildoutFacet.getExtraPathForAllOpenModules());
    return Joiner.on(File.pathSeparator).join(ContainerUtil.mapNotNull(paths, (Function<VirtualFile, Object>) file -> {
        if (file.isInLocalFileSystem()) {
            final File canonicalFile = new File(file.getPath());
            if (canonicalFile.exists() && !FileUtil.filesEqual(canonicalFile, skeletons) && !FileUtil.filesEqual(canonicalFile, userSkeletons) && !FileUtil.filesEqual(canonicalFile, remoteSources)) {
                return file.getPath();
            }
        }
        return null;
    }));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Function(com.intellij.util.Function) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 52 with Function

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

the class Import method onlyCallDefinitionClauseCallFilter.

@NotNull
private static Function<Call, Boolean> onlyCallDefinitionClauseCallFilter(PsiElement element) {
    final Map<String, List<Integer>> aritiesByName = aritiesByNameFromNameByArityKeywordList(element);
    return new Function<Call, Boolean>() {

        @Override
        public Boolean fun(Call call) {
            Pair<String, IntRange> callNameArityRange = nameArityRange(call);
            boolean include = false;
            if (callNameArityRange != null) {
                String callName = callNameArityRange.first;
                if (callName != null) {
                    List<Integer> arities = aritiesByName.get(callName);
                    if (arities != null) {
                        IntRange callArityRange = callNameArityRange.second;
                        for (int arity : arities) {
                            if (callArityRange.containsInteger(arity)) {
                                include = true;
                                break;
                            }
                        }
                    }
                }
            }
            return include;
        }
    };
}
Also used : Function(com.intellij.util.Function) Call(org.elixir_lang.psi.call.Call) IntRange(org.apache.commons.lang.math.IntRange) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with Function

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

the class CallDefinitionClause method implicitImports.

private boolean implicitImports(@NotNull PsiElement element, @NotNull ResolveState state) {
    Project project = element.getProject();
    boolean keepProcessing = org.elixir_lang.reference.Module.forEachNavigationElement(project, KERNEL, new Function<PsiElement, Boolean>() {

        @Override
        public Boolean fun(PsiElement navigationElement) {
            boolean keepProcessingNavigationElements = true;
            if (navigationElement instanceof Call) {
                Call modular = (Call) navigationElement;
                keepProcessingNavigationElements = Modular.callDefinitionClauseCallWhile(modular, new Function<Call, Boolean>() {

                    @Override
                    public Boolean fun(Call callDefinitionClause) {
                        return executeOnCallDefinitionClause(callDefinitionClause, state);
                    }
                });
            }
            return keepProcessingNavigationElements;
        }
    });
    // the implicit `import Kernel.SpecialForms`
    if (keepProcessing) {
        ResolveState modularCanonicalNameState = state.put(MODULAR_CANONICAL_NAME, KERNEL_SPECIAL_FORMS);
        keepProcessing = org.elixir_lang.reference.Module.forEachNavigationElement(project, KERNEL_SPECIAL_FORMS, new Function<PsiElement, Boolean>() {

            @Override
            public Boolean fun(PsiElement navigationElement) {
                boolean keepProcessingNavigationElements = true;
                if (navigationElement instanceof Call) {
                    Call modular = (Call) navigationElement;
                    keepProcessingNavigationElements = Modular.callDefinitionClauseCallWhile(modular, new Function<Call, Boolean>() {

                        @Override
                        public Boolean fun(Call callDefinitionClause) {
                            return executeOnCallDefinitionClause(callDefinitionClause, modularCanonicalNameState);
                        }
                    });
                }
                return keepProcessingNavigationElements;
            }
        });
    }
    return keepProcessing;
}
Also used : Project(com.intellij.openapi.project.Project) Call(org.elixir_lang.psi.call.Call) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) ResolveState(com.intellij.psi.ResolveState)

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