Path: blob/master/test/langtools/jdk/jshell/JavadocTest.java
40931 views
/*1* Copyright (c) 2015, 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 8131019 8169561 817424526* @summary Test Javadoc27* @library /tools/lib28* @modules jdk.compiler/com.sun.tools.javac.api29* jdk.compiler/com.sun.tools.javac.main30* jdk.jshell/jdk.jshell:open31* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask32* @build KullaTesting TestingInputStream Compiler33* @run testng JavadocTest34*/3536import java.io.IOException;37import java.lang.reflect.Field;38import java.nio.file.Files;39import java.nio.file.Path;40import java.nio.file.Paths;41import java.util.Arrays;42import java.util.jar.JarEntry;43import java.util.jar.JarOutputStream;4445import org.testng.annotations.Test;4647@Test48public class JavadocTest extends KullaTesting {4950private final Compiler compiler = new Compiler();5152public void testJavadoc() {53prepareZip();54assertJavadoc("test.Clazz|", "test.Clazz\n" +55"Top level. ");56assertEval("test.Clazz clz = null;");57assertJavadoc("clz.test(|", "String test.Clazz.test(int p) throws IllegalStateException\n" +58" javadoc1A\n" +59"\n" +60" @param p param\n" +61" @throws IllegalStateException exc\n" +62" @return value\n");63//undefined handling:64assertJavadoc("clz.undef|");65}6667public void testVariableInRepl() {68assertEval("Object o;");69assertSignature("o|", "o:java.lang.Object");70}7172private void prepareZip() {73String clazz =74"package test;\n" +75"/**Top level." +76" */\n" +77"public class Clazz {\n" +78" /**\n" +79" * javadoc1A\n" +80" *\n" +81" * @param p param\n" +82" * @throws IllegalStateException exc\n" +83" * @return value\n" +84" */\n" +85" public String test(int p) throws IllegalStateException { return null;}\n" +86"}\n";8788Path srcZip = Paths.get("src.zip");8990try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {91out.putNextEntry(new JarEntry("test/Clazz.java"));92out.write(clazz.getBytes());93} catch (IOException ex) {94throw new IllegalStateException(ex);95}9697compiler.compile(clazz);9899try {100Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");101availableSources.setAccessible(true);102availableSources.set(getAnalysis(), Arrays.asList(srcZip));103} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {104throw new IllegalStateException(ex);105}106addToClasspath(compiler.getClassDir());107}108109public void testCollectionsMin() {110prepareJavaUtilZip();111assertJavadoc("java.util.Collections.min(|",112"T java.util.Collections.<T>min(java.util.Collection<? extends T> coll, java.util.Comparator<? super T> comp)\n" +113" min comparator\n",114"T java.util.Collections.<T extends Object & Comparable<? super T>>min(java.util.Collection<? extends T> coll)\n" +115" min comparable\n");116}117118private void prepareJavaUtilZip() {119String clazz =120"package java.util;\n" +121"/**Top level." +122" */\n" +123"public class Collections {\n" +124" /**\n" +125" * min comparable\n" +126" */\n" +127" public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {" +128" return null;\n" +129" }\n" +130" /**\n" +131" * min comparator\n" +132" */\n" +133" public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {\n" +134" return null;\n" +135" }\n" +136"}\n";137138Path srcZip = Paths.get("src.zip");139140try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {141out.putNextEntry(new JarEntry("java/util/Collections.java"));142out.write(clazz.getBytes());143} catch (IOException ex) {144throw new IllegalStateException(ex);145}146147try {148Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");149availableSources.setAccessible(true);150availableSources.set(getAnalysis(), Arrays.asList(srcZip));151} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {152throw new IllegalStateException(ex);153}154}155156}157158159