test/langtools/tools/javac/parser/T4910483.java
author jjg
Tue, 02 Jan 2018 16:07:47 -0800
changeset 48423 35cf3c947420
parent 47216 71c04702a3d5
permissions -rw-r--r--
8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc) Reviewed-by: vromero, cushon
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     1
/*
48423
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     4
 *
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     8
 *
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    13
 * accompanied this code).
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    14
 *
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    18
 *
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    21
 * questions.
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    22
 */
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    23
23398
295a722619ad 8034980: Fix @summary tag of test/tools/javac/parser/T4910483.java
dlsmith
parents: 23113
diff changeset
    24
/*
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    25
 * @test
48423
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    26
 * @bug     4910483 8183961
23398
295a722619ad 8034980: Fix @summary tag of test/tools/javac/parser/T4910483.java
dlsmith
parents: 23113
diff changeset
    27
 * @summary Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 23398
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 23398
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 23398
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.tree
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 23398
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.util
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    32
 * @run main T4910483
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    33
 */
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    34
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    35
import java.io.File;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    36
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    37
import com.sun.tools.javac.main.JavaCompiler;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    38
import com.sun.tools.javac.file.JavacFileManager;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    39
import com.sun.tools.javac.tree.JCTree;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    40
import com.sun.tools.javac.util.Context;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    41
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    42
import javax.tools.JavaFileObject;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    43
48423
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    44
// Test the original issue ("\\") as well as other appearances of '\',
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    45
// including a vanilla Unicode escape (U+0021, '!'), and a sequence
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    46
// which is not a Unicode escape
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    47
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    48
/**Test comment abc*\\def\
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    49
 *xyz\u0021\\u0021*/
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    50
public class T4910483 {
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    51
    public static void main(String... args) {
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    52
        JavaCompiler compiler = JavaCompiler.instance(new Context());
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    53
        compiler.keepComments = true;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    54
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    55
        String testSrc = System.getProperty("test.src");
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    56
        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    57
        JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + "T4910483.java");
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    58
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    59
        JCTree.JCCompilationUnit cu = compiler.parse(f);
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    60
        JCTree classDef = cu.getTypeDecls().head;
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    61
        String commentText = cu.docComments.getCommentText(classDef);
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    62
48423
35cf3c947420 8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
jjg
parents: 47216
diff changeset
    63
        String expected = "Test comment abc*\\\\def\\\nxyz!\\\\u0021"; // 4 '\' escapes to 2 in a string literal
23113
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    64
        if (!expected.equals(commentText)) {
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    65
            throw new AssertionError("Incorrect comment text: [" + commentText + "], expected [" + expected + "]");
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    66
        }
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    67
    }
5d44044f4f64 4910483: Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
dlsmith
parents:
diff changeset
    68
}