langtools/test/tools/javac/processing/model/LocalClasses/LocalClassesModel.java
author darcy
Fri, 27 Jan 2017 16:22:08 -0800
changeset 43646 017aba6e9260
parent 42407 f3702cff2933
permissions -rw-r--r--
8028544: Add SourceVersion.RELEASE_10 8028546: Add -source 10 and -target 10 to javac Reviewed-by: jjg, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41991
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     1
/*
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42407
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
41991
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     4
 *
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     8
 *
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    14
 *
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    18
 *
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    21
 * questions.
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    22
 */
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    23
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    24
/**
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    25
 * @test
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    26
 * @bug 8166700
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    27
 * @summary Check that local classes originating in static initializer can be loaded properly.
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    28
 * @modules jdk.compiler
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42407
diff changeset
    29
 * @library /tools/javac/lib
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42407
diff changeset
    30
 * @build LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest JavacTestingAbstractProcessor
41991
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    31
 * @compile LocalClassesModel.java
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    32
 * @compile/process/ref=LocalClassesModel.out -processor LocalClassesModel LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    33
 */
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    34
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    35
import java.util.Set;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    36
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    37
import javax.annotation.processing.AbstractProcessor;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    38
import javax.annotation.processing.RoundEnvironment;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    39
import javax.annotation.processing.SupportedAnnotationTypes;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    40
import javax.lang.model.SourceVersion;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    41
import javax.lang.model.element.ExecutableElement;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    42
import javax.lang.model.element.TypeElement;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    43
import javax.lang.model.element.VariableElement;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    44
import javax.lang.model.util.ElementFilter;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    45
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42407
diff changeset
    46
public class LocalClassesModel extends JavacTestingAbstractProcessor {
41991
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    47
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    48
    @Override
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    49
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    50
        for (TypeElement root : ElementFilter.typesIn(roundEnv.getRootElements())) {
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    51
            System.out.println(processingEnv.getElementUtils().getBinaryName(root));
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    52
            for (ExecutableElement constr : ElementFilter.constructorsIn(root.getEnclosedElements())) {
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    53
                System.out.print("  (");
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    54
                boolean first = true;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    55
                for (VariableElement param : constr.getParameters()) {
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    56
                    if (!first) {
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    57
                        System.out.print(", ");
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    58
                    }
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    59
                    first = false;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    60
                    System.out.print(param.asType().toString());
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    61
                }
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    62
                System.out.println(")");
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    63
            }
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    64
        }
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    65
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    66
        return false;
cc8a2784dd4c 8166700: NPE during invoking getEnclosedElements() on javax.lang.model.element.Element instance representing a package
jlahoda
parents:
diff changeset
    67
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41991
diff changeset
    68
}