Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:06+00:00 2026-05-22T03:16:06+00:00

I am creating a builder which accepts Groovy closures as markup. However I am

  • 0

I am creating a builder which accepts Groovy closures as markup. However I am having trouble catching method calls with nested closures.

Closure nested = {
   foo ()       //will throw missingMethod exception
}
Closure root = {
   foo ()       //prints 'missing foo []'
   inline_nested {
     foo ()     //prints 'missing foo []'
   }
   nested ()    
}
builder.execute (root)

// ...
class MyBuilder {
  void execute (Closure closure) {
    def clone = closure.clone()
    clone.delegate = this
    clone()
  }
  def missingMethod (String name, args) {
     println "missing ${name} ${args}"
  }
}

Is there any way I can set the delegate property for nested closures?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:16:07+00:00Added an answer on May 22, 2026 at 3:16 am

    i’d go with no, you cant. and you probably don’t need it.
    first. you are either the owner or the delegate of a closure. if you directly call a closure defined somewhere else, the call is resolved without your builder assistance.
    second. do you really need that nested()? i believe you could easily use execute nested instead

    here’s an example of what i mean

    def nested2 = {
      someMethodAtNested2 '3'
      println "nested2! - $it"
    }
    def nested1 = {arg1,arg2->
      someMethodAtNested1 '2'
      println "nested1! - $arg1"
      include nested2, arg2
    }
    def root = {
      someMethodAtRoot '1'
      println "root!"
      include nested1, 'param1', 'param2'
    }
    new FooBuilder().build root
    
    class FooBuilder {
      void build(Closure closure) {
        include closure
      }
      def include(Closure closure, ...args) {
        def clone = closure.clone()
        clone.delegate = this
        clone.resolveStrategy = Closure.DELEGATE_FIRST
        clone(*args)
      }
      def methodMissing(String name, args) {
        println "missing ${name} ${args}"
      }
    }
    

    as a side note, i don’t think builder support is the way to go. it might be useful for creating builders in java. but pure groovy is far easier. at least for small to medium complexity builders (never wrote a really large one).
    you do need some knowledge of groovy’s method dispatch process though

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an app with one UIViewController and many UIViews. I have MainViewController with
Im fairly new at programming and was wondering if the Jigloo gui builder plugin
I have a bunch of custom UITableCells that I have built in interface builder.
I'm always looking for a modern Java library that makes creating valid (X)HTML snippets
I am resetting up my development machine and I cannot seem to remember where
right now I'm following an Matlab tutorial http://www.mathworks.com/help/techdoc/creating_guis/brpat2g.html . The Problem is my Matlab
When working on small projects or some test classes , I would prefer to
FlexUnit is quite an impressive framework for testing and with the new integration in
Sorry but I found no clear answer on that. I have an iphone app
I am trying to get a JSON response from our server and the response

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.