langtools/test/jdk/jshell/JavadocTest.java
author tschatzl
Fri, 04 Aug 2017 14:15:42 +0200
changeset 46750 bcab0128a16f
parent 43773 8d8593871575
permissions -rw-r--r--
8184346: Clean up G1CMBitmap Summary: Trim down and improve the G1CMBitMap class structure. Reviewed-by: mgerdin, shade, rkennke
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     1
/*
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     4
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     8
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    14
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    18
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    21
 * questions.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    22
 */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    23
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    24
/*
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    25
 * @test
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
    26
 * @bug 8131019 8169561 8174245
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    27
 * @summary Test Javadoc
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    28
 * @library /tools/lib
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41865
diff changeset
    31
 *          jdk.jshell/jdk.jshell:open
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    33
 * @build KullaTesting TestingInputStream Compiler
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    34
 * @run testng JavadocTest
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    35
 */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    36
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    37
import java.io.IOException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    38
import java.lang.reflect.Field;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    39
import java.nio.file.Files;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    40
import java.nio.file.Path;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    41
import java.nio.file.Paths;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    42
import java.util.Arrays;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    43
import java.util.jar.JarEntry;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    44
import java.util.jar.JarOutputStream;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    45
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    46
import org.testng.annotations.Test;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    47
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    48
@Test
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    49
public class JavadocTest extends KullaTesting {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    50
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    51
    private final Compiler compiler = new Compiler();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    52
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    53
    public void testJavadoc() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    54
        prepareZip();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    55
        assertJavadoc("test.Clazz|", "test.Clazz\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    56
                                     "Top level. ");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    57
        assertEval("test.Clazz clz = null;");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    58
        assertJavadoc("clz.test(|", "String test.Clazz.test(int p) throws IllegalStateException\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    59
                                    " javadoc1A\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    60
                                    "\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    61
                                    " @param p param\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    62
                                    " @throws IllegalStateException exc\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    63
                                    " @return value\n");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    64
        //undefined handling:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    65
        assertJavadoc("clz.undef|");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    66
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    67
42258
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
    68
    public void testVariableInRepl() {
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
    69
        assertEval("Object o;");
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
    70
        assertSignature("o|", "o:java.lang.Object");
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
    71
    }
a1aafd5ea6ec 8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents: 41865
diff changeset
    72
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    73
    private void prepareZip() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    74
        String clazz =
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    75
                "package test;\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    76
                "/**Top level." +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    77
                " */\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    78
                "public class Clazz {\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    79
                "    /**\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    80
                "     * javadoc1A\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    81
                "     *\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    82
                "     * @param p param\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    83
                "     * @throws IllegalStateException exc\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    84
                "     * @return value\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    85
                "     */\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    86
                "    public String test(int p) throws IllegalStateException { return null;}\n" +
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    87
                "}\n";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    88
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    89
        Path srcZip = Paths.get("src.zip");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    90
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    91
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    92
            out.putNextEntry(new JarEntry("test/Clazz.java"));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    93
            out.write(clazz.getBytes());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    94
        } catch (IOException ex) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    95
            throw new IllegalStateException(ex);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    96
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    97
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    98
        compiler.compile(clazz);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    99
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   100
        try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   101
            Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   102
            availableSources.setAccessible(true);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   103
            availableSources.set(getAnalysis(), Arrays.asList(srcZip));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   104
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   105
            throw new IllegalStateException(ex);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   106
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   107
        addToClasspath(compiler.getClassDir());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   108
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   109
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   110
    public void testCollectionsMin() {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   111
        prepareJavaUtilZip();
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   112
        assertJavadoc("java.util.Collections.min(|",
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   113
                      "T java.util.Collections.<T>min(java.util.Collection<? extends T> coll, java.util.Comparator<? super T> comp)\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   114
                       " min comparator\n",
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   115
                       "T java.util.Collections.<T extends Object & Comparable<? super T>>min(java.util.Collection<? extends T> coll)\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   116
                       " min comparable\n");
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   117
    }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   118
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   119
    private void prepareJavaUtilZip() {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   120
        String clazz =
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   121
                "package java.util;\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   122
                "/**Top level." +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   123
                " */\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   124
                "public class Collections {\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   125
                "    /**\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   126
                "     * min comparable\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   127
                "     */\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   128
                "    public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   129
                "        return null;\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   130
                "    }\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   131
                "    /**\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   132
                "     * min comparator\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   133
                "     */\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   134
                "        public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   135
                "        return null;\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   136
                "    }\n" +
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   137
                "}\n";
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   138
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   139
        Path srcZip = Paths.get("src.zip");
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   140
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   141
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   142
            out.putNextEntry(new JarEntry("java/util/Collections.java"));
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   143
            out.write(clazz.getBytes());
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   144
        } catch (IOException ex) {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   145
            throw new IllegalStateException(ex);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   146
        }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   147
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   148
        try {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   149
            Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   150
            availableSources.setAccessible(true);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   151
            availableSources.set(getAnalysis(), Arrays.asList(srcZip));
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   152
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   153
            throw new IllegalStateException(ex);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   154
        }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   155
    }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42408
diff changeset
   156
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   157
}