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


Java UsageTarget类代码示例

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


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

示例1: getTargets

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
  if (editor == null || file == null) return null;

  PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
  if (element == null) return null;

  if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
    return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
  }

  final PsiElement parent = element.getParent();
  if (parent instanceof PsiThrowStatement) {
    return new UsageTarget[] {new PsiElement2UsageTargetAdapter(parent)};
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ThrowsUsageTargetProvider.java

示例2: showObjectUpcastedUsageView

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
private void showObjectUpcastedUsageView(final ObjectUpcastedUsageInfo[] usages) {
  UsageViewPresentation presentation = new UsageViewPresentation();
  presentation.setTargetsNodeText(RefactoringBundle.message("replacing.inheritance.with.delegation"));
  presentation.setCodeUsagesString(RefactoringBundle.message("instances.casted.to.java.lang.object"));
  final String upcastedString = RefactoringBundle.message("instances.upcasted.to.object");
  presentation.setUsagesString(upcastedString);
  presentation.setTabText(upcastedString);

  UsageViewManager manager = UsageViewManager.getInstance(myProject);
  manager.showUsages(
    new UsageTarget[]{new PsiElement2UsageTargetAdapter(myClass)},
    UsageInfoToUsageConverter.convert(new PsiElement[]{myClass}, usages),
    presentation
  );

  WindowManager.getInstance().getStatusBar(myProject).setInfo(RefactoringBundle.message("instances.upcasted.to.java.lang.object.found"));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:InheritanceToDelegationProcessor.java

示例3: UsageViewTreeModelBuilder

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
public UsageViewTreeModelBuilder(UsageViewPresentation presentation, UsageTarget[] targets) {
  //noinspection HardCodedStringLiteral
  super(new DefaultMutableTreeNode("temp root"));
  myPresentation = presentation;
  myRootNode = new RootGroupNode();
  setRoot(myRootNode);

  myTargets = targets;
  myTargetsNodeText = presentation.getTargetsNodeText();
  if (myTargetsNodeText != null) {
    myTargetsNode = new TargetsRootNode(myTargetsNodeText);
    addTargetNodes();
  }
  else {
    myTargetsNode = null;
  }
  myDetachedMode = presentation.isDetachedMode();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:UsageViewTreeModelBuilder.java

示例4: addTargetNodes

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
private void addTargetNodes() {
  if (myTargets.length == 0) return;
  myTargetNodes = new UsageTargetNode[myTargets.length];
  myTargetsNode.removeAllChildren();
  for (int i = 0; i < myTargets.length; i++) {
    UsageTarget target = myTargets[i];
    UsageTargetNode targetNode = new UsageTargetNode(target, this);
    myTargetsNode.add(targetNode);
    myTargetNodes[i] = targetNode;
  }
  myRootNode.addNode(myTargetsNode, new Consumer<Runnable>() {
    @Override
    public void consume(Runnable runnable) {
      UIUtil.invokeLaterIfNeeded(runnable);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:UsageViewTreeModelBuilder.java

示例5: isEnabled

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
private static boolean isEnabled(DataContext dataContext) {
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return false;
  }

  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (editor == null) {
    UsageTarget[] target = UsageView.USAGE_TARGETS_KEY.getData(dataContext);
    return target != null && target.length > 0;
  }
  else {
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
      return false;
    }

    Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language == null) {
      language = file.getLanguage();
    }
    return !(LanguageFindUsages.INSTANCE.forLanguage(language) instanceof EmptyFindUsagesProvider);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:FindUsagesInFileAction.java

示例6: showConflicts

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
/**
 * Shows a panel with name redefinition conflicts, if needed.
 * @param project
 * @param conflicts what {@link #findDefinitions} would return
 * @param obscured name or its topmost qualifier that is obscured, used at top of pane.
 * @param name full name (maybe qualified) to show as obscured and display as qualifier in "would be" chunks.
 * @return true iff conflicts is not empty and the panel is shown.
 */
public static boolean showConflicts(Project project, List<Pair<PsiElement, PsiElement>> conflicts, String obscured, @Nullable String name) {
  if (conflicts.size() > 0) {
    Usage[] usages = new Usage[conflicts.size()];
    int i = 0;
    for (Pair<PsiElement, PsiElement> pair : conflicts) {
      usages[i] = new NameUsage(pair.getFirst(), pair.getSecond(), name != null? name : obscured, name != null);
      i += 1;
    }
    UsageViewPresentation prsnt = new UsageViewPresentation();
    prsnt.setTabText(PyBundle.message("CONFLICT.name.$0.obscured", obscured));
    prsnt.setCodeUsagesString(PyBundle.message("CONFLICT.name.$0.obscured.cannot.convert", obscured));
    prsnt.setUsagesWord(PyBundle.message("CONFLICT.occurrence.sing"));
    prsnt.setUsagesString(PyBundle.message("CONFLICT.occurrence.pl"));
    UsageViewManager.getInstance(project).showUsages(UsageTarget.EMPTY_ARRAY, usages, prsnt);
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:DeclarationConflictChecker.java

示例7: search

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
protected List<PsiElement> search(VirtualFile file) throws IOException {
  final MapDataContext context = createDataContext(file);
  UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {
    @Override
    public Object getData(@NonNls String dataId) {
      return context.getData(dataId);
    }
  });
  PsiElement target = ((PsiElement2UsageTargetAdapter)targets[0]).getElement();
  List<PsiReference> result = new ArrayList<PsiReference>(ReferencesSearch.search(target).findAll());
  return ContainerUtil.map(result, new Function<PsiReference, PsiElement>() {
    @Override
    public PsiElement fun(PsiReference psiReference) {
      return psiReference.getElement();
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:MavenDomTestCase.java

示例8: getTargets

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
  if (editor == null || file == null) return null;

  PsiElement element = file.findElementAt(TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
  if (element == null) return null;

  if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
    return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
  }

  final PsiElement parent = element.getParent();
  if (parent instanceof PsiThrowStatement) {
    return new UsageTarget[] {new PsiElement2UsageTargetAdapter(parent)};
  }

  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:ThrowsUsageTargetProvider.java

示例9: showObjectUpcastedUsageView

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
private void showObjectUpcastedUsageView(final ObjectUpcastedUsageInfo[] usages) {
  UsageViewPresentation presentation = new UsageViewPresentation();
  presentation.setTargetsNodeText(RefactoringBundle.message("replacing.inheritance.with.delegation"));
  presentation.setCodeUsagesString(RefactoringBundle.message("instances.casted.to.java.lang.object"));
  final String upcastedString = RefactoringBundle.message("instances.upcasted.to.object");
  presentation.setUsagesString(upcastedString);
  presentation.setTabText(upcastedString);

  UsageViewManager manager = UsageViewManager.getInstance(myProject);
  manager.showUsages(
    new UsageTarget[]{new PsiElement2UsageTargetAdapter(myClass)},
    UsageInfoToUsageConverter.convert(new UsageInfoToUsageConverter.TargetElementsDescriptor(myClass), usages),
    presentation
  );

  WindowManager.getInstance().getStatusBar(myProject).setInfo(RefactoringBundle.message("instances.upcasted.to.java.lang.object.found"));
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:InheritanceToDelegationProcessor.java

示例10: isAvailableFor

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
@Override
public boolean isAvailableFor(@NotNull UsageView usageView) {
  UsageTarget[] targets = ((UsageViewImpl)usageView).getTargets();
  if (targets.length == 0) return false;
  UsageTarget target = targets[0];
  if (!(target instanceof PsiElementUsageTarget)) return false;
  PsiElement element = ((PsiElementUsageTarget)target).getElement();
  if (element == null || !element.isValid()) return false;

  Project project = element.getProject();
  DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.PSI_ELEMENT.getName(), element,
                                                           SimpleDataContext.getProjectContext(project));
  HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context);
  if (provider == null) return false;
  PsiElement providerTarget = provider.getTarget(context);
  return providerTarget != null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:UsageContextCallHierarchyPanel.java

示例11: isEnabled

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
private static boolean isEnabled(DataContext dataContext) {
  Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return false;
  }

  Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
  if (editor == null) {
    UsageTarget[] target = UsageView.USAGE_TARGETS_KEY.getData(dataContext);
    return target != null && target.length > 0;
  }
  else {
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
      return false;
    }

    Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language == null) {
      language = file.getLanguage();
    }
    return !(LanguageFindUsages.INSTANCE.forLanguage(language) instanceof EmptyFindUsagesProvider);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:FindUsagesInFileAction.java

示例12: getTargets

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
@Nullable
@Override
public UsageTarget[] getTargets(Editor editor, PsiFile psiFile) {
    final PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
    if (element != null) {
        if (!TranslationUtils.isTranslationFile(psiFile)) {
            return UsageTarget.EMPTY_ARRAY;
        }
        ArrayHashElement hashElement = PsiTreeUtil.getParentOfType(element, ArrayHashElement.class);
        if (hashElement == null) {
            return UsageTarget.EMPTY_ARRAY;
        }
        return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
    }
    return UsageTarget.EMPTY_ARRAY;
}
 
开发者ID:letsdrink,项目名称:ouzo-phpstorm-plugin,代码行数:17,代码来源:TranslationUsageTargetProvider.java

示例13: shouldShow

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
@Override public boolean shouldShow(UsageTarget target, Usage usage) {
  PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();

  PsiField field = PsiConsultantImpl.findField(element);
  if (field != null //
      && PsiConsultantImpl.hasAnnotation(field, CLASS_INJECT) //
      && PsiConsultantImpl.hasQuailifierAnnotations(field, qualifierAnnotations)
      && PsiConsultantImpl.hasTypeParameters(field, typeParameters)) {
    return true;
  }

  PsiMethod method = PsiConsultantImpl.findMethod(element);
  if (method != null && (PsiConsultantImpl.hasAnnotation(method, CLASS_INJECT)
          || PsiConsultantImpl.hasAnnotation(method, CLASS_PROVIDES))) {
    for (PsiParameter parameter : method.getParameterList().getParameters()) {
      PsiClass parameterClass = PsiConsultantImpl.checkForLazyOrProvider(parameter);
      if (parameterClass.equals(returnType) && PsiConsultantImpl.hasQuailifierAnnotations(
          parameter, qualifierAnnotations)
          && PsiConsultantImpl.hasTypeParameters(parameter, typeParameters)) {
        return true;
      }
    }
  }

  return false;
}
 
开发者ID:square,项目名称:dagger-intellij-plugin,代码行数:27,代码来源:Decider.java

示例14: isEnabled

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
private static boolean isEnabled(DataContext dataContext) {
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return false;
  }

  Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);
  if (editor == null) {
    UsageTarget[] target = dataContext.getData(UsageView.USAGE_TARGETS_KEY);
    return target != null && target.length > 0;
  }
  else {
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
      return false;
    }

    Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language == null) {
      language = file.getLanguage();
    }
    return !(LanguageFindUsages.INSTANCE.forLanguage(language) instanceof EmptyFindUsagesProvider);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:FindUsagesInFileAction.java

示例15: isAvailableFor

import com.intellij.usages.UsageTarget; //导入依赖的package包/类
@Override
public boolean isAvailableFor(@NotNull UsageView usageView)
{
	UsageTarget[] targets = ((UsageViewImpl) usageView).getTargets();
	if(targets.length == 0)
	{
		return false;
	}
	UsageTarget target = targets[0];
	if(!(target instanceof PsiElementUsageTarget))
	{
		return false;
	}
	PsiElement element = ((PsiElementUsageTarget) target).getElement();
	if(element == null || !element.isValid())
	{
		return false;
	}
	if(!(element instanceof PsiVariable))
	{
		return false;
	}
	PsiFile file = element.getContainingFile();
	return file instanceof PsiJavaFile;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:UsageContextDataflowToPanel.java


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