private static ResourceType getResourceType(Element element) { String tagName = element.getTagName(); if (tagName.equals(TAG_ITEM)) { String typeName = element.getAttribute(ATTR_TYPE); if (!typeName.isEmpty()) { return ResourceType.getEnum(typeName); } } else if ("string-array".equals(tagName) || "integer-array".equals(tagName)) { return ResourceType.ARRAY; } else { return ResourceType.getEnum(tagName); } return null; }
@Override public String toString() { return getName(); } }
@Override public int hashCode() { int result = type != null ? type.hashCode() : 0; result = 31 * result + (name != null ? name.hashCode() : 0); return result; }
if (innerSelect.astIdentifier().astValue().equals(R_CLASS)) { String typeName = select.astIdentifier().astValue(); ResourceType type = ResourceType.getEnum(typeName); return type != null ? Collections.singletonList(type) : null; if (reference.astIdentifier().astValue().equals(R_CLASS)) { String typeName = select.astIdentifier().astValue(); ResourceType type = ResourceType.getEnum(typeName); return type != null ? Collections.singletonList(type) : null; Select typeSelect = (Select) typeOperand; String typeName = typeSelect.astIdentifier().astValue(); ResourceType type = ResourceType.getEnum(typeName); return type != null ? Collections.singletonList(type) : null; String typeString = signature.substring(SUPPORT_ANNOTATIONS_PREFIX.length(), signature.length() - RES_SUFFIX.length()).toLowerCase(Locale.US); ResourceType type = ResourceType.getEnum(typeString); if (type != null) { return Collections.singletonList(type); } else if (typeString.equals("any")) { // @AnyRes ResourceType[] types = ResourceType.values(); List<ResourceType> result = Lists.newArrayListWithExpectedSize( types.length);
Location itemLocation = itemLocations.iterator().next(); String next = chain.get((i + 1) % chain.size()); String label = "Reference from @" + type.getName() + "/" + item + " to " + type.getName() + "/" + next + " here"; itemLocation.setMessage(label); itemLocation.setSecondary(location); type.getDisplayName(), Joiner.on(" => ").join(chain));
/** * Returns the enum by its name as it appears in the XML or the R class. * @param name name of the resource * @return the matching {@link ResourceType} or <code>null</code> if no match was found. */ public static ResourceType getEnum(String name) { for (ResourceType rType : values()) { if (rType.mName.equals(name)) { return rType; } else if (rType.mAlternateXmlNames != null) { // if there are alternate Xml Names, we test those too for (String alternate : rType.mAlternateXmlNames) { if (alternate.equals(name)) { return rType; } } } } return null; }
@Override public int compare(Resource resource1, Resource resource2) { int delta = resource1.type.compareTo(resource2.type); if (delta != 0) { return delta; } return resource1.name.compareTo(resource2.name); } });
Location itemLocation = itemLocations.iterator().next(); String next = chain.get((i + 1) % chain.size()); String label = "Reference from @" + type.getName() + "/" + item + " to " + type.getName() + "/" + next + " here"; itemLocation.setMessage(label); itemLocation.setSecondary(location); type.getDisplayName(), Joiner.on(" => ").join(chain));
/** * Makes the maps safe by replacing the current list values with unmodifiable lists. */ private static void makeSafe() { for (ResourceType type : ResourceType.values()) { List<ResourceFolderType> list = mTypeToFolderMap.get(type); if (list != null) { // replace with a unmodifiable list wrapper around the current list. mTypeToFolderMap.put(type, Collections.unmodifiableList(list)); } } for (ResourceFolderType folder : ResourceFolderType.values()) { List<ResourceType> list = mFolderToTypeMap.get(folder); if (list != null) { // replace with a unmodifiable list wrapper around the current list. mFolderToTypeMap.put(folder, Collections.unmodifiableList(list)); } } } }
@Override public int compareTo(@NonNull Resource other) { if (type != other.type) { return type.compareTo(other.type); } return name.compareTo(other.name); } }
public static ResourceType getResourceType(Element element) { String tagName = element.getTagName(); if (tagName.equals(TAG_ITEM)) { String typeName = element.getAttribute(ATTR_TYPE); if (!typeName.isEmpty()) { return ResourceType.getEnum(typeName); } } else if ("string-array".equals(tagName) || "integer-array".equals(tagName)) { return ResourceType.ARRAY; } else { return ResourceType.getEnum(tagName); } return null; }
if (typeString == null || typeString.isEmpty()) { if (element.getParentNode().getNodeName().equals( ResourceType.STYLE.getName()) && isFirstElementChild(element)) { checkUniqueNames(context, (Element) element.getParentNode()); ResourceType type = ResourceType.getEnum(typeString); if (type == null) { return; ResourceType.DECLARE_STYLEABLE.getName())) { if (isFirstElementChild(element)) { checkUniqueNames(context, (Element) element.getParentNode());
@Override public String toString() { return getName(); } }
@Override public int hashCode() { int result = type != null ? type.hashCode() : 0; result = 31 * result + (name != null ? name.hashCode() : 0); return result; }
/** * Makes the maps safe by replacing the current list values with unmodifiable lists. */ private static void makeSafe() { for (ResourceType type : ResourceType.values()) { List<ResourceFolderType> list = mTypeToFolderMap.get(type); if (list != null) { // replace with a unmodifiable list wrapper around the current list. mTypeToFolderMap.put(type, Collections.unmodifiableList(list)); } } for (ResourceFolderType folder : ResourceFolderType.values()) { List<ResourceType> list = mFolderToTypeMap.get(folder); if (list != null) { // replace with a unmodifiable list wrapper around the current list. mFolderToTypeMap.put(folder, Collections.unmodifiableList(list)); } } } }
public String dumpResourceModel() { StringBuilder sb = new StringBuilder(1000); Collections.sort(mResources, (resource1, resource2) -> { int delta = resource1.type.compareTo(resource2.type); if (delta != 0) { return delta; } return resource1.name.compareTo(resource2.name); }); for (Resource resource : mResources) { sb.append(resource.getUrl()).append(" : reachable=").append(resource.isReachable()); sb.append("\n"); if (resource.references != null) { for (Resource referenced : resource.references) { sb.append(" "); sb.append(referenced.getUrl()); sb.append("\n"); } } } return sb.toString(); }