1/* 2 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 4673477 27 * @summary The first definition found for each class should be documented 28 * @author gafter 29 * @modules jdk.javadoc/jdk.javadoc.internal.tool 30 */ 31 32import java.io.File; 33import java.util.*; 34 35import javax.lang.model.SourceVersion; 36import javax.lang.model.element.Element; 37import javax.lang.model.element.ElementKind; 38import javax.lang.model.element.TypeElement; 39import javax.lang.model.util.ElementFilter; 40 41import jdk.javadoc.doclet.Doclet; 42import jdk.javadoc.doclet.Reporter; 43import jdk.javadoc.doclet.DocletEnvironment; 44 45public class DupOk implements Doclet 46{ 47 public static void main(String[] args) { 48 File srcFile = new File(System.getProperty("test.src", ".")); 49 String path1 = new File(srcFile, "sp1").getPath(); 50 String path2 = new File(srcFile, "sp2").getPath(); 51 String[] aargs = { 52 "-docletpath", 53 new File(System.getProperty("test.classes", ".")).getPath(), 54 "-doclet", 55 "DupOk", 56 "-sourcepath", 57 path1 + System.getProperty("path.separator") + path2, 58 "p" 59 }; 60 // run javadoc on package p 61 if (jdk.javadoc.internal.tool.Main.execute(aargs) != 0) 62 throw new Error(); 63 } 64 65 public boolean run(DocletEnvironment root) { 66 Set<TypeElement> classes = ElementFilter.typesIn(root.getIncludedElements()); 67 if (classes.size() != 2) 68 throw new Error("1 " + Arrays.asList(classes)); 69 for (TypeElement clazz : classes) { 70 if (getFields(clazz).size() != 1) 71 throw new Error("2 " + clazz + " " + getFields(clazz)); 72 } 73 return true; 74 } 75 76 List<Element> getFields(TypeElement klass) { 77 List<Element> out = new ArrayList<>(); 78 for (Element e : klass.getEnclosedElements()) { 79 if (e.getKind() == ElementKind.FIELD) { 80 out.add(e); 81 } 82 } 83 return out; 84 } 85 86 @Override 87 public String getName() { 88 return "Test"; 89 } 90 91 @Override 92 public Set<Option> getSupportedOptions() { 93 return Collections.emptySet(); 94 } 95 96 @Override 97 public SourceVersion getSupportedSourceVersion() { 98 return SourceVersion.latest(); 99 } 100 101 @Override 102 public void init(Locale locale, Reporter reporter) { 103 return; 104 } 105} 106