当前位置: 首页>>代码示例>>Java>>正文


Java ReferencesSearch.search方法代码示例

本文整理汇总了Java中com.intellij.psi.search.searches.ReferencesSearch.search方法的典型用法代码示例。如果您正苦于以下问题:Java ReferencesSearch.search方法的具体用法?Java ReferencesSearch.search怎么用?Java ReferencesSearch.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.search.searches.ReferencesSearch的用法示例。


在下文中一共展示了ReferencesSearch.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Nullable
@Override
public List<UsageInfo> findUsages( PsiFile psiFile, PsiDirectory newParent, boolean searchInComments, boolean searchInNonJavaFiles )
{
  Module mod = ModuleUtilCore.findModuleForPsiElement( psiFile );
  ManModule module = ManProject.getModule( mod );
  PsiClass psiClass = findPsiClass( psiFile );
  if( psiClass == null )
  {
    return Collections.emptyList();
  }

  Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ) );
  List<UsageInfo> usages = new ArrayList<>();
  for( PsiReference ref: search.findAll() )
  {
    usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
      ref.getRangeInElement().getEndOffset(), psiClass,
      ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
  }
  return usages;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:23,代码来源:MoveTypeManifoldFileProcessor.java

示例2: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static List<UsageInfo> findUsages( PsiElement element, PsiElement ctx )
  {
//    Module mod = ModuleUtilCore.findModuleForPsiElement( element );
//    if( mod == null )
//    {
//      return Collections.emptyList();
//    }

    Query<PsiReference> search = ReferencesSearch.search( element, GlobalSearchScope.moduleScope( ModuleUtilCore.findModuleForPsiElement( ctx ) ) );
    List<UsageInfo> usages = new ArrayList<>();
    for( PsiReference ref : search.findAll() )
    {
      MoveRenameUsageInfo usageInfo = new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
                                                               ref.getRangeInElement().getEndOffset(), element,
                                                               ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) );
      usages.add( usageInfo );
    }
    return usages;
  }
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:20,代码来源:RenameResourceElementProcessor.java

