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


Java ReferencesSearch类代码示例

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


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

示例1: doExecute

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
private Boolean doExecute(ReferencesSearch.SearchParameters queryParameters, final Processor<PsiReference> consumer) {
  final PsiElement element = queryParameters.getElementToSearch(); //was selector_identifier->redefined in
  DictionaryComponent dictionaryComponent = null;
  if (element instanceof DictionaryComponent) {
    dictionaryComponent = (DictionaryComponent) element;
  }

  if (dictionaryComponent == null) return true;

  final List<String> parts = dictionaryComponent.getNameIdentifiers();
  if (parts.isEmpty())
    return true;
  final String componentName = dictionaryComponent.getName(); //or just getName()...
  final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());

  String searchWord = parts.get(0);
  return searchWord.isEmpty() || helper.processElementsWithWord(new MyOccurrenceProcessor(dictionaryComponent, componentName, consumer), 
      queryParameters.getScopeDeterminedByUser(), searchWord, UsageSearchContext.IN_CODE, true);

}
 
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:21,代码来源:AppleScriptDictionaryComponentReferencesSearch.java

示例2: should_process_reference

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
@Test
public void should_process_reference() throws Exception {
    // given
    PsiReference reference1 = mock(PsiReference.class);
    PsiReference reference2 = mock(PsiReference.class);

    PsiField field = mock(PsiField.class);
    ReferencesSearch.SearchParameters searchParameters = mock(ReferencesSearch.SearchParameters.class);
    when(searchParameters.getElementToSearch()).thenReturn(field);
    when(searchParameters.getEffectiveSearchScope()).thenReturn(mock(GlobalSearchScope.class));
    when(scenarioStateReferenceProvider.findReferences(field)).thenReturn(Arrays.asList(reference1, reference2));
    when(scenarioStateProvider.isJGivenScenarioState(field)).thenReturn(true);

    // when
    referenceProvider.processQuery(searchParameters, processor);

    // then
    verify(processor).process(reference1);
    verify(processor).process(reference2);
}
 
开发者ID:TNG,项目名称:jgiven-intellij-plugin,代码行数:21,代码来源:ReferenceProviderTest.java

示例3: 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

示例4: 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

