# HG changeset patch # User darcy # Date 1547145270 28800 # Node ID e81edc1f6f7e4092a4465c500391cfb93bed2d7d # Parent 7327a62f3c042a346e474932122cc745880a46b9 8216404: Elements.getPackageOf should handle modules Reviewed-by: jlahoda diff -r 7327a62f3c04 -r e81edc1f6f7e src/java.compiler/share/classes/javax/lang/model/util/Elements.java --- a/src/java.compiler/share/classes/javax/lang/model/util/Elements.java Thu Jan 10 10:28:51 2019 -0800 +++ b/src/java.compiler/share/classes/javax/lang/model/util/Elements.java Thu Jan 10 10:34:30 2019 -0800 @@ -451,6 +451,7 @@ /** * Returns the package of an element. The package of a package is * itself. + * The package of a module is {@code null}. * * @param type the element being examined * @return the package of an element diff -r 7327a62f3c04 -r e81edc1f6f7e src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java Thu Jan 10 10:28:51 2019 -0800 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java Thu Jan 10 10:34:30 2019 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -436,7 +436,10 @@ @DefinedBy(Api.LANGUAGE_MODEL) public PackageElement getPackageOf(Element e) { - return cast(Symbol.class, e).packge(); + if (e.getKind() == ElementKind.MODULE) + return null; + else + return cast(Symbol.class, e).packge(); } @DefinedBy(Api.LANGUAGE_MODEL) diff -r 7327a62f3c04 -r e81edc1f6f7e test/langtools/tools/javac/processing/model/util/elements/TestGetPackageOf.java --- a/test/langtools/tools/javac/processing/model/util/elements/TestGetPackageOf.java Thu Jan 10 10:28:51 2019 -0800 +++ b/test/langtools/tools/javac/processing/model/util/elements/TestGetPackageOf.java Thu Jan 10 10:34:30 2019 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 6453386 + * @bug 6453386 8216404 * @summary Test Elements.getPackageOf * @author Joseph D. Darcy * @library /tools/javac/lib @@ -56,6 +56,7 @@ TypeElement stringElt = eltUtils.getTypeElement("java.lang.String"); PackageElement javaLangPkg = eltUtils.getPackageElement("java.lang"); PackageElement unnamedPkg = eltUtils.getPackageElement(""); + ModuleElement moduleElt = eltUtils.getModuleElement("java.base"); PackageElement pkg = null; if (!javaLangPkg.equals(pkg=eltUtils.getPackageOf(stringElt) ) ) @@ -66,6 +67,10 @@ if (!unnamedPkg.equals(pkg=eltUtils.getPackageOf(unnamedPkg) ) ) throw new RuntimeException("Unexpected package for unnamed pkg: " + pkg); + + if (eltUtils.getPackageOf(moduleElt) != null) + throw new RuntimeException("Unexpected package for module" + + moduleElt.getSimpleName()); } return true; }