本文整理汇总了Java中groovy.lang.DelegatesTo类的典型用法代码示例。如果您正苦于以下问题:Java DelegatesTo类的具体用法?Java DelegatesTo怎么用?Java DelegatesTo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DelegatesTo类属于groovy.lang包,在下文中一共展示了DelegatesTo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeCollectionWithClosure
import groovy.lang.DelegatesTo; //导入依赖的package包/类
private static Object writeCollectionWithClosure(Writer writer, Iterable coll, @DelegatesTo(StreamingJsonDelegate.class) Closure closure, JsonGenerator generator)
throws IOException {
writer.write(JsonOutput.OPEN_BRACKET);
boolean first = true;
for (Object it : coll) {
if (!first) {
writer.write(JsonOutput.COMMA);
} else {
first = false;
}
writeObject(writer, it, closure, generator);
}
writer.write(JsonOutput.CLOSE_BRACKET);
return writer;
}
示例2: deploymentDescriptor
import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
* Configures the deployment descriptor for this EAR archive.
*
* <p>The given closure is executed to configure the deployment descriptor. The {@link DeploymentDescriptor} is passed to the closure as its delegate.</p>
*
* @param configureClosure The closure.
* @return This.
*/
public Ear deploymentDescriptor(@DelegatesTo(value = DeploymentDescriptor.class, strategy = Closure.DELEGATE_FIRST) Closure configureClosure) {
if (deploymentDescriptor == null) {
deploymentDescriptor = getInstantiator().newInstance(DefaultDeploymentDescriptor.class, getFileResolver(), getInstantiator());
}
ConfigureUtil.configure(configureClosure, deploymentDescriptor);
return this;
}
示例3: on
import groovy.lang.DelegatesTo; //导入依赖的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;
}
示例4: multipart
import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
* Configures multipart request content using a Groovy closure (delegated to {@link MultipartContent}).
*
* @param closure the configuration closure
* @return a configured instance of {@link MultipartContent}
*/
public static MultipartContent multipart(@DelegatesTo(MultipartContent.class) Closure closure) {
MultipartContent content = new MultipartContent();
closure.setDelegate(content);
closure.call();
return content;
}
示例5: call
import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
* If you use named arguments and a closure as last argument,
* the key/value pairs of the map (as named arguments)
* and the key/value pairs represented in the closure
* will be merged together —
* the closure properties overriding the map key/values
* in case the same key is used.
*
* <pre class="groovyTestCase">
* new StringWriter().with { w ->
* def json = new groovy.json.StreamingJsonBuilder(w)
* json.person(name: "Tim", age: 35) { town "Manchester" }
*
* assert w.toString() == '{"person":{"name":"Tim","age":35,"town":"Manchester"}}'
* }
* </pre>
*
* @param name The name of the JSON object
* @param map The attributes of the JSON object
* @param callable Additional attributes of the JSON object represented by the closure
* @throws IOException
*/
public void call(String name, Map map, @DelegatesTo(StreamingJsonDelegate.class) Closure callable) throws IOException {
writer.write(JsonOutput.OPEN_BRACE);
writer.write(generator.toJson(name));
writer.write(COLON_WITH_OPEN_BRACE);
boolean first = true;
for (Object it : map.entrySet()) {
if (!first) {
writer.write(JsonOutput.COMMA);
} else {
first = false;
}
Map.Entry entry = (Map.Entry) it;
String key = entry.getKey().toString();
if (generator.isExcludingFieldsNamed(key)) {
continue;
}
Object value = entry.getValue();
if (generator.isExcludingValues(value)) {
return;
}
writer.write(generator.toJson(key));
writer.write(JsonOutput.COLON);
writer.write(generator.toJson(value));
}
StreamingJsonDelegate.cloneDelegateAndGetContent(writer, callable, map.size() == 0, generator);
writer.write(DOUBLE_CLOSE_BRACKET);
}
示例6: cloneDelegateAndGetContent
import groovy.lang.DelegatesTo; //导入依赖的package包/类
private static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(StreamingJsonDelegate.class) Closure c, boolean first, JsonGenerator generator) {
StreamingJsonDelegate delegate = new StreamingJsonDelegate(w, first, generator);
Closure cloned = (Closure) c.clone();
cloned.setDelegate(delegate);
cloned.setResolveStrategy(Closure.DELEGATE_FIRST);
cloned.call();
}
示例7: curryDelegateAndGetContent
import groovy.lang.DelegatesTo; //导入依赖的package包/类
private static void curryDelegateAndGetContent(Writer w, @DelegatesTo(StreamingJsonDelegate.class) Closure c, Object o, boolean first, JsonGenerator generator) {
StreamingJsonDelegate delegate = new StreamingJsonDelegate(w, first, generator);
Closure curried = c.curry(o);
curried.setDelegate(delegate);
curried.setResolveStrategy(Closure.DELEGATE_FIRST);
curried.call();
}
示例8: build
import groovy.lang.DelegatesTo; //导入依赖的package包/类
public static EmbeddedApp build(@DelegatesTo(value = Spec.class, strategy = Closure.DELEGATE_FIRST) Closure<?> closure) {
return new LaunchConfigEmbeddedApp() {
@Override
protected LaunchConfig createLaunchConfig() {
final SpecWrapper spec = new SpecWrapper();
configureDelegateFirst(spec.getSpec(), closure);
LaunchConfigBuilder launchConfigBuilder;
if (spec.baseDirSupplier != null) {
Path baseDirPath = spec.baseDirSupplier.get();
launchConfigBuilder = LaunchConfigBuilder.baseDir(baseDirPath);
} else {
launchConfigBuilder = LaunchConfigBuilder.noBaseDir();
}
configureDelegateFirst(launchConfigBuilder.port(0), spec.launchConfig);
final Action<? super BindingsSpec> bindingsAction = bindingsSpec -> configureDelegateFirst(new DefaultGroovyBindingsSpec(bindingsSpec), spec.bindings);
return launchConfigBuilder.build(launchConfig -> {
Guice.Builder builder = Guice.builder(launchConfig);
if (spec.parentInjector != null) {
builder.parent(spec.parentInjector);
}
return builder.bindings(bindingsAction).build(chain -> Groovy.chain(chain, spec.handlers));
});
}
};
}
示例9: reports
import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
* Configures the reports to be generated by this task.
*/
public PmdReports reports(@DelegatesTo(value = PmdReports.class, strategy = Closure.DELEGATE_FIRST) Closure closure) {
return reports(new ClosureBackedAction<PmdReports>(closure));
}
示例10: beforeExecute
import groovy.lang.DelegatesTo; //导入依赖的package包/类
public void beforeExecute(@DelegatesTo(GradleExecuter.class) Closure action) {
beforeExecute.add(new ClosureBackedAction<GradleExecuter>(action));
}
示例11: afterExecute
import groovy.lang.DelegatesTo; //导入依赖的package包/类
public void afterExecute(@DelegatesTo(GradleExecuter.class) Closure action) {
afterExecute.add(new ClosureBackedAction<GradleExecuter>(action));
}
示例12: writeObjects
import groovy.lang.DelegatesTo; //导入依赖的package包/类
private void writeObjects(Iterable coll, @DelegatesTo(StreamingJsonDelegate.class) Closure c) throws IOException {
verifyValue();
writeCollectionWithClosure(writer, coll, c, generator);
}
示例13: matches
import groovy.lang.DelegatesTo; //导入依赖的package包/类
public boolean matches(@DelegatesTo(value=ASTNode.class, strategy=Closure.DELEGATE_FIRST) Closure<Boolean> predicate) {
return MatcherUtils.cloneWithDelegate(predicate, node).call();
}
示例14: afterVisit
import groovy.lang.DelegatesTo; //导入依赖的package包/类
public void afterVisit(@DelegatesTo(value=TreeContext.class, strategy=Closure.DELEGATE_FIRST) Closure<?> action) {
Closure<?> clone = MatcherUtils.cloneWithDelegate(action, this);
afterVisit(DefaultGroovyMethods.asType(clone, TreeContextAction.class));
}
示例15: macro
import groovy.lang.DelegatesTo; //导入依赖的package包/类
public static <T> T macro(Object self, @DelegatesTo(MacroValuePlaceholder.class) Closure cl) {
throw new IllegalStateException("MacroGroovyMethods.macro(Closure) should never be called at runtime. Are you sure you are using it correctly?");
}