/** * Given an error message produced by this lint detector, returns the new value to be put into the * source code. * * <p>Intended for IDE quickfix implementations. * * @param errorMessage the error message associated with the error * @param format the format of the error message * @return the corresponding new value, or null if not recognized */ @Nullable public static String getNewValue(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); String attribute = LintUtils.findSubstring(errorMessage, " should use ", " "); if (attribute == null) { attribute = LintUtils.findSubstring(errorMessage, " should use ", null); } return attribute; }
/** * Given an error message produced by this lint detector, returns the old value to be replaced in * the source code. * * <p>Intended for IDE quickfix implementations. * * @param errorMessage the error message associated with the error * @param format the format of the error message * @return the corresponding old value, or null if not recognized */ @Nullable public static String getOldValue(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); String attribute = LintUtils.findSubstring(errorMessage, " should use ", " "); if (attribute == null) { attribute = LintUtils.findSubstring(errorMessage, " should use ", null); } if (attribute != null) { int index = attribute.indexOf(':'); if (index != -1) { return ANDROID_NS_NAME + attribute.substring(index); } } return null; }