langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
author jlahoda
Wed, 27 Aug 2014 07:44:00 +0200
changeset 26266 2d24bda701dc
parent 25874 83c19f00452c
child 29291 076c277565f7
permissions -rw-r--r--
8056061: Mark implementations of public interfaces with an annotation Summary: Adding @DefinedBy annotation to mark methods that implement public API methods; annotating the methods; adding a coding rules analyzer to enforce all such methods are annotated. Reviewed-by: jjg, mcimadamore, jfranck Contributed-by: jan.lahoda@oracle.com, jonathan.gibbons@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     1
/*
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     4
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    10
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    15
 * accompanied this code).
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    16
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    20
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    23
 * questions.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    24
 */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    25
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    26
package com.sun.tools.doclint;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    27
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    28
import java.io.IOException;
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    29
import java.io.StringWriter;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    30
import java.net.URI;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    31
import java.net.URISyntaxException;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    32
import java.util.Deque;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    33
import java.util.EnumSet;
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
    34
import java.util.HashMap;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    35
import java.util.HashSet;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    36
import java.util.LinkedList;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    37
import java.util.List;
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
    38
import java.util.Map;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    39
import java.util.Set;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    40
import java.util.regex.Matcher;
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    41
import java.util.regex.Pattern;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    42
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    43
import javax.lang.model.element.Element;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    44
import javax.lang.model.element.ElementKind;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    45
import javax.lang.model.element.ExecutableElement;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    46
import javax.lang.model.element.Name;
20255
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
    47
import javax.lang.model.element.VariableElement;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    48
import javax.lang.model.type.TypeKind;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    49
import javax.lang.model.type.TypeMirror;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    50
import javax.tools.Diagnostic.Kind;
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
    51
import javax.tools.JavaFileObject;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    52
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    53
import com.sun.source.doctree.AttributeTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    54
import com.sun.source.doctree.AuthorTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    55
import com.sun.source.doctree.DocCommentTree;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    56
import com.sun.source.doctree.DocRootTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    57
import com.sun.source.doctree.DocTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    58
import com.sun.source.doctree.EndElementTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    59
import com.sun.source.doctree.EntityTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    60
import com.sun.source.doctree.ErroneousTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    61
import com.sun.source.doctree.IdentifierTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    62
import com.sun.source.doctree.InheritDocTree;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    63
import com.sun.source.doctree.LinkTree;
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    64
import com.sun.source.doctree.LiteralTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    65
import com.sun.source.doctree.ParamTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    66
import com.sun.source.doctree.ReferenceTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    67
import com.sun.source.doctree.ReturnTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    68
import com.sun.source.doctree.SerialDataTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    69
import com.sun.source.doctree.SerialFieldTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    70
import com.sun.source.doctree.SinceTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    71
import com.sun.source.doctree.StartElementTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    72
import com.sun.source.doctree.TextTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    73
import com.sun.source.doctree.ThrowsTree;
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
    74
import com.sun.source.doctree.UnknownBlockTagTree;
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
    75
import com.sun.source.doctree.UnknownInlineTagTree;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    76
import com.sun.source.doctree.ValueTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    77
import com.sun.source.doctree.VersionTree;
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22153
diff changeset
    78
import com.sun.source.tree.Tree;
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
    79
import com.sun.source.util.DocTreePath;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
    80
import com.sun.source.util.DocTreePathScanner;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    81
import com.sun.source.util.TreePath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    82
import com.sun.tools.doclint.HtmlTag.AttrKind;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    83
import com.sun.tools.javac.tree.DocPretty;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    84
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    85
import com.sun.tools.javac.util.DefinedBy.Api;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
    86
import com.sun.tools.javac.util.StringUtils;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    87
import static com.sun.tools.doclint.Messages.Group.*;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    88
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    89
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    90
/**
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    91
 * Validate a doc comment.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    92
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    93
 * <p><b>This is NOT part of any supported API.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    94
 * If you write code that depends on this, you do so at your own
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    95
 * risk.  This code and its internal interfaces are subject to change
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    96
 * or deletion without notice.</b></p>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    97
 */
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
    98
