/** Like {@link LintUtils#isBitmapFile(File)} but (a) operates on Strings instead * of files and (b) also considers XML drawables as images */ private static boolean isDrawableFile(String name) { // endsWith(name, DOT_PNG) is also true for endsWith(name, DOT_9PNG) return endsWith(name, DOT_PNG)|| endsWith(name, DOT_JPG) || endsWith(name, DOT_GIF) || endsWith(name, DOT_XML) || endsWith(name, DOT_JPEG) || endsWith(name, DOT_WEBP); }
private void checkForMediaSearchIntentFilter(Element element) { if (!mMediaSearchIntentFilterFound) { for (Element filterChild : LintUtils.getChildren(element)) { if (NODE_ACTION.equals(filterChild.getTagName())) { String actionValue = filterChild.getAttributeNS(ANDROID_URI, ATTR_NAME); if (ACTION_MEDIA_PLAY_FROM_SEARCH.equals(actionValue)) { mMediaSearchIntentFilterFound = true; break; } } } } }
/** Is the given target id the id of a {@code <Button>} within this RelativeLayout? */ private static boolean isButtonId(Element parent, String targetId) { for (Element child : LintUtils.getChildren(parent)) { String id = child.getAttributeNS(ANDROID_URI, ATTR_ID); if (LintUtils.idReferencesMatch(id, targetId)) { return child.getTagName().equals(BUTTON); } } return false; } }
if (!ids.isEmpty()) { for (String matchWith : ids) { matchWith = stripIdPrefix(matchWith); int distance = editDistance(id, matchWith, maxDistance); if (distance <= maxDistance) { matches.put(distance, matchWith);
File file = context.file; boolean isXmlFile = LintUtils.isXmlFile(file); if (isXmlFile || LintUtils.isBitmapFile(file)) { String fileName = file.getName(); String parentName = file.getParentFile().getName(); 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;
@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); } }
String.format("Missing density variation folders in `%1$s`: %2$s", context.getProject().getDisplayPath(res), LintUtils.formatList(missing, -1))); String.format( "The following images appear in both `-nodpi` and in a density folder: %1$s", LintUtils.formatList(list, context.getDriver().isAbbreviating() ? 10 : -1))); String folderName = entry.getKey().getName(); for (String name : names) { if (endsWith(name, DOT_XML)) { 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)); boolean seenNonXml = false; for (File f : lists) { boolean isXml = endsWith(f.getPath(), DOT_XML); if (isXml && !seenXml) { fileNames.add(context.getProject().getDisplayPath(f)); String.format(
if (assertionsEnabled()) { Document document = checkDocument(pkg, xml, false); if (document == null) {
@Override public boolean appliesTo(Context context, File file) { return LintUtils.isXmlFile(file); }
"\"res\" folder or resource folder", file.getPath()); } else if (file.isFile() && LintUtils.isXmlFile(file)) { } else if (binaryChecks != null && file.isFile() && LintUtils.isBitmapFile(file)) {
@Override public void visitElement(Context context, Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 2) { List<Element> children = LintUtils.getChildren(element); Element first = children.get(0); Element second = children.get(1); if ((first.getTagName().equals(IMAGE_VIEW) && second.getTagName().equals(TEXT_VIEW) && !first.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)) || ((second.getTagName().equals(IMAGE_VIEW) && first.getTagName().equals(TEXT_VIEW) && !second.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)))) { context.client.report(context, ISSUE, context.getLocation(element), "This tag and its children can be replaced by one <TextView/> and " + "a compound drawable", null); } } } }
writer.write("<br/>\n"); writer.write(String.format("%1$s found", describeCounts(stats.errorCount, stats.warningCount, false))); if (stats.baselineErrorCount > 0 || stats.baselineWarningCount > 0) { File baselineFile = flags.getBaselineFile(); assert baselineFile != null; writer.write(String.format(" (%1$s filtered by baseline %2$s)", describeCounts(stats.baselineErrorCount, stats.baselineWarningCount, false), baselineFile.getName())); if (!(endsWith(name, DOT_PNG) || endsWith(name, DOT_JPG))) { CharSequence s = client.readFile(l.getFile()); if (s.length() > 0) {
@Override public void visitElement(Context context, Element element) { Attr attribute = element.getAttributeNode(ATTR_NAME); if (attribute == null || attribute.getValue().length() == 0) { context.client.report(context, INCONSISTENT, context.getLocation(element), String.format("Missing name attribute in %1$s declaration", element.getTagName()), null); } else { String name = attribute.getValue(); int childCount = LintUtils.getChildCount(element); mFileToArrayCount.put(context.file, Pair.of(name, childCount)); } } }
sharedRoot = LintUtils.getCommonParent(files); if (sharedRoot != null && sharedRoot.getParentFile() == null) { // "/" ? sharedRoot = null; if (LintUtils.assertionsEnabled()) {
continue; if (LintUtils.editDistance(suggestion, tag) <= MAX_EDIT_DISTANCE) { if (suggestions == null) { suggestions = Lists.newArrayList(); suggestions.get(0), suggestions.get(1)); } else { suggestionString = LintUtils.formatList(suggestions, -1);
for (Element child : LintUtils.getChildren(node)) { String tagName = child.getTagName(); if (TAG_PIN.equals(tagName)) { Attr digestAttr = child.getAttributeNode(ATTR_DIGEST); if (!PIN_DIGEST_ALGORITHM.equalsIgnoreCase(digestAttr.getValue())) { String values = LintUtils.formatList(getSupportedPinDigestAlgorithms(), 2); context.report(ISSUE, digestAttr, context.getValueLocation(digestAttr), String.format(INVALID_DIGEST_ALGORITHM, values));
private void writeNavigationHeader(@NonNull Stats stats, @NonNull Runnable appender) { append("" + "<div class=\"mdl-layout mdl-js-layout mdl-layout--fixed-header\">\n" + " <header class=\"mdl-layout__header\">\n" + " <div class=\"mdl-layout__header-row\">\n" + " <span class=\"mdl-layout-title\">" + title + ": " + LintUtils.describeCounts(stats.errorCount, stats.warningCount, false) + "</span>\n" + " <div class=\"mdl-layout-spacer\"></div>\n" + " <nav class=\"mdl-navigation mdl-layout--large-screen-only\">\n"); append(String.format("Check performed at %1$s", new Date().toString())); append("" + " </nav>\n" + " </div>\n" + " </header>\n" + " <div class=\"mdl-layout__drawer\">\n" + " <span class=\"mdl-layout-title\">Issue Types</span>\n" + " <nav class=\"mdl-navigation\">\n"); appender.run(); append("" + " </nav>\n" + " </div>\n" + " <main class=\"mdl-layout__content\">\n" + " <div class=\"mdl-layout__tab-panel is-active\">"); }
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); } } }
public static String formatSet(@NonNull EnumSet<Quantity> set) { List<String> list = new ArrayList<String>(set.size()); for (Quantity quantity : set) { list.add('`' + quantity.name() + '`'); } return LintUtils.formatList(list, Integer.MAX_VALUE); } }