blackdrag commented on code in PR #3227: URL: https://github.com/apache/groovy/pull/3227#discussion_r4554115092
########## src/test/groovy/bugs/Groovy11916.groovy: ########## @@ -0,0 +1,727 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bugs + +import groovy.lang.GroovyClassLoader +import org.codehaus.groovy.control.CompilationUnit +import org.codehaus.groovy.control.CompilerConfiguration +import org.codehaus.groovy.control.Phases +import org.codehaus.groovy.control.customizers.ImportCustomizer +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test + +import java.lang.reflect.Modifier + +import static groovy.test.GroovyAssert.assertScript +import static groovy.test.GroovyAssert.shouldFail + +/** + * Star imports, module imports, and default imports resolve only accessible + * types. A source import shadows those defaults, including {@code java.lang}. + * Two source star imports bind the first accessible type in source order. + * An explicit single-type import, a fully qualified name, and + * {@code Class.forName} still name a type that is not public. + */ +final class Groovy11916 { + + private static GroovyClassLoader types + + @BeforeAll + static void compilePackagePrivateTypes() { + types = compile(Groovy11916.classLoader, [ + 'p/Types': ''' + package p + + @groovy.transform.PackageScope + class Hidden {} + + class Visible {} + + @groovy.transform.PackageScope + class Outer { + public static class Inner {} + } + + class Protector { + protected static class Secret {} + } + + class Priv { + private static class Secret {} + public static class Shown {} + } + + @groovy.transform.PackageScope + class Collision {} + ''' + ]) + assert !Modifier.isPublic(types.loadClass('p.Hidden').modifiers) + assert !Modifier.isPublic(types.loadClass('p.Collision').modifiers) + assert Modifier.isPublic(types.loadClass('p.Visible').modifiers) + assert !Modifier.isPublic(types.loadClass('p.Outer').modifiers) + assert Modifier.isPublic(types.loadClass('p.Outer$Inner').modifiers) + assert Modifier.isProtected(types.loadClass('p.Protector$Secret').modifiers) + assert Modifier.isPrivate(types.loadClass('p.Priv$Secret').modifiers) Review Comment: but you know, isStarImportAccessible and this here need documentation. Assume I change that test, I would not be able to tell why the modifiers are checked here really. Maybe that makes for completeness in the topic, but I expect such a test in other places. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
