Java Code Examples for com.android.tools.lint.detector.api.LintUtils#findSubstring()

The following examples show how to use com.android.tools.lint.detector.api.LintUtils#findSubstring() . 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 vote down vote up
/**
 * 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: GridLayoutDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 3
Source File: MissingClassDetector.java    From javaide with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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 4
Source File: MissingClassDetector.java    From javaide with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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 5
Source File: PropertyFileDetector.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: DuplicateResourceDetector.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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 @", "/");
}
 
Example 7
Source File: WrongCallDetector.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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 8
Source File: WrongCallDetector.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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 \"", "\"");
}
 
Example 9
Source File: WrongCaseDetector.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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 <", ">");
}
 
Example 10
Source File: WrongCaseDetector.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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 <", ">");
}