示例5: removeParametersUsedInExitsOnly

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
public void removeParametersUsedInExitsOnly(PsiElement codeFragment,
                                            Collection<PsiStatement> exitStatements,
                                            ControlFlow controlFlow,
                                            int startOffset,
                                            int endOffset) {
  final LocalSearchScope scope = new LocalSearchScope(codeFragment);
  Variables:
  for (Iterator<VariableData> iterator = myInputVariables.iterator(); iterator.hasNext();) {
    final VariableData data = iterator.next();
    for (PsiReference ref : ReferencesSearch.search(data.variable, scope)) {
      PsiElement element = ref.getElement();
      int elementOffset = controlFlow.getStartOffset(element);
      if (elementOffset >= startOffset && elementOffset <= endOffset) {
        if (!isInExitStatements(element, exitStatements)) continue Variables;
      }
    }
    iterator.remove();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:InputVariables.java

示例6: moveDeclaration

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement moveDeclaration(@NotNull final Project project, @NotNull final PsiField variable) {
  final Map<PsiCodeBlock, Collection<PsiReference>> refs = new HashMap<PsiCodeBlock, Collection<PsiReference>>();
  if (!groupByCodeBlocks(ReferencesSearch.search(variable).findAll(), refs)) return null;
  PsiElement element = null;
  for (Collection<PsiReference> psiReferences : refs.values()) {
    element = super.moveDeclaration(project, variable, psiReferences, false);
  }
  if (element != null) {
    final PsiElement finalElement = element;
    Runnable runnable = new Runnable() {
      public void run() {
        beforeDelete(project, variable, finalElement);
        variable.normalizeDeclaration();
        variable.delete();
      }
    };
    ApplicationManager.getApplication().runWriteAction(runnable);
  }
  return element;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:FieldCanBeLocalInspection.java

示例7: variableSometimesAssignedNull

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
private boolean variableSometimesAssignedNull(@NotNull PsiVariable variable) {
  final PsiExpression initializer = variable.getInitializer();
  if (initializer != null && expressionIsSometimesNull(initializer)) {
    return true;
  }
  final Query<PsiReference> references = ReferencesSearch.search(variable);
  for (final PsiReference reference : references) {
    final PsiElement element = reference.getElement();
    if (!(element instanceof PsiReferenceExpression)) {
      continue;
    }
    final PsiElement parent = element.getParent();
    if (!(parent instanceof PsiAssignmentExpression)) {
      continue;
    }
    final PsiAssignmentExpression assignment = (PsiAssignmentExpression)parent;
    if (assignment.getLExpression().equals(element) && expressionIsSometimesNull(assignment.getRExpression())) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:NullityInferrer.java

示例8: canBeDeclaredFinal

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
private static boolean canBeDeclaredFinal(@NotNull final PsiVariable variable, @Nullable final PsiElement scope) {
  if (scope == null) {
    return false;
  }
  final Collection<PsiReference> references = ReferencesSearch.search(variable, new LocalSearchScope(scope)).findAll();
  boolean foundOnce = (variable instanceof PsiParameter) || (variable.getInitializer() != null);
  for (PsiReference reference : references) {
    if (reference instanceof PsiReferenceExpression) {
      if (PsiUtil.isAccessedForWriting((PsiReferenceExpression) reference)) {
        if (foundOnce) {
          return false;
        }
        foundOnce = true;
      }
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JavaWithRunnableSurrounder.java

示例9: addContainerReferences

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
private static void addContainerReferences(@NotNull PsiVariable variable,
                                           @NotNull final Processor<SliceUsage> processor,
                                           @NotNull final SliceUsage parent,
                                           @NotNull final PsiSubstitutor parentSubstitutor,
                                           final int indexNesting,
                                           @NotNull final String syntheticField) {
  if (indexNesting != 0) {
    ReferencesSearch.search(variable).forEach(new Processor<PsiReference>() {
      @Override
      public boolean process(PsiReference reference) {
        PsiElement element = reference.getElement();
        if (element instanceof PsiExpression && !element.getManager().areElementsEquivalent(element, parent.getElement())) {
          PsiExpression expression = (PsiExpression)element;
          if (!addContainerItemModification(expression, processor, parent, parentSubstitutor, indexNesting, syntheticField)) return false;
        }
        return true;
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:SliceUtil.java

示例10: searchFields

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
private static void searchFields(final PsiClass allIcons, final UsageView view, final ProgressIndicator indicator) {
  ApplicationManager.getApplication().runReadAction(new Runnable() {
    @Override
    public void run() {
      indicator.setText("Searching for: " + allIcons.getQualifiedName());
    }
  });

  ReferencesSearch.search(allIcons).forEach(new Processor<PsiReference>() {
    @Override
    public boolean process(PsiReference reference) {
      PsiElement elt = reference.getElement();

      while (elt instanceof PsiExpression) elt = elt.getParent();

      if (elt instanceof PsiField) {
        UsageInfo info = new UsageInfo(elt, false);
        view.appendUsage(new UsageInfo2UsageAdapter(info));
      }

      return true;
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:StaticIconFieldsAction.java

示例11: 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

示例12: 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

示例13: testMethod

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
public void testMethod() throws Exception {
  String text =
          "void method(final int i) {" +
          "  Runnable runnable = new Runnable() {" +
          "    public void run() {" +
          "      System.out.println(i);" +
          "    }" +
          "  };" +
          "  System.out.println(i);" +
          "}";
  final PsiManager psiManager = PsiManager.getInstance(myProject);
  final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
  final PsiMethod methodFromText = elementFactory.createMethodFromText(text, null);
  final PsiParameter[] parameters = methodFromText.getParameterList().getParameters();
  final PsiReference[] references =
    ReferencesSearch.search(parameters[0], new LocalSearchScope(methodFromText), false).toArray(new PsiReference[0]);
  Assert.assertEquals(references.length, 2);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FindParameterTest.java

示例14: collectTargets

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
private static <T> void collectTargets(PsiField field, final ArrayList<T> targets, final Function<PsiElement, T> fun, final boolean stopAtFirst) {
  final PsiClass containingClass = field.getContainingClass();
  LOG.assertTrue(containingClass != null);
  final String qualifiedName = containingClass.getQualifiedName();
  LOG.assertTrue(qualifiedName != null);
  final List<VirtualFile> fxmls = JavaFxControllerClassIndex.findFxmlsWithController(field.getProject(), qualifiedName);
  if (fxmls.isEmpty()) return;
  ReferencesSearch.search(field, GlobalSearchScope.filesScope(field.getProject(), fxmls)).forEach(
    new Processor<PsiReference>() {
      @Override
      public boolean process(PsiReference reference) {
        final PsiElement referenceElement = reference.getElement();
        if (referenceElement == null) return true;
        final PsiFile containingFile = referenceElement.getContainingFile();
        if (containingFile == null) return true;
        if (!JavaFxFileTypeFactory.isFxml(containingFile)) return true;
        if (!(referenceElement instanceof XmlAttributeValue)) return true;
        final XmlAttributeValue attributeValue = (XmlAttributeValue)referenceElement;
        final PsiElement parent = attributeValue.getParent();
        if (!(parent instanceof XmlAttribute)) return true;
        if (!FxmlConstants.FX_ID.equals(((XmlAttribute)parent).getName())) return true;
        targets.add(fun.fun(parent));
        return !stopAtFirst;
      }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavaFxRelatedItemLineMarkerProvider.java

示例15: findUsages

import com.intellij.psi.search.searches.ReferencesSearch; //导入依赖的package包/类
@NotNull
protected UsageInfo[] findUsages() {
  final List<UsageInfo> usagesList = new ArrayList<UsageInfo>();
  for (PsiMember member : myMembersToMove) {
    for (PsiReference psiReference : ReferencesSearch.search(member)) {
      PsiElement ref = psiReference.getElement();
      final MoveMemberHandler handler = MoveMemberHandler.EP_NAME.forLanguage(ref.getLanguage());
      MoveMembersUsageInfo usage = null;
      if (handler != null && myTargetClass != null) {
        usage = handler.getUsage(member, psiReference, myMembersToMove, myTargetClass);
      }
      if (usage != null) {
        usagesList.add(usage);
      }
      else {
        if (!isInMovedElement(ref)) {
          usagesList.add(new MoveMembersUsageInfo(member, ref, null, ref, psiReference));
        }
      }
    }
  }
  UsageInfo[] usageInfos = usagesList.toArray(new UsageInfo[usagesList.size()]);
  usageInfos = UsageViewUtil.removeDuplicatedUsages(usageInfos);
  return usageInfos;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MoveMembersProcessor.java


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