use of com.intellij.psi.search.GlobalSearchScope in project qi4j-sdk by Qi4j.
the class Qi4jSideEffectUtil method getSideEffectOfClass.
/**
* @param searchContext Search context.
* @return {@code SideEffectOf} class given the search context. {@code null} if not found.
* @since 0.1
*/
@Nullable
public static PsiClass getSideEffectOfClass(@NotNull PsiElement searchContext) {
Project project = searchContext.getProject();
GlobalSearchScope searchScope = determineSearchScope(searchContext);
return getSideEffectOfClass(project, searchScope);
}
use of com.intellij.psi.search.GlobalSearchScope in project qi4j-sdk by Qi4j.
the class SideEffectsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @SideEffects, ignore
PsiAnnotation sideEffectsAnnotation = getSideEffectsAnnotation(psiClass);
if (sideEffectsAnnotation == null) {
return null;
}
// If @SideEffects declared in class, suggest remove @SideEffects annotation
if (!psiClass.isInterface()) {
String message = message("side.effects.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveSideEffectsAnnotationFix fix = new RemoveSideEffectsAnnotationFix(sideEffectsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @SideEffects annotation is empty, ignore
List<PsiAnnotationMemberValue> sideEffectsAnnotationValue = getSideEffectsAnnotationValue(sideEffectsAnnotation);
if (sideEffectsAnnotationValue.isEmpty()) {
return null;
}
// If SideEffectOf is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass sideEffectOfClass = Qi4jSideEffectUtil.getGenericSideEffectClass(project, searchScope);
if (sideEffectOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue sideEffectClassReferenceWrapper : sideEffectsAnnotationValue) {
PsiJavaCodeReferenceElement sideEffectClassReference = getSideEffectClassReference(sideEffectClassReferenceWrapper);
// If it's not a class reference, ignore
if (sideEffectClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass sideEffectClass = (PsiClass) sideEffectClassReference.resolve();
if (sideEffectClass == null) {
continue;
}
// If side effect class does not inherit SideEffectOf class, suggest remove that reference.
if (!sideEffectClass.isInheritor(sideEffectOfClass, true)) {
String message = Qi4jResourceBundle.message("side.effects.annotation.declared.correctly.error.side.effect.does.not.extend.side.effect.of", sideEffectClass.getQualifiedName());
RemoveAnnotationValueFix fix = new RemoveAnnotationValueFix(sideEffectClassReferenceWrapper, sideEffectClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectClassReferenceWrapper, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic side effect
// TODO: Test whether it is a specific side effect
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.search.GlobalSearchScope in project AndroidPermissionsUsage by RomainPiel.
the class AndroidSDKScope method getAllExceptScope.
public static GlobalSearchScope getAllExceptScope(Module module) {
Project project = module.getProject();
GlobalSearchScope cached = project.getUserData(ALL_EXCEPT_ANDROID_SDK_SCOPE_KEY);
if (cached != null) {
return cached;
} else {
init(module);
return project.getUserData(ALL_EXCEPT_ANDROID_SDK_SCOPE_KEY);
}
}
use of com.intellij.psi.search.GlobalSearchScope in project android-butterknife-zelezny by avast.
the class Utils method resolveLayoutResourceFile.
private static PsiFile resolveLayoutResourceFile(PsiElement element, Project project, String name) {
// restricting the search to the current module - searching the whole project could return wrong layouts
Module module = ModuleUtil.findModuleForPsiElement(element);
PsiFile[] files = null;
if (module != null) {
// first omit libraries, it might cause issues like (#103)
GlobalSearchScope moduleScope = module.getModuleWithDependenciesScope();
files = FilenameIndex.getFilesByName(project, name, moduleScope);
if (files == null || files.length <= 0) {
// now let's do a fallback including the libraries
moduleScope = module.getModuleWithDependenciesAndLibrariesScope(false);
files = FilenameIndex.getFilesByName(project, name, moduleScope);
}
}
if (files == null || files.length <= 0) {
// fallback to search through the whole project
// useful when the project is not properly configured - when the resource directory is not configured
files = FilenameIndex.getFilesByName(project, name, new EverythingGlobalScope(project));
if (files.length <= 0) {
//no matching files
return null;
}
}
// we need to resolve R class properly and find the proper layout for the R class
for (PsiFile file : files) {
log.info("Resolved layout resource file for name [" + name + "]: " + file.getVirtualFile());
}
return files[0];
}
use of com.intellij.psi.search.GlobalSearchScope in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestFunctionCompletionProvider method collectAllTestNames.
@NotNull
private static Set<String> collectAllTestNames(@NotNull Collection<String> names, @NotNull Project project, @NotNull GoFile file) {
Set<String> result = ContainerUtil.newHashSet();
GlobalSearchScope packageScope = GoPackageUtil.packageScope(file);
GlobalSearchScope scope = new GoUtil.TestsScope(packageScope);
IdFilter idFilter = GoIdFilter.getFilesFilter(packageScope);
for (String name : names) {
if (GoTestFunctionType.fromName(name) != null) {
GoFunctionIndex.process(name, project, scope, idFilter, declaration -> {
result.add(name);
return false;
});
}
}
return result;
}
Aggregations