use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidInferNullityAnnotationAction method findModulesFromUsage.
private static Map<Module, PsiFile> findModulesFromUsage(UsageInfo[] infos) {
// We need 1 file from each module that requires changes (the file may be overwritten below):
Map<Module, PsiFile> modules = new HashMap<>();
for (UsageInfo info : infos) {
PsiElement element = info.getElement();
assert element != null;
Module module = ModuleUtilCore.findModuleForPsiElement(element);
PsiFile file = element.getContainingFile();
modules.put(module, file);
}
return modules;
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidComponentSafeDeleteProcessor method findUsages.
@Override
public NonCodeUsageSearchInfo findUsages(@NotNull PsiElement element, @NotNull PsiElement[] allElementsToDelete, @NotNull List<UsageInfo> result) {
final ArrayList<UsageInfo> usages = new ArrayList<UsageInfo>();
final NonCodeUsageSearchInfo info = getBaseHandler().findUsages(element, allElementsToDelete, usages);
if (info == null) {
return info;
}
assert element instanceof PsiClass;
final PsiClass componentClass = (PsiClass) element;
final AndroidAttributeValue<PsiClass> declaration = AndroidDomUtil.findComponentDeclarationInManifest(componentClass);
if (declaration == null) {
return info;
}
final XmlAttributeValue declarationAttributeValue = declaration.getXmlAttributeValue();
for (UsageInfo usage : usages) {
if (declarationAttributeValue != usage.getElement()) {
result.add(usage);
}
}
return info;
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class UnusedResourcesProcessor method findUsages.
@Override
@NotNull
protected UsageInfo[] findUsages() {
Map<Issue, Map<File, List<ProblemData>>> map = computeUnusedMap();
List<PsiElement> elements = computeUnusedDeclarationElements(map);
myElements = elements.toArray(new PsiElement[elements.size()]);
UsageInfo[] result = new UsageInfo[myElements.length];
for (int i = 0, n = myElements.length; i < n; i++) {
PsiElement element = myElements[i];
if (element instanceof PsiBinaryFile) {
// The usage view doesn't handle binaries at all. Work around this (for example,
// the UsageInfo class asserts in the constructor if the element doesn't have
// a text range.)
SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
SmartPsiElementPointer<PsiElement> smartPointer = smartPointerManager.createSmartPsiElementPointer(element);
SmartPsiFileRange smartFileRange = smartPointerManager.createSmartPsiFileRangePointer((PsiBinaryFile) element, TextRange.EMPTY_RANGE);
result[i] = new UsageInfo(smartPointer, smartFileRange, false, false) {
@Override
public boolean isValid() {
return true;
}
@Override
@Nullable
public Segment getSegment() {
return null;
}
};
} else {
result[i] = new UsageInfo(element);
}
}
return UsageViewUtil.removeDuplicatedUsages(result);
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidInlineAllStyleUsagesProcessor method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
final List<StyleUsageData> inlineInfos = new ArrayList<StyleUsageData>();
for (UsageInfo usage : usages) {
final PsiElement element = usage.getElement();
if (element == null)
continue;
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
StyleUsageData usageData = tag != null ? AndroidInlineUtil.getStyleUsageData(tag) : null;
if (usageData != null && usageData.getReference().computeTargetElements().length == 1) {
inlineInfos.add(usageData);
}
}
for (StyleUsageData info : inlineInfos) {
info.inline(myAttributeValues, myParentStyleRef);
}
myStyleTag.delete();
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidInlineAllStyleUsagesProcessor method findUsages.
@NotNull
@Override
protected UsageInfo[] findUsages() {
final Set<UsageInfo> usages = new HashSet<UsageInfo>();
AndroidInlineUtil.addReferences(myStyleElement, usages);
for (PsiField field : AndroidResourceUtil.findResourceFieldsForValueResource(myStyleTag, false)) {
AndroidInlineUtil.addReferences(field, usages);
}
return usages.toArray(new UsageInfo[usages.size()]);
}
Aggregations