public static int getRequiredVersion(@NonNull Issue issue, @NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); if (issue == UNSUPPORTED || issue == INLINED) { Pattern pattern = Pattern.compile("\\s(\\d+)\\s"); Matcher matcher = pattern.matcher(errorMessage); if (matcher.find()) { return Integer.parseInt(matcher.group(1)); } } return -1; }
public static int getRequiredVersion(@NonNull Issue issue, @NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); if (issue == UNSUPPORTED || issue == INLINED) { Pattern pattern = Pattern.compile("\\s(\\d+)\\s"); //$NON-NLS-1$ Matcher matcher = pattern.matcher(errorMessage); if (matcher.find()) { return Integer.parseInt(matcher.group(1)); } } return -1; }
/** * Given an error message produced by this lint detector for the given issue type, * determines whether this corresponds to the warning (produced by * {link {@link #reportBaselineIssues(LintDriver, Project)} above) that one or * more issues have been filtered out. * <p> * Intended for IDE quickfix implementations. */ @SuppressWarnings("unused") // Used from the IDE public static boolean isFilteredMessage(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); return errorMessage.contains("were filtered out"); }
/** * Given an error message produced by this lint detector for the given issue type, * determines whether this corresponds to the warning (produced by * {link {@link #reportBaselineIssues(LintDriver, Project)} above) that one or * more issues have been fixed (present in baseline but not in project.) * <p> * Intended for IDE quickfix implementations. */ @SuppressWarnings("unused") // Used from the IDE public static boolean isFixedMessage(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); return errorMessage.contains("perhaps they have been fixed"); }
/** * For an error message for an {@link #USE_VALUE_OF} issue reported by this detector, * returns the type being replaced. Intended to use for IDE quickfix implementations. */ @Nullable public static String getReplacedType(@NonNull String message, @NonNull TextFormat format) { message = format.toText(message); int index = message.indexOf('.'); if (index != -1 && message.startsWith("Use ")) { return message.substring(4, index); } return null; }
/** * For an error message for an {@link #USE_VALUE_OF} issue reported by this detector, * returns the type being replaced. Intended to use for IDE quickfix implementations. */ @SuppressWarnings("unused") // Used by the IDE @Nullable public static String getReplacedType(@NonNull String message, @NonNull TextFormat format) { message = format.toText(message); int index = message.indexOf('.'); if (index != -1 && message.startsWith("Use ")) { return message.substring(4, index); } return null; }
/** * Returns the resource type expected for a {@link #TYPE_MISMATCH} error reported by * this lint detector. Intended for IDE quickfix implementations. * * @param message the error message created by this lint detector * @param format the format of the error message */ public static String getExpectedType(@NonNull String message, @NonNull TextFormat format) { return LintUtils.findSubstring(format.toText(message), "value of type @", "/"); } }
/** * Returns the resource type expected for a {@link #TYPE_MISMATCH} error reported by * this lint detector. Intended for IDE quickfix implementations. * * @param message the error message created by this lint detector * @param format the format of the error message */ public static String getExpectedType(@NonNull String message, @NonNull TextFormat format) { return LintUtils.findSubstring(format.toText(message), "value of type @", "/"); } }
/** * Returns the escaped string value suggested by the error message which should have * been computed by this lint detector. * * @param message the error message created by this lint detector * @param format the format of the error message * @return the suggested escaped value */ @Nullable public static String getSuggestedEscape(@NonNull String message, @NonNull TextFormat format) { return LintUtils.findSubstring(format.toText(message), "; use ", null); } }
/** * Returns the escaped string value suggested by the error message which should have * been computed by this lint detector. * * @param message the error message created by this lint detector * @param format the format of the error message * @return the suggested escaped value */ @Nullable public static String getSuggestedEscape(@NonNull String message, @NonNull TextFormat format) { return LintUtils.findSubstring(format.toText(message), "; use ", null); } }
/** * Given an error message produced by this lint detector for the given issue type, * 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) { return LintUtils.findSubstring(format.toText(errorMessage), " tag <", ">"); }
/** * Given an error message produced by this lint detector for the given issue type, * 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) { return LintUtils.findSubstring(format.toText(errorMessage), " tag <", ">"); }
/** * Given an error message produced by this lint detector for the given issue type, * 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); return LintUtils.findSubstring(errorMessage, "call \"", "\""); } }
/** * Given an error message created by this lint check, return the corresponding * resource field name for the resource that is described as unused. * (Intended to support quickfix implementations for this lint check.) * * @param errorMessage the error message originally produced by this detector * @param format the format of the error message * @return the corresponding resource field name, e.g. {@code R.string.foo} */ @Nullable public static String getUnusedResource(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); return findSubstring(errorMessage, "The resource ", " appears "); }
/** * Given an error message produced by this lint detector for the given issue type, * 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) { return LintUtils.findSubstring(format.toText(errorMessage), " should be <", ">"); } }
/** * Given an error message produced by this lint detector for the given issue type, * 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); return LintUtils.findSubstring(errorMessage, "than \"", "\""); }
/** * Given an error message produced by this lint detector for the given issue type, * 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); return LintUtils.findSubstring(errorMessage, "than \"", "\""); }
/** * Given an error message produced by this lint detector for the given issue type, * 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) { return LintUtils.findSubstring(format.toText(errorMessage), " should be <", ">"); } }
/** * Given an error message produced by this lint detector for the given issue type, * 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); return LintUtils.findSubstring(errorMessage, "call \"", "\""); } }
/** * Given an error message produced by this lint detector, returns the suggested * super class fully qualified name. * <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 super class name, or null if not found */ @Nullable public static String getSuggestedSuperClass(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); return findSubstring(errorMessage, "extend ", " instead"); } }