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


Java FindUsagesHandler类代码示例

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


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

示例1: findTagUsage

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
private int findTagUsage(XmlTag element) {
    final FindUsagesHandler handler = FindUsageUtils.getFindUsagesHandler(element, element.getProject());
    if (handler != null) {
        final FindUsagesOptions findUsagesOptions = handler.getFindUsagesOptions();
        final PsiElement[] primaryElements = handler.getPrimaryElements();
        final PsiElement[] secondaryElements = handler.getSecondaryElements();
        Factory factory = new Factory() {
            public UsageSearcher create() {
                return FindUsageUtils.createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, (PsiFile) null);
            }
        };
        UsageSearcher usageSearcher = (UsageSearcher)factory.create();
        final AtomicInteger mCount = new AtomicInteger(0);
        usageSearcher.generate(new Processor<Usage>() {
            @Override
            public boolean process(Usage usage) {
                if (ResourceUsageCountUtils.isUsefulUsageToCount(usage)) {
                    mCount.incrementAndGet();
                }
                return true;
            }
        });
        return mCount.get();
    }
    return 0;
}
 
开发者ID:niorgai,项目名称:Android-Resource-Usage-Count,代码行数:27,代码来源:UsageCountLineProvider.java

示例2: findUsages

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@NotNull
public Collection<UsageInfo> findUsages(@NotNull final PsiElement targetElement, @Nullable SearchScope scope) {
  final Project project = getProject();
  final FindUsagesHandler handler =
    ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager().getFindUsagesHandler(targetElement, false);

  final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
  Assert.assertNotNull("Cannot find handler for: " + targetElement, handler);
  final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
  final FindUsagesOptions options = handler.getFindUsagesOptions(null);
  if (scope != null) options.searchScope = scope; 
  for (PsiElement psiElement : psiElements) {
    handler.processElementUsages(psiElement, processor, options);
  }
  return processor.getResults();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CodeInsightTestFixtureImpl.java

示例3: createFindUsageHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
/**
 * @see {@link com.jetbrains.python.findUsages.PyFindUsagesHandlerFactory#createFindUsagesHandler(com.intellij.psi.PsiElement, boolean) createFindUsagesHandler}
 */
@Nullable
private static FindUsagesHandler createFindUsageHandler(@NotNull final PsiElement element) {
  if (element instanceof PyFunction) {
    final TypeEvalContext context = TypeEvalContext.userInitiated(element.getProject(), null);
    final Collection<PsiElement> superMethods = PySuperMethodsSearch.search((PyFunction)element, true, context).findAll();
    if (superMethods.size() > 0) {
      final PsiElement next = superMethods.iterator().next();
      if (next instanceof PyFunction && !isInObject((PyFunction)next)) {
        List<PsiElement> allMethods = Lists.newArrayList();
        allMethods.add(element);
        allMethods.addAll(superMethods);

        return new PyFunctionFindUsagesHandler(element, allMethods);
      }
    }
    return new PyFunctionFindUsagesHandler(element);
  }
  if (element instanceof PyClass) {
    return new PyClassFindUsagesHandler((PyClass)element);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyStaticCallHierarchyUtil.java

示例4: createSettingsButton

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings,
      new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
          });
          cancelAction.run();
        }
      }
  );
}
 
开发者ID:square,项目名称:dagger-intellij-plugin,代码行数:25,代码来源:ShowUsagesAction.java

示例5: createSettingsButton

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
        }
      });
      cancelAction.run();
    }
  });
}
 
开发者ID:square,项目名称:otto-intellij-plugin,代码行数:25,代码来源:ShowUsagesAction.java

示例6: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler(
    @NotNull final PsiElement element, final boolean forHighlightUsages
) {
    if (canFindUsages(element)) {
        return new FindUsagesHandler(element) {

        };
    }
    return null;

}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:14,代码来源:MacrosFindUsagesHandlerFactory.java

