当前位置: 首页>>代码示例>>Java>>正文


Java Location.create方法代码示例

本文整理汇总了Java中com.android.tools.lint.detector.api.Location.create方法的典型用法代码示例。如果您正苦于以下问题:Java Location.create方法的具体用法?Java Location.create怎么用?Java Location.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.tools.lint.detector.api.Location的用法示例。


在下文中一共展示了Location.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reportMap

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
private void reportMap(Context context, Issue issue, Map<String, Location> map) {
    if (map != null) {
        for (Map.Entry<String, Location> entry : map.entrySet()) {
            Location location = entry.getValue();
            String name = entry.getKey();
            String message = mDescriptions.get(name);

            if (location == null) {
                location = Location.create(context.getProject().getDir());
            }

            // We were prepending locations, but we want to prefer the base folders
            location = Location.reverse(location);

            context.report(issue, location, message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TranslationDetector.java

示例2: resolve

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@NonNull
@Override
public Location resolve() {
  if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
    return ApplicationManager.getApplication().runReadAction(new Computable<Location>() {
      @Override
      public Location compute() {
        return resolve();
      }
    });
  }
  TextRange textRange = DomPsiConverter.getTextRange(myNode);
  Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
  Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
  return Location.create(myFile, start, end);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DomPsiParser.java

示例3: checkBinaryResource

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@Override
public void checkBinaryResource(ResourceContext context) {

    String filename = context.file.getName();

    if (filename.contains(IGNORE_IMAGE_NIGHT_PNG)) {
        return;
    }

    if (filename.contains(CHECK_IMAGE_WEBP) || filename.contains(CHECK_IMAGE_PNG) || filename.contains(CHECK_IMAGE_JPEG) || filename.contains(CHECK_IMAGE_JPG)) {
        String filePath = context.file.getPath();
        String pattern = ".*?[mipmap|drawable]\\-xhdpi.*?";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(filePath);
        if (m.find()) {
            String threePlotFilePath = filePath.replace("xhdpi", "xxhdpi");
            File threePlotFile = new File(threePlotFilePath);
            try {
                BufferedImage targetImage = ImageIO.read(context.file);
                int targetWidth = targetImage.getWidth();
                int targetHeight = targetImage.getHeight();

                BufferedImage threePlotImage = ImageIO.read(threePlotFile);
                int threePlotWidth = threePlotImage.getWidth();
                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 + "),不符合比例关系。");
                }
            } catch (Exception ignored) {
            }
        }
    }

}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:37,代码来源:QMUIImageScaleDetector.java

示例4: checkBinaryResource

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@Override
public void checkBinaryResource(ResourceContext context) {

    String filename = context.file.getName();

    if (filename.contains(IGNORE_IMAGE_NIGHT_PNG)) {
        return;
    }

    if (filename.contains(CHECK_IMAGE_WEBP) || filename.contains(CHECK_IMAGE_PNG) || filename.contains(CHECK_IMAGE_JPEG) || filename.contains(CHECK_IMAGE_JPG)) {
        String filePath = context.file.getPath();
        String pattern = ".*?[mipmap|drawable]\\-(x*)hdpi.*?";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(filePath);
        if (m.find()) {
            double multiple = 1.5;
            if (m.group(1).length() > 0) {
                multiple = m.group(1).length() + 1;
            }
            try {
                BufferedImage targetImage = ImageIO.read(context.file);
                int width = targetImage.getWidth();
                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 + ")。");
                }
            } catch (Exception ignored) {
            }
        }
    }

}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:34,代码来源:QMUIImageSizeDetector.java

示例5: createLocation

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
private Location createLocation(@NonNull File file, @NonNull String contents, int startOffset, int endOffset) {
    DefaultPosition startPosition = new DefaultPosition(
            getLineNumber(contents, startOffset), getColumnNumber(contents, startOffset), startOffset);

    DefaultPosition endPosition = new DefaultPosition(
            getLineNumber(contents, endOffset), getColumnNumber(contents, endOffset), endOffset);

    return Location.create(mContext.file, startPosition, endPosition);
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:10,代码来源:MultiFunctionFlagStructureDetector.java

示例6: createLocation

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@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()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GradleDetectorTest.java

示例7: getLocation

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node, int startDelta, int endDelta) {
  TextRange textRange = DomPsiConverter.getTextRange(node);
  Position start = new DefaultPosition(-1, -1, textRange.getStartOffset() + startDelta);
  Position end = new DefaultPosition(-1, -1, textRange.getStartOffset() + endDelta);
  return Location.create(context.file, start, end);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:DomPsiParser.java

示例8: afterCheckProject

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@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");
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:RtlDetector.java

示例9: getValueLocation

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@NonNull
@Override
public Location getValueLocation(@NonNull XmlContext context, @NonNull Attr node) {
  TextRange textRange = DomPsiConverter.getTextValueRange(node);
  Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
  Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
  return Location.create(context.file, start, end);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:DomPsiParser.java

示例10: getLocation

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@NonNull
@Override
public Location getLocation(@NonNull JavaContext context, @NonNull Node node) {
  Position position = node.getPosition();
  if (position == null) {
    myClient.log(Severity.WARNING, null, "No position data found for node %1$s", node);
    return Location.create(context.file);
  }
  return Location.create(context.file, null, position.getStart(), position.getEnd());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:LombokPsiParser.java

示例11: afterCheckProject

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@Override
public void afterCheckProject(@NonNull Context context) {
    if (mCandidates == null) {
        return;
    }

    Set<String> seen = Sets.newHashSet();

    for (Candidate candidate : mCandidates) {
        String type = candidate.mClass;
        if (mJavaxLibraryClasses.contains(type)) {
            continue;
        }
        File jarFile = candidate.mJarFile;
        String referencedIn = candidate.mReferencedIn;

        Location location = Location.create(jarFile);
        String pkg = getPackageName(type);
        if (seen.contains(pkg)) {
            continue;
        }
        seen.add(pkg);

        if (pkg.equals("javax.inject")) {
            String name = jarFile.getName();
            //noinspection SpellCheckingInspection
            if (name.startsWith("dagger-") || name.startsWith("guice-")) {
                // White listed
                return;
            }
        }

        String message = String.format(
                "Invalid package reference in library; not included in Android: `%1$s`. " +
                "Referenced from `%2$s`.", pkg, ClassContext.getFqcn(referencedIn));
        context.report(ISSUE, location, message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:InvalidPackageDetector.java

示例12: beforeCheckFile

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
    File file = context.file;
    boolean isXmlFile = LintUtils.isXmlFile(file);
    if (!isXmlFile && !LintUtils.isBitmapFile(file)) {
        return;
    }
    String parentName = file.getParentFile().getName();
    int dash = parentName.indexOf('-');
    if (dash != -1 || FD_RES_VALUES.equals(parentName)) {
        return;
    }
    ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
    if (folderType == null) {
        return;
    }
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType);
    if (types.isEmpty()) {
        return;
    }
    ResourceType type = types.get(0);
    String resourceName = getResourceFieldName(getBaseName(file.getName()));
    if (isPrivate(context, type, resourceName)) {
        String message = createOverrideErrorMessage(context, type, resourceName);
        Location location = Location.create(file);
        context.report(ISSUE, location, message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PrivateResourceDetector.java

示例13: getNameLocation

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
@NonNull
@Override
public Location getNameLocation(@NonNull XmlContext context, @NonNull Node node) {
  TextRange textRange = DomPsiConverter.getTextNameRange(node);
  Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
  Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
  return Location.create(context.file, start, end);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:DomPsiParser.java

示例14: testMessagePatternIgnore

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
public void testMessagePatternIgnore() throws Exception {
    File projectDir = getProjectDir(null,
            "res/layout/onclick.xml=>res/layout/onclick.xml"
    );
    LintClient client = new TestLintClient();
    Project project = Project.create(client, projectDir, projectDir);
    LintDriver driver = new LintDriver(new BuiltinIssueRegistry(), client);
    File file = new File(projectDir,
            "res" + File.separator + "layout" + File.separator + "onclick.xml");
    assertTrue(file.exists());
    Context plainContext = new Context(driver, project, project, file);
    Location location = Location.create(file);

    assertEquals(Severity.WARNING, ObsoleteLayoutParamsDetector.ISSUE.getDefaultSeverity());

    DefaultConfiguration configuration = getConfiguration(""
            + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<lint>\n"
            + "    <issue id=\"ObsoleteLayoutParam\">\n"
            + "        <ignore regexp=\"sample_icon\\.gif\" />\n"
            + "        <ignore regexp=\"javax\\.swing\" />\n"
            + "    </issue>\n"
            + "</lint>");

    assertFalse(configuration.isIgnored(plainContext, ObsoleteLayoutParamsDetector.ISSUE,
            location,
            "Missing the following drawables in drawable-hdpi: some_random.gif (found in drawable-mdpi)"));
    assertTrue(configuration.isIgnored(plainContext, ObsoleteLayoutParamsDetector.ISSUE,
            location,
            "Missing the following drawables in drawable-hdpi: sample_icon.gif (found in drawable-mdpi)"));

    assertFalse(configuration.isIgnored(plainContext, ObsoleteLayoutParamsDetector.ISSUE,
            location,
            "Invalid package reference in library; not included in Android: java.awt. Referenced from test.pkg.LibraryClass."));
    assertTrue(configuration.isIgnored(plainContext, ObsoleteLayoutParamsDetector.ISSUE,
            location,
            "Invalid package reference in library; not included in Android: javax.swing. Referenced from test.pkg.LibraryClass."));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:DefaultConfigurationTest.java

示例15: reportNonExistingIssueId

import com.android.tools.lint.detector.api.Location; //导入方法依赖的package包/类
protected void reportNonExistingIssueId(@Nullable Project project, @NonNull String id) {
    String message = String.format("Unknown issue id \"%1$s\"", id);

    if (mDriver != null && project != null) {
        Location location = Location.create(project.getDir());
        if (!isSuppressed(IssueRegistry.LINT_ERROR)) {
            report(new Context(mDriver, project, project, project.getDir()),
                    IssueRegistry.LINT_ERROR,
                    project.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
                    location, message, TextFormat.RAW);
        }
    } else {
        log(Severity.ERROR, null, "Lint: %1$s", message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:LintCliClient.java


注:本文中的com.android.tools.lint.detector.api.Location.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。