T4910483.java revision 3155:30e288cb2d22
1/*
2 * Copyright (c) 2014, 2015, 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     4910483
27 * @summary Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
28 * @modules jdk.compiler/com.sun.tools.javac.file
29 *          jdk.compiler/com.sun.tools.javac.main
30 *          jdk.compiler/com.sun.tools.javac.tree
31 *          jdk.compiler/com.sun.tools.javac.util
32 * @run main T4910483
33 */
34
35import java.io.File;
36
37import com.sun.tools.javac.main.JavaCompiler;
38import com.sun.tools.javac.file.JavacFileManager;
39import com.sun.tools.javac.tree.JCTree;
40import com.sun.tools.javac.util.Context;
41
42import javax.tools.JavaFileObject;
43
44/**Test comment abc*\\def*/
45public class T4910483 {
46    public static void main(String... args) {
47        JavaCompiler compiler = JavaCompiler.instance(new Context());
48        compiler.keepComments = true;
49
50        String testSrc = System.getProperty("test.src");
51        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
52        JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + "T4910483.java");
53
54        JCTree.JCCompilationUnit cu = compiler.parse(f);
55        JCTree classDef = cu.getTypeDecls().head;
56        String commentText = cu.docComments.getCommentText(classDef);
57
58        String expected = "Test comment abc*\\\\def"; // 4 '\' escapes to 2 in a string literal
59        if (!expected.equals(commentText)) {
60            throw new AssertionError("Incorrect comment text: [" + commentText + "], expected [" + expected + "]");
61        }
62    }
63}
64