src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
author hannesw
Thu, 22 Nov 2018 15:38:20 +0100
changeset 52664 15fc92f4ae9a
parent 52648 12956ca371c2
child 52871 c09bff7928e8
permissions -rw-r--r--
8200432: javadoc fails with ClassCastException on {@link byte[]} Reviewed-by: jjg, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     1
/*
43374
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
     2
 * Copyright (c) 2012, 2017, 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;
52648
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
    62
import com.sun.source.doctree.IndexTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    63
import com.sun.source.doctree.InheritDocTree;
52648
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
    64
import com.sun.source.doctree.InlineTagTree;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    65
import com.sun.source.doctree.LinkTree;
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    66
import com.sun.source.doctree.LiteralTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    67
import com.sun.source.doctree.ParamTree;
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
    68
import com.sun.source.doctree.ProvidesTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    69
import com.sun.source.doctree.ReferenceTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    70
import com.sun.source.doctree.ReturnTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    71
import com.sun.source.doctree.SerialDataTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    72
import com.sun.source.doctree.SerialFieldTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    73
import com.sun.source.doctree.SinceTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    74
import com.sun.source.doctree.StartElementTree;
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
    75
import com.sun.source.doctree.SummaryTree;
52648
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
    76
import com.sun.source.doctree.SystemPropertyTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    77
import com.sun.source.doctree.TextTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    78
import com.sun.source.doctree.ThrowsTree;
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
    79
import com.sun.source.doctree.UnknownBlockTagTree;
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
    80
import com.sun.source.doctree.UnknownInlineTagTree;
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
    81
import com.sun.source.doctree.UsesTree;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    82
import com.sun.source.doctree.ValueTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    83
import com.sun.source.doctree.VersionTree;
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22153
diff changeset
    84
import com.sun.source.tree.Tree;
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
    85
import com.sun.source.util.DocTreePath;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
    86
import com.sun.source.util.DocTreePathScanner;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    87
import com.sun.source.util.TreePath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    88
import com.sun.tools.doclint.HtmlTag.AttrKind;
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
    89
import com.sun.tools.javac.tree.DocPretty;
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 26266
diff changeset
    90
import com.sun.tools.javac.util.Assert;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    91
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    92
import com.sun.tools.javac.util.DefinedBy.Api;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
    93
import com.sun.tools.javac.util.StringUtils;
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
    94
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    95
import static com.sun.tools.doclint.Messages.Group.*;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    96
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    97
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    98
/**
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    99
 * Validate a doc comment.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   100
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   101
 * <p><b>This is NOT part of any supported API.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   102
 * If you write code that depends on this, you do so at your own
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   103
 * risk.  This code and its internal interfaces are subject to change
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   104
 * or deletion without notice.</b></p>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   105
 */
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   106
public class Checker extends DocTreePathScanner<Void, Void> {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   107
    final Env env;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   108
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   109
    Set<Element> foundParams = new HashSet<>();
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   110
    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
   111
    Map<Element, Set<String>> foundAnchors = new HashMap<>();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   112
    boolean foundInheritDoc = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   113
    boolean foundReturn = false;
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   114
    boolean hasNonWhitespaceText = false;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   115
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 15366
diff changeset
   116
    public enum Flag {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   117
        TABLE_HAS_CAPTION,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   118
        HAS_ELEMENT,
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   119
        HAS_HEADING,
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   120
        HAS_INLINE_TAG,
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   121
        HAS_TEXT,
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   122
        REPORTED_BAD_INLINE
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   123
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   124
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   125
    static class TagStackItem {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   126
        final DocTree tree; // typically, but not always, StartElementTree
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   127
        final HtmlTag tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   128
        final Set<HtmlTag.Attr> attrs;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   129
        final Set<Flag> flags;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   130
        TagStackItem(DocTree tree, HtmlTag tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   131
            this.tree = tree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   132
            this.tag = tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   133
            attrs = EnumSet.noneOf(HtmlTag.Attr.class);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   134
            flags = EnumSet.noneOf(Flag.class);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   135
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   136
        @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   137
        public String toString() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   138
            return String.valueOf(tag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   139
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   140
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   141
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   142
    private final Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   143
    private HtmlTag currHeaderTag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   144
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   145
    private final int implicitHeaderLevel;
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   146
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   147
    // <editor-fold defaultstate="collapsed" desc="Top level">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   148
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   149
    Checker(Env env) {
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 26266
diff changeset
   150
        this.env = Assert.checkNonNull(env);
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   151
        tagStack = new LinkedList<>();
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   152
        implicitHeaderLevel = env.implicitHeaderLevel;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   153
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   154
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   155
    public Void scan(DocCommentTree tree, TreePath p) {
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 29291
diff changeset
   156
        env.initTypes();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   157
        env.setCurrent(p, tree);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   158
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   159
        boolean isOverridingMethod = !env.currOverriddenMethods.isEmpty();
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   160
        JavaFileObject fo = p.getCompilationUnit().getSourceFile();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   161
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22153
diff changeset
   162
        if (p.getLeaf().getKind() == Tree.Kind.PACKAGE) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22153
diff changeset
   163
            // 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
   164
            // package declaration (if any) for the compilation unit.
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   165
            // 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
   166
            // expected in package-info files.
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   167
            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
   168
            if (tree == null) {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   169
                if (isPkgInfo)
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   170
                    reportMissing("dc.missing.comment");
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   171
                return null;
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   172
            } else {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   173
                if (!isPkgInfo)
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   174
                    reportReference("dc.unexpected.comment");
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   175
            }
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   176
        } else if (tree != null && fo.isNameCompatible("package", JavaFileObject.Kind.HTML)) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   177
            // a package.html file with a DocCommentTree
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   178
            if (tree.getFullBody().isEmpty()) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   179
                reportMissing("dc.missing.comment");
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   180
                return null;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 29957
diff changeset
   181
            }
19123
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   182
        } else {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   183
            if (tree == null) {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   184
                if (!isSynthetic() && !isOverridingMethod)
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   185
                    reportMissing("dc.missing.comment");
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   186
                return null;
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   187
            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   188
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   189
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   190
        tagStack.clear();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   191
        currHeaderTag = null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   192
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   193
        foundParams.clear();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   194
        foundThrows.clear();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   195
        foundInheritDoc = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   196
        foundReturn = false;
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   197
        hasNonWhitespaceText = false;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   198
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   199
        scan(new DocTreePath(p, tree), null);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   200
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   201
        if (!isOverridingMethod) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   202
            switch (env.currElement.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   203
                case METHOD:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   204
                case CONSTRUCTOR: {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   205
                    ExecutableElement ee = (ExecutableElement) env.currElement;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   206
                    checkParamsDocumented(ee.getTypeParameters());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   207
                    checkParamsDocumented(ee.getParameters());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   208
                    switch (ee.getReturnType().getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   209
                        case VOID:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   210
                        case NONE:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   211
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   212
                        default:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   213
                            if (!foundReturn
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   214
                                    && !foundInheritDoc
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   215
                                    && !env.types.isSameType(ee.getReturnType(), env.java_lang_Void)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   216
                                reportMissing("dc.missing.return");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   217
                            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   218
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   219
                    checkThrowsDocumented(ee.getThrownTypes());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   220
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   221
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   222
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   223
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   224
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   225
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   226
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   227
    private void reportMissing(String code, Object... args) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   228
        env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   229
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   230
19123
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   231
    private void reportReference(String code, Object... args) {
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
diff changeset
   232
        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
   233
    }
50733e28eaca 8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents: 19120
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 visitDocComment(DocCommentTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   237
        super.visitDocComment(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   238
        for (TagStackItem tsi: tagStack) {
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   239
            warnIfEmpty(tsi, null);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   240
            if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   241
                    && tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   242
                StartElementTree t = (StartElementTree) tsi.tree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   243
                env.messages.error(HTML, t, "dc.tag.not.closed", t.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   244
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   245
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   246
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   247
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   248
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   249
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   250
    // <editor-fold defaultstate="collapsed" desc="Text and entities.">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   251
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   252
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   253
    public Void visitText(TextTree tree, Void ignore) {
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   254
        hasNonWhitespaceText = hasNonWhitespace(tree);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   255
        if (hasNonWhitespaceText) {
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   256
            checkAllowsText(tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   257
            markEnclosingTag(Flag.HAS_TEXT);
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
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   262
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   263
    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
   264
        checkAllowsText(tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   265
        markEnclosingTag(Flag.HAS_TEXT);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   266
        String name = tree.getName().toString();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   267
        if (name.startsWith("#")) {
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 21500
diff changeset
   268
            int v = StringUtils.toLowerCase(name).startsWith("#x")
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   269
                    ? Integer.parseInt(name.substring(2), 16)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   270
                    : Integer.parseInt(name.substring(1), 10);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   271
            if (!Entity.isValid(v)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   272
                env.messages.error(HTML, tree, "dc.entity.invalid", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   273
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   274
        } else if (!Entity.isValid(name)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   275
            env.messages.error(HTML, tree, "dc.entity.invalid", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   276
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   277
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   278
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   279
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   280
    void checkAllowsText(DocTree tree) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   281
        TagStackItem top = tagStack.peek();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   282
        if (top != null
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   283
                && top.tree.getKind() == DocTree.Kind.START_ELEMENT
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   284
                && !top.tag.acceptsText()) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   285
            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
   286
                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
   287
                        ((StartElementTree) top.tree).getName());
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   288
            }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   289
        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   290
    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   291
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   292
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   293
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   294
    // <editor-fold defaultstate="collapsed" desc="HTML elements">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   295
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   296
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   297
    public Void visitStartElement(StartElementTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   298
        final Name treeName = tree.getName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   299
        final HtmlTag t = HtmlTag.get(treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   300
        if (t == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   301
            env.messages.error(HTML, tree, "dc.tag.unknown", treeName);
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   302
        } else if (t.allowedVersion != HtmlVersion.ALL && t.allowedVersion != env.htmlVersion) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   303
            env.messages.error(HTML, tree, "dc.tag.not.supported", treeName);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   304
        } else {
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   305
            boolean done = false;
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   306
            for (TagStackItem tsi: tagStack) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   307
                if (tsi.tag.accepts(t)) {
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   308
                    while (tagStack.peek() != tsi) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   309
                        warnIfEmpty(tagStack.peek(), null);
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   310
                        tagStack.pop();
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   311
                    }
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   312
                    done = true;
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   313
                    break;
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   314
                } else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) {
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   315
                    done = true;
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   316
                    break;
15707
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   317
                }
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   318
            }
7b2411328a5c 8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents: 15371
diff changeset
   319
            if (!done && HtmlTag.BODY.accepts(t)) {
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   320
                while (!tagStack.isEmpty()) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   321
                    warnIfEmpty(tagStack.peek(), null);
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   322
                    tagStack.pop();
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   323
                }
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   324
            }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   325
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   326
            markEnclosingTag(Flag.HAS_ELEMENT);
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   327
            checkStructure(tree, t);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   328
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   329
            // tag specific checks
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   330
            switch (t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   331
                // check for out of sequence headers, such as <h1>...</h1>  <h3>...</h3>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   332
                case H1: case H2: case H3: case H4: case H5: case H6:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   333
                    checkHeader(tree, t);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   334
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   335
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   336
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   337
            if (t.flags.contains(HtmlTag.Flag.NO_NEST)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   338
                for (TagStackItem i: tagStack) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   339
                    if (t == i.tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   340
                        env.messages.warning(HTML, tree, "dc.tag.nested.not.allowed", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   341
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   342
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   343
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   344
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   345
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   346
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   347
        // check for self closing tags, such as <a id="name"/>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   348
        if (tree.isSelfClosing()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   349
            env.messages.error(HTML, tree, "dc.tag.self.closing", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   350
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   351
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   352
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   353
            TagStackItem parent = tagStack.peek();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   354
            TagStackItem top = new TagStackItem(tree, t);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   355
            tagStack.push(top);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   356
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   357
            super.visitStartElement(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   358
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   359
            // handle attributes that may or may not have been found in start element
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   360
            if (t != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   361
                switch (t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   362
                    case CAPTION:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   363
                        if (parent != null && parent.tag == HtmlTag.TABLE)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   364
                            parent.flags.add(Flag.TABLE_HAS_CAPTION);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   365
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   366
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   367
                    case H1: case H2: case H3: case H4: case H5: case H6:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   368
                        if (parent != null && (parent.tag == HtmlTag.SECTION || parent.tag == HtmlTag.ARTICLE)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   369
                            parent.flags.add(Flag.HAS_HEADING);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   370
                        }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   371
                        break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   372
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   373
                    case IMG:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   374
                        if (!top.attrs.contains(HtmlTag.Attr.ALT))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   375
                            env.messages.error(ACCESSIBILITY, tree, "dc.no.alt.attr.for.image");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   376
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   377
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   378
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   379
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   380
            return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   381
        } finally {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   382
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   383
            if (t == null || t.endKind == HtmlTag.EndKind.NONE)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   384
                tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   385
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   386
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   387
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   388
    private void checkStructure(StartElementTree tree, HtmlTag t) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   389
        Name treeName = tree.getName();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   390
        TagStackItem top = tagStack.peek();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   391
        switch (t.blockType) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   392
            case BLOCK:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   393
                if (top == null || top.tag.accepts(t))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   394
                    return;
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
                switch (top.tree.getKind()) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   397
                    case START_ELEMENT: {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   398
                        if (top.tag.blockType == HtmlTag.BlockType.INLINE) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   399
                            Name name = ((StartElementTree) top.tree).getName();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   400
                            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
   401
                                    treeName, name);
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
                    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   405
                    break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   406
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   407
                    case LINK:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   408
                    case LINK_PLAIN: {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   409
                        String name = top.tree.getKind().tagName;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   410
                        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
   411
                                treeName, name);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   412
                        return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   413
                    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   414
                }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   415
                break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   416
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   417
            case INLINE:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   418
                if (top == null || top.tag.accepts(t))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   419
                    return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   420
                break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   421
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   422
            case LIST_ITEM:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   423
            case TABLE_ITEM:
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   424
                if (top != null) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   425
                    // 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
   426
                    top.flags.remove(Flag.REPORTED_BAD_INLINE);
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   427
                    if (top.tag.accepts(t))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   428
                        return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   429
                }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   430
                break;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   431
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   432
            case OTHER:
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   433
                switch (t) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   434
                    case SCRIPT:
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   435
                        // <script> may or may not be allowed, depending on --allow-script-in-comments
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   436
                        // but we allow it here, and rely on a separate scanner to detect all uses
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   437
                        // of JavaScript, including <script> tags, and use in attributes, etc.
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   438
                        break;
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   439
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   440
                    default:
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   441
                        env.messages.error(HTML, tree, "dc.tag.not.allowed", treeName);
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   442
                }
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   443
                return;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   444
        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   445
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   446
        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
   447
    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
   448
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   449
    private void checkHeader(StartElementTree tree, HtmlTag tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   450
        // verify the new tag
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   451
        if (getHeaderLevel(tag) > getHeaderLevel(currHeaderTag) + 1) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   452
            if (currHeaderTag == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   453
                env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.1", tag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   454
            } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   455
                env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.2",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   456
                    tag, currHeaderTag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   457
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   458
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   459
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   460
        currHeaderTag = tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   461
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   462
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   463
    private int getHeaderLevel(HtmlTag tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   464
        if (tag == null)
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 16562
diff changeset
   465
            return implicitHeaderLevel;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   466
        switch (tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   467
            case H1: return 1;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   468
            case H2: return 2;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   469
            case H3: return 3;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   470
            case H4: return 4;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   471
            case H5: return 5;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   472
            case H6: return 6;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   473
            default: throw new IllegalArgumentException();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   474
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   475
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   476
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   477
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   478
    public Void visitEndElement(EndElementTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   479
        final Name treeName = tree.getName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   480
        final HtmlTag t = HtmlTag.get(treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   481
        if (t == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   482
            env.messages.error(HTML, tree, "dc.tag.unknown", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   483
        } else if (t.endKind == HtmlTag.EndKind.NONE) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   484
            env.messages.error(HTML, tree, "dc.tag.end.not.permitted", treeName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   485
        } else {
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   486
            boolean done = false;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   487
            while (!tagStack.isEmpty()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   488
                TagStackItem top = tagStack.peek();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   489
                if (t == top.tag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   490
                    switch (t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   491
                        case TABLE:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   492
                            if (!top.attrs.contains(HtmlTag.Attr.SUMMARY)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   493
                                    && !top.flags.contains(Flag.TABLE_HAS_CAPTION)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   494
                                env.messages.error(ACCESSIBILITY, tree,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   495
                                        "dc.no.summary.or.caption.for.table");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   496
                            }
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   497
                            break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   498
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   499
                        case SECTION:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   500
                        case ARTICLE:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   501
                            if (env.htmlVersion == HtmlVersion.HTML5 && !top.flags.contains(Flag.HAS_HEADING)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   502
                                env.messages.error(HTML, tree, "dc.tag.requires.heading", treeName);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   503
                            }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   504
                            break;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   505
                    }
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   506
                    warnIfEmpty(top, tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   507
                    tagStack.pop();
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   508
                    done = true;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   509
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   510
                } else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   511
                    tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   512
                } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   513
                    boolean found = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   514
                    for (TagStackItem si: tagStack) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   515
                        if (si.tag == t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   516
                            found = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   517
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   518
                        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   519
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   520
                    if (found && top.tree.getKind() == DocTree.Kind.START_ELEMENT) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   521
                        env.messages.error(HTML, top.tree, "dc.tag.start.unmatched",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   522
                                ((StartElementTree) top.tree).getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   523
                        tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   524
                    } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   525
                        env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   526
                        done = true;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   527
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   528
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   529
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   530
            }
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   531
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   532
            if (!done && tagStack.isEmpty()) {
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   533
                env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   534
            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   535
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   536
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   537
        return super.visitEndElement(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   538
    }
21017
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   539
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   540
    void warnIfEmpty(TagStackItem tsi, DocTree endTree) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   541
        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
   542
            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
   543
                    && !tsi.flags.contains(Flag.HAS_TEXT)
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   544
                    && !tsi.flags.contains(Flag.HAS_ELEMENT)
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   545
                    && !tsi.flags.contains(Flag.HAS_INLINE_TAG)) {
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   546
                DocTree tree = (endTree != null) ? endTree : tsi.tree;
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   547
                Name treeName = ((StartElementTree) tsi.tree).getName();
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   548
                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
   549
            }
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   550
        }
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   551
    }
f61558e07e14 8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents: 20256
diff changeset
   552
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   553
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   554
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   555
    // <editor-fold defaultstate="collapsed" desc="HTML attributes">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   556
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   557
    @Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough")
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   558
    public Void visitAttribute(AttributeTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   559
        HtmlTag currTag = tagStack.peek().tag;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   560
        if (currTag != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   561
            Name name = tree.getName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   562
            HtmlTag.Attr attr = currTag.getAttr(name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   563
            if (attr != null) {
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   564
                if (env.htmlVersion == HtmlVersion.HTML4 && attr.name().contains("-")) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   565
                    env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   566
                }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   567
                boolean first = tagStack.peek().attrs.add(attr);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   568
                if (!first)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   569
                    env.messages.error(HTML, tree, "dc.attr.repeated", name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   570
            }
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   571
            // for now, doclint allows all attribute names beginning with "on" as event handler names,
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   572
            // without checking the validity or applicability of the name
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   573
            if (!name.toString().startsWith("on")) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   574
                AttrKind k = currTag.getAttrKind(name);
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   575
                switch (env.htmlVersion) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   576
                    case HTML4:
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   577
                        validateHtml4Attrs(tree, name, k);
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   578
                        break;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   579
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   580
                    case HTML5:
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   581
                        validateHtml5Attrs(tree, name, k);
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   582
                        break;
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   583
                }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   584
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   585
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   586
            if (attr != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   587
                switch (attr) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   588
                    case NAME:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   589
                        if (currTag != HtmlTag.A) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   590
                            break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   591
                        }
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   592
                        // fallthrough
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   593
                    case ID:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   594
                        String value = getAttrValue(tree);
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   595
                        if (value == null) {
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   596
                            env.messages.error(HTML, tree, "dc.anchor.value.missing");
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   597
                        } else {
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   598
                            if (!validName.matcher(value).matches()) {
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   599
                                env.messages.error(HTML, tree, "dc.invalid.anchor", value);
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   600
                            }
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   601
                            if (!checkAnchor(value)) {
15359
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   602
                                env.messages.error(HTML, tree, "dc.anchor.already.defined", value);
a73dcb8dcbae 8006224: Doclint NPE for attribute with no value
jjg
parents: 14952
diff changeset
   603
                            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   604
                        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   605
                        break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   606
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   607
                    case HREF:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   608
                        if (currTag == HtmlTag.A) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   609
                            String v = getAttrValue(tree);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   610
                            if (v == null || v.isEmpty()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   611
                                env.messages.error(HTML, tree, "dc.attr.lacks.value");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   612
                            } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   613
                                Matcher m = docRoot.matcher(v);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   614
                                if (m.matches()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   615
                                    String rest = m.group(2);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   616
                                    if (!rest.isEmpty())
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   617
                                        checkURI(tree, rest);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   618
                                } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   619
                                    checkURI(tree, v);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   620
                                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   621
                            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   622
                        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   623
                        break;
18001
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   624
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   625
                    case VALUE:
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   626
                        if (currTag == HtmlTag.LI) {
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   627
                            String v = getAttrValue(tree);
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   628
                            if (v == null || v.isEmpty()) {
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   629
                                env.messages.error(HTML, tree, "dc.attr.lacks.value");
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   630
                            } else if (!validNumber.matcher(v).matches()) {
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   631
                                env.messages.error(HTML, tree, "dc.attr.not.number");
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   632
                            }
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   633
                        }
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   634
                        break;
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   635
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   636
                    case BORDER:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   637
                        if (currTag == HtmlTag.TABLE) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   638
                            String v = getAttrValue(tree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   639
                            try {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   640
                                if (env.htmlVersion == HtmlVersion.HTML5
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   641
                                        && (v == null || (!v.isEmpty() && Integer.parseInt(v) != 1))) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   642
                                    env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   643
                                }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   644
                            } catch (NumberFormatException ex) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   645
                                env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   646
                            }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   647
                        }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   648
                        break;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   649
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   650
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   651
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   652
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   653
        // TODO: basic check on value
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   654
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   655
        return super.visitAttribute(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   656
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   657
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   658
    private void validateHtml4Attrs(AttributeTree tree, Name name, AttrKind k) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   659
        switch (k) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   660
            case ALL:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   661
            case HTML4:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   662
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   663
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   664
            case INVALID:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   665
                env.messages.error(HTML, tree, "dc.attr.unknown", name);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   666
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   667
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   668
            case OBSOLETE:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   669
                env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   670
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   671
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   672
            case USE_CSS:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   673
                env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   674
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   675
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   676
            case HTML5:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   677
                env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   678
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   679
        }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   680
    }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   681
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   682
    private void validateHtml5Attrs(AttributeTree tree, Name name, AttrKind k) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   683
        switch (k) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   684
            case ALL:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   685
            case HTML5:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   686
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   687
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   688
            case INVALID:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   689
            case OBSOLETE:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   690
            case USE_CSS:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   691
            case HTML4:
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   692
                env.messages.error(HTML, tree, "dc.attr.not.supported.html5", name);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   693
                break;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   694
        }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   695
    }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   696
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   697
    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
   698
        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
   699
        if (e == null)
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   700
            return true;
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   701
        Set<String> set = foundAnchors.get(e);
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   702
        if (set == null)
20254
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   703
            foundAnchors.put(e, set = new HashSet<>());
19120
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   704
        return set.add(name);
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   705
    }
7766f69bffc7 8020313: doclint doesn't reset HTML anchors correctly
jjg
parents: 18001
diff changeset
   706
20254
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   707
    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
   708
        while (e != null) {
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   709
            switch (e.getKind()) {
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   710
                case CLASS:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   711
                case ENUM:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   712
                case INTERFACE:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   713
                case PACKAGE:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   714
                    return e;
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   715
                default:
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   716
                    e = e.getEnclosingElement();
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   717
            }
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   718
        }
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   719
        return e;
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   720
    }
8246fe4d6638 8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents: 19125
diff changeset
   721
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   722
    // http://www.w3.org/TR/html401/types.html#type-name
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   723
    private static final Pattern validName = Pattern.compile("[A-Za-z][A-Za-z0-9-_:.]*");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   724
18001
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   725
    private static final Pattern validNumber = Pattern.compile("-?[0-9]+");
e6193c14cc7e 8013405: DocLint should support <LI value="value">
jjg
parents: 17549
diff changeset
   726
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   727
    // pattern to remove leading {@docRoot}/?
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   728
    private static final Pattern docRoot = Pattern.compile("(?i)(\\{@docRoot *\\}/?)?(.*)");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   729
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   730
    private String getAttrValue(AttributeTree tree) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   731
        if (tree.getValue() == null)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   732
            return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   733
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   734
        StringWriter sw = new StringWriter();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   735
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   736
            new DocPretty(sw).print(tree.getValue());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   737
        } catch (IOException e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   738
            // cannot happen
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   739
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   740
        // ignore potential use of entities for now
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   741
        return sw.toString();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   742
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   743
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   744
    private void checkURI(AttributeTree tree, String uri) {
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   745
        // allow URIs beginning with javascript:, which would otherwise be rejected by the URI API.
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   746
        if (uri.startsWith("javascript:"))
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42831
diff changeset
   747
            return;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   748
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   749
            URI u = new URI(uri);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   750
        } catch (URISyntaxException e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   751
            env.messages.error(HTML, tree, "dc.invalid.uri", uri);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   752
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   753
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   754
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   755
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   756
    // <editor-fold defaultstate="collapsed" desc="javadoc tags">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   757
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   758
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   759
    public Void visitAuthor(AuthorTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   760
        warnIfEmpty(tree, tree.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   761
        return super.visitAuthor(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   762
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   763
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   764
    @Override @DefinedBy(Api.COMPILER_TREE)
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   765
    public Void visitDocRoot(DocRootTree tree, Void ignore) {
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   766
        markEnclosingTag(Flag.HAS_INLINE_TAG);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   767
        return super.visitDocRoot(tree, ignore);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   768
    }
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   769
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   770
    @Override @DefinedBy(Api.COMPILER_TREE)
52648
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   771
    public Void visitIndex(IndexTree tree, Void ignore) {
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   772
        for (TagStackItem tsi : tagStack) {
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   773
            if (tsi.tag == HtmlTag.A) {
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   774
                env.messages.warning(HTML, tree, "dc.tag.a.within.a",
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   775
                        "{@" + tree.getTagName() + "}");
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   776
                break;
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   777
            }
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   778
        }
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   779
        return super.visitIndex(tree, ignore);
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   780
    }
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   781
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   782
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   783
    public Void visitInheritDoc(InheritDocTree tree, Void ignore) {
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   784
        markEnclosingTag(Flag.HAS_INLINE_TAG);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   785
        // TODO: verify on overridden method
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   786
        foundInheritDoc = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   787
        return super.visitInheritDoc(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   788
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   789
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   790
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   791
    public Void visitLink(LinkTree tree, Void ignore) {
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   792
        markEnclosingTag(Flag.HAS_INLINE_TAG);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   793
        // simulate inline context on tag stack
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   794
        HtmlTag t = (tree.getKind() == DocTree.Kind.LINK)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   795
                ? HtmlTag.CODE : HtmlTag.SPAN;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   796
        tagStack.push(new TagStackItem(tree, t));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   797
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   798
            return super.visitLink(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   799
        } finally {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   800
            tagStack.pop();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   801
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   802
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   803
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   804
    @Override @DefinedBy(Api.COMPILER_TREE)
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   805
    public Void visitLiteral(LiteralTree tree, Void ignore) {
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
   806
        markEnclosingTag(Flag.HAS_INLINE_TAG);
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   807
        if (tree.getKind() == DocTree.Kind.CODE) {
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   808
            for (TagStackItem tsi: tagStack) {
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   809
                if (tsi.tag == HtmlTag.CODE) {
15366
545307ec740c 8006228: Doclint doesn't detect <code> {@code nested inline} </code>
jjg
parents: 15363
diff changeset
   810
                    env.messages.warning(HTML, tree, "dc.tag.code.within.code");
15363
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   811
                    break;
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   812
                }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   813
            }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   814
        }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   815
        return super.visitLiteral(tree, ignore);
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   816
    }
5c503b455dc8 8006236: doclint: structural issue hidden
jjg
parents: 15359
diff changeset
   817
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   818
    @Override @DefinedBy(Api.COMPILER_TREE)
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   819
    @SuppressWarnings("fallthrough")
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   820
    public Void visitParam(ParamTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   821
        boolean typaram = tree.isTypeParameter();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   822
        IdentifierTree nameTree = tree.getName();
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   823
        Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   824
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   825
        if (paramElement == null) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   826
            switch (env.currElement.getKind()) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   827
                case CLASS: case INTERFACE: {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   828
                    if (!typaram) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   829
                        env.messages.error(REFERENCE, tree, "dc.invalid.param");
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   830
                        break;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   831
                    }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   832
                }
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   833
                case METHOD: case CONSTRUCTOR: {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   834
                    env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   835
                    break;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   836
                }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   837
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   838
                default:
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   839
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   840
                    break;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   841
            }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   842
        } else {
43374
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   843
            boolean unique = foundParams.add(paramElement);
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   844
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   845
            if (!unique) {
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   846
                env.messages.warning(REFERENCE, tree, "dc.exists.param", nameTree);
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   847
            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   848
        }
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   849
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   850
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   851
        return super.visitParam(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   852
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   853
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   854
    private void checkParamsDocumented(List<? extends Element> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   855
        if (foundInheritDoc)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   856
            return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   857
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   858
        for (Element e: list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   859
            if (!foundParams.contains(e)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   860
                CharSequence paramName = (e.getKind() == ElementKind.TYPE_PARAMETER)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   861
                        ? "<" + e.getSimpleName() + ">"
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   862
                        : e.getSimpleName();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   863
                reportMissing("dc.missing.param", paramName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   864
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   865
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   866
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   867
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   868
    @Override @DefinedBy(Api.COMPILER_TREE)
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   869
    public Void visitProvides(ProvidesTree tree, Void ignore) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   870
        Element e = env.trees.getElement(env.currPath);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   871
        if (e.getKind() != ElementKind.MODULE) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   872
            env.messages.error(REFERENCE, tree, "dc.invalid.provides");
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   873
        }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   874
        ReferenceTree serviceType = tree.getServiceType();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   875
        Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType));
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   876
        if (se == null) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   877
            env.messages.error(REFERENCE, tree, "dc.service.not.found");
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   878
        }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   879
        return super.visitProvides(tree, ignore);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   880
    }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   881
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
   882
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   883
    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
   884
        String sig = tree.getSignature();
52664
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   885
        if (sig.contains("<") || sig.contains(">")) {
20256
9154c5cc0d9f 8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents: 20255
diff changeset
   886
            env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed");
52664
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   887
        } else if (isArrayType(sig)) {
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   888
            env.messages.error(REFERENCE, tree, "dc.array.type.not.allowed");
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   889
        } else {
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   890
            Element e = env.trees.getElement(getCurrentPath());
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   891
            if (e == null)
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   892
                env.messages.error(REFERENCE, tree, "dc.ref.not.found");
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   893
        }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   894
        return super.visitReference(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   895
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   896
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   897
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   898
    public Void visitReturn(ReturnTree tree, Void ignore) {
43374
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   899
        if (foundReturn) {
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   900
            env.messages.warning(REFERENCE, tree, "dc.exists.return");
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   901
        }
d312a15c5fcf 8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents: 43261
diff changeset
   902
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   903
        Element e = env.trees.getElement(env.currPath);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   904
        if (e.getKind() != ElementKind.METHOD
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   905
                || ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   906
            env.messages.error(REFERENCE, tree, "dc.invalid.return");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   907
        foundReturn = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   908
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   909
        return super.visitReturn(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   910
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   911
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   912
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   913
    public Void visitSerialData(SerialDataTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   914
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   915
        return super.visitSerialData(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   916
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   917
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   918
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   919
    public Void visitSerialField(SerialFieldTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   920
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   921
        return super.visitSerialField(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   922
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   923
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   924
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   925
    public Void visitSince(SinceTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   926
        warnIfEmpty(tree, tree.getBody());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   927
        return super.visitSince(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   928
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   929
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   930
    @Override @DefinedBy(Api.COMPILER_TREE)
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   931
    public Void visitSummary(SummaryTree node, Void aVoid) {
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   932
        int idx = env.currDocComment.getFullBody().indexOf(node);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   933
        // Warn if the node is preceded by non-whitespace characters,
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   934
        // or other non-text nodes.
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   935
        if ((idx == 1 && hasNonWhitespaceText) || idx > 1) {
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   936
            env.messages.warning(SYNTAX, node, "dc.invalid.summary", node.getTagName());
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   937
        }
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   938
        return super.visitSummary(node, aVoid);
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   939
    }
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   940
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
   941
    @Override @DefinedBy(Api.COMPILER_TREE)
52648
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   942
    public Void visitSystemProperty(SystemPropertyTree tree, Void ignore) {
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   943
        for (TagStackItem tsi : tagStack) {
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   944
            if (tsi.tag == HtmlTag.A) {
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   945
                env.messages.warning(HTML, tree, "dc.tag.a.within.a",
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   946
                        "{@" + tree.getTagName() + "}");
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   947
                break;
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   948
            }
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   949
        }
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   950
        return super.visitSystemProperty(tree, ignore);
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   951
    }
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   952
12956ca371c2 8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents: 47216
diff changeset
   953
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   954
    public Void visitThrows(ThrowsTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   955
        ReferenceTree exName = tree.getExceptionName();
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 16799
diff changeset
   956
        Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   957
        if (ex == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   958
            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
   959
        } else if (isThrowable(ex.asType())) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   960
            switch (env.currElement.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   961
                case CONSTRUCTOR:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   962
                case METHOD:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   963
                    if (isCheckedException(ex.asType())) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   964
                        ExecutableElement ee = (ExecutableElement) env.currElement;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   965
                        checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   966
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   967
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   968
                default:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   969
                    env.messages.error(REFERENCE, tree, "dc.invalid.throws");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   970
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   971
        } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   972
            env.messages.error(REFERENCE, tree, "dc.invalid.throws");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   973
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   974
        warnIfEmpty(tree, tree.getDescription());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   975
        return scan(tree.getDescription(), ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   976
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   977
52664
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   978
    private boolean isArrayType(String signature) {
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   979
        int brackets = signature.indexOf('[');
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   980
        int parens = signature.indexOf('(');
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   981
        return brackets >= 0 && (parens < 0 || brackets < parens);
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   982
    }
15fc92f4ae9a 8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents: 52648
diff changeset
   983
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   984
    private boolean isThrowable(TypeMirror tm) {
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   985
        switch (tm.getKind()) {
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   986
            case DECLARED:
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   987
            case TYPEVAR:
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   988
                return env.types.isAssignable(tm, env.java_lang_Throwable);
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   989
        }
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   990
        return false;
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   991
    }
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 19123
diff changeset
   992
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   993
    private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   994
        boolean found = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   995
        for (TypeMirror tl : list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   996
            if (env.types.isAssignable(t, tl)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   997
                foundThrows.add(tl);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   998
                found = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   999
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1000
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1001
        if (!found)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1002
            env.messages.error(REFERENCE, tree, "dc.exception.not.thrown", t);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1003
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1004
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1005
    private void checkThrowsDocumented(List<? extends TypeMirror> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1006
        if (foundInheritDoc)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1007
            return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1008
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1009
        for (TypeMirror tl: list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1010
            if (isCheckedException(tl) && !foundThrows.contains(tl))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1011
                reportMissing("dc.missing.throws", tl);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1012
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1013
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1014
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1015
    @Override @DefinedBy(Api.COMPILER_TREE)
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1016
    public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void ignore) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1017
        checkUnknownTag(tree, tree.getTagName());
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1018
        return super.visitUnknownBlockTag(tree, ignore);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1019
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1020
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1021
    @Override @DefinedBy(Api.COMPILER_TREE)
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1022
    public Void visitUnknownInlineTag(UnknownInlineTagTree tree, Void ignore) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1023
        checkUnknownTag(tree, tree.getTagName());
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1024
        return super.visitUnknownInlineTag(tree, ignore);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1025
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1026
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1027
    private void checkUnknownTag(DocTree tree, String tagName) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1028
        if (env.customTags != null && !env.customTags.contains(tagName))
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1029
            env.messages.error(SYNTAX, tree, "dc.tag.unknown", tagName);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1030
    }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 21017
diff changeset
  1031
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1032
    @Override @DefinedBy(Api.COMPILER_TREE)
42831
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1033
    public Void visitUses(UsesTree tree, Void ignore) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1034
        Element e = env.trees.getElement(env.currPath);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1035
        if (e.getKind() != ElementKind.MODULE) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1036
            env.messages.error(REFERENCE, tree, "dc.invalid.uses");
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1037
        }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1038
        ReferenceTree serviceType = tree.getServiceType();
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1039
        Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType));
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1040
        if (se == null) {
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1041
            env.messages.error(REFERENCE, tree, "dc.service.not.found");
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1042
        }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1043
        return super.visitUses(tree, ignore);
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1044
    }
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1045
feff6f296019 8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents: 36045
diff changeset
  1046
    @Override @DefinedBy(Api.COMPILER_TREE)
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
  1047
    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
  1048
        ReferenceTree ref = tree.getReference();
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1049
        if (ref == null || ref.getSignature().isEmpty()) {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1050
            if (!isConstant(env.currElement))
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1051
                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
  1052
        } else {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1053
            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
  1054
            if (!isConstant(e))
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1055
                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
  1056
        }
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1057
16562
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
  1058
        markEnclosingTag(Flag.HAS_INLINE_TAG);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
  1059
        return super.visitValue(tree, ignore);
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
  1060
    }
9f09744e221a 8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents: 15707
diff changeset
  1061
20255
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1062
    private boolean isConstant(Element e) {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1063
        if (e == null)
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1064
            return false;
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1065
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1066
        switch (e.getKind()) {
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1067
            case FIELD:
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1068
                Object value = ((VariableElement) e).getConstantValue();
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1069
                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
  1070
            default:
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1071
                return false;
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1072
        }
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1073
    }
f8be1ea20e1a 8025272: doclint needs to check for valid usage of @value tag
jjg
parents: 20254
diff changeset
  1074
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1075
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1076
    public Void visitVersion(VersionTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1077
        warnIfEmpty(tree, tree.getBody());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1078
        return super.visitVersion(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1079
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1080
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1081
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1082
    public Void visitErroneous(ErroneousTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1083
        env.messages.error(SYNTAX, tree, null, tree.getDiagnostic().getMessage(null));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1084
        return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1085
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1086
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1087
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1088
    // <editor-fold defaultstate="collapsed" desc="Utility methods">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1089
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1090
    private boolean isCheckedException(TypeMirror t) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1091
        return !(env.types.isAssignable(t, env.java_lang_Error)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1092
                || env.types.isAssignable(t, env.java_lang_RuntimeException));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1093
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1094
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1095
    private boolean isSynthetic() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1096
        switch (env.currElement.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1097
            case CONSTRUCTOR:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1098
                // A synthetic default constructor has the same pos as the
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1099
                // enclosing class
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1100
                TreePath p = env.currPath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1101
                return env.getPos(p) == env.getPos(p.getParentPath());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1102
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1103
        return false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1104
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1105
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1106
    void markEnclosingTag(Flag flag) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1107
        TagStackItem top = tagStack.peek();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1108
        if (top != null)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1109
            top.flags.add(flag);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1110
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1111
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1112
    String toString(TreePath p) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1113
        StringBuilder sb = new StringBuilder("TreePath[");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1114
        toString(p, sb);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1115
        sb.append("]");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1116
        return sb.toString();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1117
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1118
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1119
    void toString(TreePath p, StringBuilder sb) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1120
        TreePath parent = p.getParentPath();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1121
        if (parent != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1122
            toString(parent, sb);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1123
            sb.append(",");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1124
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1125
       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
  1126
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1127
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1128
    void warnIfEmpty(DocTree tree, List<? extends DocTree> list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1129
        for (DocTree d: list) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1130
            switch (d.getKind()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1131
                case TEXT:
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1132
                    if (hasNonWhitespace((TextTree) d))
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1133
                        return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1134
                    break;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1135
                default:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1136
                    return;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1137
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1138
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1139
        env.messages.warning(SYNTAX, tree, "dc.empty", tree.getKind().tagName);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1140
    }
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1141
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1142
    boolean hasNonWhitespace(TextTree tree) {
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1143
        String s = tree.getBody();
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1144
        for (int i = 0; i < s.length(); i++) {
46184
f1325703ea85 8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents: 43374
diff changeset
  1145
            Character c = s.charAt(i);
15371
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1146
            if (!Character.isWhitespace(s.charAt(i)))
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1147
                return true;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1148
        }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1149
        return false;
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1150
    }
8f719dc43e1f 8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents: 15370
diff changeset
  1151
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1152
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1153
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
  1154
}