use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class JavaFxPsiUtil method computeInjectedControllerClass.
@Nullable
private static CachedValueProvider.Result<PsiClass> computeInjectedControllerClass(PsiFile containingFile) {
return ourGuard.doPreventingRecursion(containingFile, true, () -> {
final Project project = containingFile.getProject();
final Ref<PsiClass> injectedController = new Ref<>();
final PsiClass fxmlLoader = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonNames.JAVAFX_FXML_FXMLLOADER, GlobalSearchScope.allScope(project));
if (fxmlLoader != null) {
final PsiMethod[] injectControllerMethods = fxmlLoader.findMethodsByName("setController", false);
if (injectControllerMethods.length == 1) {
final GlobalSearchScope globalSearchScope = GlobalSearchScope.getScopeRestrictedByFileTypes(containingFile.getResolveScope(), StdFileTypes.JAVA);
final VirtualFile[] virtualFiles = CacheManager.SERVICE.getInstance(project).getVirtualFilesWithWord(ClassUtil.extractClassName(JavaFxCommonNames.JAVAFX_FXML_FXMLLOADER), UsageSearchContext.IN_CODE, globalSearchScope, true);
if (virtualFiles.length == 0) {
return new CachedValueProvider.Result<>(null, PsiModificationTracker.MODIFICATION_COUNT);
}
final GlobalSearchScope filesScope = GlobalSearchScope.filesScope(project, Arrays.asList(virtualFiles));
final Processor<PsiReference> processor = loaderReference -> findControllerClassInjection(loaderReference, injectedController, injectControllerMethods[0]);
ReferencesSearch.search(containingFile, filesScope).forEach(reference -> {
final PsiElement element = reference.getElement();
if (element instanceof PsiLiteralExpression) {
final PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class);
if (expression != null) {
final PsiType type = expression.getType();
if (type != null && type.equalsToText(JavaFxCommonNames.JAVAFX_FXML_FXMLLOADER)) {
final PsiElement parent = expression.getParent();
if (parent instanceof PsiLocalVariable) {
ReferencesSearch.search(parent).forEach(processor);
final PsiClass controller = injectedController.get();
if (controller != null) {
return false;
}
}
}
}
}
return true;
});
}
}
return new CachedValueProvider.Result<>(injectedController.get(), PsiModificationTracker.MODIFICATION_COUNT);
});
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PyStubsTest method ensureVariableNotInIndex.
private void ensureVariableNotInIndex(String name) {
getTestFile();
GlobalSearchScope scope = GlobalSearchScope.allScope(myFixture.getProject());
Collection<PyTargetExpression> result = PyVariableNameIndex.find(name, myFixture.getProject(), scope);
assertEquals(0, result.size());
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PropertiesInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
final PsiElement element = queryParameters.getElement();
Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
return;
}
ReadAction.run(() -> {
final String key = prop.getKey();
if (!prop.isValid() || key == null)
return;
final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
LOG.assertTrue(currentFile != null);
final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
ProgressManager.checkCanceled();
return !consumer.process(psiElement);
});
});
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PyClassNameCompletionContributor method addVariantsFromIndex.
private static <T extends PsiNamedElement> void addVariantsFromIndex(final CompletionResultSet resultSet, final PsiFile targetFile, final StubIndexKey<String, T> key, final InsertHandler<LookupElement> insertHandler, final Condition<? super T> condition, Class<T> elementClass) {
final Project project = targetFile.getProject();
GlobalSearchScope scope = PyProjectScopeBuilder.excludeSdkTestsScope(targetFile);
Collection<String> keys = StubIndex.getInstance().getAllKeys(key, project);
for (final String elementName : CompletionUtil.sortMatching(resultSet.getPrefixMatcher(), keys)) {
for (T element : StubIndex.getElements(key, elementName, project, scope, elementClass)) {
if (condition.value(element)) {
final String name = element.getName();
if (name != null) {
resultSet.addElement(LookupElementBuilder.createWithSmartPointer(name, element).withIcon(element.getIcon(0)).withTailText(" " + ((NavigationItem) element).getPresentation().getLocationString(), true).withInsertHandler(insertHandler));
}
}
}
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class Html5CustomAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag tag) {
if (tag == null || !HtmlUtil.isHtml5Context(tag)) {
return XmlAttributeDescriptor.EMPTY;
}
final List<String> currentAttrs = new ArrayList<>();
for (XmlAttribute attribute : tag.getAttributes()) {
currentAttrs.add(attribute.getName());
}
final Project project = tag.getProject();
final Collection<String> keys = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
final Collection<String> keys1 = FileBasedIndex.getInstance().getAllKeys(Html5CustomAttributesIndex.INDEX_ID, project);
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
return CachedValueProvider.Result.<Collection<String>>create(ContainerUtil.filter(keys1, key -> !FileBasedIndex.getInstance().processValues(Html5CustomAttributesIndex.INDEX_ID, key, null, (file, value) -> false, scope)), PsiModificationTracker.MODIFICATION_COUNT);
});
if (keys.isEmpty())
return XmlAttributeDescriptor.EMPTY;
final List<XmlAttributeDescriptor> result = new ArrayList<>();
for (String key : keys) {
boolean add = true;
for (String attr : currentAttrs) {
if (attr.startsWith(key)) {
add = false;
}
}
if (add) {
result.add(new AnyXmlAttributeDescriptor(key));
}
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Aggregations