示例7: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler( @NotNull PsiElement element, boolean forHighlightUsages )
{
  List<PsiElement> javaElements = ResourceToManifoldUtil.findJavaElementsFor( element );
  if( javaElements.isEmpty() )
  {
    return null;
  }

  if( element instanceof PsiDirectory )
  {
    final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage( (PsiDirectory)element );
    return psiPackage == null ? null : new JavaFindUsagesHandler( psiPackage, this );
  }

  if( element instanceof PsiMethod && !forHighlightUsages )
  {
    final PsiMethod[] methods = SuperMethodWarningUtil.checkSuperMethods( (PsiMethod)element, ACTION_STRING );
    if( methods.length > 1 )
    {
      return new JavaFindUsagesHandler( element, methods, this );
    }
    if( methods.length == 1 )
    {
      return new JavaFindUsagesHandler( methods[0], this );
    }
    return FindUsagesHandler.NULL_HANDLER;
  }

  return new JavaFindUsagesHandler( element, this ) {
    @NotNull
    @Override
    public PsiElement[] getPrimaryElements()
    {
      return javaElements.toArray( new PsiElement[javaElements.size()] );
    }
  };
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:40,代码来源:ManifoldFindUsagesHandlerFactory.java

示例8: getHighlightUsages

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
/**
 * Returns read and write usages of psi element inside a single element
 *
 * @param target target psi element
 * @param psiElement psi element to search in
 * @return a pair where first element is read usages and second is write usages
 */
public static Couple<Collection<TextRange>> getHighlightUsages(@NotNull PsiElement target, PsiElement psiElement, boolean withDeclarations) {
  Collection<TextRange> readRanges = new ArrayList<TextRange>();
  Collection<TextRange> writeRanges = new ArrayList<TextRange>();
  final ReadWriteAccessDetector detector = ReadWriteAccessDetector.findDetector(target);
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(target.getProject())).getFindUsagesManager();
  final FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(target, true);
  final LocalSearchScope scope = new LocalSearchScope(psiElement);
  Collection<PsiReference> refs = findUsagesHandler != null
                            ? findUsagesHandler.findReferencesToHighlight(target, scope)
                            : ReferencesSearch.search(target, scope).findAll();
  for (PsiReference psiReference : refs) {
    if (psiReference == null) {
      LOG.error("Null reference returned, findUsagesHandler=" + findUsagesHandler + "; target=" + target + " of " + target.getClass());
      continue;
    }
    final List<TextRange> textRanges = HighlightUsagesHandler.getRangesToHighlight(psiReference);
    if (detector == null || detector.getReferenceAccess(target, psiReference) == ReadWriteAccessDetector.Access.Read) {
      readRanges.addAll(textRanges);
    }
    else {
      writeRanges.addAll(textRanges);
    }
  }

  if (withDeclarations) {
    final TextRange declRange = HighlightUsagesHandler.getNameIdentifierRange(psiElement.getContainingFile(), target);
    if (declRange != null) {
      if (detector != null && detector.isDeclarationWriteAccess(target)) {
        writeRanges.add(declRange);
      }
      else {
        readRanges.add(declRange);
      }
    }
  }

  return Couple.of(readRanges, writeRanges);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:46,代码来源:IdentifierHighlighterPass.java

示例9: findUsages

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
private static Collection<UsageInfo> findUsages(@NotNull final PsiElement element) {
  final FindUsagesHandler handler = createFindUsageHandler(element);
  if (handler == null) {
    return Lists.newArrayList();
  }
  final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
  final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
  final FindUsagesOptions options = handler.getFindUsagesOptions(null);
  for (PsiElement psiElement : psiElements) {
    handler.processElementUsages(psiElement, processor, options);
  }
  return processor.getResults();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PyStaticCallHierarchyUtil.java

示例10: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Override
  public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
    return new JavaFindUsagesHandler(element, this) {
      @NotNull
      @Override
      public PsiElement[] getSecondaryElements() {
//                final PsiField psiField = (PsiField) getPsiElement();
//                final PsiClass containingClass = psiField.getContainingClass();
//                if (containingClass != null) {
//                    final AccessorsInfo accessorsInfo = AccessorsInfo.build(psiField);
//                    final String psiFieldName = psiField.getName();
//
//                    final String fieldName = accessorsInfo.removePrefix(psiFieldName);
//                    if (!fieldName.equals(psiFieldName)) {
//                        final boolean isBoolean = PsiType.BOOLEAN.equals(psiField.getType());
//
//                        final String getterName = LombokUtils.toGetterName(accessorsInfo, psiFieldName, isBoolean);
//                        final String setterName = LombokUtils.toSetterName(accessorsInfo, psiFieldName, isBoolean);
//
//                        final PsiMethod[] psiGetterMethods = containingClass.findMethodsByName(getterName, false);
//                        final PsiMethod[] psiSetterMethods = containingClass.findMethodsByName(setterName, false);
//
//                        final Set<PsiElement> elements = new THashSet<PsiElement>(psiGetterMethods.length + psiSetterMethods.length);
//                        for (PsiMethod accessor : psiGetterMethods) {
//                            ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(accessor, ACTION_STRING));
//                        }
//                        for (PsiMethod accessor : psiSetterMethods) {
//                            ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(accessor, ACTION_STRING));
//                        }
//                        return PsiUtilCore.toPsiElementArray(elements);
//                    }
//                }
        return super.getSecondaryElements();
      }
    };
  }
 
开发者ID:SiimKinks,项目名称:sqlitemagic,代码行数:37,代码来源:SqliteMagicFieldFindUsagesHandlerFactory.java

示例11: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {

    if (canFindUsages(element)) {
        return new FindUsagesHandler(element) {};
    }

    return null;

}
 
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:12,代码来源:JSGraphQLEndpointFindUsagesHandlerFactory.java

示例12: highlightTargetUsages

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
private void highlightTargetUsages(@NotNull PsiElement target) {
  final ReadWriteAccessDetector detector = ReadWriteAccessDetector.findDetector(target);
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(target.getProject())).getFindUsagesManager();
  final FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(target, true);
  final LocalSearchScope scope = new LocalSearchScope(myFile);
  Collection<PsiReference> refs = findUsagesHandler != null
                            ? findUsagesHandler.findReferencesToHighlight(target, scope)
                            : ReferencesSearch.search(target, scope).findAll();
  for (PsiReference psiReference : refs) {
    final List<TextRange> textRanges = HighlightUsagesHandler.getRangesToHighlight(psiReference);
    if (detector == null || detector.getReferenceAccess(target, psiReference) == ReadWriteAccessDetector.Access.Read) {
      myReadAccessRanges.addAll(textRanges);
    }
    else {
      myWriteAccessRanges.addAll(textRanges);
    }
  }

  final TextRange declRange = HighlightUsagesHandler.getNameIdentifierRange(myFile, target);
  if (declRange != null) {
    if (detector != null && detector.isDeclarationWriteAccess(target)) {
      myWriteAccessRanges.add(declRange);
    }
    else {
      myReadAccessRanges.add(declRange);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:IdentifierHighlighterPass.java

示例13: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull final PsiElement element, final boolean forHighlightUsages) {
  if (canFindUsages(element)) {
    PsiElement target = HaxeFindUsagesUtil.getTargetElement(element);

    if (!forHighlightUsages) {
      if (target instanceof PsiReference) {
        PsiElement resolved = ((PsiReference)target).resolve();
        if (null != resolved && resolved instanceof HaxeMethod) {
          target = resolved;
        }
      }
      if (target instanceof HaxeMethod) {
        PsiMethod[] supers = ((HaxeMethod)target).findSuperMethods();
        if (supers.length != 0) {
          String chosen = askWhetherToSearchForOverridingMethods(target);
          if (CURRENT_CLASS == chosen)    { return new HaxeFindUsagesHandler(target); }
          else if (BASE_CLASS == chosen)  { return new HaxeFindUsagesHandler(supers[supers.length - 1]); }
          else /* ANCESTOR_CLASSES */     { return new HaxeFindUsagesHandler(target, supers); }
        }
      }
    }

    return new HaxeFindUsagesHandler(target != null ? target : element);
  }
  return FindUsagesHandler.NULL_HANDLER;
}
 
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:28,代码来源:HaxeFindUsagesHandlerFactory.java

示例14: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
  return new FindUsagesHandler(element) {
    @NotNull
    @Override
    public PsiElement[] getSecondaryElements() {
      final PsiField psiField = (PsiField) getPsiElement();
      final PsiClass containingClass = psiField.getContainingClass();
      if (containingClass != null) {
        final AccessorsInfo accessorsInfo = AccessorsInfo.build(psiField);
        final String psiFieldName = psiField.getName();

        final String fieldName = accessorsInfo.removePrefix(psiFieldName);
        if (!fieldName.equals(psiFieldName)) {
          final boolean isBoolean = PsiType.BOOLEAN.equals(psiField.getType());

          final String getterName = LombokUtils.toGetterName(accessorsInfo, psiFieldName, isBoolean);
          final String setterName = LombokUtils.toSetterName(accessorsInfo, psiFieldName, isBoolean);

          final PsiMethod[] psiGetterMethods = containingClass.findMethodsByName(getterName, false);
          final PsiMethod[] psiSetterMethods = containingClass.findMethodsByName(setterName, false);

          final Set<PsiElement> elements = new THashSet<PsiElement>(psiGetterMethods.length + psiSetterMethods.length);
          ContainerUtil.addAll(elements, psiGetterMethods);
          ContainerUtil.addAll(elements, psiSetterMethods);
          return PsiUtilCore.toPsiElementArray(elements);
        }
      }
      return PsiElement.EMPTY_ARRAY;
    }
  };
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:33,代码来源:LombokFieldFindUsagesHandlerFactory.java

示例15: createFindUsagesHandler

import com.intellij.find.findUsages.FindUsagesHandler; //导入依赖的package包/类
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull final PsiElement element,
                                                 final boolean forHighlightUsages) {
    if (canFindUsages(element)) {
        return new XQueryFindUsagesHandler(element);
    }
    return null;
}
 
开发者ID:ligasgr,项目名称:intellij-xquery,代码行数:9,代码来源:XQueryFindUsagesHandlerFactory.java


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