本文整理匯總了Java中groovy.lang.Closure.setDelegate方法的典型用法代碼示例。如果您正苦於以下問題:Java Closure.setDelegate方法的具體用法?Java Closure.setDelegate怎麽用?Java Closure.setDelegate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類groovy.lang.Closure
的用法示例。
在下文中一共展示了Closure.setDelegate方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import groovy.lang.Closure; //導入方法依賴的package包/類
public void execute(T delegate) {
if (closure == null) {
return;
}
try {
if (configureableAware && delegate instanceof Configurable) {
((Configurable) delegate).configure(closure);
} else {
Closure copy = (Closure) closure.clone();
copy.setResolveStrategy(resolveStrategy);
copy.setDelegate(delegate);
if (copy.getMaximumNumberOfParameters() == 0) {
copy.call();
} else {
copy.call(delegate);
}
}
} catch (groovy.lang.MissingMethodException e) {
if (Objects.equal(e.getType(), closure.getClass()) && Objects.equal(e.getMethod(), "doCall")) {
throw new InvalidActionClosureException(closure, delegate);
}
throw e;
}
}
示例2: execute
import groovy.lang.Closure; //導入方法依賴的package包/類
public void execute(T subject, List<?> inputs) {
Closure copy = (Closure) closure.clone();
copy.setResolveStrategy(Closure.DELEGATE_FIRST);
copy.setDelegate(subject);
if (closure.getMaximumNumberOfParameters() == 0) {
copy.call();
} else {
Object[] argList = new Object[inputs.size() + 1];
argList[0] = subject;
int i = 1;
for (Object arg : inputs) {
argList[i++] = arg;
}
copy.call(argList);
}
}
示例3: configure
import groovy.lang.Closure; //導入方法依賴的package包/類
@Override
public LazyCredentialsExtension configure(Closure c) {
if (!Closure.class.isInstance(c.getDelegate()) ||
DefaultMavenArtifactRepository.class.isInstance(((Closure)c.getDelegate()))) {
throw new IllegalStateException("This extension can only be used in maven repository config.");
}
LazyCredentials credentials = new LazyCredentials(project);
Object originalDelegate = ((Closure)c.getDelegate()).getDelegate();
c.setResolveStrategy(Closure.DELEGATE_FIRST);
c.setDelegate(credentials);
c.call();
((DefaultMavenArtifactRepository) originalDelegate).setConfiguredCredentials(credentials);
return this;
}
示例4: on
import groovy.lang.Closure; //導入方法依賴的package包/類
/**
* Allows executing a consumer with some context to setup events.
*
* @param aggregate The aggregate on which the consumer must operate
* @param entityConsumer A Consumer that decides what happens when apply is called on an
* entity
* @param positionSupplier A supplier which offers the default position number for an event
* when it is not provided
* @param timestampSupplier A supplier that provides the date for an event if it isn't set
* @param closure The block of code to execute with the aggregate
*
* @return The aggregate after all the code has been executed
*/
public AggregateT on(
AggregateT aggregate, Consumer entityConsumer, Supplier<Long> positionSupplier,
Supplier<Date> timestampSupplier, @DelegatesTo(OnSpec.class) Closure closure) {
OnSpec<AggregateT, EventIdT, EventT, ?, ?> spec = new OnSpec<>();
spec.setAggregate(aggregate);
spec.setEntityConsumer(entityConsumer);
spec.setTimestampSupplier(timestampSupplier);
spec.setPositionSupplier(positionSupplier);
closure.setDelegate(spec);
closure.call(spec);
return aggregate;
}
示例5: invokeBeanDefiningClosure
import groovy.lang.Closure; //導入方法依賴的package包/類
/**
* When a method argument is only a closure it is a set of bean definitions.
* @param callable the closure argument
* @return this GroovyBeanDefinitionReader instance
*/
protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) {
callable.setDelegate(this);
callable.call();
finalizeDeferredProperties();
return this;
}
示例6: handleClosure
import groovy.lang.Closure; //導入方法依賴的package包/類
private CfnObject handleClosure(final String name, Closure<?> closure, @Nullable final Object currentValue) {
if ((currentValue != null) && !(currentValue instanceof CfnObject)) {
throw new IllegalArgumentException("Cannot overwrite CfnObject with " + currentValue.getClass());
}
// merge properties into existing object if it exists
CfnObject delegate = (currentValue != null) ? (CfnObject) currentValue : new CfnObject(resourceType, propertyPath + '.' + name);
closure.setDelegate(delegate);
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
closure.call();
return delegate;
}
示例7: when
import groovy.lang.Closure; //導入方法依賴的package包/類
void when(Object obj, Closure cl) {
while(true){
whenCycle = false;
CaseCollector caseCollector = new CaseCollector();
cl.setDelegate(caseCollector);
cl.call();
Function result = caseCollector.execute(obj);
result.apply(obj);
if(!whenCycle) return;
obj = receive();
}
}
示例8: closureInit
import groovy.lang.Closure; //導入方法依賴的package包/類
void closureInit(Closure cl, Object delegate) {
cl.setDelegate(delegate);
cl.call();
}
示例9: prepareDelegation
import groovy.lang.Closure; //導入方法依賴的package包/類
public void prepareDelegation(Closure configureClosure) {
ClientModuleConfigureDelegate delegate = new ClientModuleConfigureDelegate(clientModule, this);
configureClosure.setDelegate(delegate);
configureClosure.setResolveStrategy(Closure.DELEGATE_FIRST);
}