com.android.tools.lint.detector.api.Location.setMessage()方法的使用及代码示例

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

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

Location.setMessage介绍

[英]Sets a custom message for this location. This is typically used for secondary locations, to describe the significance of this alternate location. For example, for a duplicate id warning, the primary location might say "This is a duplicate id", pointing to the second occurrence of id declaration, and then the secondary location could point to the original declaration with the custom message "Originally defined here".
[中]设置此位置的自定义消息。这通常用于辅助位置,以描述此备用位置的重要性。例如,对于重复id警告,主位置可能会说“这是一个重复id”,指向第二次出现的id声明,然后辅助位置可能会指向带有自定义消息“最初定义在此处”的原始声明。

代码示例

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

/**
 * Sets a custom message for this location. This is typically used for
 * secondary locations, to describe the significance of this alternate
 * location. For example, for a duplicate id warning, the primary location
 * might say "This is a duplicate id", pointing to the second occurrence of
 * id declaration, and then the secondary location could point to the
 * original declaration with the custom message "Originally defined here".
 *
 * @param message the message to apply to this location
 * @return this, for constructor chaining
 */
public Location setMessage(@NonNull String message) {
  return setMessage(message, false);
}

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

private static void checkUniqueNames(XmlContext context, Element parent) {
  List<Element> items = LintUtils.getChildren(parent);
  if (items.size() > 1) {
    Set<String> names = Sets.newHashSet();
    for (Element item : items) {
      Attr nameNode = item.getAttributeNode(ATTR_NAME);
      if (nameNode != null) {
        String name = nameNode.getValue();
        if (names.contains(name) && context.isEnabled(ISSUE)) {
          Location location = context.getLocation(nameNode);
          for (Element prevItem : items) {
           Attr attribute = item.getAttributeNode(ATTR_NAME);
           if (attribute != null && name.equals(attribute.getValue())) {
              assert prevItem != item;
              Location prev = context.getLocation(prevItem);
              prev.setMessage("Previously defined here");
              location.setSecondary(prev);
              break;
            }
          }
          String message = String.format(
              "`%1$s` has already been defined in this `<%2$s>`",
              name, parent.getTagName());
          context.report(ISSUE, nameNode, location, message);
        }
        names.add(name);
      }
    }
  }
}

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

private static void checkUniqueNames(XmlContext context, Element parent) {
  List<Element> items = LintUtils.getChildren(parent);
  if (items.size() > 1) {
    Set<String> names = Sets.newHashSet();
    for (Element item : items) {
      Attr nameNode = item.getAttributeNode(ATTR_NAME);
      if (nameNode != null) {
        String name = nameNode.getValue();
        if (names.contains(name) && context.isEnabled(ISSUE)) {
          Location location = context.getLocation(nameNode);
          for (Element prevItem : items) {
           Attr attribute = item.getAttributeNode(ATTR_NAME);
           if (attribute != null && name.equals(attribute.getValue())) {
              assert prevItem != item;
              Location prev = context.getLocation(prevItem);
              prev.setMessage("Previously defined here");
              location.setSecondary(prev);
              break;
            }
          }
          String message = String.format(
              "`%1$s` has already been defined in this `<%2$s>`",
              name, parent.getTagName());
          context.report(ISSUE, nameNode, location, message);
        }
        names.add(name);
      }
    }
  }
}

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

Location location = context.getLocation(attr);
String folder = context.file.getParentFile().getName();
location.setMessage(String.format("Occurrence in %1$s", folder));
locations.add(location);

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

Location location = context.getLocation(attr);
String folder = context.file.getParentFile().getName();
location.setMessage(String.format("Occurrence in %1$s", folder));
locations.add(location);

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

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

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

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

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

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

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.android.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.android.tools.lint/lint-checks

if (first != null && first != attribute) {
  Location secondLocation = context.getLocation(first);
  secondLocation.setMessage(String.format("Duplicate id `%1$s` originally defined here", id), true);
  location.setSecondary(secondLocation);
        location.setMessage(occurrence.message);
        location.setSecondary(occurrence.location);
        occurrence.location = location;

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

if (first != null && first != attribute) {
  Location secondLocation = context.getLocation(first);
  secondLocation.setMessage(String.format("`%1$s` originally defined here", id));
  location.setSecondary(secondLocation);
        location.setMessage(occurrence.message);
        location.setSecondary(occurrence.location);
        occurrence.location = location;

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

/**
 * Sets a secondary location with the given message and returns the current location
 * updated with the given secondary location.
 *
 * @param secondary       a secondary location associated with this location
 * @param message         a message to be set on the secondary location
 * @param selfExplanatory if true, the message is itself self-explanatory; see
 *                        {@link #isSelfExplanatory()}}
 * @return current location updated with the secondary location
 */
@NonNull
public Location withSecondary(@NonNull Location secondary, @NonNull String message,
               boolean selfExplanatory) {
  secondary.setMessage(message, selfExplanatory);
  setSecondary(secondary);
  return this;
}
/**

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

location.setMessage(String.format("Declaration with array size (%1$d)",
        LintUtils.getChildCount(element)));
location.setSecondary(mLocations.get(name));

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

location.setMessage(String.format("Declaration with array size (%1$d)",
        LintUtils.getChildCount(element)));
location.setSecondary(mLocations.get(name));

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

/**
 * Checks a String.format call that is using a string that doesn't contain format placeholders.
 * @param context the context to report errors to
 * @param call the AST node for the {@link String#format}
 * @param name the string name
 * @param handle the string location
 */
private static void checkNotFormattedHandle(
    JavaContext context,
    PsiMethodCallExpression call,
    String name,
    Handle handle) {
  Object clientData = handle.getClientData();
  if (clientData instanceof Node) {
    if (context.getDriver().isSuppressed(null, INVALID, (Node) clientData)) {
      return;
    }
  }
  Location location = context.getLocation(call);
  Location secondary = handle.resolve();
  secondary.setMessage("This definition does not require arguments");
  location.setSecondary(secondary);
  String message = String.format(
      "Format string '`%1$s`' is not a valid format string so it should not be " +
          "passed to `String.format`",
      name);
  context.report(INVALID, call, location, message);
}

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

l.setMessage("<No location-specific message");

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

l.setMessage("<No location-specific message");

相关文章