本文整理汇总了Java中com.intellij.usages.Usage类的典型用法代码示例。如果您正苦于以下问题:Java Usage类的具体用法?Java Usage怎么用?Java Usage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Usage类属于com.intellij.usages包,在下文中一共展示了Usage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSelected
import com.intellij.usages.Usage; //导入依赖的package包/类
@Override
public void setSelected(AnActionEvent e, boolean state) {
JGivenSettings.getInstance().setJGivenFilteringEnabled(state);
if (e.getProject() == null) {
return;
}
Set<Usage> scenarioStateUsages = usageView.getUsages().stream()
.filter(u -> u instanceof ReadWriteAccessUsageInfo2UsageAdapter &&
scenarioStateAnnotationProvider.isJGivenScenarioState(((ReadWriteAccessUsageInfo2UsageAdapter) u).getElement()))
.collect(Collectors.toSet());
if (state) {
excludedUsages.stream()
.filter(u -> !scenarioStateUsages.contains(u))
.forEach(usageView::appendUsage);
} else {
excludedUsages = usageView.getUsages().stream()
.filter(scenarioStateUsages::contains)
.collect(Collectors.toSet());
excludedUsages.forEach(usageView::removeUsage);
}
e.getProject().getMessageBus().syncPublisher(UsageFilteringRuleProvider.RULES_CHANGED).run();
}
示例2: findTagUsage
import com.intellij.usages.Usage; //导入依赖的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;
}
示例3: customizeCellRenderer
import com.intellij.usages.Usage; //导入依赖的package包/类
@Override
public void customizeCellRenderer(@NotNull SliceUsageCellRendererBase renderer,
@NotNull JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
Usage usage = getValue();
renderer.append("Value: ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
if (usage instanceof UsageInfo2UsageAdapter) {
PsiElement element = ((UsageInfo2UsageAdapter)usage).getElement();
if (element == null) {
renderer.append(UsageViewBundle.message("node.invalid") + " ", SliceUsageCellRenderer.ourInvalidAttributes);
}
else {
appendElementText((UsageInfo2UsageAdapter)usage, element, renderer);
}
}
else {
renderer.append("Other", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
}
}
示例4: testFindWholeWords
import com.intellij.usages.Usage; //导入依赖的package包/类
public void testFindWholeWords() {
configureByText(FileTypes.PLAIN_TEXT, "-- -- ---");
FindModel model = new FindModel();
model.setStringToFind("--");
model.setWholeWordsOnly(true);
List<Usage> usages = FindUtil.findAll(myProject, myEditor, model);
assertNotNull(usages);
assertEquals(2, usages.size());
configureByText(FileTypes.PLAIN_TEXT, "[email protected]");
model = new FindModel();
model.setStringToFind("@AspectJ");
model.setWholeWordsOnly(true);
usages = FindUtil.findAll(myProject, myEditor, model);
assertNotNull(usages);
assertEquals(1, usages.size());
}
示例5: appendUsage
import com.intellij.usages.Usage; //导入依赖的package包/类
@Nullable
UsageNode appendUsage(@NotNull Usage usage, @NotNull Consumer<Runnable> edtQueue) {
if (!isVisible(usage)) return null;
final boolean dumb = DumbService.isDumb(myProject);
GroupNode lastGroupNode = myRoot;
for (int i = 0; i < myGroupingRules.length; i++) {
final UsageGroupingRule rule = myGroupingRules[i];
if (dumb && !DumbService.isDumbAware(rule)) continue;
final UsageGroup group;
if (rule instanceof UsageGroupingRuleEx) {
group = ((UsageGroupingRuleEx) rule).groupUsage(usage, myTargets);
}
else {
group = rule.groupUsage(usage);
}
if (group != null) {
lastGroupNode = lastGroupNode.addGroup(group, i, edtQueue);
}
}
return lastGroupNode.addUsage(usage, edtQueue);
}
示例6: tryMerge
import com.intellij.usages.Usage; //导入依赖的package包/类
@Nullable UsageNode tryMerge(@NotNull Usage usage) {
if (!(usage instanceof MergeableUsage)) return null;
MergeableUsage mergeableUsage = (MergeableUsage)usage;
for (UsageNode node : myUsageNodes) {
Usage original = node.getUsage();
if (original == mergeableUsage) {
// search returned duplicate usage, ignore
return node;
}
if (original instanceof MergeableUsage) {
if (((MergeableUsage)original).merge(mergeableUsage)) return node;
}
}
return null;
}
示例7: addUsage
import com.intellij.usages.Usage; //导入依赖的package包/类
public UsageNode addUsage(@NotNull Usage usage, @NotNull Consumer<Runnable> edtQueue) {
final UsageNode node;
synchronized (lock) {
if (myUsageTreeModel.isFilterDuplicatedLine()) {
UsageNode mergedWith = tryMerge(usage);
if (mergedWith != null) {
return mergedWith;
}
}
node = new UsageNode(usage, getBuilder());
myUsageNodes.add(node);
}
if (!getBuilder().isDetachedMode()) {
edtQueue.consume(new Runnable() {
@Override
public void run() {
myTreeModel.insertNodeInto(node, GroupNode.this, getNodeIndex(node));
incrementUsageCount();
}
});
}
return node;
}
示例8: groupUsage
import com.intellij.usages.Usage; //导入依赖的package包/类
@Override
public UsageGroup groupUsage(@NotNull Usage usage) {
if (usage instanceof UsageInModule) {
UsageInModule usageInModule = (UsageInModule)usage;
Module module = usageInModule.getModule();
if (module != null) return new ModuleUsageGroup(module);
}
if (usage instanceof UsageInLibrary) {
UsageInLibrary usageInLibrary = (UsageInLibrary)usage;
OrderEntry entry = usageInLibrary.getLibraryEntry();
if (entry != null) return new LibraryUsageGroup(entry);
}
return null;
}
示例9: groupUsage
import com.intellij.usages.Usage; //导入依赖的package包/类
@Override
public UsageGroup groupUsage(@NotNull Usage usage) {
if (!(usage instanceof PsiElementUsage)) {
return null;
}
PsiElementUsage elementUsage = (PsiElementUsage)usage;
PsiElement element = elementUsage.getElement();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
if (virtualFile == null) {
return null;
}
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
boolean isInLib = fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile);
if (isInLib) return LIBRARY;
boolean isInTest = fileIndex.isInTestSourceContent(virtualFile);
return isInTest ? TEST : PRODUCTION;
}
示例10: groupUsage
import com.intellij.usages.Usage; //导入依赖的package包/类
@Override
@Nullable
public UsageGroup groupUsage(@NotNull Usage usage) {
if (usage instanceof UsageInFile) {
UsageInFile usageInFile = (UsageInFile)usage;
VirtualFile file = usageInFile.getFile();
if (file != null) {
if (file instanceof VirtualFileWindow) {
file = ((VirtualFileWindow)file).getDelegate();
}
VirtualFile dir = file.getParent();
if (dir == null) return null;
return getGroupForFile(dir);
}
}
return null;
}
示例11: collectFiles
import com.intellij.usages.Usage; //导入依赖的package包/类
protected static Set<VirtualFile> collectFiles(Set<Usage> usages, boolean findFirst) {
final Set<VirtualFile> files = new HashSet<VirtualFile>();
for (Usage usage : usages) {
if (usage instanceof PsiElementUsage) {
PsiElement psiElement = ((PsiElementUsage)usage).getElement();
if (psiElement != null && psiElement.isValid()) {
PsiFile psiFile = psiElement.getContainingFile();
if (psiFile != null) {
VirtualFile file = psiFile.getVirtualFile();
if (file != null) {
files.add(file);
if (findFirst) return files;
}
}
}
}
}
return files;
}
示例12: getBackgroundColor
import com.intellij.usages.Usage; //导入依赖的package包/类
private Color getBackgroundColor(boolean isSelected, Usage usage) {
Color fileBgColor = null;
if (isSelected) {
fileBgColor = UIUtil.getListSelectionBackground();
}
else {
VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null;
if (virtualFile != null) {
Project project = myUsageView.getProject();
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile != null && psiFile.isValid()) {
final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile);
if (color != null) fileBgColor = color;
}
}
}
return fileBgColor;
}
示例13: customizeCellRenderer
import com.intellij.usages.Usage; //导入依赖的package包/类
@Override
protected void customizeCellRenderer(final JList list,
final Object value,
final int index,
final boolean selected,
final boolean hasFocus) {
Usage usage = (Usage)value;
UsagePresentation presentation = usage.getPresentation();
setIcon(presentation.getIcon());
VirtualFile virtualFile = getVirtualFile(usage);
if (virtualFile != null) {
append(virtualFile.getName() + ": ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
setIcon(virtualFile.getFileType().getIcon());
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
if (psiFile != null) {
setIcon(psiFile.getIcon(0));
}
}
TextChunk[] text = presentation.getText();
for (TextChunk textChunk : text) {
SimpleTextAttributes simples = textChunk.getSimpleAttributesIgnoreBackground();
append(textChunk.getText(), simples);
}
}
示例14: showConflicts
import com.intellij.usages.Usage; //导入依赖的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;
}
示例15: findUsage
import com.intellij.usages.Usage; //导入依赖的package包/类
/**
* Finds all usages of element. Works much like method in {@link com.intellij.testFramework.fixtures.CodeInsightTestFixture#findUsages(com.intellij.psi.PsiElement)},
* but supports {@link com.intellij.find.findUsages.CustomUsageSearcher} and {@link com.intellij.psi.search.searches.ReferencesSearch} as well
*
* @param element what to find
* @return usages
*/
@NotNull
protected Collection<PsiElement> findUsage(@NotNull final PsiElement element) {
final Collection<PsiElement> result = new ArrayList<PsiElement>();
final CollectProcessor<Usage> usageCollector = new CollectProcessor<Usage>();
for (final CustomUsageSearcher searcher : CustomUsageSearcher.EP_NAME.getExtensions()) {
searcher.processElementUsages(element, usageCollector, new FindUsagesOptions(myFixture.getProject()));
}
for (final Usage usage : usageCollector.getResults()) {
if (usage instanceof PsiElementUsage) {
result.add(((PsiElementUsage)usage).getElement());
}
}
for (final PsiReference reference : ReferencesSearch.search(element).findAll()) {
result.add(reference.getElement());
}
for (final UsageInfo info : myFixture.findUsages(element)) {
result.add(info.getElement());
}
return result;
}