private int resolveDimensionValue(String name, Context context){ LintClient client = context.getDriver().getClient(); LintProject project = context.getDriver().getProject(); AbstractResourceRepository resources = client.getProjectResources(project, true); return Integer.valueOf(resources.getResourceItem(ResourceType.DIMEN, name).get(0).getResourceValue(false).getValue()); }
@Override public void beforeCheckProject(@NonNull Context context) { if (context.getDriver().getPhase() == 1) { mFileToNames = new HashMap<File, Set<String>>(); } }
@Override public void beforeCheckProject(@NonNull Context context) { if (context.getDriver().getPhase() == 1) { mFileToNames = new HashMap<>(); } }
private boolean isActionBarIcon(Context context, String folderName, String name, File file) { if (isActionBarIcon(folderName, name)) { return true; } // As of Android 3.0 ic_menu_ are action icons //noinspection SimplifiableIfStatement,RedundantIfStatement if (file != null && name.startsWith("ic_menu_") && isAndroid30(context, context.getDriver().getResourceFolderVersion(file))) { // Naming convention return true; } return false; }
private boolean isActionBarIcon(Context context, String name, File file) { if (isActionBarIcon(name)) { return true; } // As of Android 3.0 ic_menu_ are action icons //noinspection SimplifiableIfStatement,RedundantIfStatement if (file != null && name.startsWith("ic_menu_") //$NON-NLS-1$ && isAndroid30(context, context.getDriver().getResourceFolderVersion(file))) { // Naming convention return true; } return false; }
@Override public void afterCheckProject(@NonNull Context context) { if (mNames != null && !mNames.isEmpty() && mHaveBytecode) { List<String> names = new ArrayList<String>(mNames.keySet()); Collections.sort(names); LintDriver driver = context.getDriver(); for (String name : names) { Handle handle = mNames.get(name); Object clientData = handle.getClientData(); if (clientData instanceof Node) { if (driver.isSuppressed(null, ISSUE, (Node) clientData)) { continue; } } Location location = handle.resolve(); String message = String.format( "Corresponding method handler '`public void %1$s(android.view.View)`' not found", name); List<String> similar = mSimilar != null ? mSimilar.get(name) : null; if (similar != null) { Collections.sort(similar); message += String.format(" (did you mean `%1$s` ?)", Joiner.on(", ").join(similar)); } context.report(ISSUE, location, message); } } }
@Override public void afterCheckProject(@NonNull Context context) { int phase = context.getPhase(); if (phase == 1 && mApplicableResources != null) { // We found resources for the string "Cancel"; perform a second pass // where we check layout text attributes against these strings. context.getDriver().requestRepeat(this, Scope.RESOURCE_FILE_SCOPE); } }
@Override public void afterCheckProject(@NonNull Context context) { int phase = context.getPhase(); if (phase == 1 && mApplicableResources != null) { // We found resources for the string "Cancel"; perform a second pass // where we check layout text attributes against these strings. context.getDriver().requestRepeat(this, Scope.RESOURCE_FILE_SCOPE); } }
@Override public void afterCheckProject(@NonNull Context context) { LintDriver driver = context.getDriver(); if (driver.getPhase() == 1) { // First phase: gather all the ids and look for consistency issues. // If any are found, request location computation in phase 2 by // writing the ids needed for each layout in the {@link #mLocations} map. for (Map.Entry<String,List<Pair<File,Map<String,String>>>> entry : mMap.entrySet()) { String layout = entry.getKey(); List<Pair<File, Map<String, String>>> files = entry.getValue(); if (files.size() < 2) { // No consistency problems for files that don't have resource variations continue; } checkConsistentIds(layout, files); } if (mLocations != null) { driver.requestRepeat(this, Scope.ALL_RESOURCES_SCOPE); } } else { // Collect results and print if (!mLocations.isEmpty()) { reportErrors(context); } } }
@Override public void afterCheckProject(@NonNull Context context) { LintDriver driver = context.getDriver(); if (driver.getPhase() == 1) { // First phase: gather all the ids and look for consistency issues. // If any are found, request location computation in phase 2 by // writing the ids needed for each layout in the {@link #mLocations} map. for (Map.Entry<String,List<Pair<File,Map<String,String>>>> entry : mMap.entrySet()) { String layout = entry.getKey(); List<Pair<File, Map<String, String>>> files = entry.getValue(); if (files.size() < 2) { // No consistency problems for files that don't have resource variations continue; } checkConsistentIds(layout, files); } if (mLocations != null) { driver.requestRepeat(this, Scope.ALL_RESOURCES_SCOPE); } } else { // Collect results and print if (!mLocations.isEmpty()) { reportErrors(context); } } }
private static void report(Context context, Issue issue, Handle handle, String message) { Location location = handle.resolve(); Object clientData = handle.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, issue, (Node) clientData)) { return; } } context.report(issue, location, message); }
private static void report(Context context, Issue issue, Handle handle, String message) { Location location = handle.resolve(); Object clientData = handle.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, issue, (Node) clientData)) { return; } } context.report(issue, location, message); }
@Override public void afterCheckProject(@NonNull Context context) { if (mRootAttributes != null) { for (Pair<Location, String> pair : mRootAttributes) { Location location = pair.getFirst(); Object clientData = location.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) { return; } } String layoutName = location.getFile().getName(); if (endsWith(layoutName, DOT_XML)) { layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length()); } String theme = getTheme(context, layoutName); if (theme == null || !isBlankTheme(theme)) { String drawable = pair.getSecond(); String message = String.format( "Possible overdraw: Root element paints background `%1$s` with " + "a theme that also paints a background (inferred theme is `%2$s`)", drawable, theme); // TODO: Compute applicable scope node context.report(ISSUE, location, message); } } } }
@Override public void afterCheckProject(@NonNull Context context) { if (mRootAttributes != null) { for (Pair<Location, String> pair : mRootAttributes) { Location location = pair.getFirst(); Object clientData = location.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) { return; } } String layoutName = location.getFile().getName(); if (endsWith(layoutName, DOT_XML)) { layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length()); } String theme = getTheme(context, layoutName); if (theme == null || !isBlankTheme(theme)) { String drawable = pair.getSecond(); String message = String.format( "Possible overdraw: Root element paints background `%1$s` with " + "a theme that also paints a background (inferred theme is `%2$s`)", drawable, theme); // TODO: Compute applicable scope node context.report(ISSUE, location, message); } } } }
@Override public void afterCheckProject(@NonNull Context context) { if (mPending != null && mWhitelistedLayouts != null) { // Process all the root FrameLayouts that are eligible, and generate // suggestions for <merge> replacements for any layouts that are included // from other layouts for (Pair<String, Handle> pair : mPending) { String layout = pair.getFirst(); if (mWhitelistedLayouts.contains(layout)) { Handle handle = pair.getSecond(); Object clientData = handle.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) { return; } } Location location = handle.resolve(); context.report(ISSUE, location, "This `<FrameLayout>` can be replaced with a `<merge>` tag"); } } } }
@Override public void afterCheckProject(@NonNull Context context) { if (mPending != null && mWhitelistedLayouts != null) { // Process all the root FrameLayouts that are eligible, and generate // suggestions for <merge> replacements for any layouts that are included // from other layouts for (Pair<String, Handle> pair : mPending) { String layout = pair.getFirst(); if (mWhitelistedLayouts.contains(layout)) { Handle handle = pair.getSecond(); Object clientData = handle.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) { return; } } Location location = handle.resolve(); context.report(ISSUE, location, "This `<FrameLayout>` can be replaced with a `<merge>` tag"); } } } }
@Override public void afterCheckProject(@NonNull Context context) { if (context.getPhase() == 1) { // NOTE - this will look for the presence of translation strings. // If you create a resource folder but don't actually place a file in it // we won't detect that, but it seems like a smaller problem. checkTranslations(context); mFileToNames = null; if (mMissingLocations != null || mExtraLocations != null) { context.getDriver().requestRepeat(this, Scope.ALL_RESOURCES_SCOPE); } } else { assert context.getPhase() == 2; reportMap(context, MISSING, mMissingLocations); reportMap(context, EXTRA, mExtraLocations); mMissingLocations = null; mExtraLocations = null; mDescriptions = null; } }
@Override public void afterCheckProject(@NonNull Context context) { if (context.getPhase() == 1) { // NOTE - this will look for the presence of translation strings. // If you create a resource folder but don't actually place a file in it // we won't detect that, but it seems like a smaller problem. checkTranslations(context); mFileToNames = null; if (mMissingLocations != null || mExtraLocations != null) { context.getDriver().requestRepeat(this, Scope.ALL_RESOURCES_SCOPE); } } else { assert context.getPhase() == 2; reportMap(context, MISSING, mMissingLocations); reportMap(context, EXTRA, mExtraLocations); mMissingLocations = null; mExtraLocations = null; mDescriptions = null; } }