langtools/test/tools/javac/api/TestJavacTaskScanner.java
author mcimadamore
Mon, 24 Oct 2011 13:00:20 +0100
changeset 10815 a719aa5f1631
parent 6716 71df48777dd1
child 16569 48416084b910
permissions -rw-r--r--
7096014: Javac tokens should retain state Summary: Refactor javac tokens from enum constants to stateful instances (to keep track of position, comments, etc.) Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
     2
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5016
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5016
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5016
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 * @bug     4813736
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary Additional functionality test of task and JSR 269
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 * @author  Peter von der Ah\u00e9
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    29
 * @library ./lib
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
 * @run main TestJavacTaskScanner TestJavacTaskScanner.java
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.api.JavacTaskImpl;
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
    34
import com.sun.tools.javac.parser.*;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 6716
diff changeset
    35
import com.sun.tools.javac.parser.Tokens.Token;
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
    36
import com.sun.tools.javac.util.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import java.io.*;
5016
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    38
import java.net.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import java.nio.*;
5016
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    40
import java.nio.charset.Charset;
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    41
import java.util.Arrays;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import javax.lang.model.element.Element;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import javax.lang.model.element.TypeElement;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import javax.lang.model.type.DeclaredType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import javax.lang.model.type.TypeMirror;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import javax.lang.model.util.Elements;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import javax.lang.model.util.Types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import javax.tools.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
5016
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    50
import static javax.tools.StandardLocation.CLASS_PATH;
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    51
import static javax.tools.StandardLocation.SOURCE_PATH;
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    52
import static javax.tools.StandardLocation.CLASS_OUTPUT;
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    53
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    54
public class TestJavacTaskScanner extends ToolTester {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    final JavacTaskImpl task;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    final Elements elements;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    final Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    60
    int numTokens;
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    61
    int numParseTypeElements;
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    62
    int numAllMembers;
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    63
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    64
    TestJavacTaskScanner(File file) {
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    65
        final Iterable<? extends JavaFileObject> compilationUnits =
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    66
            fm.getJavaFileObjects(new File[] {file});
5016
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    67
        StandardJavaFileManager fm = getLocalFileManager(tool, null, null);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    68
        task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, compilationUnits);
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
    69
        task.getContext().put(ScannerFactory.scannerFactoryKey,
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    70
                new MyScanner.Factory(task.getContext(), this));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        elements = task.getElements();
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        types = task.getTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public void run() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        Iterable<? extends TypeElement> toplevels;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            toplevels = task.enter(task.parse());
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        } catch (IOException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        for (TypeElement clazz : toplevels) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            System.out.format("Testing %s:%n%n", clazz.getSimpleName());
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            testParseType(clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            testGetAllMembers(clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            System.out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            System.out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            System.out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        }
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    90
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    91
        System.out.println("#tokens: " + numTokens);
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    92
        System.out.println("#parseTypeElements: " + numParseTypeElements);
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    93
        System.out.println("#allMembers: " + numAllMembers);
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    94
5016
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
    95
        check(numTokens, "#Tokens", 1222);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    96
        check(numParseTypeElements, "#parseTypeElements", 136);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 6716
diff changeset
    97
        check(numAllMembers, "#allMembers", 52);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    98
    }
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
    99
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   100
    void check(int value, String name, int expected) {
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   101
        // allow some slop in the comparison to allow for minor edits in the
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   102
        // test and in the platform
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   103
        if (value < expected * 9 / 10)
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   104
            throw new Error(name + " lower than expected; expected " + expected + "; found: " + value);
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   105
        if (value > expected * 11 / 10)
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   106
            throw new Error(name + " higher than expected; expected " + expected + "; found: " + value);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    void testParseType(TypeElement clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        DeclaredType type = (DeclaredType)task.parseType("List<String>", clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        for (Element member : elements.getAllMembers((TypeElement)type.asElement())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            TypeMirror mt = types.asMemberOf(type, member);
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   114
            numParseTypeElements++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    public static void main(String... args) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        String srcdir = System.getProperty("test.src");
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   120
        new TestJavacTaskScanner(new File(srcdir, args[0])).run();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    private void testGetAllMembers(TypeElement clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        for (Element member : elements.getAllMembers(clazz)) {
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   125
            System.out.format("%s : %s%n", member.getSimpleName(), member.asType());
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   126
            numAllMembers++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
5016
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   129
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   130
    /* Similar to ToolTester.getFileManager, except that this version also ensures
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   131
     * javac classes will be available on the classpath.  The javac classes are assumed
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   132
     * to be on the classpath used to run this test (this is true when using jtreg).
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   133
     * The classes are found by obtaining the URL for a sample javac class, using
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   134
     * getClassLoader().getResource(), and then deconstructing the URL to find the
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   135
     * underlying directory or jar file to place on the classpath.
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   136
     */
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   137
    public StandardJavaFileManager getLocalFileManager(JavaCompiler tool,
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   138
                                                        DiagnosticListener<JavaFileObject> dl,
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   139
                                                        Charset encoding) {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   140
        File javac_classes;
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   141
        try {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   142
            final String javacMainClass = "com/sun/tools/javac/Main.class";
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   143
            URL url = getClass().getClassLoader().getResource(javacMainClass);
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   144
            if (url == null)
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   145
                throw new Error("can't locate javac classes");
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   146
            URI uri = url.toURI();
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   147
            String scheme = uri.getScheme();
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   148
            String ssp = uri.getSchemeSpecificPart();
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   149
            if (scheme.equals("jar")) {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   150
                javac_classes = new File(new URI(ssp.substring(0, ssp.indexOf("!/"))));
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   151
            } else if (scheme.equals("file")) {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   152
                javac_classes = new File(ssp.substring(0, ssp.indexOf(javacMainClass)));
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   153
            } else
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   154
                throw new Error("unknown URL: " + url);
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   155
        } catch (URISyntaxException e) {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   156
            throw new Error(e);
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   157
        }
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   158
        System.err.println("javac_classes: " + javac_classes);
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   159
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   160
        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, encoding);
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   161
        try {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   162
            fm.setLocation(SOURCE_PATH,  Arrays.asList(test_src));
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   163
            fm.setLocation(CLASS_PATH,   Arrays.asList(test_classes, javac_classes));
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   164
            fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   165
        } catch (IOException e) {
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   166
            throw new AssertionError(e);
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   167
        }
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   168
        return fm;
ff5e6791d0bb 6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents: 2986
diff changeset
   169
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
}
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
class MyScanner extends Scanner {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   174
    public static class Factory extends ScannerFactory {
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   175
        public Factory(Context context, TestJavacTaskScanner test) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            super(context);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   177
            this.test = test;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        @Override
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   181
        public Scanner newScanner(CharSequence input, boolean keepDocComments) {
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   182
            assert !keepDocComments;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            if (input instanceof CharBuffer) {
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   184
                return new MyScanner(this, (CharBuffer)input, test);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                char[] array = input.toString().toCharArray();
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   187
                return newScanner(array, array.length, keepDocComments);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        @Override
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   192
        public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) {
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   193
            assert !keepDocComments;
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   194
            return new MyScanner(this, input, inputLength, test);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        }
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   196
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   197
        private TestJavacTaskScanner test;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    }
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   199
    protected MyScanner(ScannerFactory fac, CharBuffer buffer, TestJavacTaskScanner test) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        super(fac, buffer);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   201
        this.test = test;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    }
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 5520
diff changeset
   203
    protected MyScanner(ScannerFactory fac, char[] input, int inputLength, TestJavacTaskScanner test) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        super(fac, input, inputLength);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   205
        this.test = test;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    public void nextToken() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        super.nextToken();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 6716
diff changeset
   210
        Token tk = token();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 6716
diff changeset
   211
        System.err.format("Saw token %s %n", tk.kind);
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   212
        test.numTokens++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    }
2986
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   214
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   215
    private TestJavacTaskScanner test;
5370c4ae4f6f 6802102: unignore @ignored tests where possible
jjg
parents: 10
diff changeset
   216
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
}