当前位置: 首页>>代码示例>>Java>>正文


Java TextFormat.toText方法代码示例

本文整理汇总了Java中com.android.tools.lint.detector.api.TextFormat.toText方法的典型用法代码示例。如果您正苦于以下问题:Java TextFormat.toText方法的具体用法?Java TextFormat.toText怎么用?Java TextFormat.toText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.tools.lint.detector.api.TextFormat的用法示例。


在下文中一共展示了TextFormat.toText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOldValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:GridLayoutDetector.java

示例2: getRequiredVersion

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ApiDetector.java

示例3: getSuggestions

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/** 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:TypoDetector.java

示例4: getTypo

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:TypoDetector.java

示例5: getOldValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:51,代码来源:GradleDetector.java

示例6: getNewValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:GradleDetector.java

示例7: getNewValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GridLayoutDetector.java

示例8: getReplacedType

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:JavaPerformanceDetector.java

示例9: getOldValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MissingClassDetector.java

示例10: getNewValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MissingClassDetector.java

示例11: getOldValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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 \"", "\"");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:WrongCallDetector.java

示例12: getNewValue

import com.android.tools.lint.detector.api.TextFormat; //导入方法依赖的package包/类
/**
 * 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 \"", "\"");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:WrongCallDetector.java


注:本文中的com.android.tools.lint.detector.api.TextFormat.toText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。