Search in sources :

Example 1 with ATTR_NAME

use of com.android.SdkConstants.ATTR_NAME in project android by JetBrains.

the class StringResourceSafeDeleteProcessorDelegate method getElementsToSearch.

@NotNull
@Override
public Collection<? extends PsiElement> getElementsToSearch(@NotNull PsiElement element, @Nullable Module module, @NotNull Collection<PsiElement> elementsToDelete) {
    if (element instanceof XmlTag) {
        XmlTag tag = (XmlTag) element;
        XmlAttribute attribute = tag.getAttribute(ATTR_NAME);
        assert attribute != null;
        Collection<PsiElement> elements = new ArrayList<>();
        // Find usages of the string element's name attribute value, such as @string/string_name references in XML files
        elements.add(attribute.getValueElement());
        // R.string.string_name references in Java files that are not LightElements
        Collection<PsiField> fields = Arrays.stream(AndroidResourceUtil.findResourceFieldsForValueResource(tag, true)).filter(field -> !(field instanceof LightElement)).collect(Collectors.toList());
        elements.addAll(fields);
        return elements;
    } else if (element instanceof XmlAttributeValue) {
        return getElementsToSearch(element.getParent().getParent(), module, elementsToDelete);
    } else {
        return Collections.emptyList();
    }
}
Also used : java.util(java.util) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ATTR_NAME(com.android.SdkConstants.ATTR_NAME) LightElement(com.intellij.psi.impl.light.LightElement) UsageInfo(com.intellij.usageView.UsageInfo) TAG_STRING(com.android.SdkConstants.TAG_STRING) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) SafeDeleteProcessorDelegateBase(com.intellij.refactoring.safeDelete.SafeDeleteProcessorDelegateBase) PsiElement(com.intellij.psi.PsiElement) AndroidResourceUtil(org.jetbrains.android.util.AndroidResourceUtil) Project(com.intellij.openapi.project.Project) PsiField(com.intellij.psi.PsiField) PsiNamedElement(com.intellij.psi.PsiNamedElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) SafeDeleteProcessor(com.intellij.refactoring.safeDelete.SafeDeleteProcessor) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) XmlTag(com.intellij.psi.xml.XmlTag) NonCodeUsageSearchInfo(com.intellij.refactoring.safeDelete.NonCodeUsageSearchInfo) XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiField(com.intellij.psi.PsiField) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) LightElement(com.intellij.psi.impl.light.LightElement) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ATTR_NAME (com.android.SdkConstants.ATTR_NAME)1 TAG_STRING (com.android.SdkConstants.TAG_STRING)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 LightElement (com.intellij.psi.impl.light.LightElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NonCodeUsageSearchInfo (com.intellij.refactoring.safeDelete.NonCodeUsageSearchInfo)1 SafeDeleteProcessor (com.intellij.refactoring.safeDelete.SafeDeleteProcessor)1 SafeDeleteProcessorDelegateBase (com.intellij.refactoring.safeDelete.SafeDeleteProcessorDelegateBase)1 UsageInfo (com.intellij.usageView.UsageInfo)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 AndroidResourceUtil (org.jetbrains.android.util.AndroidResourceUtil)1 NotNull (org.jetbrains.annotations.NotNull)1