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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations