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

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

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

Location.create介绍

[英]Creates a new location for the given file
[中]为给定文件创建新位置

代码示例

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

int height = targetImage.getHeight();
if (width % multiple != 0 || height % multiple != 0) {
  Location fileLocation = Location.create(context.file);
  context.report(ISSUE_IMAGE_SIZE, fileLocation, filePath + " 为" + trimZeroAndDot(multiple) + "倍图,其宽高应该是" + trimZeroAndDot(multiple) + "的倍数,目前宽高为 (" + width + ", " + height + ")。");

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

@Override
@NonNull
public Location resolve() {
  return create(file, contents, startOffset, endOffset);
}

代码示例来源:origin: com.android.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

@NonNull
@Override
public Location resolve() {
  return Location.create(file, PositionXmlParser.getPosition(node));
}

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

/**
 * Check that launcher icons are PNG or JPEG
 */
private static void checkLauncherIconFormat(Context context, File file) {
  String path = file.getPath();
  if (endsWithIgnoreCase(path, DOT_PNG) || endsWithIgnoreCase(path, DOT_JPEG)) {
    return;
  }
  Location location = Location.create(file);
  String message = "Launcher icons must be in PNG format";
  context.report(ICON_LAUNCHER_FORMAT, location, message);
}

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

@NonNull
private Location getMainApplicationTagLocation(@NonNull Context context) {
  if (mApplicationTagHandle != null) {
    return mApplicationTagHandle.resolve();
  }
  List<File> manifestFiles = context.getMainProject().getManifestFiles();
  if (!manifestFiles.isEmpty()) {
    return Location.create(manifestFiles.get(0));
  }
  return Location.NONE;
}

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

@Override
public void afterCheckProject(@NonNull Context context) {
  if (mUsesRtlAttributes && mEnabledRtlSupport == null && rtlApplies(context)) {
    List<File> manifestFile = context.getMainProject().getManifestFiles();
    if (!manifestFile.isEmpty()) {
      Location location = Location.create(manifestFile.get(0));
      context.report(ENABLED, location,
          "The project references RTL attributes, but does not explicitly enable " +
          "or disable RTL support with `android:supportsRtl` in the manifest");
    }
  }
}

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

@NonNull
@Override
public Location resolve() {
  // TODO: Look up the exact item location more
  // closely
  ResourceFile source = item.getSource();
  assert source != null : item;
  return create(source.getFile());
}

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

@Override
public void afterCheckProject(@NonNull Context context) {
  if (mUsesRtlAttributes && mEnabledRtlSupport == null && rtlApplies(context)) {
    List<File> manifestFile = context.getMainProject().getManifestFiles();
    if (!manifestFile.isEmpty()) {
      Location location = Location.create(manifestFile.get(0));
      context.report(ENABLED, location,
          "The project references RTL attributes, but does not explicitly enable " +
          "or disable RTL support with `android:supportsRtl` in the manifest");
    }
  }
}

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

@Nullable
private Location getMainApplicationTagLocation(@NonNull Context context) {
  if (mApplicationTagHandle != null) {
    return mApplicationTagHandle.resolve();
  }
  List<File> manifestFiles = context.getMainProject().getManifestFiles();
  if (!manifestFiles.isEmpty()) {
    return Location.create(manifestFiles.get(0));
  }
  return null;
}

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

/**
 * Creates a new location for the given file, with the given contents, for
 * the given line number.
 *
 * @param file the file containing the location
 * @param contents the current contents of the file
 * @param line the line number (0-based) for the position
 * @return a new location
 */
@NonNull
public static Location create(@NonNull File file, @NonNull String contents, int line) {
  return create(file, contents, line, null, null, null);
}

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

@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node) {
  return Location.create(context.file, PositionXmlParser.getPosition(node));
}

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

@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node,
    int start, int end) {
  return Location.create(context.file, PositionXmlParser.getPosition(node, start, end));
}

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

@NonNull
@Override
public Location resolve() {
  lombok.ast.Position pos = mNode.getPosition();
  return Location.create(mFile, null /*contents*/, pos.getStart(), pos.getEnd());
}

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

@Override
public void beforeCheckProject(@NonNull Context context) {
  mApiDatabase = ApiLookup.get(context.getClient());
  // We can't look up the minimum API required by the project here:
  // The manifest file hasn't been processed yet in the -before- project hook.
  // For now it's initialized lazily in getMinSdk(Context), but the
  // lint infrastructure should be fixed to parse manifest file up front.
  if (mApiDatabase == null && !mWarnedMissingDb) {
    mWarnedMissingDb = true;
    context.report(IssueRegistry.LINT_ERROR, Location.create(context.file),
          "Can't find API database; API check not performed");
  }
}

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

@NonNull
public Location createLocation(@NonNull PsiElement element) {
  TextRange range = element.getTextRange();
  PsiFile containingFile = element.getContainingFile();
  CharSequence contents;
  File file = getFile(containingFile);
  if (file == null) {
    return Location.NONE;
  }
  contents = getFileContents(containingFile);
  return Location.create(file, contents, range.getStartOffset(),
      range.getEndOffset());
}

代码示例来源:origin: com.amazon.device.tools.build/gradle-core

@Override
  protected Location createLocation(@NonNull Context context, @NonNull Object cookie) {
    ASTNode node = (ASTNode) cookie;
    Pair<Integer, Integer> offsets = getOffsets(node, context);
    int fromLine = node.getLineNumber() - 1;
    int fromColumn = node.getColumnNumber() - 1;
    int toLine = node.getLastLineNumber() - 1;
    int toColumn = node.getLastColumnNumber() - 1;
    return Location.create(context.file,
        new DefaultPosition(fromLine, fromColumn, offsets.getFirst()),
        new DefaultPosition(toLine, toColumn, offsets.getSecond()));
  }
}

代码示例来源:origin: com.android.tools.build/gradle-core

@Override
  protected Location createLocation(@NonNull Context context, @NonNull Object cookie) {
    ASTNode node = (ASTNode) cookie;
    Pair<Integer, Integer> offsets = getOffsets(node, context);
    int fromLine = node.getLineNumber() - 1;
    int fromColumn = node.getColumnNumber() - 1;
    int toLine = node.getLastLineNumber() - 1;
    int toColumn = node.getLastColumnNumber() - 1;
    return Location.create(context.file,
        new DefaultPosition(fromLine, fromColumn, offsets.getFirst()),
        new DefaultPosition(toLine, toColumn, offsets.getSecond()));
  }
}

相关文章