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

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


                if (warning.file != null) {
                    assert warning.location.getFile() == warning.file;
                }

                Location location = warning.location;
                if (location != null) {
                    mWriter.write(">\n"); //$NON-NLS-1$
                    while (location != null) {
                        indent(mWriter, 2);
                        mWriter.write("<location"); //$NON-NLS-1$
                        String path = mClient.getDisplayPath(warning.project, location.getFile());
                        writeAttribute(mWriter, 3, "file", path)//$NON-NLS-1$
                        Position start = location.getStart();
                        if (start != null) {
                            int line = start.getLine();
                            int column = start.getColumn();
                            if (line >= 0) {
                                // +1: Line numbers internally are 0-based, report should be
                                // 1-based.
                                writeAttribute(mWriter, 3, "line",         //$NON-NLS-1$
                                        Integer.toString(line + 1));
                                if (column >= 0) {
                                    writeAttribute(mWriter, 3, "column",   //$NON-NLS-1$
                                            Integer.toString(column + 1));
                                }
                            }
                        }

                        mWriter.write("/>\n"); //$NON-NLS-1$
                        location = location.getSecondary();
                    }
                    indent(mWriter, 1);
                    mWriter.write("</issue>\n"); //$NON-NLS-1$
                } else {
                    mWriter.write('\n');
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

        if (!CONTAINERS.contains(parentTag)) {
            return;
        }

        boolean hasId = element.hasAttributeNS(ANDROID_URI, ATTR_ID);
        Location location = context.getLocation(element);
        String tag = element.getTagName();
        String format;
        if (hasId) {
            format = "This %1$s layout or its %2$s parent is possibly useless";
        } else {
View Full Code Here

        if (element.hasAttributeNS(ANDROID_URI, ATTR_BACKGROUND)) {
            return;
        }

        Location location = context.getLocation(element);
        String tag = element.getTagName();
        String message = String.format(
                "This %1$s view is useless (no children, no background, no id)", tag);
        context.client.report(context, USELESS_LEAF, location, message, null);
    }
View Full Code Here

                if (reportMissing) {
                    Set<String> difference = LintUtils.difference(defaultStrings, strings);
                    if (difference.size() > 0) {
                        List<String> sorted = new ArrayList<String>(difference);
                        Collections.sort(sorted);
                        Location location = getLocation(language, parentFolderToLanguage);
                        context.client.report(context, MISSING, location,
                            String.format("Locale %1$s is missing translations for: %2$s",
                                language, LintUtils.formatList(sorted, 4)), null);
                    }
                }

                if (reportExtra) {
                    Set<String> difference = LintUtils.difference(strings, defaultStrings);
                    if (difference.size() > 0) {
                        List<String> sorted = new ArrayList<String>(difference);
                        Collections.sort(sorted);
                        Location location = getLocation(language, parentFolderToLanguage);
                        context.client.report(context, EXTRA, location, String.format(
                              "Locale %1$s is translating names not found in default locale: %2$s",
                              language, LintUtils.formatList(sorted, 4)), null);
                    }
                }
View Full Code Here

            }
        }
    }

    private Location getLocation(String language, Map<File, String> parentFolderToLanguage) {
        Location location = null;
        for (Entry<File, String> e : parentFolderToLanguage.entrySet()) {
            if (e.getValue().equals(language)) {
                // Use the location of the parent folder for this language
                location = new Location(e.getKey(), null, null);
                break;
            }
        }
        return location;
    }
View Full Code Here

                    }
                }
                if (!haveUpperCase) {
                    String message = "Use '$' instead of '.' for inner classes " +
                            "(or use only lowercase letters in package names)";
                    Location location = context.getLocation(classNameNode);
                    context.report(INNERCLASS, element, location, message, null);
                }
            }

            // The internal name contains a $ which means it's an inner class.
View Full Code Here

                }

                String message = String.format(
                        "Class referenced in the manifest, %1$s, was not found in the " +
                                "project or the libraries", fqcn);
                Location location = handle.resolve();
                File parentFile = location.getFile().getParentFile();
                if (parentFile != null) {
                    String parent = parentFile.getName();
                    ResourceFolderType type = ResourceFolderType.getFolderType(parent);
                    if (type == LAYOUT) {
                        message = String.format(
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();
                    boolean omitted = false;
                    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');
                        } else {
                            omitted = true;
                        }

                        location = location.getSecondary();
                    }

                    if (!abbreviate && omitted) {
                        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

            context.client.report(
                    context,
                    // Must provide an issue since API guarantees that the issue parameter
                    // is valid
                    IssueRegistry.PARSER_ERROR,
                    new Location(context.file, null, null),
                    e.getCause() != null ? e.getCause().getLocalizedMessage() :
                        e.getLocalizedMessage(),
                    null);
        } catch (Throwable t) {
            context.client.log(t, null);
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.