本文整理汇总了Java中com.android.tools.lint.detector.api.Location.setMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Location.setMessage方法的具体用法?Java Location.setMessage怎么用?Java Location.setMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.detector.api.Location
的用法示例。
在下文中一共展示了Location.setMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitElement
import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
Node parentNode = element.getParentNode();
if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
Element parent = (Element)parentNode;
Attr width = parent.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_WIDTH);
Attr height = parent.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_HEIGHT);
Attr attr = null;
if (width != null && VALUE_WRAP_CONTENT.equals(width.getValue())) {
attr = width;
}
if (height != null && VALUE_WRAP_CONTENT.equals(height.getValue())) {
attr = height;
}
if (attr != null) {
String message = String.format("Placing a `<WebView>` in a parent element that "
+ "uses a `wrap_content %1$s` can lead to subtle bugs; use `match_parent` "
+ "instead", attr.getLocalName());
Location location = context.getLocation(element);
Location secondary = context.getLocation(attr);
secondary.setMessage("`wrap_content` here may not work well with WebView below");
location.setSecondary(secondary);
context.report(ISSUE, element, location, message);
}
}
}
示例2: reportMismatch
import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
private static void reportMismatch(XmlContext context, Attr idNode, Node inputTypeNode,
String message) {
Location location;
if (inputTypeNode != null) {
location = context.getLocation(inputTypeNode);
Location secondary = context.getLocation(idNode);
secondary.setMessage("id defined here");
location.setSecondary(secondary);
} else {
location = context.getLocation(idNode);
}
context.report(ISSUE, idNode.getOwnerElement(), location, message);
}
示例3: visitMethod
import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation call) {
String lhs = getLhs(call);
if (lhs == null) {
return;
}
Node method = JavaContext.findSurroundingMethod(call);
if (method == null) {
return;
} else if (method != mLastMethod) {
mIds = Maps.newHashMap();
mLhs = Maps.newHashMap();
mCallOperands = Maps.newHashMap();
mLastMethod = method;
}
String callOperand = call.astOperand() != null ? call.astOperand().toString() : "";
Expression first = call.astArguments().first();
if (first instanceof Select) {
Select select = (Select) first;
String id = select.astIdentifier().astValue();
Expression operand = select.astOperand();
if (operand instanceof Select) {
Select type = (Select) operand;
if (type.astIdentifier().astValue().equals(RESOURCE_CLZ_ID)) {
if (mIds.containsKey(id)) {
if (lhs.equals(mLhs.get(id))) {
return;
}
if (!callOperand.equals(mCallOperands.get(id))) {
return;
}
MethodInvocation earlierCall = mIds.get(id);
if (!isReachableFrom(method, earlierCall, call)) {
return;
}
Location location = context.getLocation(call);
Location secondary = context.getLocation(earlierCall);
secondary.setMessage("First usage here");
location.setSecondary(secondary);
context.report(ISSUE, call, location, String.format(
"The id `%1$s` has already been looked up in this method; possible " +
"cut & paste error?", first.toString()));
} else {
mIds.put(id, call);
mLhs.put(id, lhs);
mCallOperands.put(id, callOperand);
}
}
}
}
}
示例4: test
import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
public void test() throws Exception {
File file = new File(getTargetDir(), "report");
try {
LintCliClient client = new LintCliClient() {
@Override
String getRevision() {
return "unittest"; // Hardcode version to keep unit test output stable
}
};
//noinspection ResultOfMethodCallIgnored
file.getParentFile().mkdirs();
FileWriter writer = new FileWriter(file);
TextReporter reporter = new TextReporter(client, client.mFlags, file, writer, true);
Project project = Project.create(client, new File("/foo/bar/Foo"),
new File("/foo/bar/Foo"));
client.mFlags.setShowEverything(true);
Warning warning1 = new Warning(ManifestDetector.USES_SDK,
"<uses-sdk> tag should specify a target API level (the highest verified " +
"version; when running on later versions, compatibility behaviors may " +
"be enabled) with android:targetSdkVersion=\"?\"",
Severity.WARNING, project);
warning1.line = 6;
warning1.file = new File("/foo/bar/Foo/AndroidManifest.xml");
warning1.errorLine = " <uses-sdk android:minSdkVersion=\"8\" />\n ^\n";
warning1.path = "AndroidManifest.xml";
warning1.location = Location.create(warning1.file,
new DefaultPosition(6, 4, 198), new DefaultPosition(6, 42, 236));
Location secondary = Location.create(warning1.file,
new DefaultPosition(7, 4, 198), new DefaultPosition(7, 42, 236));
secondary.setMessage("Secondary location");
warning1.location.setSecondary(secondary);
Warning warning2 = new Warning(HardcodedValuesDetector.ISSUE,
"[I18N] Hardcoded string \"Fooo\", should use @string resource",
Severity.WARNING, project);
warning2.line = 11;
warning2.file = new File("/foo/bar/Foo/res/layout/main.xml");
warning2.errorLine = " android:text=\"Fooo\" />\n" +
" ~~~~~~~~~~~~~~~~~~~\n";
warning2.path = "res/layout/main.xml";
warning2.location = Location.create(warning2.file,
new DefaultPosition(11, 8, 377), new DefaultPosition(11, 27, 396));
secondary = Location.create(warning1.file,
new DefaultPosition(7, 4, 198), new DefaultPosition(7, 42, 236));
secondary.setMessage("Secondary location");
warning2.location.setSecondary(secondary);
Location tertiary = Location.create(warning2.file,
new DefaultPosition(5, 4, 198), new DefaultPosition(5, 42, 236));
secondary.setSecondary(tertiary);
List<Warning> warnings = new ArrayList<Warning>();
warnings.add(warning1);
warnings.add(warning2);
Collections.sort(warnings);
reporter.write(0, 2, warnings);
String report = Files.toString(file, Charsets.UTF_8);
assertEquals(""
+ "AndroidManifest.xml:7: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\" [UsesMinSdkAttributes]\n"
+ " <uses-sdk android:minSdkVersion=\"8\" />\n"
+ " ^\n"
+ " AndroidManifest.xml:8: Secondary location\n"
+ "res/layout/main.xml:12: Warning: [I18N] Hardcoded string \"Fooo\", should use @string resource [HardcodedText]\n"
+ " android:text=\"Fooo\" />\n"
+ " ~~~~~~~~~~~~~~~~~~~\n"
+ " AndroidManifest.xml:8: Secondary location\n"
+ "Also affects: res/layout/main.xml:6\n"
+ "0 errors, 2 warnings\n",
report);
} finally {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
}