本文整理汇总了Java中com.android.tools.lint.detector.api.TextFormat类的典型用法代码示例。如果您正苦于以下问题:Java TextFormat类的具体用法?Java TextFormat怎么用?Java TextFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextFormat类属于com.android.tools.lint.detector.api包,在下文中一共展示了TextFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitAnnotation
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
@Override
public boolean visitAnnotation(Annotation node) {
String type = node.astAnnotationTypeReference().getTypeName();
if (DAGGER_MODULE.equals(type)) {
Node parent = node.getParent();
if (parent instanceof Modifiers) {
parent = parent.getParent();
if (parent instanceof ClassDeclaration) {
int flags = ((ClassDeclaration) parent).astModifiers().getEffectiveModifierFlags();
if ((flags & Modifier.ABSTRACT) == 0) {
context.report(ISSUE, Location.create(context.file), ISSUE.getBriefDescription(TextFormat.TEXT));
}
}
}
}
return super.visitAnnotation(node);
}
示例2: 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;
}
示例3: visitCallExpression
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
@Override
public boolean visitCallExpression(UCallExpression node) {
if (!METHOD_NAME.equals(node.getMethodName())) return false;
final JavaUCompositeQualifiedExpression exp =
(JavaUCompositeQualifiedExpression) node.getUastParent();
if (exp == null
|| !CLASS_SQLITE_OPERATOR.equals(exp.receiver.toString())
|| node.getValueArgumentCount() != 2) return false;
final JavaUClassLiteralExpression classLiteral =
(JavaUClassLiteralExpression) node.getValueArguments().get(PARAM_INDEX);
if (classLiteral == null) return false;
final PsiClass psiClass = mContext.getEvaluator().findClass(classLiteral.toString());
if (psiClass == null
|| psiClass.getModifierList() == null) return false;
boolean found = false;
for (final PsiAnnotation annotation : psiClass.getModifierList().getAnnotations()) {
if (!ANNOTATION_TYPE_LONG.equals(annotation.getQualifiedName())) continue;
found = true;
break;
}
if (!found) {
mContext.report(ISSUE, mContext.getLocation(classLiteral),
String.format(ISSUE.getExplanation(TextFormat.TEXT), classLiteral));
return true;
}
return false;
}
示例4: report
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
@Override
public void report(
@NonNull Context context,
@NonNull Issue issue,
@NonNull Severity severity,
@Nullable Location location,
@NonNull String message,
@NonNull TextFormat format) {
assert mCurrentProject != null;
if (!mCurrentProject.getReportIssues()) {
return;
}
Configuration configuration = context.getConfiguration();
if (!configuration.isEnabled(issue)) {
if (issue != IssueRegistry.PARSER_ERROR && issue != IssueRegistry.LINT_ERROR) {
mDelegate.log(null, "Incorrect detector reported disabled issue %1$s",
issue.toString());
}
return;
}
if (configuration.isIgnored(context, issue, location, message)) {
return;
}
if (severity == Severity.IGNORE) {
return;
}
mDelegate.report(context, issue, severity, location, message, format);
}
示例5: formatError
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
private void formatError(String message, Object... args) {
if (args != null && args.length > 0) {
message = String.format(message, args);
}
message = "Failed to parse `lint.xml` configuration file: " + message;
LintDriver driver = new LintDriver(new IssueRegistry() {
@Override @NonNull public List<Issue> getIssues() {
return Collections.emptyList();
}
}, mClient);
mClient.report(new Context(driver, mProject, mProject, mConfigFile),
IssueRegistry.LINT_ERROR,
mProject.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
Location.create(mConfigFile), message, TextFormat.RAW);
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例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) {
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;
}
示例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) {
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;
}
示例11: 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;
}
示例12: 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;
}
示例13: getMessagePart
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
@Nullable
private static String getMessagePart(@NonNull String errorMessage, int group,
@NonNull TextFormat format) {
List<String> parameters = LintUtils.getFormattedParameters(
RAW.convertTo(ERROR_MESSAGE_FORMAT, format),
errorMessage);
if (parameters.size() == 2 && group <= 2) {
return parameters.get(group - 1);
}
return null;
}
示例14: explainIssue
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
private void explainIssue(@NonNull StringBuilder output, @Nullable Issue issue)
throws IOException {
if (issue == null || !mFlags.isExplainIssues() || issue == IssueRegistry.LINT_ERROR) {
return;
}
String explanation = issue.getExplanation(TextFormat.TEXT);
if (explanation.trim().isEmpty()) {
return;
}
String indent = " ";
String formatted = SdkUtils.wrap(explanation, Main.MAX_LINE_WIDTH - indent.length(), null);
output.append('\n');
output.append(indent);
output.append("Explanation for issues of type \"").append(issue.getId()).append("\":\n");
for (String line : Splitter.on('\n').split(formatted)) {
if (!line.isEmpty()) {
output.append(indent);
output.append(line);
}
output.append('\n');
}
List<String> moreInfo = issue.getMoreInfo();
if (!moreInfo.isEmpty()) {
for (String url : moreInfo) {
if (formatted.contains(url)) {
continue;
}
output.append(indent);
output.append(url);
output.append('\n');
}
output.append('\n');
}
}
示例15: reportNonExistingIssueId
import com.android.tools.lint.detector.api.TextFormat; //导入依赖的package包/类
protected void reportNonExistingIssueId(@Nullable Project project, @NonNull String id) {
String message = String.format("Unknown issue id \"%1$s\"", id);
if (mDriver != null && project != null) {
Location location = Location.create(project.getDir());
if (!isSuppressed(IssueRegistry.LINT_ERROR)) {
report(new Context(mDriver, project, project, project.getDir()),
IssueRegistry.LINT_ERROR,
project.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
location, message, TextFormat.RAW);
}
} else {
log(Severity.ERROR, null, "Lint: %1$s", message);
}
}