• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DelegatesTo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中groovy.lang.DelegatesTo的典型用法代码示例。如果您正苦于以下问题:Java DelegatesTo类的具体用法?Java DelegatesTo怎么用?Java DelegatesTo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DelegatesTo类属于groovy.lang包,在下文中一共展示了DelegatesTo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:StreamingJsonBuilder.java


示例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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:17,代码来源:Ear.java


示例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;
}
 
开发者ID:rahulsom,项目名称:grooves,代码行数:27,代码来源:GroovyEventsDsl.java


示例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;
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:13,代码来源:MultipartContent.java


示例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 &mdash;
 * 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);
}
 
开发者ID:apache,项目名称:groovy,代码行数:51,代码来源:StreamingJsonBuilder.java


示例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();
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:StreamingJsonBuilder.java


示例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();
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:StreamingJsonBuilder.java


示例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));
                });
            }
        };
    }
 
开发者ID:jprante,项目名称:elasticsearch-plugin-ratpack,代码行数:33,代码来源:GroovyEmbeddedApp.java


示例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));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:7,代码来源:Pmd.java


示例10: beforeExecute

import groovy.lang.DelegatesTo; //导入依赖的package包/类
public void beforeExecute(@DelegatesTo(GradleExecuter.class) Closure action) {
    beforeExecute.add(new ClosureBackedAction<GradleExecuter>(action));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:4,代码来源:AbstractGradleExecuter.java


示例11: afterExecute

import groovy.lang.DelegatesTo; //导入依赖的package包/类
public void afterExecute(@DelegatesTo(GradleExecuter.class) Closure action) {
    afterExecute.add(new ClosureBackedAction<GradleExecuter>(action));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:4,代码来源:AbstractGradleExecuter.java


示例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);
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:StreamingJsonBuilder.java


示例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();
}
 
开发者ID:apache,项目名称:groovy,代码行数:4,代码来源:TreeContext.java


示例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));
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:TreeContext.java


示例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?");
}
 
开发者ID:apache,项目名称:groovy,代码行数:4,代码来源:MacroGroovyMethods.java


示例16: with

import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
 * Allows the closure to be called for the object reference self.
 * <p/>
 * Any method invoked inside the closure will first be invoked on the
 * self reference. For example, the following method calls to the append()
 * method are invoked on the StringBuilder instance and then, because
 * 'returning' is true, the self instance is returned:
 * <pre class="groovyTestCase">
 * def b = new StringBuilder().with(true) {
 *   append('foo')
 *   append('bar')
 * }
 * assert b.toString() == 'foobar'
 * </pre>
 * The returning parameter is commonly set to true when using with to simplify object
 * creation, such as this example:
 * <pre>
 * def p = new Person().with(true) {
 *   firstName = 'John'
 *   lastName = 'Doe'
 * }
 * </pre>
 * Alternatively, 'tap' is an alias for 'with(true)', so that method can be used instead.
 *
 * The other main use case for with is when returning a value calculated using self as shown here:
 * <pre>
 * def fullName = person.with(false){ "$firstName $lastName" }
 * </pre>
 * Alternatively, 'with' is an alias for 'with(false)', so the boolean parameter can be ommitted instead.
 *
 * @param self      the object to have a closure act upon
 * @param returning if true, return the self object; otherwise, the result of calling the closure
 * @param closure   the closure to call on the object
 * @return the self object or the result of calling the closure depending on 'returning'
 * @see #with(Object, Closure)
 * @see #tap(Object, Closure)
 * @since 2.5.0
 */
public static <T,U extends T, V extends T> T with(
        @DelegatesTo.Target("self") U self,
        boolean returning,
        @DelegatesTo(value=DelegatesTo.Target.class,
                target="self",
                strategy=Closure.DELEGATE_FIRST)
        @ClosureParams(FirstParam.class)
        Closure<T> closure) {
    @SuppressWarnings("unchecked")
    final Closure<V> clonedClosure = (Closure<V>) closure.clone();
    clonedClosure.setResolveStrategy(Closure.DELEGATE_FIRST);
    clonedClosure.setDelegate(self);
    V result = clonedClosure.call(self);
    return returning ? self : result;
}
 