public class Checker extends DocTreePathScanner<Void, Void> {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    99
    final Env env;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   100
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   101
    Set<Element> foundParams = new HashSet<>();
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   102
    Set<TypeMirror> foundThrows = new HashSet<>();
20254
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   103
    Map<Element, Set<String>> foundAnchors = new HashMap<>();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   104
    boolean foundInheritDoc = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   105
    boolean foundReturn = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   106
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 15366
diff changeset
   107
    public enum Flag {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   108
        TABLE_HAS_CAPTION,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   109
        HAS_ELEMENT,
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   110
        HAS_INLINE_TAG,
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   111
        HAS_TEXT,
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   112
        REPORTED_BAD_INLINE
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   113
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   114
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   115
    static class TagStackItem {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   116
        final DocTree tree; // typically, but not always, StartElementTree
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   117
        final HtmlTag tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   118
        final Set<HtmlTag.Attr> attrs;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   119
        final Set<Flag> flags;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   120
        TagStackItem(DocTree tree, HtmlTag tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   121
            this.tree = tree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   122
            this.tag = tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   123
            attrs = EnumSet.noneOf(HtmlTag.Attr.class);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   124
            flags = EnumSet.noneOf(Flag.class);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   125
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   126
        @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   127
        public String toString() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   128
            return String.valueOf(tag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   129
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   130
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   131
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   132
    private Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   133
    private HtmlTag currHeaderTag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   134
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   135
    private final int implicitHeaderLevel;
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   136
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   137
    // <editor-fold defaultstate="collapsed" desc="Top level">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   138
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   139
    Checker(Env env) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   140
        env.getClass();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   141
        this.env = env;
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   142
        tagStack = new LinkedList<>();
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   143
        implicitHeaderLevel = env.implicitHeaderLevel;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   144
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   145
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   146
    public Void scan(DocCommentTree tree, TreePath p) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   147
        env.setCurrent(p, tree);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   148
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   149
        boolean isOverridingMethod = !env.currOverriddenMethods.isEmpty();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   150
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22153
diff changeset
   151
        if (p.getLeaf().getKind() == Tree.Kind.PACKAGE) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22153
diff changeset
   152
            // If p points to a package, the implied declaration is the
19123
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   153
            // package declaration (if any) for the compilation unit.
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   154
            // Handle this case specially, because doc comments are only
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   155
            // expected in package-info files.
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   156
            JavaFileObject fo = p.getCompilationUnit().getSourceFile();
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   157
            boolean isPkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE);
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   158
            if (tree == null) {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   159
                if (isPkgInfo)
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   160
                    reportMissing("dc.missing.comment");
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   161
                return null;
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   162
            } else {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   163
                if (!isPkgInfo)
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   164
                    reportReference("dc.unexpected.comment");
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   165
            }
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   166
        } else {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   167
            if (tree == null) {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   168
                if (!isSynthetic() && !isOverridingMethod)
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   169
                    reportMissing("dc.missing.comment");
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   170
                return null;
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   171
            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   172
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   173
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   174
        tagStack.clear();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   175
        currHeaderTag = null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   176
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   177
        foundParams.clear();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   178
        foundThrows.clear();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   179
        foundInheritDoc = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   180
        foundReturn = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   181
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   182
        scan(new DocTreePath(p, tree), null);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   183
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   184
        if (!isOverridingMethod) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   185
            switch (env.currElement.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   186
                case METHOD:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   187
                case CONSTRUCTOR: {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   188
                    ExecutableElement ee = (ExecutableElement) env.currElement;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   189
                    checkParamsDocumented(ee.getTypeParameters());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   190
                    checkParamsDocumented(ee.getParameters());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   191
                    switch (ee.getReturnType().getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   192
                        case VOID:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   193
                        case NONE:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   194
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   195
                        default:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   196
                            if (!foundReturn
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   197
                                    && !foundInheritDoc
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   198
                                    && !env.types.isSameType(ee.getReturnType(), env.java_lang_Void)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   199
                                reportMissing("dc.missing.return");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   200
                            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   201
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   202
                    checkThrowsDocumented(ee.getThrownTypes());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   203
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   204
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   205
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   206
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   207
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   208
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   209
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   210
    private void reportMissing(String code, Object... args) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   211
        env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   212
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   213
19123
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   214
    private void reportReference(String code, Object... args) {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   215
        env.messages.report(REFERENCE, Kind.WARNING, env.currPath.getLeaf(), code, args);
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   216
    }
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   217
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   218
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   219
    public Void visitDocComment(DocCommentTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   220
        super.visitDocComment(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   221
        for (TagStackItem tsi: tagStack) {
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   222
            warnIfEmpty(tsi, null);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   223
            if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   224
                    && tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   225
                StartElementTree t = (StartElementTree) tsi.tree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   226
                env.messages.error(HTML, t, "dc.tag.not.closed", t.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   227
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   228
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   229
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   230
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   231
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   232
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   233
    // <editor-fold defaultstate="collapsed" desc="Text and entities.">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   234
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   235
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   236
    public Void visitText(TextTree tree, Void ignore) {
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   237
        if (hasNonWhitespace(tree)) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   238
            checkAllowsText(tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   239
            markEnclosingTag(Flag.HAS_TEXT);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   240
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   241
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   242
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   243
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   244
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   245
    public Void visitEntity(EntityTree tree, Void ignore) {
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   246
        checkAllowsText(tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   247
        markEnclosingTag(Flag.HAS_TEXT);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   248
        String name = tree.getName().toString();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   249
        if (name.startsWith("#")) {
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
   250
            int v = StringUtils.toLowerCase(name).startsWith("#x")
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   251
                    ? Integer.parseInt(name.substring(2), 16)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   252
                    : Integer.parseInt(name.substring(1), 10);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   253
            if (!Entity.isValid(v)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   254
                env.messages.error(HTML, tree, "dc.entity.invalid", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   255
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   256
        } else if (!Entity.isValid(name)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   257
            env.messages.error(HTML, tree, "dc.entity.invalid", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   258
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   259
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   260
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   261
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   262
    void checkAllowsText(DocTree tree) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   263
        TagStackItem top = tagStack.peek();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   264
        if (top != null
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   265
                && top.tree.getKind() == DocTree.Kind.START_ELEMENT
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   266
                && !top.tag.acceptsText()) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   267
            if (top.flags.add(Flag.REPORTED_BAD_INLINE)) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   268
                env.messages.error(HTML, tree, "dc.text.not.allowed",
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   269
                        ((StartElementTree) top.tree).getName());
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   270
            }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   271
        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   272
    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   273
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   274
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   275
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   276
    // <editor-fold defaultstate="collapsed" desc="HTML elements">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   277
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   278
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   279
    public Void visitStartElement(StartElementTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   280
        final Name treeName = tree.getName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   281
        final HtmlTag t = HtmlTag.get(treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   282
        if (t == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   283
            env.messages.error(HTML, tree, "dc.tag.unknown", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   284
        } else {
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   285
            boolean done = false;
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   286
            for (TagStackItem tsi: tagStack) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   287
                if (tsi.tag.accepts(t)) {
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   288
                    while (tagStack.peek() != tsi) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   289
                        warnIfEmpty(tagStack.peek(), null);
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   290
                        tagStack.pop();
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   291
                    }
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   292
                    done = true;
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   293
                    break;
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   294
                } else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) {
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   295
                    done = true;
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   296
                    break;
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   297
                }
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   298
            }
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   299
            if (!done && HtmlTag.BODY.accepts(t)) {
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   300
                while (!tagStack.isEmpty()) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   301
                    warnIfEmpty(tagStack.peek(), null);
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   302
                    tagStack.pop();
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   303
                }
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   304
            }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   305
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   306
            markEnclosingTag(Flag.HAS_ELEMENT);
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   307
            checkStructure(tree, t);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   308
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   309
            // tag specific checks
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   310
            switch (t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   311
                // check for out of sequence headers, such as <h1>...</h1>  <h3>...</h3>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   312
                case H1: case H2: case H3: case H4: case H5: case H6:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   313
                    checkHeader(tree, t);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   314
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   315
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   316
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   317
            if (t.flags.contains(HtmlTag.Flag.NO_NEST)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   318
                for (TagStackItem i: tagStack) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   319
                    if (t == i.tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   320
                        env.messages.warning(HTML, tree, "dc.tag.nested.not.allowed", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   321
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   322
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   323
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   324
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   325
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   326
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   327
        // check for self closing tags, such as <a id="name"/>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   328
        if (tree.isSelfClosing()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   329
            env.messages.error(HTML, tree, "dc.tag.self.closing", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   330
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   331
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   332
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   333
            TagStackItem parent = tagStack.peek();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   334
            TagStackItem top = new TagStackItem(tree, t);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   335
            tagStack.push(top);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   336
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   337
            super.visitStartElement(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   338
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   339
            // handle attributes that may or may not have been found in start element
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   340
            if (t != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   341
                switch (t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   342
                    case CAPTION:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   343
                        if (parent != null && parent.tag == HtmlTag.TABLE)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   344
                            parent.flags.add(Flag.TABLE_HAS_CAPTION);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   345
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   346
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   347
                    case IMG:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   348
                        if (!top.attrs.contains(HtmlTag.Attr.ALT))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   349
                            env.messages.error(ACCESSIBILITY, tree, "dc.no.alt.attr.for.image");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   350
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   351
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   352
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   353
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   354
            return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   355
        } finally {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   356
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   357
            if (t == null || t.endKind == HtmlTag.EndKind.NONE)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   358
                tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   359
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   360
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   361
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   362
    private void checkStructure(StartElementTree tree, HtmlTag t) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   363
        Name treeName = tree.getName();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   364
        TagStackItem top = tagStack.peek();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   365
        switch (t.blockType) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   366
            case BLOCK:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   367
                if (top == null || top.tag.accepts(t))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   368
                    return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   369
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   370
                switch (top.tree.getKind()) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   371
                    case START_ELEMENT: {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   372
                        if (top.tag.blockType == HtmlTag.BlockType.INLINE) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   373
                            Name name = ((StartElementTree) top.tree).getName();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   374
                            env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.element",
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   375
                                    treeName, name);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   376
                            return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   377
                        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   378
                    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   379
                    break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   380
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   381
                    case LINK:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   382
                    case LINK_PLAIN: {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   383
                        String name = top.tree.getKind().tagName;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   384
                        env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.tag",
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   385
                                treeName, name);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   386
                        return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   387
                    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   388
                }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   389
                break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   390
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   391
            case INLINE:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   392
                if (top == null || top.tag.accepts(t))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   393
                    return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   394
                break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   395
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   396
            case LIST_ITEM:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   397
            case TABLE_ITEM:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   398
                if (top != null) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   399
                    // reset this flag so subsequent bad inline content gets reported
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   400
                    top.flags.remove(Flag.REPORTED_BAD_INLINE);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   401
                    if (top.tag.accepts(t))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   402
                        return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   403
                }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   404
                break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   405
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   406
            case OTHER:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   407
                env.messages.error(HTML, tree, "dc.tag.not.allowed", treeName);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   408
                return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   409
        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   410
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   411
        env.messages.error(HTML, tree, "dc.tag.not.allowed.here", treeName);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   412
    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   413
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   414
    private void checkHeader(StartElementTree tree, HtmlTag tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   415
        // verify the new tag
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   416
        if (getHeaderLevel(tag) > getHeaderLevel(currHeaderTag) + 1) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   417
            if (currHeaderTag == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   418
                env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.1", tag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   419
            } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   420
                env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.2",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   421
                    tag, currHeaderTag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   422
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   423
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   424
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   425
        currHeaderTag = tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   426
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   427
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   428
    private int getHeaderLevel(HtmlTag tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   429
        if (tag == null)
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   430
            return implicitHeaderLevel;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   431
        switch (tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   432
            case H1: return 1;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   433
            case H2: return 2;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   434
            case H3: return 3;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   435
            case H4: return 4;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   436
            case H5: return 5;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   437
            case H6: return 6;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   438
            default: throw new IllegalArgumentException();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   439
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   440
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   441
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   442
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   443
    public Void visitEndElement(EndElementTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   444
        final Name treeName = tree.getName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   445
        final HtmlTag t = HtmlTag.get(treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   446
        if (t == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   447
            env.messages.error(HTML, tree, "dc.tag.unknown", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   448
        } else if (t.endKind == HtmlTag.EndKind.NONE) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   449
            env.messages.error(HTML, tree, "dc.tag.end.not.permitted", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   450
        } else {
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   451
            boolean done = false;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   452
            while (!tagStack.isEmpty()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   453
                TagStackItem top = tagStack.peek();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   454
                if (t == top.tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   455
                    switch (t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   456
                        case TABLE:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   457
                            if (!top.attrs.contains(HtmlTag.Attr.SUMMARY)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   458
                                    && !top.flags.contains(Flag.TABLE_HAS_CAPTION)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   459
                                env.messages.error(ACCESSIBILITY, tree,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   460
                                        "dc.no.summary.or.caption.for.table");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   461
                            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   462
                    }
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   463
                    warnIfEmpty(top, tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   464
                    tagStack.pop();
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   465
                    done = true;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   466
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   467
                } else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   468
                    tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   469
                } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   470
                    boolean found = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   471
                    for (TagStackItem si: tagStack) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   472
                        if (si.tag == t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   473
                            found = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   474
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   475
                        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   476
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   477
                    if (found && top.tree.getKind() == DocTree.Kind.START_ELEMENT) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   478
                        env.messages.error(HTML, top.tree, "dc.tag.start.unmatched",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   479
                                ((StartElementTree) top.tree).getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   480
                        tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   481
                    } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   482
                        env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   483
                        done = true;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   484
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   485
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   486
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   487
            }
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   488
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   489
            if (!done && tagStack.isEmpty()) {
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   490
                env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   491
            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   492
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   493
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   494
        return super.visitEndElement(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   495
    }
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   496
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   497
    void warnIfEmpty(TagStackItem tsi, DocTree endTree) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   498
        if (tsi.tag != null && tsi.tree instanceof StartElementTree) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   499
            if (tsi.tag.flags.contains(HtmlTag.Flag.EXPECT_CONTENT)
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   500
                    && !tsi.flags.contains(Flag.HAS_TEXT)
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   501
                    && !tsi.flags.contains(Flag.HAS_ELEMENT)
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   502
                    && !tsi.flags.contains(Flag.HAS_INLINE_TAG)) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   503
                DocTree tree = (endTree != null) ? endTree : tsi.tree;
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   504
                Name treeName = ((StartElementTree) tsi.tree).getName();
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   505
                env.messages.warning(HTML, tree, "dc.tag.empty", treeName);
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   506
            }
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   507
        }
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   508
    }
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   509
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   510
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   511
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   512
    // <editor-fold defaultstate="collapsed" desc="HTML attributes">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   513
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   514
    @Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough")
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   515
    public Void visitAttribute(AttributeTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   516
        HtmlTag currTag = tagStack.peek().tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   517
        if (currTag != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   518
            Name name = tree.getName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   519
            HtmlTag.Attr attr = currTag.getAttr(name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   520
            if (attr != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   521
                boolean first = tagStack.peek().attrs.add(attr);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   522
                if (!first)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   523
                    env.messages.error(HTML, tree, "dc.attr.repeated", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   524
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   525
            AttrKind k = currTag.getAttrKind(name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   526
            switch (k) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   527
                case OK:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   528
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   529
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   530
                case INVALID:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   531
                    env.messages.error(HTML, tree, "dc.attr.unknown", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   532
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   533
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   534
                case OBSOLETE:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   535
                    env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   536
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   537
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   538
                case USE_CSS:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   539
                    env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   540
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   541
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   542
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   543
            if (attr != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   544
                switch (attr) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   545
                    case NAME:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   546
                        if (currTag != HtmlTag.A) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   547
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   548
                        }
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   549
                        // fallthrough
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   550
                    case ID:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   551
                        String value = getAttrValue(tree);
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   552
                        if (value == null) {
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   553
                            env.messages.error(HTML, tree, "dc.anchor.value.missing");
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   554
                        } else {
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   555
                            if (!validName.matcher(value).matches()) {
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   556
                                env.messages.error(HTML, tree, "dc.invalid.anchor", value);
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   557
                            }
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   558
                            if (!checkAnchor(value)) {
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   559
                                env.messages.error(HTML, tree, "dc.anchor.already.defined", value);
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   560
                            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   561
                        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   562
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   563
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   564
                    case HREF:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   565
                        if (currTag == HtmlTag.A) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   566
                            String v = getAttrValue(tree);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   567
                            if (v == null || v.isEmpty()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   568
                                env.messages.error(HTML, tree, "dc.attr.lacks.value");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   569
                            } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   570
                                Matcher m = docRoot.matcher(v);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   571
                                if (m.matches()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   572
                                    String rest = m.group(2);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   573
                                    if (!rest.isEmpty())
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   574
                                        checkURI(tree, rest);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   575
                                } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   576
                                    checkURI(tree, v);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   577
                                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   578
                            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   579
                        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   580
                        break;
18001
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   581
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   582
                    case VALUE:
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   583
                        if (currTag == HtmlTag.LI) {
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   584
                            String v = getAttrValue(tree);
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   585
                            if (v == null || v.isEmpty()) {
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   586
                                env.messages.error(HTML, tree, "dc.attr.lacks.value");
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   587
                            } else if (!validNumber.matcher(v).matches()) {
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   588
                                env.messages.error(HTML, tree, "dc.attr.not.number");
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   589
                            }
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   590
                        }
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   591
                        break;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   592
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   593
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   594
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   595
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   596
        // TODO: basic check on value
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   597
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   598
        return super.visitAttribute(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   599
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   600
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   601
    private boolean checkAnchor(String name) {
20254
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   602
        Element e = getEnclosingPackageOrClass(env.currElement);
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   603
        if (e == null)
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   604
            return true;
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   605
        Set<String> set = foundAnchors.get(e);
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   606
        if (set == null)
20254
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   607
            foundAnchors.put(e, set = new HashSet<>());
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   608
        return set.add(name);
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   609
    }
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   610
20254
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   611
    private Element getEnclosingPackageOrClass(Element e) {
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   612
        while (e != null) {
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   613
            switch (e.getKind()) {
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   614
                case CLASS:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   615
                case ENUM:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   616
                case INTERFACE:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   617
                case PACKAGE:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   618
                    return e;
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   619
                default:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   620
                    e = e.getEnclosingElement();
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   621
            }
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   622
        }
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   623
        return e;
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   624
    }
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   625
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   626
    // http://www.w3.org/TR/html401/types.html#type-name
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   627
    private static final Pattern validName = Pattern.compile("[A-Za-z][A-Za-z0-9-_:.]*");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   628
18001
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   629
    private static final Pattern validNumber = Pattern.compile("-?[0-9]+");
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   630
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   631
    // pattern to remove leading {@docRoot}/?
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   632
    private static final Pattern docRoot = Pattern.compile("(?i)(\\{@docRoot *\\}/?)?(.*)");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   633
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   634
    private String getAttrValue(AttributeTree tree) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   635
        if (tree.getValue() == null)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   636
            return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   637
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   638
        StringWriter sw = new StringWriter();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   639
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   640
            new DocPretty(sw).print(tree.getValue());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   641
        } catch (IOException e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   642
            // cannot happen
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   643
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   644
        // ignore potential use of entities for now
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   645
        return sw.toString();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   646
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   647
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   648
    private void checkURI(AttributeTree tree, String uri) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   649
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   650
            URI u = new URI(uri);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   651
        } catch (URISyntaxException e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   652
            env.messages.error(HTML, tree, "dc.invalid.uri", uri);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   653
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   654
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   655
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   656
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   657
    // <editor-fold defaultstate="collapsed" desc="javadoc tags">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   658
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   659
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   660
    public Void visitAuthor(AuthorTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   661
        warnIfEmpty(tree, tree.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   662
        return super.visitAuthor(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   663
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   664
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   665
    @Override @DefinedBy(Api.COMPILER_TREE)
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   666
    public Void visitDocRoot(DocRootTree tree, Void ignore) {
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   667
        markEnclosingTag(Flag.HAS_INLINE_TAG);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   668
        return super.visitDocRoot(tree, ignore);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   669
    }
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   670
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   671
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   672
    public Void visitInheritDoc(InheritDocTree tree, Void ignore) {
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   673
        markEnclosingTag(Flag.HAS_INLINE_TAG);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   674
        // TODO: verify on overridden method
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   675
        foundInheritDoc = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   676
        return super.visitInheritDoc(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   677
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   678
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   679
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   680
    public Void visitLink(LinkTree tree, Void ignore) {
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   681
        markEnclosingTag(Flag.HAS_INLINE_TAG);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   682
        // simulate inline context on tag stack
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   683
        HtmlTag t = (tree.getKind() == DocTree.Kind.LINK)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   684
                ? HtmlTag.CODE : HtmlTag.SPAN;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   685
        tagStack.push(new TagStackItem(tree, t));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   686
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   687
            return super.visitLink(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   688
        } finally {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   689
            tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   690
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   691
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   692
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   693
    @Override @DefinedBy(Api.COMPILER_TREE)
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   694
    public Void visitLiteral(LiteralTree tree, Void ignore) {
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   695
        markEnclosingTag(Flag.HAS_INLINE_TAG);
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   696
        if (tree.getKind() == DocTree.Kind.CODE) {
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   697
            for (TagStackItem tsi: tagStack) {
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   698
                if (tsi.tag == HtmlTag.CODE) {
15366
545307ec740c 8006228: Doclint doesn't detect <code> {@code nested inline} </code>
jjg
parents: 15363
diff changeset
   699
                    env.messages.warning(HTML, tree, "dc.tag.code.within.code");
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   700
                    break;
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   701
                }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   702
            }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   703
        }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   704
        return super.visitLiteral(tree, ignore);
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   705
    }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   706
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   707
    @Override @DefinedBy(Api.COMPILER_TREE)
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   708
    @SuppressWarnings("fallthrough")
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   709
    public Void visitParam(ParamTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   710
        boolean typaram = tree.isTypeParameter();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   711
        IdentifierTree nameTree = tree.getName();
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   712
        Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   713
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   714
        if (paramElement == null) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   715
            switch (env.currElement.getKind()) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   716
                case CLASS: case INTERFACE: {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   717
                    if (!typaram) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   718
                        env.messages.error(REFERENCE, tree, "dc.invalid.param");
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   719
                        break;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   720
                    }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   721
                }
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   722
                case METHOD: case CONSTRUCTOR: {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   723
                    env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   724
                    break;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   725
                }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   726
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   727
                default:
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   728
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   729
                    break;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   730
            }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   731
        } else {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   732
            foundParams.add(paramElement);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   733
        }
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   734
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   735
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   736
        return super.visitParam(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   737
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   738
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   739
    private void checkParamsDocumented(List<? extends Element> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   740
        if (foundInheritDoc)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   741
            return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   742
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   743
        for (Element e: list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   744
            if (!foundParams.contains(e)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   745
                CharSequence paramName = (e.getKind() == ElementKind.TYPE_PARAMETER)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   746
                        ? "<" + e.getSimpleName() + ">"
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   747
                        : e.getSimpleName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   748
                reportMissing("dc.missing.param", paramName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   749
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   750
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   751
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   752
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   753
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   754
    public Void visitReference(ReferenceTree tree, Void ignore) {
20256
9154c5cc0d9f 8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents: 20255
diff changeset
   755
        String sig = tree.getSignature();
9154c5cc0d9f 8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents: 20255
diff changeset
   756
        if (sig.contains("<") || sig.contains(">"))
9154c5cc0d9f 8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents: 20255
diff changeset
   757
            env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed");
9154c5cc0d9f 8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents: 20255
diff changeset
   758
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   759
        Element e = env.trees.getElement(getCurrentPath());
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   760
        if (e == null)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   761
            env.messages.error(REFERENCE, tree, "dc.ref.not.found");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   762
        return super.visitReference(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   763
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   764
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   765
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   766
    public Void visitReturn(ReturnTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   767
        Element e = env.trees.getElement(env.currPath);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   768
        if (e.getKind() != ElementKind.METHOD
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   769
                || ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   770
            env.messages.error(REFERENCE, tree, "dc.invalid.return");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   771
        foundReturn = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   772
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   773
        return super.visitReturn(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   774
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   775
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   776
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   777
    public Void visitSerialData(SerialDataTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   778
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   779
        return super.visitSerialData(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   780
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   781
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   782
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   783
    public Void visitSerialField(SerialFieldTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   784
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   785
        return super.visitSerialField(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   786
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   787
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   788
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   789
    public Void visitSince(SinceTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   790
        warnIfEmpty(tree, tree.getBody());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   791
        return super.visitSince(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   792
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   793
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   794
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   795
    public Void visitThrows(ThrowsTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   796
        ReferenceTree exName = tree.getExceptionName();
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   797
        Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   798
        if (ex == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   799
            env.messages.error(REFERENCE, tree, "dc.ref.not.found");
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   800
        } else if (isThrowable(ex.asType())) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   801
            switch (env.currElement.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   802
                case CONSTRUCTOR:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   803
                case METHOD:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   804
                    if (isCheckedException(ex.asType())) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   805
                        ExecutableElement ee = (ExecutableElement) env.currElement;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   806
                        checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   807
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   808
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   809
                default:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   810
                    env.messages.error(REFERENCE, tree, "dc.invalid.throws");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   811
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   812
        } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   813
            env.messages.error(REFERENCE, tree, "dc.invalid.throws");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   814
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   815
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   816
        return scan(tree.getDescription(), ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   817
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   818
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   819
    private boolean isThrowable(TypeMirror tm) {
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   820
        switch (tm.getKind()) {
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   821
            case DECLARED:
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   822
            case TYPEVAR:
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   823
                return env.types.isAssignable(tm, env.java_lang_Throwable);
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   824
        }
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   825
        return false;
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   826
    }
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   827
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   828
    private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   829
        boolean found = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   830
        for (TypeMirror tl : list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   831
            if (env.types.isAssignable(t, tl)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   832
                foundThrows.add(tl);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   833
                found = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   834
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   835
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   836
        if (!found)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   837
            env.messages.error(REFERENCE, tree, "dc.exception.not.thrown", t);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   838
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   839
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   840
    private void checkThrowsDocumented(List<? extends TypeMirror> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   841
        if (foundInheritDoc)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   842
            return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   843
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   844
        for (TypeMirror tl: list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   845
            if (isCheckedException(tl) && !foundThrows.contains(tl))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   846
                reportMissing("dc.missing.throws", tl);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   847
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   848
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   849
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   850
    @Override @DefinedBy(Api.COMPILER_TREE)
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   851
    public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void ignore) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   852
        checkUnknownTag(tree, tree.getTagName());
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   853
        return super.visitUnknownBlockTag(tree, ignore);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   854
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   855
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   856
    @Override @DefinedBy(Api.COMPILER_TREE)
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   857
    public Void visitUnknownInlineTag(UnknownInlineTagTree tree, Void ignore) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   858
        checkUnknownTag(tree, tree.getTagName());
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   859
        return super.visitUnknownInlineTag(tree, ignore);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   860
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   861
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   862
    private void checkUnknownTag(DocTree tree, String tagName) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   863
        if (env.customTags != null && !env.customTags.contains(tagName))
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   864
            env.messages.error(SYNTAX, tree, "dc.tag.unknown", tagName);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   865
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
   866
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   867
    @Override @DefinedBy(Api.COMPILER_TREE)
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   868
    public Void visitValue(ValueTree tree, Void ignore) {
20255
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   869
        ReferenceTree ref = tree.getReference();
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   870
        if (ref == null || ref.getSignature().isEmpty()) {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   871
            if (!isConstant(env.currElement))
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   872
                env.messages.error(REFERENCE, tree, "dc.value.not.allowed.here");
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   873
        } else {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   874
            Element e = env.trees.getElement(new DocTreePath(getCurrentPath(), ref));
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   875
            if (!isConstant(e))
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   876
                env.messages.error(REFERENCE, tree, "dc.value.not.a.constant");
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   877
        }
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   878
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   879
        markEnclosingTag(Flag.HAS_INLINE_TAG);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   880
        return super.visitValue(tree, ignore);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   881
    }
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   882
20255
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   883
    private boolean isConstant(Element e) {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   884
        if (e == null)
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   885
            return false;
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   886
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   887
        switch (e.getKind()) {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   888
            case FIELD:
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   889
                Object value = ((VariableElement) e).getConstantValue();
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   890
                return (value != null); // can't distinguish "not a constant" from "constant is null"
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   891
            default:
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   892
                return false;
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   893
        }
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   894
    }
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
   895
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   896
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   897
    public Void visitVersion(VersionTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   898
        warnIfEmpty(tree, tree.getBody());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   899
        return super.visitVersion(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   900
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   901
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   902
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   903
    public Void visitErroneous(ErroneousTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   904
        env.messages.error(SYNTAX, tree, null, tree.getDiagnostic().getMessage(null));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   905
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   906
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   907
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   908
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   909
    // <editor-fold defaultstate="collapsed" desc="Utility methods">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   910
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   911
    private boolean isCheckedException(TypeMirror t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   912
        return !(env.types.isAssignable(t, env.java_lang_Error)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   913
                || env.types.isAssignable(t, env.java_lang_RuntimeException));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   914
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   915
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   916
    private boolean isSynthetic() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   917
        switch (env.currElement.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   918
            case CONSTRUCTOR:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   919
                // A synthetic default constructor has the same pos as the
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   920
                // enclosing class
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   921
                TreePath p = env.currPath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   922
                return env.getPos(p) == env.getPos(p.getParentPath());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   923
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   924
        return false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   925
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   926
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   927
    void markEnclosingTag(Flag flag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   928
        TagStackItem top = tagStack.peek();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   929
        if (top != null)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   930
            top.flags.add(flag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   931
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   932
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   933
    String toString(TreePath p) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   934
        StringBuilder sb = new StringBuilder("TreePath[");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   935
        toString(p, sb);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   936
        sb.append("]");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   937
        return sb.toString();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   938
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   939
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   940
    void toString(TreePath p, StringBuilder sb) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   941
        TreePath parent = p.getParentPath();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   942
        if (parent != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   943
            toString(parent, sb);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   944
            sb.append(",");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   945
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   946
       sb.append(p.getLeaf().getKind()).append(":").append(env.getPos(p)).append(":S").append(env.getStartPos(p));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   947
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   948
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   949
    void warnIfEmpty(DocTree tree, List<? extends DocTree> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   950
        for (DocTree d: list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   951
            switch (d.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   952
                case TEXT:
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   953
                    if (hasNonWhitespace((TextTree) d))
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   954
                        return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   955
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   956
                default:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   957
                    return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   958
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   959
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   960
        env.messages.warning(SYNTAX, tree, "dc.empty", tree.getKind().tagName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   961
    }
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   962
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   963
    boolean hasNonWhitespace(TextTree tree) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   964
        String s = tree.getBody();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   965
        for (int i = 0; i < s.length(); i++) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   966
            if (!Character.isWhitespace(s.charAt(i)))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   967
                return true;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   968
        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   969
        return false;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   970
    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   971
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   972
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   973
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   974
}