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; }
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; }
public final Integer getResourceValue(String type, String name) { return getResourceId(ResourceType.getEnum(type), name); }
/** Returns whether the given class path points to an aapt-generated compiled R class */ @VisibleForTesting static boolean isResourceClass(@NonNull String name) { assert name.endsWith(DOT_CLASS) : name; int index = name.lastIndexOf('/'); if (index != -1 && name.startsWith("R$", index + 1)) { String typeName = name.substring(index + 3, name.length() - DOT_CLASS.length()); return ResourceType.getEnum(typeName) != null; } return false; }
/** Returns whether the given class file name points to an aapt-generated compiled R class */ @VisibleForTesting boolean isResourceClass(@NonNull String name) { if (mResourceObfuscation.containsKey(name)) { return true; } assert name.endsWith(DOT_CLASS) : name; int index = name.lastIndexOf('/'); if (index != -1 && name.startsWith("R$", index + 1)) { String typeName = name.substring(index + 3, name.length() - DOT_CLASS.length()); return ResourceType.getEnum(typeName) != null; } return false; }
@Override public void beforeCheckFile(Context context) { File file = context.file; String fileName = file.getName(); if (LintUtils.endsWith(fileName, DOT_XML)) { String parentName = file.getParentFile().getName(); int dash = parentName.indexOf('-'); String typeName = parentName.substring(0, dash == -1 ? parentName.length() : dash); ResourceType type = ResourceType.getEnum(typeName); if (type != null && LintUtils.isFileBasedResourceType(type)) { String baseName = fileName.substring(0, fileName.length() - DOT_XML.length()); String resource = R_PREFIX + typeName + '.' + baseName; mDeclarations.add(resource); mDeclarationToFile.put(resource, file); } } }
ResourceType type = ResourceType.getEnum(typeName); if (type == null) { continue;
signature.length() - RES_SUFFIX.length()) .toLowerCase(Locale.US); ResourceType type = ResourceType.getEnum(typeString); if (type != null) { return EnumSet.of(type);
ResourceType type = ResourceType.getEnum(url.substring(typeSlash + 1, nameSlash)); if (type != null) { int nameBegin = nameSlash + 1;
ResourceType type = ResourceType.getEnum(url.substring(typeSlash + 1, nameSlash)); if (type != null) { int nameBegin = nameSlash + 1;
ResourceType t = ResourceType.getEnum(type); if (t != null && isPrivate(context, t, name) && !VALUE_TRUE.equals(item.getAttributeNS(TOOLS_URI, ATTR_OVERRIDE))) {
ClassField field = (ClassField)item; ResourceType type = ResourceType.getEnum(field.getType()); boolean hasResourceTag = (type != null && RESOURCES_WITH_TAGS.contains(type));
ResourceType t = ResourceType.getEnum(type); if (t != null && isPrivate(context, t, name)) { if (overriding == null) {
ClassField field = (ClassField)item; ResourceType type = ResourceType.getEnum(field.getType()); boolean hasResourceTag = (type != null && RESOURCES_WITH_TAGS.contains(type));
typeString = item.getAttribute(ATTR_TYPE); ResourceType type = ResourceType.getEnum(typeString); if (type != null) { reportIfFound(context, qualifiers, name, type, item);
private void addDynamicResources(@NonNull Project project, @NonNull Map<String, ClassField> resValues) { Set<String> keys = resValues.keySet(); if (!keys.isEmpty()) { Location location = LintUtils.guessGradleLocation(project); for (String name : keys) { ClassField field = resValues.get(name); ResourceType type = ResourceType.getEnum(field.getType()); if (type == null) { // Highly unlikely. This would happen if in the future we add // some new ResourceType, that the Gradle plugin (and the user's // Gradle file is creating) and it's an older version of Studio which // doesn't yet have this ResourceType in its enum. continue; } Resource resource = mModel.declareResource(type, name, null); resource.recordLocation(location); } } }
int dash = parentName.indexOf('-'); String typeName = parentName.substring(0, dash == -1 ? parentName.length() : dash); ResourceType type = ResourceType.getEnum(typeName); if (type != null && LintUtils.isFileBasedResourceType(type)) { String baseName = fileName.substring(0, fileName.length() - DOT_XML.length());
String typeString = signature.substring(SUPPORT_ANNOTATIONS_PREFIX.length(), signature.length() - RES_SUFFIX.length()).toLowerCase(Locale.US); ResourceType type = ResourceType.getEnum(typeString); if (type != null) { checkResourceType(context, argument, type);
String name = expression.getReferenceName(); ResourceType type = ResourceType.getEnum(typeName); if (type != null && name != null) { boolean isFramework = if (rClass != null && R_CLASS.equals(rClass.getName())) { String name = field.getName(); ResourceType type = ResourceType.getEnum(typeClass.getName()); if (type != null && name != null) { String qualifiedName = rClass.getQualifiedName();
@Override public void visitResourceReference( @NonNull JavaContext context, @Nullable AstVisitor visitor, @NonNull Node node, @NonNull String type, @NonNull String name, boolean isFramework) { if (context.getProject().isGradleProject() && !isFramework) { Project project = context.getProject(); if (project.getGradleProjectModel() != null && project.getCurrentVariant() != null) { ResourceType resourceType = ResourceType.getEnum(type); if (resourceType != null && isPrivate(context, resourceType, name)) { String message = createUsageErrorMessage(context, resourceType, name); context.report(ISSUE, node, context.getLocation(node), message); } } } }