BreakIteratorWarning.java revision 3595:81692f730015
1181053Srwatson/*
2180701Srwatson * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3155192Srwatson * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4155192Srwatson *
5155192Srwatson * This code is free software; you can redistribute it and/or modify it
6155192Srwatson * under the terms of the GNU General Public License version 2 only, as
7155192Srwatson * published by the Free Software Foundation.
8155192Srwatson *
9155192Srwatson * This code is distributed in the hope that it will be useful, but WITHOUT
10155192Srwatson * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11155192Srwatson * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12155192Srwatson * version 2 for more details (a copy is included in the LICENSE file that
13180701Srwatson * accompanied this code).
14155192Srwatson *
15155192Srwatson * You should have received a copy of the GNU General Public License version
16155192Srwatson * 2 along with this work; if not, write to the Free Software Foundation,
17155192Srwatson * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18155192Srwatson *
19155192Srwatson * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20155192Srwatson * or visit www.oracle.com if you need additional information or have any
21155192Srwatson * questions.
22155192Srwatson */
23155192Srwatson
24155192Srwatson/*
25155192Srwatson * @test
26155192Srwatson * @bug 4959985
27155192Srwatson * @summary Verify that (verbose) warnings are no longer generated when
28155192Srwatson *          the default first-sentence algorithm doesn't match the
29155192Srwatson *          BreakIterator algorithm.
30155192Srwatson * @modules jdk.javadoc/jdk.javadoc.internal.tool
31155192Srwatson */
32155192Srwatson
33155192Srwatsonimport java.util.ArrayList;
34155192Srwatsonimport java.util.Collections;
35155192Srwatsonimport java.util.List;
36155192Srwatsonimport java.util.Locale;
37156882Srwatsonimport java.util.Set;
38178617Srwatson
39155192Srwatsonimport javax.lang.model.SourceVersion;
40155192Srwatsonimport javax.lang.model.element.ElementKind;
41155192Srwatsonimport javax.lang.model.element.TypeElement;
42155192Srwatsonimport javax.lang.model.element.VariableElement;
43155192Srwatson
44155192Srwatsonimport com.sun.source.doctree.DocCommentTree;
45155192Srwatsonimport com.sun.source.doctree.DocTree;
46155192Srwatsonimport com.sun.source.util.DocTrees;
47155192Srwatsonimport jdk.javadoc.doclet.Doclet;
48155192Srwatsonimport jdk.javadoc.doclet.Reporter;
49155192Srwatsonimport jdk.javadoc.doclet.DocletEnvironment;
50155192Srwatson
51170196Srwatsonpublic class BreakIteratorWarning implements Doclet {
52170196Srwatson
53170196Srwatson    public static void main(String[] args) {
54170196Srwatson        String thisFile = "" +
55155192Srwatson            new java.io.File(System.getProperty("test.src", "."),
56155192Srwatson                             "BreakIteratorWarning.java");
57155192Srwatson
58155192Srwatson        String[] argarray = {
59156889Srwatson            "-docletpath", System.getProperty("test.classes", "."),
60156889Srwatson            "-doclet", "BreakIteratorWarning",
61155192Srwatson            "-Xwerror",
62155192Srwatson            thisFile
63170196Srwatson        };
64170196Srwatson        if (jdk.javadoc.internal.tool.Main.execute(argarray) != 0)
65170196Srwatson            throw new Error("Javadoc encountered warnings or errors.");
66155192Srwatson    }
67155192Srwatson
68155192Srwatson    List<VariableElement> getFields(TypeElement klass) {
69155192Srwatson        List<VariableElement> fields = new ArrayList<>();
70155192Srwatson        klass.getEnclosedElements()
71156889Srwatson                .stream()
72156889Srwatson                .filter((e) -> (e.getKind() == ElementKind.FIELD))
73156889Srwatson                .forEach((e) -> { fields.add((VariableElement)e);});
74195925Srwatson        return fields;
75195925Srwatson    }
76156889Srwatson
77156889Srwatson    public boolean run(DocletEnvironment root) {
78156889Srwatson        TypeElement cd = root.getIncludedTypeElements().iterator().next();
79156889Srwatson        VariableElement fd = getFields(cd).get(0);
80156889Srwatson        DocTrees docTrees = root.getDocTrees();
81156889Srwatson        DocCommentTree docCommentTree = docTrees.getDocCommentTree(fd);
82156889Srwatson        List<? extends DocTree> firstSentence = docCommentTree.getFirstSentence();
83156889Srwatson        return true;
84156889Srwatson    }
85156889Srwatson
86156889Srwatson
87156889Srwatson    /**
88156889Srwatson     * "He'll never catch up!" the Sicilian cried.  "Inconceivable!"
89156889Srwatson     * "You keep using that word!" the Spaniard snapped.  "I do not
90156889Srwatson     * think it means what you think it means."
91156889Srwatson     *
92156889Srwatson     * <p> This comment used to trigger a warning, but no longer does.
93156889Srwatson     */
94156889Srwatson    public String author = "William Goldman";
95156889Srwatson
96156889Srwatson    @Override
97156889Srwatson    public String getName() {
98160086Srwatson        return "Test";
99156889Srwatson    }
100156889Srwatson
101171066Scsjp    @Override
102244324Spjd    public Set<Option> getSupportedOptions() {
103244324Spjd        return Collections.emptySet();
104195926Srwatson    }
105195926Srwatson
106156889Srwatson    @Override
107156889Srwatson    public SourceVersion getSupportedSourceVersion() {
108156889Srwatson        return SourceVersion.latest();
109156889Srwatson    }
110156889Srwatson
111156889Srwatson    public void init(Locale locale, Reporter reporter) {
112156889Srwatson        return;
113156889Srwatson    }
114156889Srwatson}
115161813Swsalamon