com.android.tools.lint.detector.api.Location类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中com.android.tools.lint.detector.api.Location类的一些代码示例,展示了Location类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Location类的具体详情如下:
包路径:com.android.tools.lint.detector.api.Location
类名称:Location

Location介绍

[英]Location information for a warning

NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.
[中]警告的位置信息
注意:这不是一个公开的或最终的API;如果您依赖于此,请准备为下一个工具版本调整代码。

代码示例

代码示例来源:origin: Tencent/QMUI_Android

int threePlotHeight = threePlotImage.getHeight();
if ((double) threePlotWidth / targetWidth != 1.5 || (double) threePlotHeight / targetHeight != 1.5) {
  Location fileLocation = Location.create(context.file);
  context.report(ISSUE_IMAGE_SCALE, fileLocation, "2倍图 " + filePath +
      " 与其3倍图宽高分别为 (" + targetWidth + ", " + targetHeight + ") 和 (" + threePlotWidth + ", " + threePlotHeight + "),不符合比例关系。");

代码示例来源: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

Location secondary1 = location != null ? location.getSecondary() : null;
Location secondary2 = warning.location != null ? warning.location.getSecondary() : null;
if (secondary1 != null) {
  if (secondary2 != null) {
    if (!Objects.equal(secondary1.getFile(), secondary2.getFile())) {
      return false;
    location.getStart() != null && warning.location.getStart() != null &&
    location.getStart().getColumn() != warning.location.getStart().getColumn()) {
  return false;

代码示例来源:origin: com.android.tools.lint/lint

if (warning.location != null && warning.location.getSecondary() != null) {
  Location location = warning.location.getSecondary();
  boolean omitted = false;
  while (location != null) {
    if (location.getMessage() != null
        && !location.getMessage().isEmpty()) {
      output.append("    ");
      String path = client.getDisplayPath(warning.project,
          location.getFile());
      output.append(path);
      Position start = location.getStart();
      if (start != null) {
        int line = start.getLine();
      if (location.getMessage() != null
          && !location.getMessage().isEmpty()) {
        output.append(':');
        output.append(' ');
        output.append(RAW.convertTo(location.getMessage(), TEXT));
    location = location.getSecondary();
    location = warning.location.getSecondary();
    StringBuilder sb = new StringBuilder(100);
    sb.append("Also affects: ");
    int begin = sb.length();
    while (location != null) {
      if (location.getMessage() == null

代码示例来源:origin: com.android.tools.lint/lint-checks

String label = "Reference from @" + type.getName() + "/" + item
        + " to " + type.getName() + "/" + next + " here";
    itemLocation.setMessage(label);
    itemLocation.setSecondary(location);
    location = itemLocation;
  location = Location.create(context.getProject().getDir());
} else {
  Location curr = location.getSecondary();
  while (curr != null) {
    Location next = curr.getSecondary();
    if (next == location) {
      curr.setSecondary(null);
      break;

代码示例来源:origin: com.android.tools.lint/lint-api

Position start = location.getStart();
if (start != null) {
  return Location.create(location.getFile(), start,
      new DefaultPosition(start.getLine(), start.getColumn() + length,
          start.getOffset() + length));

代码示例来源:origin: com.android.tools.lint/lint-checks

for (Occurrence occurrence : occurrences) {
  Location location = context.getLocation(element);
  location.setClientData(element);
  location.setMessage(occurrence.message);
  location.setSecondary(occurrence.location);
  occurrence.location = location;

代码示例来源:origin: com.amazon.device.tools.lint/lint-checks

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);
}

代码示例来源: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-checks

Position start = location.getStart();
if (start != null) {
  int line = start.getLine();
  location = Location.create(context.file, start, location.getEnd());

代码示例来源:origin: com.android.tools.lint/lint

private boolean addImage(String url, Location location) throws IOException {
  if (url != null && endsWith(url, DOT_PNG)) {
    if (location.getSecondary() != null) {
      while (location != null && location.getFile() != null) {
        String imageUrl = getUrl(location.getFile());
        if (imageUrl != null
            && endsWith(imageUrl, DOT_PNG)) {
          urls.add(imageUrl);
        location = location.getSecondary();

代码示例来源:origin: com.android.tools.lint.checks/lint_checks

private void reportError(Context context, String id, File first, File second, String includer,
    List<String> chain) {
  String msg = null;
  if (chain.size() > 2) { // < 2: it's a directly include & obvious
    StringBuilder sb = new StringBuilder();
    for (String layout : chain) {
      if (sb.length() > 0) {
        sb.append(" => ");
      }
      sb.append(layout);
    }
    msg = String.format(
      "Duplicate id %1$s, already defined in layout %2$s which is included in this layout (%3$s)",
      id, includer, sb.toString());
  } else {
    msg = String.format(
      "Duplicate id %1$s, already defined in layout %2$s which is included in this layout",
      id, includer);
  }
  Location location = new Location(first, null, null);
  if (second != null) {
    // Also record the secondary location
    location.setSecondary(new Location(second, null, null));
  }
  context.client.report(context, CROSS_LAYOUT, location, msg, null);
}

代码示例来源:origin: com.amazon.device.tools.lint/lint-checks

private static Location chainLocations(List<File> files) {
  // Chain locations together
  Collections.sort(files);
  Location location = null;
  for (File file : files) {
    Location linkedLocation = location;
    location = Location.create(file);
    location.setSecondary(linkedLocation);
  }
  return location;
}

代码示例来源:origin: com.android.tools.lint/lint-tests

if (location.getSecondary() != null) {
  Location l = location.getSecondary();
  if (l == location) {
    fail("Location link cycle");
    if (l.getMessage() == null) {
      l.setMessage("<No location-specific message");
    if (l == l.getSecondary()) {
      fail("Location link cycle");
    l = l.getSecondary();

代码示例来源:origin: com.android.tools.lint/lint-checks

private void reportIfFound(@NonNull XmlContext context, @NonNull  String qualifiers,
    @NonNull  String name, @NonNull  ResourceType type, @Nullable Node secondary) {
  Multimap<ResourceType, Location> typeMap = mManifestLocations.get(name);
  if (typeMap != null) {
    Collection<Location> locations = typeMap.get(type);
    if (locations != null) {
      for (Location location : locations) {
        String message = getErrorMessage(qualifiers);
        if (secondary != null) {
          Location secondaryLocation = context.getLocation(secondary);
          secondaryLocation.setSecondary(location.getSecondary());
          secondaryLocation.setMessage("This value will not be used");
          location.setSecondary(secondaryLocation);
        }
        context.report(ISSUE, location, message);
      }
    }
  }
}

代码示例来源:origin: com.android.tools.lint/lint

File file = location.getFile();
warning.file = file;
warning.path = getDisplayPath(context.getProject(), file);
Position startPosition = location.getStart();
if (startPosition != null) {
  int line = startPosition.getLine();
  warning.line = line;
  warning.offset = startPosition.getOffset();
  Position endPosition = location.getEnd();
  if (endPosition != null) {
    warning.endOffset = endPosition.getOffset();
    if (context.file == location.getFile()) {
      warning.fileContents = context.getContents();
      warning.fileContents = getContents(location.getFile());

代码示例来源:origin: com.android.tools.lint/lint-api

offset = indexOf(contents, '\n', offset);
if (offset == -1) {
  return create(file);
    index = findPreviousMatch(contents, offset, patternStart, hints);
    line = adjustLine(contents, line, offset, index);
  } else if (direction == SearchDirection.EOL_BACKWARD) {
    int lineEnd = indexOf(contents, '\n', offset);
    index = findPreviousMatch(contents, lineEnd, patternStart, hints);
    line = adjustLine(contents, line, offset, index);
  } else if (direction == SearchDirection.FORWARD) {
    index = findNextMatch(contents, offset, patternStart, hints);
    line = adjustLine(contents, line, offset, index);
  } else {
    assert direction == SearchDirection.NEAREST ||
    int before = findPreviousMatch(contents, offset, patternStart, hints);
    int after = findNextMatch(contents, offset, patternStart, hints);
      line = adjustLine(contents, line, offset, index);
    } else if (after == -1) {
      index = before;
      line = adjustLine(contents, line, offset, index);
    } else {
      int newLinesBefore = 0;
          && offset - before < after - offset) {
        index = before;

代码示例来源: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/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

location = Location.reverse(location);
boolean foundConflict = false;
Location curr;
for (curr = location; curr != null; curr = curr.getSecondary()) {
  Object clientData = curr.getClientData();
  if (clientData instanceof Node) {
    Node node = (Node) clientData;

相关文章