Search in sources :

Example 1 with DynamicResourceValueItem

use of com.android.tools.idea.res.DynamicResourceValueItem in project android by JetBrains.

the class AndroidResourceReferenceBase method resolveInner.

@NotNull
private ResolveResult[] resolveInner() {
    final List<PsiElement> elements = new ArrayList<>();
    final boolean attrReference = myResourceValue.getPrefix() == '?';
    collectTargets(myFacet, myResourceValue, elements, attrReference);
    final List<ResolveResult> result = new ArrayList<>();
    if (elements.isEmpty() && myResourceValue.getResourceName() != null && !AndroidUtils.SYSTEM_RESOURCE_PACKAGE.equals(myResourceValue.getNamespace())) {
        // Dynamic items do not appear in the XML scanning file index; look for
        // these in the resource repositories.
        LocalResourceRepository resources = AppResourceRepository.getAppResources(myFacet.getModule(), true);
        ResourceType resourceType = myResourceValue.getType();
        if (resourceType != null && (resourceType != ResourceType.ATTR || attrReference)) {
            // If not, it could be some broken source, such as @android/test
            assert resources != null;
            List<ResourceItem> items = resources.getResourceItem(resourceType, myResourceValue.getResourceName());
            if (items != null && FolderTypeRelationship.getRelatedFolders(resourceType).contains(ResourceFolderType.VALUES)) {
                for (ResourceItem item : items) {
                    XmlTag tag = LocalResourceRepository.getItemTag(myFacet.getModule().getProject(), item);
                    if (tag != null) {
                        elements.add(tag);
                    } else if (item instanceof DynamicResourceValueItem) {
                        result.add(((DynamicResourceValueItem) item).createResolveResult());
                    }
                }
            }
        }
    }
    if (elements.size() > 1) {
        Collections.sort(elements, AndroidResourceUtil.RESOURCE_ELEMENT_COMPARATOR);
    }
    for (PsiElement target : elements) {
        result.add(new PsiElementResolveResult(target));
    }
    return result.toArray(new ResolveResult[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) DynamicResourceValueItem(com.android.tools.idea.res.DynamicResourceValueItem) ResourceType(com.android.resources.ResourceType) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) ResourceItem(com.android.ide.common.res2.ResourceItem) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResourceItem (com.android.ide.common.res2.ResourceItem)1 ResourceType (com.android.resources.ResourceType)1 DynamicResourceValueItem (com.android.tools.idea.res.DynamicResourceValueItem)1 LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)1 XmlTag (com.intellij.psi.xml.XmlTag)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1