Search in sources :

Example 41 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class TypeProvider method inferMethodParameters.

@NotNull
private PsiType[] inferMethodParameters(@NotNull GrMethod method) {
    PsiType[] psiTypes = inferredTypes.get(method);
    if (psiTypes != null)
        return psiTypes;
    final GrParameter[] parameters = method.getParameters();
    final TIntArrayList paramInds = new TIntArrayList(parameters.length);
    final PsiType[] types = PsiType.createArray(parameters.length);
    for (int i = 0; i < parameters.length; i++) {
        if (parameters[i].getTypeElementGroovy() == null) {
            paramInds.add(i);
        } else {
            types[i] = parameters[i].getType();
        }
    }
    if (!paramInds.isEmpty()) {
        final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, PsiSubstitutor.EMPTY);
        MethodReferencesSearch.search(method, true).forEach(psiReference -> {
            final PsiElement element = psiReference.getElement();
            final PsiManager manager = element.getManager();
            final GlobalSearchScope resolveScope = element.getResolveScope();
            if (element instanceof GrReferenceExpression) {
                final GrCall call = (GrCall) element.getParent();
                final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, call);
                if (argInfos == null)
                    return true;
                paramInds.forEach(new TIntProcedure() {

                    @Override
                    public boolean execute(int i) {
                        PsiType type = GrClosureSignatureUtil.getTypeByArg(argInfos[i], manager, resolveScope);
                        types[i] = TypesUtil.getLeastUpperBoundNullable(type, types[i], manager);
                        return true;
                    }
                });
            }
            return true;
        });
    }
    paramInds.forEach(new TIntProcedure() {

        @Override
        public boolean execute(int i) {
            if (types[i] == null || types[i] == PsiType.NULL) {
                types[i] = parameters[i].getType();
            }
            return true;
        }
    });
    inferredTypes.put(method, types);
    return types;
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) TIntArrayList(gnu.trove.TIntArrayList) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class MavenGroovyPomScriptType method doPatchResolveScope.

public GlobalSearchScope doPatchResolveScope(@NotNull GroovyFile file, @NotNull GlobalSearchScope baseScope) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return baseScope;
    }
    Project project = module.getProject();
    GlobalSearchScope result = baseScope;
    CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(file.getProject());
    Boolean hasGroovyModuleLib = cachedValuesManager.getCachedValue(file.getProject(), () -> CachedValueProvider.Result.createSingleDependency(hasModuleWithGroovyLibrary(project), ProjectRootManagerEx.getInstanceEx(project)));
    if (hasGroovyModuleLib) {
        final Collection<VirtualFile> files = additionalScopeFiles();
        result = result.uniteWith(new NonClasspathDirectoriesScope(files));
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonClasspathDirectoriesScope(com.intellij.psi.search.NonClasspathDirectoriesScope) Project(com.intellij.openapi.project.Project) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Example 43 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project kotlin by JetBrains.

the class JavaElementFinder method findPackage.

@Override
public PsiPackage findPackage(@NotNull String qualifiedNameString) {
    if (!FqNamesUtilKt.isValidJavaFqName(qualifiedNameString)) {
        return null;
    }
    FqName fqName = new FqName(qualifiedNameString);
    // allScope() because the contract says that the whole project
    GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
    if (lightClassGenerationSupport.packageExists(fqName, allScope)) {
        return new KtLightPackage(psiManager, fqName, allScope);
    }
    return null;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FqName(org.jetbrains.kotlin.name.FqName)

Example 44 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class GroovyStaticImportMethodFix method getMethodsToImport.

@NotNull
private List<PsiMethod> getMethodsToImport() {
    PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myMethodCall.getProject());
    GrMethodCall element = myMethodCall.getElement();
    LOG.assertTrue(element != null);
    GrReferenceExpression reference = getMethodExpression(element);
    LOG.assertTrue(reference != null);
    GrArgumentList argumentList = element.getArgumentList();
    String name = reference.getReferenceName();
    ArrayList<PsiMethod> list = new ArrayList<>();
    if (name == null)
        return list;
    GlobalSearchScope scope = element.getResolveScope();
    PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, 20);
    List<PsiMethod> applicableList = new ArrayList<>();
    for (PsiMethod method : methods) {
        ProgressManager.checkCanceled();
        if (JavaCompletionUtil.isInExcludedPackage(method, false))
            continue;
        if (!method.hasModifierProperty(PsiModifier.STATIC))
            continue;
        PsiFile file = method.getContainingFile();
        if (file instanceof PsiClassOwner && //do not show methods from default package
        !((PsiClassOwner) file).getPackageName().isEmpty() && PsiUtil.isAccessible(element, method)) {
            list.add(method);
            if (PsiUtil.isApplicable(PsiUtil.getArgumentTypes(element, true), method, PsiSubstitutor.EMPTY, element, false)) {
                applicableList.add(method);
            }
        }
    }
    List<PsiMethod> result = applicableList.isEmpty() ? list : applicableList;
    Collections.sort(result, new PsiProximityComparator(argumentList));
    return result;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) ArrayList(java.util.ArrayList) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiProximityComparator(com.intellij.psi.util.proximity.PsiProximityComparator) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class DefaultGroovyShellRunner method hasGroovyWithNeededJars.

public static boolean hasGroovyWithNeededJars(Module module) {
    GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    for (String className : REQUIRED_GROOVY_CLASSES) {
        if (facade.findClass(className, scope) == null) {
            return false;
        }
    }
    return true;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)485 Project (com.intellij.openapi.project.Project)145 NotNull (org.jetbrains.annotations.NotNull)134 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 Module (com.intellij.openapi.module.Module)101 Nullable (org.jetbrains.annotations.Nullable)78 PsiClass (com.intellij.psi.PsiClass)53 ArrayList (java.util.ArrayList)37 PsiFile (com.intellij.psi.PsiFile)32 PsiElement (com.intellij.psi.PsiElement)31 THashSet (gnu.trove.THashSet)22 SearchScope (com.intellij.psi.search.SearchScope)19 PsiDirectory (com.intellij.psi.PsiDirectory)18 ContainerUtil (com.intellij.util.containers.ContainerUtil)18 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)17 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)17 com.intellij.psi (com.intellij.psi)17 List (java.util.List)17 StringUtil (com.intellij.openapi.util.text.StringUtil)15 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)15