[ 
https://issues.apache.org/jira/browse/GROOVY-7499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15028610#comment-15028610
 ] 

Jochen Kemnade commented on GROOVY-7499:
----------------------------------------

For example, the following test will fail:
{code}
    public void testUsePropertiesFromDelegate() throws Exception {
      def cc = new CompilerConfiguration()
      cc.scriptBaseClass = DelegatingScript.class.name
      OutputStream os = new ByteArrayOutputStream()
      def binding = new Binding()
      binding.setProperty("out", new PrintStream(os))
      def sh = new GroovyShell(binding, cc)
      def script = sh.parse('''print("Hello World!")''')
      script.setDelegate([:])
      script.run()

      assert os.toString() == """Hello World!"""
    }
}
{code}
The {{out}} property from the binding will not be used, because the delegate 
map will return {{null}} for {{getProperty("out")}}.
So, should the script's bindings have precedence over the delegate? What if the 
delegate also has an {{out}} property?
And what should happen for {{setProperty("foo", "bar")}}? Should {{foo}} be set 
inside the map or in the script binding?
Should there be 
{{setResolveStrategyForGetProperty(BINDINGS_ONLY|BINDINGS_FIRST|DELEGATE_ONLY|DELEGATE_FIRST)
 and setResolveStrategyForSetProperty(...)}}? What about {{invokeMethod}}? For 
instance, {{println}} should probably not be called on a builder.

> DelegatingScript should support resolve strategies
> --------------------------------------------------
>
>                 Key: GROOVY-7499
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7499
>             Project: Groovy
>          Issue Type: Improvement
>    Affects Versions: 2.4.3, 2.4.4
>            Reporter: Jochen Kemnade
>
> It should be possible to configure a {{DelegatingScript}} wrt. its resolution 
> strategies. In some cases, it might be desirable to try to resolve properties 
> in the script binding before trying the delegate.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to