langtools/test/tools/javac/processing/model/element/TestPackageElement.java
changeset 43571 a153580d1741
parent 30730 d3ce7619db2c
child 45687 07463ccee73b
equal deleted inserted replaced
43570:c7b68caf3ab4 43571:a153580d1741
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 6449798 6399404
    26  * @bug 6449798 6399404 8173776
    27  * @summary Test basic workings of PackageElement
    27  * @summary Test basic workings of PackageElement
    28  * @author  Joseph D. Darcy
    28  * @author  Joseph D. Darcy
    29  * @library /tools/javac/lib
    29  * @library /tools/javac/lib
    30  * @modules java.compiler
    30  * @modules java.compiler
    31  *          jdk.compiler
    31  *          jdk.compiler
    32  * @build   JavacTestingAbstractProcessor TestPackageElement
    32  * @build   JavacTestingAbstractProcessor TestPackageElement
    33  * @compile -processor TestPackageElement -proc:only TestPackageElement.java
    33  * @compile -processor TestPackageElement -proc:only             TestPackageElement.java
       
    34  * @compile -processor TestPackageElement -proc:only --release 8 TestPackageElement.java
    34  */
    35  */
    35 
    36 
       
    37 import java.util.Objects;
    36 import java.util.Set;
    38 import java.util.Set;
    37 import javax.annotation.processing.*;
    39 import javax.annotation.processing.*;
    38 import javax.lang.model.SourceVersion;
    40 import javax.lang.model.SourceVersion;
    39 import static javax.lang.model.SourceVersion.*;
    41 import static javax.lang.model.SourceVersion.*;
    40 import javax.lang.model.element.*;
    42 import javax.lang.model.element.*;
    65                 throw new RuntimeException("The isUnnamed method on the unnamed package returned false!");
    67                 throw new RuntimeException("The isUnnamed method on the unnamed package returned false!");
    66 
    68 
    67             PackageElement javaLang = eltUtils.getPackageElement("java.lang");
    69             PackageElement javaLang = eltUtils.getPackageElement("java.lang");
    68             if (javaLang.isUnnamed())
    70             if (javaLang.isUnnamed())
    69                 throw new RuntimeException("Package java.lang is unnamed!");
    71                 throw new RuntimeException("Package java.lang is unnamed!");
       
    72 
       
    73             testEnclosingElement(javaLang);
    70         }
    74         }
    71         return true;
    75         return true;
    72     }
    76     }
       
    77 
       
    78     void testEnclosingElement(PackageElement javaLang) {
       
    79         SourceVersion version = processingEnv.getSourceVersion();
       
    80         Element enclosing = javaLang.getEnclosingElement();
       
    81         Element expectedEnclosing =
       
    82             (version.compareTo(RELEASE_9) < 0) ?  // No modules
       
    83             null :
       
    84             eltUtils.getModuleElement("java.base");
       
    85 
       
    86         if (!Objects.equals(enclosing, expectedEnclosing))
       
    87             throw new RuntimeException("Unexpected enclosing element under source version " +
       
    88                                        version);
       
    89     }
    73 }
    90 }