org.codehaus.gant
Class GantMetaClass

java.lang.Object
  extended by groovy.lang.DelegatingMetaClass
      extended by org.codehaus.gant.GantMetaClass
All Implemented Interfaces:
groovy.lang.GroovyObject, groovy.lang.MetaClass, groovy.lang.MetaObjectProtocol, groovy.lang.MutableMetaClass

public class GantMetaClass
extends groovy.lang.DelegatingMetaClass

This class is the metaclass used for target Closures, and any enclosed Closures.

This metaclass deals with depends method calls and redirects unknown method calls to the instance of GantBuilder. To process the depends all closures from the binding called during execution of the Gant specification must be logged so that when a depends happens the full closure call history is available.

Author:
Russel Winder

Field Summary
private  org.codehaus.gant.GantBinding binding
          The binding (aka global shared state) that is being used.
private static java.util.Set<groovy.lang.Closure> methodsInvoked
          The set of all targets that have been called.
 
Fields inherited from class groovy.lang.DelegatingMetaClass
delegate
 
Constructor Summary
GantMetaClass(groovy.lang.MetaClass metaClass, org.codehaus.gant.GantBinding binding)
           
 
Method Summary
 java.lang.Object invokeMethod(java.lang.Class sender, java.lang.Object receiver, java.lang.String methodName, java.lang.Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)
          Invoke a method on the given receiver for the specified arguments.
 java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
          Invokes a method on the given object, with the given name and single argument.
 java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
          Invokes a method on the given object with the given name and arguments.
 java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)
          Invoke the given method.
private  java.lang.Object processArgument(java.lang.Object argument)
          Process the argument to a depends call.
private  java.lang.Object processClosure(groovy.lang.Closure closure)
          Execute a Closure only if it hasn't been executed previously.
 
Methods inherited from class groovy.lang.DelegatingMetaClass
addMetaBeanProperty, addMetaMethod, addNewInstanceMethod, addNewStaticMethod, equals, getAdaptee, getAttribute, getAttribute, getClassNode, getMetaClass, getMetaMethod, getMetaMethods, getMetaProperty, getMethods, getProperties, getProperty, getProperty, getProperty, getStaticMetaMethod, getStaticMetaMethod, getTheClass, hashCode, hasProperty, initialize, invokeConstructor, invokeMissingMethod, invokeMissingProperty, invokeStaticMethod, isGroovyObject, isModified, pickMethod, respondsTo, respondsTo, selectConstructorAndTransformArguments, setAdaptee, setAttribute, setAttribute, setMetaClass, setProperty, setProperty, setProperty, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

methodsInvoked

private static final java.util.Set<groovy.lang.Closure> methodsInvoked
The set of all targets that have been called. This is a global variable shared by all instances of GantMetaClass.

TODO : This code is a long way from thread safe, and so it needs fixing. Should this variable be moved to the GantState class, which is the class that holds other bits of the internal shared state? Should a different data structure be used, one that is a bit more thread safe? Arguably it is reasonable for this to be a synchronized object.


binding

private final org.codehaus.gant.GantBinding binding
The binding (aka global shared state) that is being used.

Constructor Detail

GantMetaClass

public GantMetaClass(groovy.lang.MetaClass metaClass,
                     org.codehaus.gant.GantBinding binding)
Method Detail

processClosure

private java.lang.Object processClosure(groovy.lang.Closure closure)
Execute a Closure only if it hasn't been executed previously. If it is executed, record the execution. Only used for processing a depends call.

Parameters:
closure - The Closure to potentially call.
Returns:
the result of the Closure call, or null if the closure was not called.

processArgument

private java.lang.Object processArgument(java.lang.Object argument)
Process the argument to a depends call. If the parameter is a Closure just process it. If it is a String then do a lookup for the Closure in the binding, and if found process it.

Parameters:
argument - The argument.
Returns:
The result of the Closure.

invokeMethod

public java.lang.Object invokeMethod(java.lang.Object object,
                                     java.lang.String methodName,
                                     java.lang.Object[] arguments)
Invokes a method on the given object with the given name and arguments. The MetaClass will attempt to pick the best method for the given name and arguments. If a method cannot be invoked a MissingMethodException will be thrown.

Specified by:
invokeMethod in interface groovy.lang.MetaObjectProtocol
Overrides:
invokeMethod in class groovy.lang.DelegatingMetaClass
Parameters:
object - The instance on which the method is invoked.
methodName - The name of the method.
arguments - The arguments to the method.
Returns:
The return value of the method which is null if the return type is void.
See Also:
MissingMethodException

invokeMethod

public java.lang.Object invokeMethod(java.lang.Object object,
                                     java.lang.String methodName,
                                     java.lang.Object arguments)
Invokes a method on the given object, with the given name and single argument.

Specified by:
invokeMethod in interface groovy.lang.MetaObjectProtocol
Overrides:
invokeMethod in class groovy.lang.DelegatingMetaClass
Parameters:
object - The Object to invoke the method on
methodName - The name of the method
arguments - The argument to the method
Returns:
The return value of the method which is null if the return type is void
See Also:
invokeMethod(Object, String, Object[])

invokeMethod

public java.lang.Object invokeMethod(java.lang.String name,
                                     java.lang.Object args)
Invoke the given method.

Specified by:
invokeMethod in interface groovy.lang.GroovyObject
Overrides:
invokeMethod in class groovy.lang.DelegatingMetaClass
Parameters:
name - the name of the method to call
args - the arguments to use for the method call
Returns:
the result of invoking the method

invokeMethod

public java.lang.Object invokeMethod(java.lang.Class sender,
                                     java.lang.Object receiver,
                                     java.lang.String methodName,
                                     java.lang.Object[] arguments,
                                     boolean isCallToSuper,
                                     boolean fromInsideClass)
Invoke a method on the given receiver for the specified arguments. The sender is the class that invoked the method on the object. Attempt to establish the method to invoke based on the name and arguments provided.

The isCallToSuper and fromInsideClass help the Groovy runtime perform optimizations on the call to go directly to the superclass if necessary.

Specified by:
invokeMethod in interface groovy.lang.MetaClass
Overrides:
invokeMethod in class groovy.lang.DelegatingMetaClass
Parameters:
sender - The java.lang.Class instance that invoked the method.
receiver - The object which the method was invoked on.
methodName - The name of the method.
arguments - The arguments to the method.
isCallToSuper - Whether the method is a call to a superclass method.
fromInsideClass - Whether the call was invoked from the inside or the outside of the class.
Returns:
The return value of the method

Copyright © 2006–9 The Codehaus. All Rights Reserved.