本文整理了Java中com.android.tools.lint.detector.api.Location.getFile()
方法的一些代码示例,展示了Location.getFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Location.getFile()
方法的具体详情如下:
包路径:com.android.tools.lint.detector.api.Location
类名称:Location
方法名:getFile
[英]Returns the file containing the warning. Note that the file itself may not yet contain the error. When editing a file in the IDE for example, the tool could generate warnings in the background even before the document is saved. However, the file is used as a identifying token for the document being edited, and the IDE integration can map this back to error locations in the editor source code.
[中]返回包含警告的文件。请注意,文件本身可能尚未包含错误。例如,在IDE中编辑文件时,该工具甚至可以在保存文档之前在后台生成警告。但是,该文件用作正在编辑的文档的标识标记,IDE集成可以将其映射回编辑器源代码中的错误位置。
代码示例来源:origin: com.amazon.device.tools.lint/lint-checks
@Override
public int compare(Location location1, Location location2) {
File file1 = location1.getFile();
File file2 = location2.getFile();
String folder1 = file1.getParentFile().getName();
String folder2 = file2.getParentFile().getName();
return folder1.compareTo(folder2);
}
});
代码示例来源:origin: com.android.tools.lint/lint_api
@Override
public void ignore(Context context, Issue issue, Location location, String message,
Object data) {
// This configuration only supports suppressing warnings on a per-file basis
if (location != null) {
ignore(issue, location.getFile());
}
}
代码示例来源:origin: stackoverflow.com
protected File asAbsoluteFile(File f) {
String path = f.getPath();
// ensure we're getting a path in the form that URL can handle
if (path != null) {
path = path.replaceAll("\\\\", "/");
}
Location location = getLocation(path);
if (location == null) {
//can't find the file, let the parent implementation have a try
return super.asAbsoluteFile(f);
}
try {
return location.getFile();
} catch (IOException e) {
throw new RuntimeException("unable to read file " + f.getPath(), e);
}
}
代码示例来源:origin: com.android.tools.lint/lint-checks
@NonNull
private static Location chainLocations(@NonNull List<Location> locations) {
assert !locations.isEmpty();
// Sort locations by the file parent folders
if (locations.size() > 1) {
Collections.sort(locations, (location1, location2) -> {
File file1 = location1.getFile();
File file2 = location2.getFile();
String folder1 = file1.getParentFile().getName();
String folder2 = file2.getParentFile().getName();
return folder1.compareTo(folder2);
});
// Chain locations together
Iterator<Location> iterator = locations.iterator();
assert iterator.hasNext();
Location prev = iterator.next();
while (iterator.hasNext()) {
Location next = iterator.next();
prev.setSecondary(next);
prev = next;
}
}
return locations.get(0);
}
代码示例来源:origin: com.android.tools.lint.checks/lint_checks
@Override
public void afterCheckProject(Context context) {
if (mRootAttributes != null) {
for (Pair<Location, String> pair : mRootAttributes) {
Location location = pair.getFirst();
String layoutName = location.getFile().getName();
if (endsWith(layoutName, DOT_XML)) {
layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length());
}
String theme = getTheme(context, layoutName);
if (theme == null || !isBlankTheme(theme)) {
String drawable = pair.getSecond();
String message = String.format(
"Possible overdraw: Root element paints background %1$s with " +
"a theme that also paints a background (inferred theme is %2$s)",
drawable, theme);
context.client.report(context, ISSUE, location, message, null);
}
}
}
}
代码示例来源:origin: com.android.tools.lint/lint_api
@Override
public boolean isIgnored(Context context, Issue issue, Location location, String message,
Object data) {
ensureInitialized();
String id = issue.getId();
List<String> paths = mSuppressed.get(id);
if (paths != null && location != null) {
File file = location.getFile();
String relativePath = context.project.getRelativePath(file);
for (String suppressedPath : paths) {
if (suppressedPath.equals(relativePath)) {
return true;
}
}
}
if (mParent != null) {
return mParent.isIgnored(context, issue, location, message, data);
}
return false;
}
代码示例来源:origin: com.amazon.device.tools.lint/lint-checks
private static Location refineLocation(Context context, Location location,
String formatString, int substringStart, int substringEnd) {
Position startLocation = location.getStart();
Position endLocation = location.getEnd();
if (startLocation != null && endLocation != null) {
int startOffset = startLocation.getOffset();
int endOffset = endLocation.getOffset();
if (startOffset >= 0) {
String contents = context.getClient().readFile(location.getFile());
if (endOffset <= contents.length() && startOffset < endOffset) {
int formatOffset = contents.indexOf(formatString, startOffset);
if (formatOffset != -1 && formatOffset <= endOffset) {
return Location.create(location.getFile(), contents,
formatOffset + substringStart, formatOffset + substringEnd);
}
}
}
}
return location;
}
代码示例来源:origin: com.android.tools.lint/lint-api
writer.write('<');
writer.write(TAG_LOCATION);
String path = getDisplayPath(project, currentLocation.getFile());
writeAttribute(writer, 3, ATTR_FILE, path);
Position start = currentLocation.getStart();
代码示例来源:origin: com.android.tools.lint/lint-checks
private static Location refineLocation(Context context, Location location,
String formatString, int substringStart, int substringEnd) {
Position startLocation = location.getStart();
Position endLocation = location.getEnd();
if (startLocation != null && endLocation != null) {
int startOffset = startLocation.getOffset();
int endOffset = endLocation.getOffset();
if (startOffset >= 0) {
CharSequence contents = context.getClient().readFile(location.getFile());
if (endOffset <= contents.length() && startOffset < endOffset) {
int formatOffset = indexOf(contents, formatString, startOffset);
if (formatOffset != -1 && formatOffset <= endOffset) {
return Location.create(location.getFile(), contents,
formatOffset + substringStart, formatOffset + substringEnd);
}
}
}
}
return location;
}
代码示例来源:origin: com.android.tools.lint/lint-api
@Override
public void ignore(
@NonNull Context context,
@NonNull Issue issue,
@Nullable Location location,
@NonNull String message) {
// This configuration only supports suppressing warnings on a per-file basis
if (location != null) {
ignore(issue, location.getFile());
}
}
代码示例来源:origin: com.android.tools.lint/lint-api
File file = location.getFile();
String path = file.getPath();
String issueId = issue.getId();
代码示例来源:origin: com.android.tools.lint/lint-checks
@Override
public void afterCheckProject(@NonNull Context context) {
if (mRootAttributes != null) {
for (Pair<Location, String> pair : mRootAttributes) {
Location location = pair.getFirst();
Object clientData = location.getClientData();
if (clientData instanceof Node) {
if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) {
return;
}
}
String layoutName = location.getFile().getName();
if (endsWith(layoutName, DOT_XML)) {
layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length());
}
String theme = getTheme(context, layoutName);
if (theme == null || !isBlankTheme(theme)) {
String drawable = pair.getSecond();
String message = String.format(
"Possible overdraw: Root element paints background `%1$s` with " +
"a theme that also paints a background (inferred theme is `%2$s`)",
drawable, theme);
// TODO: Compute applicable scope node
context.report(ISSUE, location, message);
}
}
}
}
代码示例来源:origin: com.amazon.device.tools.lint/lint-checks
@Override
public void afterCheckProject(@NonNull Context context) {
if (mRootAttributes != null) {
for (Pair<Location, String> pair : mRootAttributes) {
Location location = pair.getFirst();
Object clientData = location.getClientData();
if (clientData instanceof Node) {
if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) {
return;
}
}
String layoutName = location.getFile().getName();
if (endsWith(layoutName, DOT_XML)) {
layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length());
}
String theme = getTheme(context, layoutName);
if (theme == null || !isBlankTheme(theme)) {
String drawable = pair.getSecond();
String message = String.format(
"Possible overdraw: Root element paints background `%1$s` with " +
"a theme that also paints a background (inferred theme is `%2$s`)",
drawable, theme);
// TODO: Compute applicable scope node
context.report(ISSUE, location, message);
}
}
}
}
代码示例来源:origin: com.android.tools.lint/lint
if (secondary1 != null) {
if (secondary2 != null) {
if (!Objects.equal(secondary1.getFile(), secondary2.getFile())) {
return false;
代码示例来源:origin: com.android.tools.lint/lint-api
return Location.create(location.getFile(), start,
new DefaultPosition(start.getLine(), start.getColumn() + length,
start.getOffset() + length));
代码示例来源:origin: com.android.tools.lint/lint
@Override
@NonNull
public Location getNameLocation(@NonNull XmlContext context, @NonNull Node node) {
Location location = getLocation(context, node);
Position start = location.getStart();
Position end = location.getEnd();
if (start == null || end == null) {
return location;
}
int delta = node instanceof Element ? 1 : 0; // Elements: skip "<"
int length = node.getNodeName().length();
int startOffset = start.getOffset() + delta;
int startColumn = start.getColumn() + delta;
return Location.create(location.getFile(),
new DefaultPosition(start.getLine(), startColumn, startOffset),
new DefaultPosition(end.getLine(), startColumn + length, startOffset + length));
}
代码示例来源:origin: com.android.tools.lint/lint
String imageUrl = getUrl(location.getFile());
if (imageUrl != null
&& endsWith(imageUrl, DOT_PNG)) {
代码示例来源:origin: com.android.tools.lint/lint
@Override
@NonNull
public Location getValueLocation(@NonNull XmlContext context, @NonNull Attr node) {
Location location = getLocation(context, node);
Position start = location.getStart();
Position end = location.getEnd();
if (start == null || end == null) {
return location;
}
int totalLength = end.getOffset() - start.getOffset();
int length = node.getValue().length();
int delta = totalLength - 1 - length;
int startOffset = start.getOffset() + delta;
int startColumn = start.getColumn() + delta;
return Location.create(location.getFile(),
new DefaultPosition(start.getLine(), startColumn, startOffset),
new DefaultPosition(end.getLine(), startColumn + length, startOffset + length));
}
代码示例来源:origin: com.android.tools.lint/lint
@Override
@NonNull
public Location getNameLocation(@NonNull JavaContext context, @NonNull Node node) {
// The range on method name identifiers is wrong in the ECJ nodes; just take start of
// name + length of name
if (node instanceof MethodDeclaration) {
MethodDeclaration declaration = (MethodDeclaration) node;
Identifier identifier = declaration.astMethodName();
Location location = getLocation(context, identifier);
com.android.tools.lint.detector.api.Position start = location.getStart();
com.android.tools.lint.detector.api.Position end = location.getEnd();
int methodNameLength = identifier.astValue().length();
if (start != null && end != null &&
end.getOffset() - start.getOffset() > methodNameLength) {
end = new DefaultPosition(start.getLine(), start.getColumn() + methodNameLength,
start.getOffset() + methodNameLength);
return Location.create(location.getFile(), start, end);
}
return location;
}
return super.getNameLocation(context, node);
}
代码示例来源:origin: com.android.tools.lint/lint-api
Project project = driver.findProjectFor(location.getFile());
if (project != null) {
configuration = project.getConfiguration(driver);
内容来源于网络,如有侵权,请联系作者删除!