當前位置: 首頁>>代碼示例>>Java>>正文


Java Closure.setDelegate方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:26,代碼來源:ClosureBackedAction.java

示例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);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:18,代碼來源:ClosureBackedRuleAction.java

示例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;
}
 
開發者ID:Unity-Group,項目名稱:gradle-lazy-credentials,代碼行數:18,代碼來源:LazyCredentialsExtension.java

示例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;
}
 
開發者ID:rahulsom,項目名稱:grooves,代碼行數:27,代碼來源:GroovyEventsDsl.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:GroovyBeanDefinitionReader.java

示例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;
}
 
開發者ID:cslee00,項目名稱:cfn-core,代碼行數:14,代碼來源:CfnObject.java

示例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();
    }
}
 
開發者ID:DeskChan,項目名稱:DeskChan,代碼行數:13,代碼來源:Scenario.java

示例8: closureInit

import groovy.lang.Closure; //導入方法依賴的package包/類
void closureInit(Closure cl, Object delegate) {
    cl.setDelegate(delegate);
    cl.call();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:5,代碼來源:JUnit4GroovyMockery.java

示例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);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:6,代碼來源:ModuleFactoryDelegate.java


注:本文中的groovy.lang.Closure.setDelegate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。