本文整理匯總了Java中groovy.lang.Closure.setResolveStrategy方法的典型用法代碼示例。如果您正苦於以下問題:Java Closure.setResolveStrategy方法的具體用法?Java Closure.setResolveStrategy怎麽用?Java Closure.setResolveStrategy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類groovy.lang.Closure
的用法示例。
在下文中一共展示了Closure.setResolveStrategy方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: invokeMethod
import groovy.lang.Closure; //導入方法依賴的package包/類
@Override
public void invokeMethod(String name, InvokeMethodResult result, Object... arguments) {
super.invokeMethod(name, result, arguments);
if (result.isFound()) {
return;
}
GetPropertyResult propertyLookup = new GetPropertyResult();
getProperty(name, propertyLookup);
if (propertyLookup.isFound()) {
Object property = propertyLookup.getValue();
if (property instanceof Closure) {
Closure closure = (Closure) property;
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
BeanDynamicObject dynamicObject = new BeanDynamicObject(closure);
dynamicObject.invokeMethod("doCall", result, arguments);
if (!result.isFound() && !(closure instanceof GeneratedClosure)) {
result.result(closure.call(arguments));
}
}
}
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}