|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package groovy.bugs |
| 20 | + |
| 21 | +class Groovy7994Bug extends GroovyTestCase { |
| 22 | + void testJavaBeanPropertiesAvailableInInnerClasses() { |
| 23 | + assertScript ''' |
| 24 | + import groovy.transform.CompileStatic |
| 25 | +
|
| 26 | + @CompileStatic |
| 27 | + class Outer { |
| 28 | + String prop = 'wally' |
| 29 | + String getName() { "sally" } |
| 30 | + class Inner { |
| 31 | + String innerGo() { new Other(name).text + new Other(Outer.this.name).text + new Other(getName()).text } |
| 32 | + } |
| 33 | + String go() { |
| 34 | + new Other(name).text + new Other(getName()).text |
| 35 | + } |
| 36 | + def makeAIC() { |
| 37 | + new Object() { |
| 38 | + String aicGo() { new Other(name).text + new Other(Outer.this.name).text + new Other(getName()).text } |
| 39 | + String staticMethodGo() { Other.foo(name) + Other.foo(Outer.this.name) + Other.foo(getName()) } |
| 40 | + String instanceMethodGo() { new Other().bar(name) + new Other().bar(getName()) } |
| 41 | + String methodWithClosureGo() { new Other().with { bar(name) + bar(getName()) } } |
| 42 | + String propGo() { new Other(prop).text + new Other(getProp()).text } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +
|
| 47 | + @CompileStatic |
| 48 | + class Other { |
| 49 | + public final String text |
| 50 | + static String foo(Object object) { "Object|$object:" } |
| 51 | + static String foo(String string) { "String|$string:" } |
| 52 | + String bar(Object object) { "Object|$object:" } |
| 53 | + String bar(String string) { "String|$string:" } |
| 54 | + Other(Object object) { text = "Object:$object|" } |
| 55 | + Other(String string) { text = "String:$string|" } |
| 56 | + Other() {} |
| 57 | + } |
| 58 | +
|
| 59 | + def o = new Outer() |
| 60 | + assert o.go() == 'String:sally|String:sally|' |
| 61 | + assert o.makeAIC().aicGo() == 'String:sally|String:sally|String:sally|' |
| 62 | + assert o.makeAIC().propGo() == 'String:wally|String:wally|' |
| 63 | + assert o.makeAIC().staticMethodGo() == 'String|sally:String|sally:String|sally:' |
| 64 | + assert o.makeAIC().instanceMethodGo() == 'String|sally:String|sally:' |
| 65 | + assert o.makeAIC().methodWithClosureGo() == 'String|sally:String|sally:' |
| 66 | + assert new Outer.Inner(o).innerGo() == 'String:sally|String:sally|String:sally|' |
| 67 | + ''' |
| 68 | + } |
| 69 | +} |
0 commit comments