Path: blob/master/test/langtools/jdk/javadoc/doclet/testBaseClass/BaseClass.java
40971 views
/*1* Copyright (c) 1999, 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* Regression test for:25* Javadoc does not process base class. If user specifies few classes on the26* command line and few packages, with a situation where one of the specified27* classes(on the command line) extends a class from one of the packages, then28* due to some anomaly in ordering in which all the class and package objects29* get constructed, few classes were getting marked as "not included", even30* thought they were included in this run and hence documentation for those31* packages was wrong. The test case for which javadoc was failing is given32* in bug# 4197513.33*34* @bug 419751335* @summary Javadoc does not process base class.36* @build BaseClass.java37*/3839import java.util.Collections;40import java.util.LinkedHashSet;41import java.util.List;42import java.util.Locale;43import java.util.Set;44import java.util.stream.Collectors;4546import javax.lang.model.SourceVersion;4748import javax.lang.model.element.Element;49import javax.lang.model.element.ElementKind;50import javax.lang.model.element.TypeElement;51import javax.lang.model.util.ElementFilter;52import javax.lang.model.util.Elements;5354import jdk.javadoc.doclet.*;5556public class BaseClass implements Doclet {5758public boolean run(DocletEnvironment root) {59Elements elementUtils = root.getElementUtils();60TypeElement klass = elementUtils.getTypeElement("baz.Foo");61if (!root.isIncluded(klass)) {62throw new AssertionError("Base class is not included: baz.Foo");63}6465for (TypeElement te : ElementFilter.typesIn(root.getSpecifiedElements())) {66if (te.getKind() == ElementKind.CLASS &&67te.getSimpleName().contentEquals("Bar")) {68klass = te;69}70}71if (klass == null) {72throw new AssertionError("class Bar not found");73}74List<? extends Element> members = klass.getEnclosedElements();757677boolean foundPublic = false;78boolean foundProtected = false;7980boolean foundPackagePrivate = false;81boolean foundPrivate = false;8283List<Element> included = members.stream()84.filter(cls -> root.isIncluded(cls))85.collect(Collectors.toList());8687for (Element e : included) {88System.out.println("element: " + e);89if (e.getSimpleName().toString().equals("aPublicMethod")) {90foundPublic = true;91}92if (e.getSimpleName().toString().equals("aProtectedMethod")) {93foundProtected = true;94}95if (e.getSimpleName().toString().equals("aPackagePrivateMethod")) {96foundPackagePrivate = true;97}98if (e.getSimpleName().toString().equals("aPackagePrivateMethod")) {99foundPrivate = true;100}101}102if (!foundPublic || !foundProtected) {103throw new AssertionError("selected methods not found");104}105106if (foundPrivate || foundPackagePrivate) {107throw new AssertionError("unselected methods found");108}109110return true;111}112113public Set<Doclet.Option> getSupportedOptions() {114return Collections.emptySet();115}116117public void init(Locale locale, Reporter reporter) {118return;119}120121@Override122public String getName() {123return "BaseClass";124}125126@Override127public SourceVersion getSupportedSourceVersion() {128return SourceVersion.latest();129}130}131132133