test/langtools/tools/javac/classreader/T7031108.java
author yzheng
Wed, 16 Oct 2019 16:54:56 +0200
changeset 58650 d068b1e534de
parent 49197 cc2673fa8c20
permissions -rw-r--r--
8231754: [JVMCI] Make r27 unconditionally reserved in JVMCI Summary: Reserve r27 (heap base register) on AArch64 unconditionally Reviewed-by: adinn, dlong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     4
 *
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     8
 *
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    13
 * accompanied this code).
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    14
 *
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    18
 *
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    21
 * questions.
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    22
 */
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    23
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    24
/*
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    25
 * @test
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    26
 * @bug 7031108
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    27
 * @summary NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
14963
974d4423c999 8005282: Use @library tag with non-relative path for javac tests
darcy
parents: 9077
diff changeset
    28
 * @library /tools/javac/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    29
 * @modules java.compiler
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    30
 *          jdk.compiler
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    31
 * @build JavacTestingAbstractProcessor T7031108
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    32
 * @run main T7031108
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    33
 */
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    34
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    35
import java.io.*;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    36
import java.net.*;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    37
import java.util.*;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    38
import javax.annotation.processing.*;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    39
import javax.lang.model.element.*;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    40
import javax.tools.*;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    41
import javax.tools.JavaCompiler.CompilationTask;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    42
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    43
public class T7031108 extends JavacTestingAbstractProcessor {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    44
    public static void main(String... args) throws Exception {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    45
        new T7031108().run();
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    46
    }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    47
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    48
    /* Class containing a local class definition;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    49
     * compiled class file will have an EnclosedMethod attribute.
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    50
     */
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    51
    static final JavaSource pC =
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    52
            new JavaSource("p/C.java",
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    53
                  "package p;\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    54
                + "class C {\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    55
                + "    void m() {\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    56
                + "        new Runnable() {\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    57
                + "            public void run() {\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    58
                + "                new Runnable() {\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    59
                + "                    public void run() { }\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    60
                + "                };\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    61
                + "            }\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    62
                + "        };\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    63
                + "    }\n"
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    64
                + "}");
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    65
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
    66
    private static final String PACKAGE_CONTENT_ERROR = "package does not contain C";
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
    67
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    68
    /* Dummy source file to compile while running anno processor. */
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    69
    static final JavaSource dummy =
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    70
            new JavaSource("Dummy.java",
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    71
                "class Dummy { }");
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    72
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    73
    void run() throws Exception {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    74
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    75
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    76
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    77
            // step 1: compile test classes
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    78
            File cwd = new File(".");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    79
            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    80
            compile(comp, fm, null, null, pC);
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    81
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    82
            // step 2: verify functioning of processor
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    83
            fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    84
                    fm.getLocation(StandardLocation.CLASS_PATH));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    85
            fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    86
            compile(comp, fm, null, getClass().getName(), dummy);
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    87
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    88
            File pC_class = new File(new File("p"), "C.class");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    89
            pC_class.delete();
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    90
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    91
            DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    92
            compile(comp, fm, dc, getClass().getName(), dummy);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    93
            List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
    94
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    95
            System.err.println(diags);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    96
            switch (diags.size()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    97
                case 0:
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    98
                    throw new Exception("no diagnostics received");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
    99
                case 1:
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   100
                    String code = diags.get(0).getCode();
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   101
                    String expect = "compiler.err.proc.messager";
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   102
                    if (!expect.equals(code))
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   103
                        throw new Exception("unexpected diag code: " + code
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   104
                                + ", expected: " + expect);
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   105
                    String message = diags.get(0).getMessage(null);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   106
                    if (!PACKAGE_CONTENT_ERROR.equals(message)) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   107
                        throw new Exception("unexpected diag message: " + code
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   108
                                + ", expected: " + PACKAGE_CONTENT_ERROR);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   109
                    }
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   110
                    break;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   111
                default:
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   112
                    throw new Exception("unexpected diags received");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14963
diff changeset
   113
            }
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   114
        }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   115
    }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   116
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   117
    void compile(JavaCompiler comp, JavaFileManager fm,
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   118
            DiagnosticListener<JavaFileObject> dl,
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   119
            String processor, JavaFileObject... files) throws Exception {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   120
        System.err.println("compile processor:" + processor + ", files:" + Arrays.asList(files));
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   121
        List<String> opts = new ArrayList<String>();
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   122
        if (processor != null) {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   123
            // opts.add("-verbose");
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   124
            opts.addAll(Arrays.asList("-processor", processor));
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   125
        }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   126
        CompilationTask task = comp.getTask(null, fm, dl, opts, null, Arrays.asList(files));
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   127
        boolean ok = task.call();
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   128
        if (dl == null && !ok)
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   129
            throw new Exception("compilation failed");
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   130
    }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   131
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   132
    static class JavaSource extends SimpleJavaFileObject {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   133
        JavaSource(String name, String text) {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   134
            super(URI.create("js://" + name), JavaFileObject.Kind.SOURCE);
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   135
            this.text = text;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   136
        }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   137
        @Override
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   138
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   139
            return text;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   140
        }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   141
        final String text;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   142
    }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   143
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   144
    // annotation processor method
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   145
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   146
    @Override
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   147
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   148
        if (!roundEnv.processingOver()) {
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   149
            PackageElement p = elements.getPackageElement("p");
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   150
            List<? extends Element> elems = p.getEnclosedElements();
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   151
            System.err.println("contents of package p: " + elems);
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   152
            if (elems.size() != 1 || !elems.get(0).getSimpleName().contentEquals("C")) {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 47216
diff changeset
   153
                messager.printMessage(Diagnostic.Kind.ERROR, PACKAGE_CONTENT_ERROR);
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   154
            }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   155
        }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   156
        return true;
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   157
    }
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   158
}
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
diff changeset
   159