本文整理汇总了Java中com.intellij.util.Query.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java Query.forEach方法的具体用法?Java Query.forEach怎么用?Java Query.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.util.Query
的用法示例。
在下文中一共展示了Query.forEach方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: syncDeclaredXposedHooks
import com.intellij.util.Query; //导入方法依赖的package包/类
public void syncDeclaredXposedHooks() {
if (mXposedModCls == null) {
mXposedModCls = findXposedModCls();
}
GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(mModule);
Query<PsiClass> query = ClassInheritorsSearch.search(mXposedModCls, moduleScope, true);
mDeclaredXposedHooks.clear();
query.forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass psiClass) {
mDeclaredXposedHooks.add(psiClass.getQualifiedName());
return true;
}
});
writeXposedInitFile();
}
示例2: addMaxSuperMembers
import com.intellij.util.Query; //导入方法依赖的package包/类
private static void addMaxSuperMembers(@NotNull SchemaTypeDef currentType,
@NotNull Function<SchemaTypeDef, PsiNamedElement> typeFunc,
@NotNull List<PsiNamedElement> acc) {
final int accSizeBefore = acc.size();
Query<SchemaTypeDef> parentsQuery = SchemaDirectTypeParentsSearch.search(currentType);
parentsQuery.forEach(typeDef -> {
PsiNamedElement member = typeFunc.apply(typeDef);
if (member != null) addMaxSuperMembers(typeDef, typeFunc, acc);
return true;
});
if (acc.size() == accSizeBefore /*&& accSizeBefore > 0*/) acc.add(currentType);
}
示例3: execute
import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
final PsiElement refElement = p.getElementToSearch();
boolean isAnnotation = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return PsiUtil.isAnnotationMethod(refElement);
}
});
if (isAnnotation) {
final PsiMethod method = (PsiMethod)refElement;
PsiClass containingClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
@Override
public PsiClass compute() {
boolean isValueMethod =
PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) && method.getParameterList().getParametersCount() == 0;
return isValueMethod ? method.getContainingClass() : null;
}
});
if (containingClass != null) {
SearchScope scope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
public SearchScope compute() {
return p.getEffectiveSearchScope();
}
});
final Query<PsiReference> query = ReferencesSearch.search(containingClass, scope, p.isIgnoreAccessScope());
return query.forEach(createImplicitDefaultAnnotationMethodConsumer(consumer));
}
}
return true;
}
示例4: removeException
import com.intellij.util.Query; //导入方法依赖的package包/类
private static void removeException(final RefMethod refMethod,
final PsiType exceptionType,
final List<PsiJavaCodeReferenceElement> refsToDelete,
final PsiMethod psiMethod) {
PsiManager psiManager = psiMethod.getManager();
PsiJavaCodeReferenceElement[] refs = psiMethod.getThrowsList().getReferenceElements();
for (PsiJavaCodeReferenceElement ref : refs) {
PsiType refType = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createType(ref);
if (exceptionType.isAssignableFrom(refType)) {
refsToDelete.add(ref);
}
}
if (refMethod != null) {
for (RefMethod refDerived : refMethod.getDerivedMethods()) {
PsiModifierListOwner method = refDerived.getElement();
if (method != null) {
removeException(refDerived, exceptionType, refsToDelete, (PsiMethod)method);
}
}
} else {
final Query<Pair<PsiMethod,PsiMethod>> query = AllOverridingMethodsSearch.search(psiMethod.getContainingClass());
query.forEach(new Processor<Pair<PsiMethod, PsiMethod>>(){
@Override
public boolean process(final Pair<PsiMethod, PsiMethod> pair) {
if (pair.first == psiMethod) {
removeException(null, exceptionType, refsToDelete, pair.second);
}
return true;
}
});
}
}
示例5: applyFix
import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethod.class, false);
if (psiMethod != null) {
final List<PsiElement> psiElements = new ArrayList<PsiElement>();
psiElements.add(psiMethod);
if (Boolean.valueOf(myHint).booleanValue()) {
final Query<Pair<PsiMethod, PsiMethod>> query = AllOverridingMethodsSearch.search(psiMethod.getContainingClass());
query.forEach(new Processor<Pair<PsiMethod, PsiMethod>>() {
@Override
public boolean process(final Pair<PsiMethod, PsiMethod> pair) {
if (pair.first == psiMethod) {
psiElements.add(pair.second);
}
return true;
}
});
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
SafeDeleteHandler.invoke(project, PsiUtilCore.toPsiElementArray(psiElements), false);
}
}, project.getDisposed());
}
}
示例6: collectRefs
import com.intellij.util.Query; //导入方法依赖的package包/类
protected Collection<PsiReference> collectRefs(SearchScope referencesSearchScope) {
final Query<PsiReference> search = ReferencesSearch.search(myElementToRename, referencesSearchScope, false);
final CommonProcessors.CollectProcessor<PsiReference> processor = new CommonProcessors.CollectProcessor<PsiReference>() {
@Override
protected boolean accept(PsiReference reference) {
return acceptReference(reference);
}
};
search.forEach(processor);
return processor.getResults();
}
示例7: navigate
import com.intellij.util.Query; //导入方法依赖的package包/类
public void navigate(final MouseEvent e, final T elt) {
final List<NavigatablePsiElement> navElements = new ArrayList<NavigatablePsiElement>();
Query<T> elementQuery = search(elt);
if (elementQuery == null) return;
elementQuery.forEach(new Processor<T>() {
public boolean process(final T psiElement) {
if (psiElement instanceof NavigatablePsiElement) {
navElements.add((NavigatablePsiElement)psiElement);
}
return true;
}
});
final NavigatablePsiElement[] methods = navElements.toArray(new NavigatablePsiElement[navElements.size()]);
PsiElementListNavigator.openTargets(e, methods, getTitle(elt), null, new DefaultPsiElementCellRenderer());
}
示例8: isOnlyAccessedFromInnerClass
import com.intellij.util.Query; //导入方法依赖的package包/类
public boolean isOnlyAccessedFromInnerClass() {
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject());
final ProgressManager progressManager = ProgressManager.getInstance();
final ProgressIndicator progressIndicator = progressManager.getProgressIndicator();
final PsiSearchHelper.SearchCostResult searchCost =
searchHelper.isCheapEnoughToSearch(method.getName(), method.getResolveScope(), null, progressIndicator);
if (searchCost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES ||
searchCost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES) {
return onlyAccessedFromInnerClass;
}
final Query<PsiReference> query = ReferencesSearch.search(method);
query.forEach(this);
return onlyAccessedFromInnerClass;
}
示例9: newOnlyAssignsToStaticSelfInstance
import com.intellij.util.Query; //导入方法依赖的package包/类
private static boolean newOnlyAssignsToStaticSelfInstance(
PsiMethod method, final PsiField field) {
final Query<PsiReference> search =
MethodReferencesSearch.search(method, field.getUseScope(),
false);
final NewOnlyAssignedToFieldProcessor processor =
new NewOnlyAssignedToFieldProcessor(field);
search.forEach(processor);
return processor.isNewOnlyAssignedToField();
}
示例10: isImplicitUsage
import com.intellij.util.Query; //导入方法依赖的package包/类
public boolean isImplicitUsage(PsiElement element) {
if (!(element instanceof XmlAttribute)) {
return false;
}
final XmlAttribute attr = (XmlAttribute)element;
if (!attr.isNamespaceDeclaration()) {
return false;
}
final PsiFile file = attr.getContainingFile();
if (!(file instanceof XmlFile)) {
return false;
}
// also catch namespace declarations in "normal" XML files that have XPath injected into some attributes
// ContextProvider.hasXPathInjections() is an optimization that avoids to run the references search on totally XPath-free XML files
if (!ContextProvider.hasXPathInjections((XmlFile)file) && !XsltSupport.isXsltFile(file)) {
return false;
}
// This need to catch both prefix references from injected XPathFiles and prefixes from mode declarations/references:
// <xsl:template match="*" mode="prefix:name" />
// BTW: Almost the same logic applies to other XML dialects (RELAX-NG).
// Pull this class into the platform?
final String prefix = attr.getLocalName();
final SchemaPrefix target = new SchemaPrefix(attr, TextRange.from("xmlns:".length(), prefix.length()), prefix);
final Query<PsiReference> q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent()));
return !q.forEach(new Processor<PsiReference>() {
public boolean process(PsiReference psiReference) {
if (psiReference.getElement() == attr) {
return true;
}
return false;
}
});
}
示例11: implementsSurprisingInterface
import com.intellij.util.Query; //导入方法依赖的package包/类
private boolean implementsSurprisingInterface(final PsiMethod method) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null) {
return false;
}
final Query<PsiClass> search = ClassInheritorsSearch.search(containingClass, method.getUseScope(), true, true, false);
final boolean[] result = new boolean[1];
search.forEach(new Processor<PsiClass>() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean process(PsiClass subClass) {
if (count.incrementAndGet() > 5) {
result[0] = true;
return false;
}
final PsiReferenceList list = subClass.getImplementsList();
if (list == null) {
return true;
}
final PsiJavaCodeReferenceElement[] referenceElements = list.getReferenceElements();
for (PsiJavaCodeReferenceElement referenceElement : referenceElements) {
final PsiElement target = referenceElement.resolve();
if (!(target instanceof PsiClass)) {
result[0] = true;
return false;
}
final PsiClass aClass = (PsiClass)target;
if (!aClass.isInterface()) {
result[0] = true;
return false;
}
if (aClass.findMethodBySignature(method, true) != null) {
result[0] = true;
return false;
}
}
return true;
}
});
return result[0];
}
示例12: existsMutualSubclass
import com.intellij.util.Query; //导入方法依赖的package包/类
public static boolean existsMutualSubclass(PsiClass class1, final PsiClass class2, final boolean avoidExpensiveProcessing) {
if (class1 instanceof PsiTypeParameter) {
final PsiClass[] superClasses = class1.getSupers();
for (PsiClass superClass : superClasses) {
if (!existsMutualSubclass(superClass, class2, avoidExpensiveProcessing)) {
return false;
}
}
return true;
}
if (class2 instanceof PsiTypeParameter) {
return existsMutualSubclass(class2, class1, avoidExpensiveProcessing);
}
final String className = class1.getQualifiedName();
if (CommonClassNames.JAVA_LANG_OBJECT.equals(className)) {
return true;
}
final String class2Name = class2.getQualifiedName();
if (CommonClassNames.JAVA_LANG_OBJECT.equals(class2Name)) {
return true;
}
if (class1.isInheritor(class2, true) || class2.isInheritor(class1, true)) {
return true;
}
final SearchScope scope = GlobalSearchScope.allScope(class1.getProject());
final Query<PsiClass> search = ClassInheritorsSearch.search(class1, scope, true, true);
final boolean[] result = new boolean[1];
search.forEach(new Processor<PsiClass>() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean process(PsiClass inheritor) {
if (inheritor.equals(class2) || inheritor.isInheritor(class2, true) || (avoidExpensiveProcessing && count.incrementAndGet() > 20)) {
result[0] = true;
return false;
}
return true;
}
});
return result[0];
}
示例13: processIntention
import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
final PsiClass anInterface = (PsiClass)element.getParent();
final SearchScope searchScope = anInterface.getUseScope();
final Query<PsiClass> query = ClassInheritorsSearch.search(anInterface, searchScope, false);
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
query.forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass aClass) {
final PsiReferenceList extendsList = aClass.getExtendsList();
if (extendsList == null) {
return true;
}
final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements();
if (referenceElements.length > 0) {
final PsiElement target = referenceElements[0].resolve();
if (target != null) {
conflicts.putValue(aClass, IntentionPowerPackBundle.message(
"0.already.extends.1.and.will.not.compile.after.converting.2.to.a.class",
RefactoringUIUtil.getDescription(aClass, true), RefactoringUIUtil.getDescription(target, true),
RefactoringUIUtil.getDescription(anInterface, false)));
}
}
return true;
}
});
final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(anInterface, searchScope).findFirst();
if (functionalExpression != null) {
final String conflictMessage = ClassPresentationUtil.getFunctionalExpressionPresentation(functionalExpression, true) +
" will not compile after converting " + RefactoringUIUtil.getDescription(anInterface, false) + " to a class";
conflicts.putValue(functionalExpression, conflictMessage);
}
final boolean conflictsDialogOK;
if (conflicts.isEmpty()) {
conflictsDialogOK = true;
} else {
if (getApplication().isUnitTestMode()) {
throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
}
final ConflictsDialog conflictsDialog = new ConflictsDialog(anInterface.getProject(), conflicts, new Runnable() {
@Override
public void run() {
final AccessToken token = start();
try {
convertInterfaceToClass(anInterface);
}
finally {
token.finish();
}
}
});
conflictsDialogOK = conflictsDialog.showAndGet();
}
if (conflictsDialogOK) {
convertInterfaceToClass(anInterface);
}
}