groovy.lang.DelegatesTo Java Examples
The following examples show how to use
groovy.lang.DelegatesTo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectDsl.java From jira-groovioli with BSD 2-Clause "Simplified" License | 6 votes |
public Project findProject(@DelegatesTo(FindProjectHandler.class) Closure closure) { FindProjectHandler findProjectHandler = new FindProjectHandler(); closure.setDelegate(findProjectHandler); closure.call(); if (!findProjectHandler.isValid()) { throw new ScriptDslException("Invalid parameters for findProject"); } ProjectManager projectManager = (ProjectManager) closure.getProperty("projectManager"); if (StringUtils.isNotBlank(findProjectHandler.key)) { return projectManager.getProjectObjByKey(findProjectHandler.key); } else { return projectManager.getProjectObjByName(findProjectHandler.name); } }
Example #2
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 5 votes |
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(); }
Example #4
Source File: ConstantDsl.java From jira-groovioli with BSD 2-Clause "Simplified" License | 5 votes |
public IssueType findIssueType(@DelegatesTo(FindIssueTypeHandler.class) Closure closure) { FindIssueTypeHandler findIssueTypeHandler = new FindIssueTypeHandler(); closure.setDelegate(findIssueTypeHandler); closure.call(); ConstantsManager constantsManager = (ConstantsManager) closure.getProperty("constantsManager"); Collection<IssueType> allIssueTypeObjects = constantsManager.getAllIssueTypeObjects(); for (IssueType issueType : allIssueTypeObjects) { if (issueType.getName().equals(findIssueTypeHandler.name)) { return issueType; } } return null; }
Example #5
Source File: MultipartContent.java From http-builder-ng with Apache License 2.0 | 5 votes |
/** * 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; }
Example #6
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 5 votes |
/** * Writes the name and another JSON object * * @param name The attribute name * @param value The value * @throws IOException */ public void call(String name,@DelegatesTo(StreamingJsonDelegate.class) Closure value) throws IOException { if (generator.isExcludingFieldsNamed(name)) { return; } writeName(name); verifyValue(); writer.write(JsonOutput.OPEN_BRACE); StreamingJsonDelegate.cloneDelegateAndGetContent(writer, value, true, generator); writer.write(JsonOutput.CLOSE_BRACE); }
Example #7
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 5 votes |
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(); }
Example #8
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 5 votes |
/** * 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 {@code ->} * 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); }
Example #9
Source File: Response.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * @deprecated Deprecated in favor of bodyMatchers to support other future * bodyMatchers too * @param consumer function to manipulate the URL */ @Deprecated public void testMatchers(@DelegatesTo(ResponseBodyMatchers.class) Closure consumer) { log.warn("testMatchers method is deprecated. Please use bodyMatchers instead"); bodyMatchers(consumer); }
Example #10
Source File: Contract.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * The input part of the contract. * @param consumer function to manipulate the input */ public void input(@DelegatesTo(Input.class) Closure consumer) { this.input = new Input(); consumer.setDelegate(this.input); consumer.call(); }
Example #11
Source File: MacroGroovyMethods.java From groovy with Apache License 2.0 | 4 votes |
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?"); }
Example #12
Source File: Contract.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * The HTTP request part of the contract. * @param consumer function to manipulate the request */ public void request(@DelegatesTo(Request.class) Closure consumer) { this.request = new Request(); consumer.setDelegate(this.request); consumer.call(); }
Example #13
Source File: Url.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * The query parameters part of the contract. * @param consumer function to manipulate the query parameters */ public void queryParameters(@DelegatesTo(QueryParameters.class) Closure consumer) { this.queryParameters = new QueryParameters(); consumer.setDelegate(this.queryParameters); consumer.call(); }
Example #14
Source File: Response.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * Allows to configure HTTP cookies. * @param consumer function to manipulate the URL */ public void cookies(@DelegatesTo(Cookies.class) Closure consumer) { this.cookies = new Response.ResponseCookies(); consumer.setDelegate(this.cookies); consumer.call(); }
Example #15
Source File: Request.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * Allows to set matchers for the body. * @param consumer function to manipulate the URL */ public void bodyMatchers(@DelegatesTo(BodyMatchers.class) Closure consumer) { this.bodyMatchers = new BodyMatchers(); consumer.setDelegate(this.bodyMatchers); consumer.call(); }
Example #16
Source File: Response.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * Allows to set matchers for the body. * @param consumer function to manipulate the URL */ public void bodyMatchers(@DelegatesTo(ResponseBodyMatchers.class) Closure consumer) { this.bodyMatchers = new ResponseBodyMatchers(); consumer.setDelegate(this.bodyMatchers); consumer.call(); }
Example #17
Source File: Response.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * Allows to configure HTTP headers. * @param consumer function to manipulate the URL */ public void headers(@DelegatesTo(Headers.class) Closure consumer) { this.headers = new Response.ResponseHeaders(); consumer.setDelegate(this.headers); consumer.call(); }
Example #18
Source File: MacroGroovyMethods.java From groovy with Apache License 2.0 | 4 votes |
public static <T> T macro(Object self, boolean asIs, @DelegatesTo(MacroValuePlaceholder.class) Closure cl) { throw new IllegalStateException("MacroGroovyMethods.macro(boolean, Closure) should never be called at runtime. Are you sure you are using it correctly?"); }
Example #19
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
public static void curryDelegateAndGetContent(Writer w, @DelegatesTo(StreamingJsonDelegate.class) Closure c, Object o, boolean first) { curryDelegateAndGetContent(w, c, o, first, JsonOutput.DEFAULT_GENERATOR); }
Example #20
Source File: Contract.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
/** * The output part of the contract. * @param consumer function to manipulate the output message */ public void outputMessage(@DelegatesTo(OutputMessage.class) Closure consumer) { this.outputMessage = new OutputMessage(); consumer.setDelegate(this.outputMessage); consumer.call(); }
Example #21
Source File: MacroGroovyMethods.java From groovy with Apache License 2.0 | 4 votes |
public static <T> T macro(Object self, CompilePhase compilePhase, boolean asIs, @DelegatesTo(MacroValuePlaceholder.class) Closure cl) { throw new IllegalStateException("MacroGroovyMethods.macro(CompilePhase, boolean, Closure) should never be called at runtime. Are you sure you are using it correctly?"); }
Example #22
Source File: TreeContext.java From groovy with Apache License 2.0 | 4 votes |
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)); }
Example #23
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
/** * Delegates to {@link #call(Iterable, Closure)} */ public Object call(Collection coll, @DelegatesTo(StreamingJsonDelegate.class) Closure c) throws IOException { return call((Iterable)coll, c); }
Example #24
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
/** * Delegates to {@link #call(String, Iterable, Closure)} */ public void call(String name, Collection coll, @DelegatesTo(StreamingJsonDelegate.class) Closure c) throws IOException { call(name, (Iterable)coll, c); }
Example #25
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
/** * Delegates to {@link #call(String, Iterable, Closure)} */ public void call(String name, Collection coll, @DelegatesTo(StreamingJsonDelegate.class) Closure c) throws IOException { call(name, (Iterable)coll, c); }
Example #26
Source File: TreeContext.java From groovy with Apache License 2.0 | 4 votes |
public boolean matches(@DelegatesTo(value=ASTNode.class, strategy=Closure.DELEGATE_FIRST) Closure<Boolean> predicate) { return MatcherUtils.cloneWithDelegate(predicate, node).call(); }
Example #27
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
private void writeObjects(Iterable coll, @DelegatesTo(StreamingJsonDelegate.class) Closure c) throws IOException { verifyValue(); writeCollectionWithClosure(writer, coll, c, generator); }
Example #28
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
public static Object writeCollectionWithClosure(Writer writer, Collection coll, @DelegatesTo(StreamingJsonDelegate.class) Closure closure) throws IOException { return writeCollectionWithClosure(writer, (Iterable)coll, closure, JsonOutput.DEFAULT_GENERATOR); }
Example #29
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
public static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(StreamingJsonDelegate.class) Closure c) { cloneDelegateAndGetContent(w, c, true); }
Example #30
Source File: StreamingJsonBuilder.java From groovy with Apache License 2.0 | 4 votes |
public static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(StreamingJsonDelegate.class) Closure c, boolean first) { cloneDelegateAndGetContent(w, c, first, JsonOutput.DEFAULT_GENERATOR); }