本文整理汇总了Java中com.intellij.psi.search.searches.MethodReferencesSearch类的典型用法代码示例。如果您正苦于以下问题:Java MethodReferencesSearch类的具体用法?Java MethodReferencesSearch怎么用?Java MethodReferencesSearch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodReferencesSearch类属于com.intellij.psi.search.searches包,在下文中一共展示了MethodReferencesSearch类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: searchMethodCalls
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@NotNull
public static Set<PsiMethodCallExpression> searchMethodCalls(@NotNull final PsiMethod psiMethod, @NotNull SearchScope searchScope) {
final Set<PsiMethodCallExpression> callExpressions = new com.intellij.util.containers.HashSet<PsiMethodCallExpression>();
final CommonProcessors.CollectUniquesProcessor<PsiReference> consumer = new CommonProcessors.CollectUniquesProcessor<PsiReference>();
MethodReferencesSearch.search(psiMethod, searchScope, true).forEach(consumer);
for (PsiReference psiReference : consumer.getResults()) {
final PsiMethodCallExpression methodCallExpression =
PsiTreeUtil.getParentOfType(psiReference.getElement(), PsiMethodCallExpression.class);
if (methodCallExpression != null) {
callExpressions.add(methodCallExpression);
}
}
return callExpressions;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:StringExpressionHelper.java
示例2: findReferencesToHighlight
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@NotNull
@Override
public Collection<PsiReference> findReferencesToHighlight(@NotNull final PsiElement target, @NotNull final SearchScope searchScope) {
if (target instanceof PsiMethod) {
final PsiMethod[] superMethods = ((PsiMethod)target).findDeepestSuperMethods();
if (superMethods.length == 0) {
return MethodReferencesSearch.search((PsiMethod)target, searchScope, true).findAll();
}
final Collection<PsiReference> result = new ArrayList<PsiReference>();
for (PsiMethod superMethod : superMethods) {
result.addAll(MethodReferencesSearch.search(superMethod, searchScope, true).findAll());
}
return result;
}
return super.findReferencesToHighlight(target, searchScope);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JavaFindUsagesHandler.java
示例3: collectRefsToInvert
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
public void collectRefsToInvert(PsiElement namedElement, Collection<PsiElement> elementsToInvert) {
final Query<PsiReference> query = namedElement instanceof PsiMethod ?
MethodReferencesSearch.search((PsiMethod)namedElement) :
ReferencesSearch.search(namedElement);
final Collection<PsiReference> refs = query.findAll();
for (PsiReference ref : refs) {
final PsiElement element = ref.getElement();
PsiElement refElement = getElementToInvert(namedElement, element);
if (refElement == null) {
refElement = getForeignElementToInvert(namedElement, element, JavaLanguage.INSTANCE);
}
if (refElement != null) {
elementsToInvert.add(refElement);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:JavaInvertBooleanDelegate.java
示例4: computeCallers
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
protected List<PsiMethod> computeCallers() {
final PsiReference[] refs =
MethodReferencesSearch.search(myMethod, GlobalSearchScope.allScope(myProject), true).toArray(PsiReference.EMPTY_ARRAY);
List<PsiMethod> result = new ArrayList<PsiMethod>();
for (PsiReference ref : refs) {
final PsiElement element = ref.getElement();
if (!(element instanceof PsiReferenceExpression) ||
!(((PsiReferenceExpression)element).getQualifierExpression() instanceof PsiSuperExpression)) {
final PsiElement enclosingContext = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiClass.class);
if (enclosingContext instanceof PsiMethod && !result.contains(enclosingContext) &&
!myMethod.equals(enclosingContext) && !myCalled.contains(myMethod)) { //do not add recursive methods
result.add((PsiMethod)enclosingContext);
}
else if (element instanceof PsiClass) {
final PsiClass aClass = (PsiClass)element;
final PsiMethod method = JavaPsiFacade.getElementFactory(myProject).createMethodFromText(aClass.getName() + "(){}", aClass);
if (!result.contains(method)) {
result.add(method);
}
}
}
}
return result;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavaMethodNode.java
示例5: testOverloadConstructors
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
public void testOverloadConstructors() throws Exception {
PsiClass aClass = myJavaFacade.findClass("B", GlobalSearchScope.allScope(myProject));
PsiMethod constructor = aClass.findMethodsByName("B", false)[0];
PsiMethodCallExpression superCall = (PsiMethodCallExpression) constructor.getBody().getStatements()[0].getFirstChild();
PsiReferenceExpression superExpr = superCall.getMethodExpression();
String[] fileNames = {"B.java", "A.java", "A.java", "B.java"};
int[] starts = {};
int[] ends = {};
final ArrayList<PsiFile> filesList = new ArrayList<PsiFile>();
final IntArrayList startsList = new IntArrayList();
final IntArrayList endsList = new IntArrayList();
PsiReference[] refs =
MethodReferencesSearch.search((PsiMethod)superExpr.resolve(), GlobalSearchScope.projectScope(myProject), false).toArray(PsiReference.EMPTY_ARRAY);
for (PsiReference ref : refs) {
addReference(ref, filesList, startsList, endsList);
}
checkResult(fileNames, filesList, starts, startsList, ends, endsList);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FindUsagesTest.java
示例6: visitMethod
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
if (!TestUtils.isJUnitTestMethod(method)) {
return;
}
final PsiReferenceList throwsList = method.getThrowsList();
final PsiJavaCodeReferenceElement[] referenceElements =
throwsList.getReferenceElements();
if (referenceElements.length < 2) {
return;
}
final Query<PsiReference> query =
MethodReferencesSearch.search(method);
final PsiReference firstReference = query.findFirst();
if (firstReference != null) {
return;
}
registerError(throwsList);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MultipleExceptionsDeclaredOnTestMethodInspection.java
示例7: getUsageClass
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
/**
* @return the class the specified method is used from, or null if it is
* used from 0 or more than 1 other classes.
*/
@Nullable
public PsiClass getUsageClass(final PsiMethod method) {
final ProgressManager progressManager = ProgressManager.getInstance();
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject());
final String name = method.getName();
final GlobalSearchScope scope = GlobalSearchScope.allScope(method.getProject());
if (searchHelper.isCheapEnoughToSearch(name, scope, null, progressManager.getProgressIndicator())
== PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
return null;
}
progressManager.runProcess(new Runnable() {
@Override
public void run() {
final Query<PsiReference> query = MethodReferencesSearch.search(method);
if (!query.forEach(UsageProcessor.this)) {
foundClass.set(null);
}
}
}, null);
return foundClass.get();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:StaticMethodOnlyUsedInOneClassInspectionBase.java
示例8: processQuery
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = p.getMethod();
final PsiClass aClass = method.getContainingClass();
if (aClass == null) return;
final String name = method.getName();
if (StringUtil.isEmpty(name)) return;
final boolean strictSignatureSearch = p.isStrictSignatureSearch();
final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[]{method} : aClass.findMethodsByName(name, false);
SearchScope accessScope = GroovyScopeUtil.getEffectiveScope(methods);
final SearchScope restrictedByAccess = GroovyScopeUtil.restrictScopeToGroovyFiles(p.getEffectiveSearchScope(), accessScope);
final String textToSearch = findLongestWord(name);
p.getOptimizer().searchWord(textToSearch, restrictedByAccess, UsageSearchContext.IN_STRINGS, true, method,
new MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, methods));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GrLiteralMethodSearcher.java
示例9: processQuery
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
if (element instanceof PsiMethod) {
final String propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod)element);
if (propertyName == null) return;
queryParameters.getOptimizer().searchWord(propertyName, GroovyScopeUtil
.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope()),
UsageSearchContext.IN_CODE, true, element);
}
else if (element instanceof GrField) {
for (GrAccessorMethod method : ((GrField)element).getGetters()) {
MethodReferencesSearch.search(method, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
final GrAccessorMethod setter = ((GrField)element).getSetter();
if (setter != null) {
MethodReferencesSearch.search(setter, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AccessorReferencesSearcher.java
示例10: processQuery
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = queryParameters.getMethod();
final String propertyName;
if (GdkMethodUtil.isCategoryMethod(method, null, null, PsiSubstitutor.EMPTY)) {
final GrGdkMethod cat = GrGdkMethodImpl.createGdkMethod(method, false, null);
propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod)cat);
}
else {
propertyName = GroovyPropertyUtils.getPropertyName(method);
}
if (propertyName == null) return;
final SearchScope onlyGroovyFiles = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope(), GroovyScopeUtil.getEffectiveScope(method));
queryParameters.getOptimizer().searchWord(propertyName, onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
if (!GroovyPropertyUtils.isPropertyName(propertyName)) {
queryParameters.getOptimizer().searchWord(StringUtil.decapitalize(propertyName), onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AccessorMethodReferencesSearcher.java
示例11: computeCallers
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
protected List<PsiMethod> computeCallers() {
final PsiReference[] refs =
MethodReferencesSearch.search(myMethod, GlobalSearchScope.allScope(myProject), true).toArray(PsiReference.EMPTY_ARRAY);
List<PsiMethod> result = new ArrayList<PsiMethod>();
for (PsiReference ref : refs) {
final PsiElement element = ref.getElement();
if (!(element instanceof PsiReferenceExpression) ||
!(((PsiReferenceExpression)element).getQualifierExpression() instanceof PsiSuperExpression)) {
final PsiElement enclosingContext = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiClass.class);
if (enclosingContext instanceof PsiMethod &&
!myMethod.equals(enclosingContext) && !myCalled.contains(myMethod)) { //do not add recursive methods
result.add((PsiMethod)enclosingContext);
}
else if (element instanceof PsiClass) {
final PsiClass aClass = (PsiClass)element;
result.add(JavaPsiFacade.getElementFactory(myProject).createMethodFromText(aClass.getName() + "(){}", aClass));
}
}
}
return result;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:JavaMethodNode.java
示例12: testOverloadConstructors
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
public void testOverloadConstructors() throws Exception {
PsiClass aClass = myJavaFacade.findClass("B", GlobalSearchScope.allScope(myProject));
PsiMethod constructor;
// constructor = myJavaFacade.getElementFactory().createConstructor();
// constructor = aClass.findMethodBySignature(constructor, false);
constructor = aClass.findMethodsByName("B", false)[0];
PsiMethodCallExpression superCall = (PsiMethodCallExpression) constructor.getBody().getStatements()[0].getFirstChild();
PsiReferenceExpression superExpr = superCall.getMethodExpression();
String[] fileNames = new String[]{"B.java", "A.java", "A.java", "B.java"};
int[] starts = new int[]{};
int[] ends = new int[]{};
final ArrayList<PsiFile> filesList = new ArrayList<PsiFile>();
final IntArrayList startsList = new IntArrayList();
final IntArrayList endsList = new IntArrayList();
PsiReference[] refs =
MethodReferencesSearch.search((PsiMethod)superExpr.resolve(), GlobalSearchScope.projectScope(myProject), false).toArray(PsiReference.EMPTY_ARRAY);
for (PsiReference ref : refs) {
addReference(ref, filesList, startsList, endsList);
}
checkResult(fileNames, filesList, starts, startsList, ends, endsList);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:FindUsagesTest.java
示例13: processQuery
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = queryParameters.getMethod();
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, DataProvider.class.getName());
if (annotation == null) return;
PsiNameValuePair[] values = annotation.getParameterList().getAttributes();
for (PsiNameValuePair value : values) {
if ("name".equals(value.getName())) {
final PsiAnnotationMemberValue dataProviderMethodName = value.getValue();
if (dataProviderMethodName != null) {
final String providerName = StringUtil.unquoteString(dataProviderMethodName.getText());
queryParameters.getOptimizer().searchWord(providerName, queryParameters.getScope(), UsageSearchContext.IN_STRINGS, true, method);
}
}
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:DataProviderSearcher.java
示例14: processQuery
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = p.getMethod();
final PsiClass aClass = method.getContainingClass();
if (aClass == null) return;
final String name = method.getName();
if (StringUtil.isEmpty(name)) return;
final boolean strictSignatureSearch = p.isStrictSignatureSearch();
final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[]{method} : aClass.findMethodsByName(name, false);
SearchScope accessScope = GroovyScopeUtil.getEffectiveScope(methods);
final SearchScope restrictedByAccess = GroovyScopeUtil.restrictScopeToGroovyFiles(p.getScope(), accessScope);
final String textToSearch = findLongestWord(name);
p.getOptimizer().searchWord(textToSearch, restrictedByAccess, UsageSearchContext.IN_STRINGS, true,
new MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, methods));
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:GrLiteralMethodSearcher.java
示例15: processQuery
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = queryParameters.getMethod();
final String propertyName;
if (GdkMethodUtil.isCategoryMethod(method, null, null, PsiSubstitutor.EMPTY)) {
final GrGdkMethod cat = GrGdkMethodImpl.createGdkMethod(method, false, null);
propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod)cat);
}
else {
propertyName = GroovyPropertyUtils.getPropertyName(method);
}
if (propertyName == null) return;
final SearchScope onlyGroovyFiles = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getScope(), GroovyScopeUtil.getEffectiveScope(method));
queryParameters.getOptimizer().searchWord(propertyName, onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
if (!GroovyPropertyUtils.isPropertyName(propertyName)) {
queryParameters.getOptimizer().searchWord(StringUtil.decapitalize(propertyName), onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:AccessorMethodReferencesSearcher.java
示例16: isUnusedInAnonymousClass
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
private static boolean isUnusedInAnonymousClass(@NotNull PsiMethod method)
{
PsiClass containingClass = method.getContainingClass();
if(!(containingClass instanceof PsiAnonymousClass))
{
return false;
}
if(containingClass.getParent() instanceof PsiNewExpression && containingClass.getParent().getParent() instanceof PsiVariable && !method.getHierarchicalMethodSignature().getSuperSignatures()
.isEmpty())
{
// references outside anonymous class can still resolve to this method, see com.intellij.psi.scope.util.PsiScopesUtil.setupAndRunProcessor()
return false;
}
return MethodReferencesSearch.search(method, new LocalSearchScope(containingClass), false).findFirst() == null;
}
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:InferenceFromSourceUtil.java
示例17: processCallsWithNullArguments
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
private static void processCallsWithNullArguments(@NotNull PsiMethod method, int argumentIdx, @NotNull Processor<PsiExpression> nullArgumentProcessor, Collection<VirtualFile> candidateFiles)
{
if(candidateFiles.isEmpty())
{
return;
}
GlobalSearchScope scope = GlobalSearchScope.filesScope(method.getProject(), candidateFiles);
MethodReferencesSearch.search(method, scope, true).forEach(ref ->
{
PsiExpression argument = getCallArgument(ref, argumentIdx);
if(argument instanceof PsiLiteralExpression && argument.textMatches(PsiKeyword.NULL))
{
return nullArgumentProcessor.process(argument);
}
return true;
});
}
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:JavaNullMethodArgumentUtil.java
示例18: findReferencesToHighlight
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
@NotNull
@Override
public Collection<PsiReference> findReferencesToHighlight(@NotNull final PsiElement target,
@NotNull final SearchScope searchScope)
{
if(target instanceof PsiMethod)
{
final PsiMethod[] superMethods = ((PsiMethod) target).findDeepestSuperMethods();
if(superMethods.length == 0)
{
return MethodReferencesSearch.search((PsiMethod) target, searchScope, true).findAll();
}
final Collection<PsiReference> result = new ArrayList<PsiReference>();
for(PsiMethod superMethod : superMethods)
{
result.addAll(MethodReferencesSearch.search(superMethod, searchScope, true).findAll());
}
return result;
}
return super.findReferencesToHighlight(target, searchScope);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:JavaFindUsagesHandler.java
示例19: isUnusedInAnonymousClass
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
private static boolean isUnusedInAnonymousClass(@NotNull PsiMethod method) {
PsiClass containingClass = method.getContainingClass();
if (!(containingClass instanceof PsiAnonymousClass)) {
return false;
}
if (containingClass.getParent() instanceof PsiNewExpression &&
containingClass.getParent().getParent() instanceof PsiVariable &&
!method.getHierarchicalMethodSignature().getSuperSignatures().isEmpty()) {
// references outside anonymous class can still resolve to this method, see com.intellij.psi.scope.util.PsiScopesUtil.setupAndRunProcessor()
return false;
}
return MethodReferencesSearch.search(method, new LocalSearchScope(containingClass), false).findFirst() == null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:InferenceFromSourceUtil.java
示例20: scanCatches
import com.intellij.psi.search.searches.MethodReferencesSearch; //导入依赖的package包/类
private static boolean scanCatches(@NotNull PsiElement elem,
@NotNull Processor<UsageInfo> processor,
@NotNull Root root,
@NotNull FindUsagesOptions options,
@NotNull Set<PsiMethod> processed) {
while (elem != null) {
final PsiElement parent = elem.getParent();
if (elem instanceof PsiMethod) {
final PsiMethod deepestSuperMethod = ((PsiMethod)elem).findDeepestSuperMethod();
final PsiMethod method = deepestSuperMethod != null ? deepestSuperMethod : (PsiMethod)elem;
if (!processed.contains(method)) {
processed.add(method);
final PsiReference[] refs = MethodReferencesSearch.search(method, options.searchScope, true).toArray(PsiReference.EMPTY_ARRAY);
for (int i = 0; i != refs.length; ++i) {
if (!scanCatches(refs[i].getElement(), processor, root, options, processed)) return false;
}
}
return true;
}
if (elem instanceof PsiTryStatement) {
final PsiTryStatement aTry = (PsiTryStatement)elem;
final PsiParameter[] catches = aTry.getCatchBlockParameters();
for (int i = 0; i != catches.length; ++i) {
if (!processExn(catches[i], processor, root)) {
return false;
}
}
}
else if (parent instanceof PsiTryStatement) {
final PsiTryStatement tryStmt = (PsiTryStatement)parent;
if (elem != tryStmt.getTryBlock()) {
elem = parent.getParent();
continue;
}
}
elem = parent;
}
return true;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ThrowSearchUtil.java
注:本文中的com.intellij.psi.search.searches.MethodReferencesSearch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论