示例3: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
public static UsageInfo[] findUsages(final PsiElement element,
                                     boolean searchInStringsAndComments,
                                     boolean searchInNonJavaFiles,
                                     final String newQName) {
  PsiManager manager = element.getManager();

  ArrayList<UsageInfo> results = new ArrayList<UsageInfo>();
  Set<PsiReference> foundReferences = new HashSet<PsiReference>();

  GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject());
  for (PsiReference reference : ReferencesSearch.search(element, projectScope, false)) {
    TextRange range = reference.getRangeInElement();
    if (foundReferences.contains(reference)) continue;
    results.add(new MoveRenameUsageInfo(reference.getElement(), reference, range.getStartOffset(), range.getEndOffset(), element, false));
    foundReferences.add(reference);
  }

  findNonCodeUsages(searchInStringsAndComments, searchInNonJavaFiles, element, newQName, results);
  preprocessUsages(results);
  return results.toArray(new UsageInfo[results.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MoveClassesOrPackagesUtil.java

示例4: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Override
@NotNull
protected UsageInfo[] findUsages() {
  ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();
  for (int i = 0; i < myElementsToMove.length; i++) {
    PsiElement element = myElementsToMove[i];
    if (mySearchForReferences) {
      for (PsiReference reference : ReferencesSearch.search(element, GlobalSearchScope.projectScope(myProject))) {
        result.add(new MyUsageInfo(reference.getElement(), i, reference));
      }
    }
    findElementUsages(result, element);
  }

  return result.toArray(new UsageInfo[result.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MoveFilesOrDirectoriesProcessor.java

示例5: processIntention

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
  if (!(element instanceof GrReferenceElement)) return;
  final GrReferenceElement ref = (GrReferenceElement)element;
  final PsiElement resolved = ref.resolve();
  if (!(resolved instanceof PsiClass)) return;

  final String qname = ((PsiClass)resolved).getQualifiedName();

  final GrImportStatement importStatement =
    GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null);

  final PsiFile containingFile = element.getContainingFile();
  if (!(containingFile instanceof GroovyFile)) return;
  ((GroovyFile)containingFile).addImport(importStatement);

  for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
    final PsiElement refElement = reference.getElement();
    if (refElement == null) continue;
    final PsiElement parent = refElement.getParent();
    if (parent instanceof GrQualifiedReference<?>) {
      org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)parent);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ImportOnDemandIntention.java

示例6: processUsagesForMethod

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
                                      List<FixableUsageInfo> usages) {
  for (PsiReference reference : ReferencesSearch.search(method)) {
    final PsiElement referenceElement = reference.getElement();
    final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent();
    final String access;
    if (call.getMethodExpression().getQualifierExpression() == null) {
      access = field.getName();
    } else {
      access = getterName + "()";
      if (getter == null) {
        getter = GenerateMembersUtil.generateGetterPrototype(field);
      }
    }
    usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName()));
  }
  if (deleteMethodHierarchy) {
    usages.add(new DeleteMethod(method));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:RemoveMiddlemanProcessor.java

示例7: getAssignmentToInline

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static Pair<PyStatement, Boolean> getAssignmentToInline(ScopeOwner containerBlock, PyReferenceExpression expr,
                                                                PyTargetExpression local, Project project) {
  if (expr != null) {
    try {
      final List<ReadWriteInstruction> candidates = PyDefUseUtil.getLatestDefs(containerBlock, local.getName(), expr, true);
      if (candidates.size() == 1) {
        final PyStatement expression = getAssignmentByLeftPart((PyElement)candidates.get(0).getElement());
        return Pair.create(expression, false);
      }
      return Pair.create(null, candidates.size() > 0);
    }
    catch (PyDefUseUtil.InstructionNotFoundException ignored) {
    }
  }
  final Query<PsiReference> query = ReferencesSearch.search(local, GlobalSearchScope.allScope(project), false);
  final PsiReference first = query.findFirst();

  final PyElement lValue = first != null ? (PyElement)first.resolve() : null;
  return lValue != null ? Pair.create(getAssignmentByLeftPart(lValue), false) : EMPTY_DEF_RESULT;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyInlineLocalHandler.java

示例8: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@NotNull protected UsageInfo[] findUsages() {
  ArrayList<EncapsulateFieldUsageInfo> array = ContainerUtil.newArrayList();
  for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
    for (final PsiReference reference : ReferencesSearch.search(fieldDescriptor.getField())) {
      final PsiElement element = reference.getElement();
      if (element == null) continue;

      final EncapsulateFieldHelper helper = EncapsulateFieldHelper.getHelper(element.getLanguage());
      if (helper != null) {
        EncapsulateFieldUsageInfo usageInfo = helper.createUsage(myDescriptor, fieldDescriptor, reference);
        if (usageInfo != null) {
          array.add(usageInfo);
        }
      }
    }
  }
  EncapsulateFieldUsageInfo[] usageInfos = array.toArray(new EncapsulateFieldUsageInfo[array.size()]);
  return UsageViewUtil.removeDuplicatedUsages(usageInfos);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:EncapsulateFieldsProcessor.java

示例9: performRefactoring

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
protected void performRefactoring(@NotNull UsageInfo[] usageInfos) {
  final PsiClass psiClass = buildClass();
  if (psiClass != null) {
    fixJavadocForConstructor(psiClass);
    super.performRefactoring(usageInfos);
    if (!myUseExistingClass) {
      for (PsiReference reference : ReferencesSearch.search(method)) {
        final PsiElement place = reference.getElement();
        VisibilityUtil.escalateVisibility(psiClass, place);
        for (PsiMethod constructor : psiClass.getConstructors()) {
          VisibilityUtil.escalateVisibility(constructor, place);
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:IntroduceParameterObjectProcessor.java

示例10: storeTypeManifoldReferences

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private void storeTypeManifoldReferences( @NotNull PsiElement element )
{
  Module mod = ModuleUtilCore.findModuleForPsiElement( element );
  if( mod == null )
  {
    return;
  }

  ManModule module = ManProject.getModule( mod );

  PsiClass psiClass = findPsiClass( (PsiFileSystemItem)element, module );
  if( psiClass == null )
  {
    return;
  }

  Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.projectScope( mod.getProject() ) );
  List<UsageInfo> usages = new ArrayList<>();
  for( PsiReference ref: search.findAll() )
  {
    usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
      ref.getRangeInElement().getEndOffset(), element,
      ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
  }
  _usages = usages;

  if( psiClass instanceof ManifoldPsiClass )
  {
    PsiElement fakeElement = ManGotoDeclarationHandler.find( psiClass, (ManifoldPsiClass)psiClass );
    if( fakeElement instanceof PsiNamedElement && isTopLevelClassDeclaration( fakeElement ) )
    {
      _classDeclElement = (PsiNamedElement)fakeElement;
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:36,代码来源:RenameTypeManifoldFileProcessor.java

示例11: execute

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:PsiAnnotationMethodReferencesSearcher.java

示例12: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@NotNull
protected UsageInfo[] findUsages() {
  GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myProject);
  List<UsageInfo> result = new ArrayList<UsageInfo>();

  boolean hadTypeParameters = myClass.hasTypeParameters();
  for (final PsiReference reference : ReferencesSearch.search(myClass, projectScope, false)) {
    if (reference.getElement() instanceof PsiJavaCodeReferenceElement) {
      PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)reference.getElement();
      PsiElement parent = referenceElement.getParent();
      if (parent instanceof PsiTypeElement && parent.getParent() instanceof PsiInstanceOfExpression) continue;
      if (parent instanceof PsiNewExpression && PsiUtil.isLanguageLevel7OrHigher(parent)) {
        final PsiReferenceParameterList parameterList = referenceElement.getParameterList();
        if (parameterList != null) {
          final PsiTypeElement[] parameterElements = parameterList.getTypeParameterElements();
          if (parameterElements.length == 1 && parameterElements[0].getType() instanceof PsiDiamondType) continue;
        }
      }
      if (parent instanceof PsiTypeElement || parent instanceof PsiNewExpression || parent instanceof PsiAnonymousClass ||
          parent instanceof PsiReferenceList) {
        if (!hadTypeParameters || referenceElement.getTypeParameters().length > 0) {
          result.add(new UsageInfo(referenceElement));
        }
      }
    }
  }
  return result.toArray(new UsageInfo[result.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:ChangeClassSignatureProcessor.java

示例13: shortenUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static boolean shortenUsages(PsiElement resolved, PsiFile containingFile) {
  boolean isAnythingShortened = false;
  for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
    final PsiElement refElement = reference.getElement();
    if (refElement instanceof GrQualifiedReference<?>) {
      boolean shortened = GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)refElement);
      isAnythingShortened |= shortened;
    }
  }
  return isAnythingShortened;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ImportStaticIntention.java

示例14: processUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static boolean processUsages(PsiElement tag, XmlAttributeValue value, LocalSearchScope scope) {
  final Query<PsiReference> query = ReferencesSearch.search(tag, scope, true);
  for (PsiReference reference : query) {
    final PsiElement e = reference.getElement();
    if (e != value) {
      final XmlTag t = PsiTreeUtil.getParentOfType(e, XmlTag.class);
      if (t != null && !PsiTreeUtil.isAncestor(tag, t, true)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:UnusedDefineInspection.java

示例15: makeMethodCallsVarargs

import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static void makeMethodCallsVarargs(PsiElement element)
  throws IncorrectOperationException {
  final PsiMethod method = (PsiMethod)element.getParent();
  final Query<PsiReference> query =
    ReferencesSearch.search(method, method.getUseScope(), false);
  for (PsiReference reference : query) {
    final PsiElement referenceElement = reference.getElement();
    if (!(referenceElement instanceof PsiReferenceExpression)) {
      continue;
    }
    final PsiReferenceExpression referenceExpression =
      (PsiReferenceExpression)referenceElement;
    final PsiMethodCallExpression methodCallExpression =
      (PsiMethodCallExpression)referenceExpression.getParent();
    final PsiExpressionList argumentList =
      methodCallExpression.getArgumentList();
    final PsiExpression[] arguments = argumentList.getExpressions();
    if (arguments.length == 0) {
      continue;
    }
    final PsiExpression lastArgument = arguments[arguments.length - 1];
    if (!(lastArgument instanceof PsiNewExpression)) {
      continue;
    }
    final PsiNewExpression newExpression =
      (PsiNewExpression)lastArgument;
    final PsiArrayInitializerExpression arrayInitializerExpression =
      newExpression.getArrayInitializer();
    if (arrayInitializerExpression == null) {
      continue;
    }
    final PsiExpression[] initializers =
      arrayInitializerExpression.getInitializers();
    for (PsiExpression initializer : initializers) {
      argumentList.add(initializer);
    }
    lastArgument.delete();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:MakeMethodVarargsIntention.java


注:本文中的com.intellij.psi.search.searches.ReferencesSearch.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。