Set<String> names1 = new HashSet<>(a.size()); for (String s : a) { names1.add(LintUtils.getBaseName(s)); names2.add(LintUtils.getBaseName(s)); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s);
Set<String> names1 = new HashSet<String>(a.size()); for (String s : a) { names1.add(LintUtils.getBaseName(s)); names2.add(LintUtils.getBaseName(s)); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s);
Set<String> names1 = new HashSet<>(a.size()); for (String s : a) { names1.add(LintUtils.getBaseName(s)); names2.add(LintUtils.getBaseName(s)); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s);
Set<String> names1 = new HashSet<String>(a.size()); for (String s : a) { names1.add(LintUtils.getBaseName(s)); names2.add(LintUtils.getBaseName(s)); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s); if (names1.contains(LintUtils.getBaseName(s))) { result.add(s);
@Override public void visitDocument(@NonNull XmlContext context, @NonNull Document document) { Element root = document.getDocumentElement(); if (root != null) { NamedNodeMap attributes = root.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attribute = (Attr) attributes.item(i); if (attribute.getLocalName() != null && attribute.getLocalName().startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) { if (mLayoutsWithRootLayoutParams == null) { mLayoutsWithRootLayoutParams = Sets.newHashSetWithExpectedSize(20); } mLayoutsWithRootLayoutParams.add(LintUtils.getBaseName(context.file.getName())); break; } } } }
/** * Saves names of all vector resources encountered. Because "drawable" is before "layout" in * alphabetical order, Lint will first call this on every vector, before calling * {@link #visitAttribute(XmlContext, Attr)} on every attribute. */ @Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { if (mSkipChecks) { return; } String resourceName = LintUtils.getBaseName(context.file.getName()); mVectors.add(resourceName); }
@Override public void visitDocument(@NonNull XmlContext context, @NonNull Document document) { Element root = document.getDocumentElement(); if (root != null) { NamedNodeMap attributes = root.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attribute = (Attr) attributes.item(i); if (attribute.getLocalName() != null && attribute.getLocalName().startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) { if (mLayoutsWithRootLayoutParams == null) { mLayoutsWithRootLayoutParams = Sets.newHashSetWithExpectedSize(20); } mLayoutsWithRootLayoutParams.add(LintUtils.getBaseName(context.file.getName())); break; } } } }
@Override public void checkBinaryResource(@NonNull ResourceContext context) { if (mPrefix != null) { ResourceFolderType folderType = context.getResourceFolderType(); if (folderType != null && folderType != ResourceFolderType.VALUES) { String name = LintUtils.getBaseName(context.file.getName()); if (!name.startsWith(mPrefix)) { Location location = Location.create(context.file); context.report(ISSUE, location, getErrorMessage(name)); } } } } }
@Override public void checkBinaryResource(@NonNull ResourceContext context) { if (mUnderlinePrefix != null) { ResourceFolderType folderType = context.getResourceFolderType(); if (folderType != null && folderType != ResourceFolderType.VALUES) { String name = LintUtils.getBaseName(context.file.getName()); if (!name.startsWith(mUnderlinePrefix)) { // Turns out the Gradle plugin will generate raw resources // for renderscript. We don't want to flag these. // We don't have a good way to recognize them today. String path = context.file.getPath(); if (path.endsWith(".bc") && folderType == ResourceFolderType.RAW) { return; } Location location = Location.create(context.file); context.report(ISSUE, location, getErrorMessage(name, folderType)); } } } } }
String name = LintUtils.getBaseName(context.file.getName()); if (mManifestLocations.containsKey(name)) { List<ResourceType> types =
@Override public void beforeCheckFile(@NonNull Context context) { File file = context.file; boolean isXmlFile = LintUtils.isXmlFile(file); if (!isXmlFile && !LintUtils.isBitmapFile(file)) { return; } String parentName = file.getParentFile().getName(); int dash = parentName.indexOf('-'); if (dash != -1 || FD_RES_VALUES.equals(parentName)) { return; } ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName); if (folderType == null) { return; } List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); if (types.isEmpty()) { return; } ResourceType type = types.get(0); String resourceName = getResourceFieldName(getBaseName(file.getName())); if (isPrivate(context, type, resourceName)) { String message = createOverrideErrorMessage(context, type, resourceName); Location location = Location.create(file); context.report(ISSUE, location, message); } }
@Override public void beforeCheckFile(@NonNull Context context) { File file = context.file; boolean isXmlFile = LintUtils.isXmlFile(file); if (!isXmlFile && !LintUtils.isBitmapFile(file)) { return; } String parentName = file.getParentFile().getName(); int dash = parentName.indexOf('-'); if (dash != -1 || FD_RES_VALUES.equals(parentName)) { return; } ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName); if (folderType == null) { return; } List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); if (types.isEmpty()) { return; } ResourceType type = types.get(0); String resourceName = getResourceFieldName(getBaseName(file.getName())); if (isPrivate(context, type, resourceName)) { String message = createOverrideErrorMessage(context, type, resourceName); Location location = Location.create(file); context.report(ISSUE, location, message); } }
public void visitXmlDocument( @NonNull File file, @Nullable ResourceFolderType folderType, @NonNull Document document) { if (folderType == null) { // Manifest file recordManifestUsages(document.getDocumentElement()); return; } Resource from = null; if (folderType != ResourceFolderType.VALUES) { // Record resource for the whole file List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes( folderType); ResourceType type = types.get(0); assert type != ResourceType.ID : folderType; String name = LintUtils.getBaseName(file.getName()); from = declareResource(type, name, document.getDocumentElement()); } else if (isAnalyticsFile(file)) { return; } nextInlinedResourceSuffix = 1; // For value files, and drawables and colors etc also pull in resource // references inside the context.file recordResourceReferences(folderType, document.getDocumentElement(), from); if (folderType == ResourceFolderType.XML) { tokenizeUnknownText(readText(file)); } }
Set<String> bases = Sets.newHashSetWithExpectedSize(overlap.size()); for (String name : overlap) { bases.add(LintUtils.getBaseName(name)); File folder = entry.getKey(); for (String n : entry.getValue()) { if (base.equals(LintUtils.getBaseName(n))) { map.put(base, new File(folder, n));
Set<String> bases = Sets.newHashSetWithExpectedSize(overlap.size()); for (String name : overlap) { bases.add(LintUtils.getBaseName(name)); File folder = entry.getKey(); for (String n : entry.getValue()) { if (base.equals(LintUtils.getBaseName(n))) { map.put(base, new File(folder, n));
@Override public void beforeCheckFile(@NonNull Context context) { if (mPrefix != null && context instanceof XmlContext) { XmlContext xmlContext = (XmlContext) context; ResourceFolderType folderType = xmlContext.getResourceFolderType(); if (folderType != null && folderType != ResourceFolderType.VALUES) { String name = LintUtils.getBaseName(context.file.getName()); if (!name.startsWith(mPrefix)) { // Attempt to report the error on the root tag of the associated // document to make suppressing the error with a tools:suppress // attribute etc possible if (xmlContext.document != null) { Element root = xmlContext.document.getDocumentElement(); if (root != null) { xmlContext.report(ISSUE, root, xmlContext.getLocation(root), getErrorMessage(name)); return; } } context.report(ISSUE, Location.create(context.file), getErrorMessage(name)); } } } }
String color = element.getAttributeNS(ANDROID_URI, ATTR_COLOR); if (color != null && color.startsWith(COLOR_RESOURCE_PREFIX)) { String currentColor = LintUtils.getBaseName(context.file.getName()); if (mLocations != null) { recordLocation(context, element, ResourceType.COLOR, String drawable = element.getAttributeNS(ANDROID_URI, ATTR_DRAWABLE); if (drawable != null && drawable.startsWith(DRAWABLE_PREFIX)) { String currentColor = LintUtils.getBaseName(context.file.getName()); if (mLocations != null) { recordLocation(context, element, ResourceType.DRAWABLE, String layout = layoutNode.getValue(); if (layout.startsWith(LAYOUT_RESOURCE_PREFIX)) { String currentLayout = LintUtils.getBaseName(context.file.getName()); if (mReferences != null) { if (mLocations != null) {
/** * See if the given URL is a URL that we can resolve to a specific resource; if so, * record it and return true, otherwise returns false. */ private boolean referencedUrl(@Nullable Resource from, @NonNull String url) { Resource resource = getResourceFromFilePath(url); if (resource == null && url.indexOf('/') == -1) { // URLs are often within the raw folder resource = getResource(ResourceType.RAW, LintUtils.getFieldName(LintUtils.getBaseName(url))); } if (resource != null) { if (from != null) { from.addReference(resource); } else { // We don't have an inclusion context, so just assume this resource is reachable markReachable(resource); } return true; } return false; }
@Override public void beforeCheckFile(@NonNull Context context) { if (mPrefix != null && context instanceof XmlContext) { XmlContext xmlContext = (XmlContext) context; ResourceFolderType folderType = xmlContext.getResourceFolderType(); if (folderType != null && folderType != ResourceFolderType.VALUES) { String name = LintUtils.getBaseName(context.file.getName()); if (!libraryPrefixMatches(mUnderlinePrefix, name)) { // Attempt to report the error on the root tag of the associated // document to make suppressing the error with a tools:suppress // attribute etc possible if (xmlContext.document != null) { Element root = xmlContext.document.getDocumentElement(); if (root != null) { xmlContext.report(ISSUE, root, xmlContext.getLocation(root), getErrorMessage(name, folderType)); return; } } context.report(ISSUE, Location.create(context.file), getErrorMessage(name, folderType)); } } } }
public void visitBinaryResource( @Nullable ResourceFolderType folderType, @NonNull File file) { Resource from = null; if (folderType != ResourceFolderType.VALUES) { // Record resource for the whole file List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes( folderType); ResourceType type = types.get(0); assert type != ResourceType.ID : folderType; String name = LintUtils.getBaseName(file.getName()); from = declareResource(type, name, null); } if (folderType == ResourceFolderType.RAW) { // Is this an HTML, CSS or JavaScript document bundled with the app? // If so tokenize and look for resource references. String path = file.getPath(); if (endsWithIgnoreCase(path, ".html") || endsWithIgnoreCase(path, ".htm")) { tokenizeHtml(from, readText(file)); } else if (endsWithIgnoreCase(path, ".css")) { tokenizeCss(from, readText(file)); } else if (endsWithIgnoreCase(path, ".js")) { tokenizeJs(from, readText(file)); } else if (file.isFile() && !LintUtils.isBitmapFile(file)) { tokenizeUnknownBinary(from, file); } } }