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 a uitableview with custom cells which I created in Interface Builder. There
Creating an iOS app in Flash Builder 4.5 which is a small Hello World
When creating a new project in Flash Builder, how does it determine which sdk
I am creating a dynamic type which has a method that I'd like to
I'm creating an actionscript project in Flex Builder. I succeed to export from Flash
I'm creating a form using the form builder in Symfony. I am adding an
I have a custom UITableViewCell which I created in Interface Builder. I am successfully
I am creating an app with Flex 4 using Flash Builder. When I try
I am creating an android app which pulls in RSS Feeds from here http://spaceflight1.nasa.gov/realdata/sightings/cities/rss/index.cgi?country=United_Kingdom&region=England&city=Manchester
I'm creating a view which provides some fields for the user to fill in

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.