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


Java Closure.call方法代碼示例

本文整理匯總了Java中groovy.lang.Closure.call方法的典型用法代碼示例。如果您正苦於以下問題:Java Closure.call方法的具體用法?Java Closure.call怎麽用?Java Closure.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在groovy.lang.Closure的用法示例。


在下文中一共展示了Closure.call方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: methodMissing

import groovy.lang.Closure; //導入方法依賴的package包/類
public Object methodMissing(String name, Object args) {
    Object item = storage.get(name);
    if (item != null && item instanceof Closure) {
        Closure closure = (Closure) item;
        return closure.call((Object[]) args);
    } else {
        throw new groovy.lang.MissingMethodException(name, getClass(), (Object[]) args);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,代碼來源:DefaultExtraPropertiesExtension.java

示例5: 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

示例6: 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

示例7: applyPropertyToBeanDefinition

import groovy.lang.Closure; //導入方法依賴的package包/類
protected void applyPropertyToBeanDefinition(String name, Object value) {
	if (value instanceof GString) {
		value = value.toString();
	}
	if (addDeferredProperty(name, value)) {
		return;
	}
	else if (value instanceof Closure) {
		GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
		try {
			Closure callable = (Closure) value;
			Class<?> parameterType = callable.getParameterTypes()[0];
			if (parameterType.equals(Object.class)) {
				this.currentBeanDefinition = new GroovyBeanDefinitionWrapper("");
				callable.call(this.currentBeanDefinition);
			}
			else {
				this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, parameterType);
				callable.call((Object) null);
			}

			value = this.currentBeanDefinition.getBeanDefinition();
		}
		finally {
			this.currentBeanDefinition = current;
		}
	}
	this.currentBeanDefinition.addProperty(name, value);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:GroovyBeanDefinitionReader.java

示例8: 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

示例9: callClosure

import groovy.lang.Closure; //導入方法依賴的package包/類
public static Object callClosure(Closure closure, Object... args) {
    try {
        return closure.call(args);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException)e.getCause();
        } else {
            throw e;
        }
    }
}
 
開發者ID:oehf,項目名稱:ipf-flow-manager,代碼行數:12,代碼來源:ClosureAdapter.java

示例10: 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

示例11: closureInit

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

示例12: configureModule

import groovy.lang.Closure; //導入方法依賴的package包/類
private void configureModule(ClientModule clientModule, Closure configureClosure) {
    ModuleFactoryDelegate moduleFactoryDelegate = new ModuleFactoryDelegate(clientModule, this);
    moduleFactoryDelegate.prepareDelegation(configureClosure);
    configureClosure.call();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:6,代碼來源:DefaultDependencyFactory.java

示例13: visitDependencies

import groovy.lang.Closure; //導入方法依賴的package包/類
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
    if (values.isEmpty()) {
        return;
    }
    Deque<Object> queue = new ArrayDeque<Object>(values);
    while (!queue.isEmpty()) {
        Object dependency = queue.removeFirst();
        if (dependency instanceof Buildable) {
            context.add(dependency);
        } else if (dependency instanceof Task) {
            context.add(dependency);
        } else if (dependency instanceof TaskDependency) {
            context.add(dependency);
        } else if (dependency instanceof Closure) {
            Closure closure = (Closure) dependency;
            Object closureResult = closure.call(context.getTask());
            if (closureResult != null) {
                queue.addFirst(closureResult);
            }
        } else if (dependency instanceof RealizableTaskCollection) {
            RealizableTaskCollection realizableTaskCollection = (RealizableTaskCollection) dependency;
            realizableTaskCollection.realizeRuleTaskTypes();
            addAllFirst(queue, realizableTaskCollection.toArray());
        } else if (dependency instanceof List) {
            List<?> list = (List) dependency;
            if (list instanceof RandomAccess) {
                for (int i = list.size() - 1; i >= 0; i--) {
                    queue.addFirst(list.get(i));
                }
            } else {
                ListIterator<?> iterator = list.listIterator(list.size());
                while (iterator.hasPrevious()) {
                    Object item = iterator.previous();
                    queue.addFirst(item);
                }
            }
        } else if (dependency instanceof Iterable) {
            Iterable<?> iterable = (Iterable) dependency;
            addAllFirst(queue, toArray(iterable, Object.class));
        } else if (dependency instanceof Map) {
            Map<?, ?> map = (Map) dependency;
            addAllFirst(queue, map.values().toArray());
        } else if (dependency instanceof Object[]) {
            Object[] array = (Object[]) dependency;
            addAllFirst(queue, array);
        } else if (dependency instanceof Callable) {
            Callable callable = (Callable) dependency;
            Object callableResult = uncheckedCall(callable);
            if (callableResult != null) {
                queue.addFirst(callableResult);
            }
        } else if (resolver != null && dependency instanceof TaskReference) {
            context.add(resolver.resolveTask((TaskReference) dependency));
        } else if (resolver != null && dependency instanceof CharSequence) {
            context.add(resolver.resolveTask(dependency.toString()));
        } else {
            List<String> formats = new ArrayList<String>();
            if (resolver != null) {
                formats.add("A String or CharSequence task name or path");
                formats.add("A TaskReference instance");
            }
            formats.add("A Task instance");
            formats.add("A Buildable instance");
            formats.add("A TaskDependency instance");
            formats.add("A Closure instance that returns any of the above types");
            formats.add("A Callable instance that returns any of the above types");
            formats.add("An Iterable, Collection, Map or array instance that contains any of the above types");
            throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
        }
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:73,代碼來源:DefaultTaskDependency.java


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