use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class ConfigurationUtil method findAllTestClasses.
// return true if there is JUnit4 test
public static boolean findAllTestClasses(final TestClassFilter testClassFilter, @Nullable final Module module, final Set<PsiClass> found) {
final PsiManager manager = testClassFilter.getPsiManager();
final Project project = manager.getProject();
GlobalSearchScope projectScopeWithoutLibraries = GlobalSearchScope.projectScope(project);
final GlobalSearchScope scope = projectScopeWithoutLibraries.intersectWith(testClassFilter.getScope());
final PsiClass base = testClassFilter.getBase();
if (base != null) {
ClassInheritorsSearch.search(base, scope, true, true, false).forEach(new ReadActionProcessor<PsiClass>() {
@Override
public boolean processInReadAction(PsiClass aClass) {
if (testClassFilter.isAccepted(aClass))
found.add(aClass);
return true;
}
});
}
// classes having suite() method
final PsiMethod[] suiteMethods = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod[]>() {
public PsiMethod[] compute() {
return PsiShortNamesCache.getInstance(project).getMethodsByName(JUnitUtil.SUITE_METHOD_NAME, scope);
}
});
for (final PsiMethod method : suiteMethods) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null)
return;
if (containingClass instanceof PsiAnonymousClass)
return;
if (containingClass.hasModifierProperty(PsiModifier.ABSTRACT))
return;
if (containingClass.getContainingClass() != null && !containingClass.hasModifierProperty(PsiModifier.STATIC))
return;
if (JUnitUtil.isSuiteMethod(method) && testClassFilter.isAccepted(containingClass)) {
found.add(containingClass);
}
});
}
Set<PsiClass> processed = ContainerUtil.newHashSet();
boolean hasJunit4 = addAnnotatedMethodsAnSubclasses(scope, testClassFilter, module, found, processed, JUnitUtil.TEST_ANNOTATION, manager.getProject());
hasJunit4 |= addAnnotatedMethodsAnSubclasses(scope, testClassFilter, module, found, processed, JUnitUtil.RUN_WITH, manager.getProject());
return hasJunit4;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class DuplicatePropertyInspection method checkFile.
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextBase context, final RefManager refManager, final ProblemDescriptionsProcessor processor) {
if (!(file instanceof PropertiesFile))
return;
if (!context.isToCheckFile(file, this) || SuppressionUtil.inspectionResultSuppressed(file, this))
return;
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
final PropertiesFile propertiesFile = (PropertiesFile) file;
final List<IProperty> properties = propertiesFile.getProperties();
Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null)
return;
final GlobalSearchScope scope = CURRENT_FILE ? GlobalSearchScope.fileScope(file) : MODULE_WITH_DEPENDENCIES ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(file.getProject());
final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator();
final ProgressIndicator progress = ProgressWrapper.wrap(original);
ProgressManager.getInstance().runProcess(() -> {
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, property -> {
if (original != null) {
if (original.isCanceled())
return false;
original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey()));
}
processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope);
processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope);
return true;
}))
throw new ProcessCanceledException();
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
Map<String, Set<String>> keyToDifferentValues = new HashMap<>();
if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original);
}
if (CHECK_DUPLICATE_VALUES)
prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original);
if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original);
}
if (!problemDescriptors.isEmpty()) {
processor.addProblemElement(refManager.getReference(file), problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]));
}
}, progress);
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CreateClassToBindFix method createBoundFields.
private void createBoundFields(final PsiClass formClass) throws IncorrectOperationException {
final Module module = myEditor.getRootContainer().getModule();
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
final PsiManager psiManager = PsiManager.getInstance(myEditor.getProject());
final Ref<IncorrectOperationException> exception = new Ref<>();
FormEditingUtil.iterate(myEditor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {
public boolean visit(final IComponent component) {
if (component.getBinding() != null) {
final PsiClass fieldClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
if (fieldClass != null) {
PsiType fieldType = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createType(fieldClass);
try {
PsiField field = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createField(component.getBinding(), fieldType);
formClass.add(field);
} catch (IncorrectOperationException e) {
exception.set(e);
return false;
}
}
}
return true;
}
});
if (!exception.isNull()) {
throw exception.get();
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PyJavaImportCandidateProvider method addImportCandidates.
@Override
public void addImportCandidates(PsiReference reference, String name, AutoImportQuickFix quickFix) {
final PsiElement element = reference.getElement();
final Project project = element.getProject();
Module module = ModuleUtil.findModuleForPsiElement(element);
GlobalSearchScope scope = module == null ? ProjectScope.getAllScope(project) : module.getModuleWithDependenciesAndLibrariesScope(false);
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
final PsiClass[] classesByName = cache.getClassesByName(name, scope);
for (PsiClass psiClass : classesByName) {
final String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null) {
continue;
}
final QualifiedName packageQName = QualifiedName.fromDottedString(qualifiedName).removeLastComponent();
quickFix.addImport(psiClass, psiClass.getContainingFile(), packageQName);
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PyJavaPackageType method getCompletionVariants.
@Override
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
List<Object> variants = new ArrayList<>();
final GlobalSearchScope scope = getScope(location.getProject());
final PsiClass[] classes = myPackage.getClasses(scope);
for (PsiClass psiClass : classes) {
variants.add(LookupElementBuilder.create(psiClass).withIcon(psiClass.getIcon(0)));
}
final PsiPackage[] subPackages = myPackage.getSubPackages(scope);
for (PsiPackage subPackage : subPackages) {
variants.add(LookupElementBuilder.create(subPackage).withIcon(subPackage.getIcon(0)));
}
return ArrayUtil.toObjectArray(variants);
}
Aggregations