Java Code Examples for com.android.tools.lint.detector.api.TextFormat#toText()
The following examples show how to use
com.android.tools.lint.detector.api.TextFormat#toText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridLayoutDetector.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example 2
Source File: ApiDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
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; }
Example 3
Source File: TypoDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
/** Returns the suggested replacements, if any, for the given typo. The error * message <b>must</b> be one supplied by lint. * * @param errorMessage the error message * @param format the format of the error message * @return a list of replacement words suggested by the error message */ @Nullable public static List<String> getSuggestions(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); // The words are all in quotes; the first word is the misspelling, // the other words are the suggested replacements List<String> words = new ArrayList<String>(); // Skip the typo int index = errorMessage.indexOf('"'); index = errorMessage.indexOf('"', index + 1); index++; while (true) { index = errorMessage.indexOf('"', index); if (index == -1) { break; } index++; int start = index; index = errorMessage.indexOf('"', index); if (index == -1) { index = errorMessage.length(); } words.add(errorMessage.substring(start, index)); index++; } return words; }
Example 4
Source File: TypoDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns the typo word in the error message from this detector * * @param errorMessage the error message produced earlier by this detector * @param format the format of the error message * @return the typo */ @Nullable public static String getTypo(@NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); // The words are all in quotes int index = errorMessage.indexOf('"'); int start = index + 1; index = errorMessage.indexOf('"', start); if (index != -1) { return errorMessage.substring(start, index); } return null; }
Example 5
Source File: GradleDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * 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 issue the corresponding issue * @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 Issue issue, @NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); // Consider extracting all the error strings as constants and handling this // using the LintUtils#getFormattedParameters() method to pull back out the information if (issue == DEPENDENCY) { // "A newer version of com.google.guava:guava than 11.0.2 is available: 17.0.0" if (errorMessage.startsWith("A newer ")) { return findSubstring(errorMessage, " than ", " "); } if (errorMessage.startsWith("Old buildToolsVersion ")) { return findSubstring(errorMessage, "Old buildToolsVersion ", ";"); } // "The targetSdkVersion (20) should not be higher than the compileSdkVersion (19)" return findSubstring(errorMessage, "targetSdkVersion (", ")"); } else if (issue == STRING_INTEGER) { return findSubstring(errorMessage, "replace ", " with "); } else if (issue == DEPRECATED) { if (errorMessage.contains(GradleDetector.APP_PLUGIN_ID) && errorMessage.contains(GradleDetector.OLD_APP_PLUGIN_ID)) { return GradleDetector.OLD_APP_PLUGIN_ID; } else if (errorMessage.contains(GradleDetector.LIB_PLUGIN_ID) && errorMessage.contains(GradleDetector.OLD_LIB_PLUGIN_ID)) { return GradleDetector.OLD_LIB_PLUGIN_ID; } // "Deprecated: Replace 'packageNameSuffix' with 'applicationIdSuffix'" return findSubstring(errorMessage, "Replace '", "'"); } else if (issue == PLUS) { return findSubstring(errorMessage, "(", ")"); } else if (issue == COMPATIBILITY) { if (errorMessage.startsWith("Version 5.2.08")) { return "5.2.08"; } } return null; }
Example 6
Source File: GradleDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * 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 issue the corresponding issue * @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 Issue issue, @NonNull String errorMessage, @NonNull TextFormat format) { errorMessage = format.toText(errorMessage); if (issue == DEPENDENCY) { // "A newer version of com.google.guava:guava than 11.0.2 is available: 17.0.0" if (errorMessage.startsWith("A newer ")) { return findSubstring(errorMessage, " is available: ", null); } if (errorMessage.startsWith("Old buildToolsVersion ")) { return findSubstring(errorMessage, " version is ", " "); } // "The targetSdkVersion (20) should not be higher than the compileSdkVersion (19)" return findSubstring(errorMessage, "compileSdkVersion (", ")"); } else if (issue == STRING_INTEGER) { return findSubstring(errorMessage, " just ", ")"); } else if (issue == DEPRECATED) { if (errorMessage.contains(GradleDetector.APP_PLUGIN_ID) && errorMessage.contains(GradleDetector.OLD_APP_PLUGIN_ID)) { return GradleDetector.APP_PLUGIN_ID; } else if (errorMessage.contains(GradleDetector.LIB_PLUGIN_ID) && errorMessage.contains(GradleDetector.OLD_LIB_PLUGIN_ID)) { return GradleDetector.LIB_PLUGIN_ID; } // "Deprecated: Replace 'packageNameSuffix' with 'applicationIdSuffix'" return findSubstring(errorMessage, " with '", "'"); } else if (issue == COMPATIBILITY) { if (errorMessage.startsWith("Version 5.2.08")) { return findSubstring(errorMessage, "Use version ", " "); } } return null; }
Example 7
Source File: GridLayoutDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 8
Source File: JavaPerformanceDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 9
Source File: MissingClassDetector.java From javaide with GNU General Public License v3.0 | 3 votes |
/** * 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 issue the corresponding issue * @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 Issue issue, @NonNull String errorMessage, @NonNull TextFormat format) { if (issue == INNERCLASS) { errorMessage = format.toText(errorMessage); return LintUtils.findSubstring(errorMessage, " replace \"", "\""); } return null; }
Example 10
Source File: MissingClassDetector.java From javaide with GNU General Public License v3.0 | 3 votes |
/** * 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 issue the corresponding issue * @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 Issue issue, @NonNull String errorMessage, @NonNull TextFormat format) { if (issue == INNERCLASS) { errorMessage = format.toText(errorMessage); return LintUtils.findSubstring(errorMessage, " with \"", "\""); } return null; }
Example 11
Source File: WrongCallDetector.java From javaide with GNU General Public License v3.0 | 2 votes |
/** * 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 \"", "\""); }
Example 12
Source File: WrongCallDetector.java From javaide with GNU General Public License v3.0 | 2 votes |
/** * 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 \"", "\""); }