开发者ID:apache,项目名称:groovy,代码行数:54,代码来源:DefaultGroovyMethods.java


示例17: author

import groovy.lang.DelegatesTo; //导入依赖的package包/类
public void author(@Nonnull @DelegatesTo(Person.class) Closure c) {
    Person person = new Person();
    ConfigureUtil.configure(c, person);
    // LOG.info("Adding author " + person);
    authors.add(person);
}
 
开发者ID:shevek,项目名称:gradle-stdproject-plugin,代码行数:7,代码来源:StdModuleExtension.java


示例18: configure

import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
 * Creates an `HttpBuilder` configured with the provided configuration closure, using the `defaultFactory` as the client factory.
 *
 * The configuration closure delegates to the {@link HttpObjectConfig} interface, which is an extension of the {@link HttpConfig} interface -
 * configuration properties from either may be applied to the global client configuration here. See the documentation for those interfaces for
 * configuration property details.
 *
 * [source,groovy]
 * ----
 * def factory = { c -> new ApacheHttpBuilder(c); } as Function
 *
 * def http = HttpBuilder.configure(factory){
 *     request.uri = 'http://localhost:10101'
 * }
 * ----
 *
 * @param factory the {@link HttpObjectConfig} factory function ({@link JavaHttpBuilder} or {@link groovyx.net.http.ApacheHttpBuilder})
 * @param closure the configuration closure (delegated to {@link HttpObjectConfig})
 * @return the configured `HttpBuilder`
 */
public static HttpBuilder configure(final Function<HttpObjectConfig, ? extends HttpBuilder> factory, @DelegatesTo(HttpObjectConfig.class) final Closure closure) {
    HttpObjectConfig impl = new HttpObjectConfigImpl();
    closure.setDelegate(impl);
    closure.setResolveStrategy(Closure.DELEGATE_FIRST);
    closure.call();
    return factory.apply(impl);
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:28,代码来源:HttpBuilder.java


示例19: identity

import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
 * Allows the closure to be called for the object reference self.
 * Synonym for 'with()'.
 *
 * @param self    the object to have a closure act upon
 * @param closure the closure to call on the object
 * @return result of calling the closure
 * @see #with(Object, Closure)
 * @since 1.0
 */
public static <T,U> T identity(
        @DelegatesTo.Target("self") U self,
        @DelegatesTo(value=DelegatesTo.Target.class,
                target="self",
                strategy=Closure.DELEGATE_FIRST)
        @ClosureParams(FirstParam.class)
                Closure<T> closure) {
    return DefaultGroovyMethods.with(self, closure);
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:DefaultGroovyMethods.java


示例20: tap

import groovy.lang.DelegatesTo; //导入依赖的package包/类
/**
 * Allows the closure to be called for the object reference self (similar
 * to <code>with</code> and always returns self.
 * <p>
 * Any method invoked inside the closure will first be invoked on the
 * self reference. For instance, the following method calls to the append()
 * method are invoked on the StringBuilder instance:
 * <pre>
 * def b = new StringBuilder().tap {
 *   append('foo')
 *   append('bar')
 * }
 * assert b.toString() == 'foobar'
 * </pre>
 * This is commonly used to simplify object creation, such as this example:
 * <pre>
 * def p = new Person().tap {
 *   firstName = 'John'
 *   lastName = 'Doe'
 * }
 * </pre>
 *
 * @param self    the object to have a closure act upon
 * @param closure the closure to call on the object
 * @return self
 * @see #with(Object, boolean, Closure)
 * @see #with(Object, Closure)
 * @since 2.5.0
 */
@SuppressWarnings("unchecked")
public static <T,U> U tap(
        @DelegatesTo.Target("self") U self,
        @DelegatesTo(value=DelegatesTo.Target.class,
                target="self",
                strategy=Closure.DELEGATE_FIRST)
        @ClosureParams(FirstParam.class)
        Closure<T> closure) {
    return (U) with(self, true, (Closure<Object>)closure);
}
 
开发者ID:apache,项目名称:groovy,代码行数:40,代码来源:DefaultGroovyMethods.java



注:本文中的groovy.lang.DelegatesTo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KickEvent类代码示例发布时间:2022-05-22
下一篇:
Java ProjectTemplate类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap