Package com.android.tools.lint.detector.api

Examples of com.android.tools.lint.detector.api.Location


                    List<String> list = new ArrayList<String>(inBoth);
                    Collections.sort(list);

                    // Chain locations together
                    Collections.sort(files);
                    Location location = null;
                    for (File file : files) {
                        Location linkedLocation = location;
                        location = new Location(file, null, null);
                        location.setSecondary(linkedLocation);
                    }

                    context.client.report(context,
                        ICON_DENSITIES,
                        location,
                        String.format(
                            "The following images appear in both -nodpi and in a density folder: %1$s",
                            LintUtils.formatList(list, 10)),
                        null);
                }
            }
        }

        if (context.configuration.isEnabled(ICON_DENSITIES)) {
            // Look for folders missing some of the specific assets
            Set<String> allNames = new HashSet<String>();
            for (Entry<File,Set<String>> entry : folderToNames.entrySet()) {
                if (!isNoDpiFolder(entry.getKey())) {
                    Set<String> names = entry.getValue();
                    allNames.addAll(names);
                }
            }

            for (Map.Entry<File, Set<String>> entry : folderToNames.entrySet()) {
                File file = entry.getKey();
                if (isNoDpiFolder(file)) {
                    continue;
                }
                Set<String> names = entry.getValue();
                if (names.size() != allNames.size()) {
                    List<String> delta =
                            new ArrayList<String>(difference(allNames, names));
                    Collections.sort(delta);
                    String foundIn = "";
                    if (delta.size() == 1) {
                        // Produce list of where the icon is actually defined
                        List<String> defined = new ArrayList<String>();
                        String name = delta.get(0);
                        for (Map.Entry<File, Set<String>> e : folderToNames.entrySet()) {
                            if (e.getValue().contains(name)) {
                                defined.add(e.getKey().getName());
                            }
                        }
                        if (defined.size() > 0) {
                            foundIn = String.format(" (found in %1$s)",
                                    LintUtils.formatList(defined, 5));
                        }
                    }

                    context.client.report(context,
                            ICON_DENSITIES,
                            new Location(file, null, null),
                            String.format(
                                    "Missing the following drawables in %1$s: %2$s%3$s",
                                    file.getName(),
                                    LintUtils.formatList(delta, 5),
                                    foundIn),
View Full Code Here


                } else if (endsWith(name, DOT_PNG)
                        || endsWith(name, DOT_JPG)
                        || endsWith(name, DOT_GIF)) {
                    context.client.report(context,
                        ICON_LOCATION,
                        new Location(file, null, null),
                        String.format("Found bitmap drawable res/drawable/%1$s in " +
                                "densityless folder",
                                file.getName()),
                        null);
                }
            }
        }

        if (context.configuration.isEnabled(GIF_USAGE)) {
            for (File file : files) {
                String name = file.getName();
                if (endsWith(name, DOT_GIF)) {
                    context.client.report(context,
                            GIF_USAGE,
                            new Location(file, null, null),
                            "Using the .gif format for bitmaps is discouraged",
                            null);
                }
            }
        }
View Full Code Here

        Dimension size = getSize(file);
        if (size != null) {
            if (exactMatch && size.width != width || size.height != height) {
                context.client.report(context,
                        ICON_EXPECTED_SIZE,
                    new Location(file, null, null),
                    String.format(
                        "Incorrect icon size for %1$s: expected %2$dx%3$d, but was %4$dx%5$d",
                        folderName + File.separator + file.getName(),
                        width, height, size.width, size.height),
                    null);
            } else if (!exactMatch && size.width > width || size.height > height) {
                context.client.report(context,
                        ICON_EXPECTED_SIZE,
                    new Location(file, null, null),
                    String.format(
                        "Incorrect icon size for %1$s: icon size should be at most %2$dx%3$d, but was %4$dx%5$d",
                        folderName + File.separator + file.getName(),
                        width, height, size.width, size.height),
                    null);
View Full Code Here

                    // that this layout is included so check the included layouts to make
                    // sure at least one included context is valid for this layout_param.
                    // We can't do that yet since we may be processing the include tag to
                    // this layout after the layout itself. Instead, stash a work order...
                    if (context.scope.contains(Scope.ALL_RESOURCE_FILES)) {
                        Location location = context.parser.getLocation(context, attribute);
                        mPending.add(Pair.of(name, location));
                    }

                    return;
                }

                String parentTag = ((Element) layoutNode).getTagName();
                if (parentTag.equals(MERGE)) {
                    // This is a merge which means we need to check the including contexts,
                    // wherever they are. This has to be done after all the files have been
                    // scanned since we are not processing the files in any particular order.
                    if (context.scope.contains(Scope.ALL_RESOURCE_FILES)) {
                        Location location = context.parser.getLocation(context, attribute);
                        mPending.add(Pair.of(name, location));
                    }

                    return;
                }
View Full Code Here

        if (mIncludes == null) {
            return;
        }

        for (Pair<String, Location> pending : mPending) {
            Location location = pending.getSecond();
            File file = location.getFile();
            String layout = file.getName();
            if (layout.endsWith(DOT_XML)) {
                layout = layout.substring(0, layout.length() - DOT_XML.length());
            }
View Full Code Here

                if (project.isGradleProject()) {
                    @SuppressWarnings("SpellCheckingInspection")
                    String message = String.format("\"%1$s\" is a Gradle project. To correctly "
                            + "analyze Gradle projects, you should run \"gradlew :lint\" instead.",
                            project.getName());
                    Location location = Location.create(project.getDir());
                    report(new Context(mDriver, project, project, project.getDir()),
                            IssueRegistry.LINT_ERROR,
                            project.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
                            location, message, null);
                }
View Full Code Here

        List<ClassEntry> classEntries;
        if (classFolders.isEmpty()) {
            String message = String.format("No .class files were found in project \"%1$s\", "
                    + "so none of the classfile based checks could be run. "
                    + "Does the project need to be built first?", project.getName());
            Location location = Location.create(project.getDir());
            mClient.report(new Context(this, project, main, project.getDir()),
                    IssueRegistry.LINT_ERROR,
                    project.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
                    location, message, null);
            classEntries = Collections.emptyList();
View Full Code Here

        List<ClassEntry> classEntries;
        if (classFolders.isEmpty()) {
            String message = String.format("No .class files were found in project \"%1$s\", "
                    + "so none of the classfile based checks could be run. "
                    + "Does the project need to be built first?", project.getName());
            Location location = Location.create(project.getDir());
            mClient.report(new Context(this, project, main, project.getDir()),
                    IssueRegistry.LINT_ERROR,
                    project.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
                    location, message, null);
            classEntries = Collections.emptyList();
View Full Code Here

                if (warning.errorLine != null && !warning.errorLine.isEmpty()) {
                    output.append(warning.errorLine);
                }

                if (warning.location != null && warning.location.getSecondary() != null) {
                    Location location = warning.location.getSecondary();
                    while (location != null) {
                        if (location.getMessage() != null
                                && !location.getMessage().isEmpty()) {
                            output.append("    "); //$NON-NLS-1$
                            String path = mClient.getDisplayPath(warning.project,
                                    location.getFile());
                            output.append(path);

                            Position start = location.getStart();
                            if (start != null) {
                                int line = start.getLine();
                                if (line >= 0) {
                                    output.append(':');
                                    output.append(Integer.toString(line + 1));
                                }
                            }

                            if (location.getMessage() != null
                                    && !location.getMessage().isEmpty()) {
                                output.append(':');
                                output.append(' ');
                                output.append(location.getMessage());
                            }

                            output.append('\n');
                        }

                        location = location.getSecondary();
                    }

                    if (!abbreviate) {
                        location = warning.location.getSecondary();
                        StringBuilder sb = new StringBuilder(100);
                        sb.append("Also affects: ");
                        int begin = sb.length();
                        while (location != null) {
                            if (location.getMessage() == null
                                    || !location.getMessage().isEmpty()) {
                                if (sb.length() > begin) {
                                    sb.append(", ");
                                }

                                String path = mClient.getDisplayPath(warning.project,
                                        location.getFile());
                                sb.append(path);

                                Position start = location.getStart();
                                if (start != null) {
                                    int line = start.getLine();
                                    if (line >= 0) {
                                        sb.append(':');
                                        sb.append(Integer.toString(line + 1));
                                    }
                                }
                            }

                            location = location.getSecondary();
                        }
                        String wrapped = Main.wrap(sb.toString(), Main.MAX_LINE_WIDTH, "     "); //$NON-NLS-1$
                        output.append(wrapped);
                    }
                }
View Full Code Here

    }

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

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

TOP

Related Classes of com.android.tools.lint.detector.api.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.