Search in sources :

Example 6 with GlobalSearchScope

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);
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GlobalSearchScope

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()]);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) LinkedList(java.util.LinkedList) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue)

Example 8 with GlobalSearchScope

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 9 with GlobalSearchScope

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];
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) EverythingGlobalScope(com.intellij.psi.search.EverythingGlobalScope) Module(com.intellij.openapi.module.Module)

Example 10 with GlobalSearchScope

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;
}
Also used : IdFilter(com.intellij.util.indexing.IdFilter) GoIdFilter(com.goide.stubs.index.GoIdFilter) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

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