Path: blob/master/test/langtools/jdk/javadoc/tool/dupOk/DupOk.java
40971 views
/*1* Copyright (c) 2002, 2019, 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 467347726* @summary The first definition found for each class should be documented27* @modules jdk.javadoc/jdk.javadoc.internal.tool28*/2930import java.io.File;31import java.util.*;3233import javax.lang.model.SourceVersion;34import javax.lang.model.element.Element;35import javax.lang.model.element.ElementKind;36import javax.lang.model.element.TypeElement;37import javax.lang.model.util.ElementFilter;3839import jdk.javadoc.doclet.Doclet;40import jdk.javadoc.doclet.Reporter;41import jdk.javadoc.doclet.DocletEnvironment;4243public class DupOk implements Doclet44{45public static void main(String[] args) {46File srcFile = new File(System.getProperty("test.src", "."));47String path1 = new File(srcFile, "sp1").getPath();48String path2 = new File(srcFile, "sp2").getPath();49String[] aargs = {50"-docletpath",51new File(System.getProperty("test.classes", ".")).getPath(),52"-doclet",53"DupOk",54"-sourcepath",55path1 + System.getProperty("path.separator") + path2,56"p"57};58// run javadoc on package p59if (jdk.javadoc.internal.tool.Main.execute(aargs) != 0)60throw new Error();61}6263public boolean run(DocletEnvironment root) {64Set<TypeElement> classes = ElementFilter.typesIn(root.getIncludedElements());65if (classes.size() != 2)66throw new Error("1 " + Arrays.asList(classes));67for (TypeElement clazz : classes) {68if (getFields(clazz).size() != 1)69throw new Error("2 " + clazz + " " + getFields(clazz));70}71return true;72}7374List<Element> getFields(TypeElement klass) {75List<Element> out = new ArrayList<>();76for (Element e : klass.getEnclosedElements()) {77if (e.getKind() == ElementKind.FIELD) {78out.add(e);79}80}81return out;82}8384@Override85public String getName() {86return "Test";87}8889@Override90public Set<Option> getSupportedOptions() {91return Collections.emptySet();92}9394@Override95public SourceVersion getSupportedSourceVersion() {96return SourceVersion.latest();97}9899@Override100public void init(Locale locale, Reporter reporter) {101return;102}103}104105106