| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (InvokeNormalMethodFromBuilder_Groovy657Bug.groovy)

This example Groovy source code file (InvokeNormalMethodFromBuilder_Groovy657Bug.groovy) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

builder, builder, buildersupport, groovytestcase, invokenormalmethodfrombuilder_bug657, map, map, object, object, string, string

The Groovy InvokeNormalMethodFromBuilder_Groovy657Bug.groovy source code

package groovy.bugs

  * <p>
  * Test that ensures that:
  * <ul>
  *   <li>it is possible to write a builder in Groovy
  *   <li>it is possible to call normal methods from the builder,
  *       without the methods being trapped endlessly by createNode()</li>
  * </ul>
  * </p>
  * @author Guillaume Laforge
class InvokeNormalMethodFromBuilder_Bug657 extends GroovyTestCase {
    void testInvokeNormalMethod() {
        def b = new Builder()
        assert b.callNormalMethod() == "first"

        def value = b.someNode() {}
        assert value == "second"

class Builder extends BuilderSupport {

    void setParent(Object parent, Object child) {}

    Object createNode(Object name)                 { return createNode(name, [:], null) }
    Object createNode(Object name, Map attributes) { return createNode(name, attributes, null) }
    Object createNode(Object name, Object value)   { return createNode(name, [:], value) }

    Object createNode(Object name, Map attributes, Object value) {
        println "create ${name}"
        return callOtherStaticallyTypedMethod()

    String callNormalMethod()               { println "normalMethod"; return "first" }
    String callOtherStaticallyTypedMethod() { println "otherMethod";  return "second" }

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy InvokeNormalMethodFromBuilder_Groovy657Bug.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.