Path: blob/master/test/langtools/jdk/javadoc/tool/BreakIteratorWarning.java
40957 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 495998526* @summary Verify that (verbose) warnings are no longer generated when27* the default first-sentence algorithm doesn't match the28* BreakIterator algorithm.29* @modules jdk.javadoc/jdk.javadoc.internal.tool30*/3132import java.util.ArrayList;33import java.util.Collections;34import java.util.List;35import java.util.Locale;36import java.util.Set;3738import javax.lang.model.SourceVersion;39import javax.lang.model.element.ElementKind;40import javax.lang.model.element.TypeElement;41import javax.lang.model.element.VariableElement;42import javax.lang.model.util.ElementFilter;4344import com.sun.source.doctree.DocCommentTree;45import com.sun.source.doctree.DocTree;46import com.sun.source.util.DocTrees;47import jdk.javadoc.doclet.Doclet;48import jdk.javadoc.doclet.Reporter;49import jdk.javadoc.doclet.DocletEnvironment;5051public class BreakIteratorWarning implements Doclet {5253public static void main(String[] args) {54String thisFile = "" +55new java.io.File(System.getProperty("test.src", "."),56"BreakIteratorWarning.java");5758String[] argarray = {59"-docletpath", System.getProperty("test.classes", "."),60"-doclet", "BreakIteratorWarning",61"-Xwerror",62thisFile63};64if (jdk.javadoc.internal.tool.Main.execute(argarray) != 0)65throw new Error("Javadoc encountered warnings or errors.");66}6768List<VariableElement> getFields(TypeElement klass) {69List<VariableElement> fields = new ArrayList<>();70klass.getEnclosedElements()71.stream()72.filter((e) -> (e.getKind() == ElementKind.FIELD))73.forEach((e) -> { fields.add((VariableElement)e);});74return fields;75}7677public boolean run(DocletEnvironment root) {78TypeElement cd = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();79VariableElement fd = getFields(cd).get(0);80DocTrees docTrees = root.getDocTrees();81DocCommentTree docCommentTree = docTrees.getDocCommentTree(fd);82List<? extends DocTree> firstSentence = docCommentTree.getFirstSentence();83return true;84}858687/**88* "He'll never catch up!" the Sicilian cried. "Inconceivable!"89* "You keep using that word!" the Spaniard snapped. "I do not90* think it means what you think it means."91*92* <p> This comment used to trigger a warning, but no longer does.93*/94public String author = "William Goldman";9596@Override97public String getName() {98return "Test";99}100101@Override102public Set<Option> getSupportedOptions() {103return Collections.emptySet();104}105106@Override107public SourceVersion getSupportedSourceVersion() {108return SourceVersion.latest();109}110111public void init(Locale locale, Reporter reporter) {112return;113}114}115116117