Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package groovy.transform.builder;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.ConstructorNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.ast.InnerClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.transform.BuilderASTTransformation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
import static org.codehaus.groovy.ast.tools.GeneralUtils.assignX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.constX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.declS;
import static org.codehaus.groovy.ast.tools.GeneralUtils.getInstancePropertyFields;
import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
import static org.codehaus.groovy.ast.tools.GenericsUtils.correctToGenericsSpecRecurse;
import static org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec;
import static org.codehaus.groovy.ast.tools.GenericsUtils.extractSuperClassGenerics;
import static org.codehaus.groovy.ast.tools.GenericsUtils.newClass;
import static org.codehaus.groovy.transform.AbstractASTTransformation.getMemberStringValue;
import static org.codehaus.groovy.transform.AbstractASTTransformation.shouldSkip;
import static org.codehaus.groovy.transform.BuilderASTTransformation.NO_EXCEPTIONS;
import static org.codehaus.groovy.transform.BuilderASTTransformation.NO_PARAMS;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
/**
* This strategy is used with the {@link Builder} AST transform to create a builder helper class
* for the fluent creation of instances of a specified class. It can be used at the class,
* static method or constructor levels.
*
* You use it as follows:
*
* import groovy.transform.builder.*
*
* {@code @Builder}
* class Person {
* String firstName
* String lastName
* int age
* }
* def person = Person.builder().firstName("Robert").lastName("Lewandowski").age(21).build()
* assert person.firstName == "Robert"
* assert person.lastName == "Lewandowski"
* assert person.age == 21
*
* The {@code prefix} annotation attribute can be used to create setters with a different naming convention. The default is the
* empty string but you could change that to "set" as follows:
*
* {@code @groovy.transform.builder.Builder}(prefix='set')
* class Person {
* String firstName
* String lastName
* int age
* }
* def p2 = Person.builder().setFirstName("Robert").setLastName("Lewandowski").setAge(21).build()
*
* or using a prefix of 'with' would result in usage like this:
*
*
* You can also use the {@code @Builder} annotation in combination with this strategy on one or more constructor or
* static method instead of or in addition to using it at the class level. An example with a constructor follows:
*
* import groovy.transform.ToString
* import groovy.transform.builder.Builder
*
* {@code @ToString}
* class Person {
* String first, last
* int born
*
* {@code @Builder}
* Person(String roleName) {
* if (roleName == 'Jack Sparrow') {
* first = 'Johnny'; last = 'Depp'; born = 1963
* }
* }
* }
* assert Person.builder().roleName("Jack Sparrow").build().toString() == 'Person(Johnny, Depp, 1963)'
*
* In this case, the parameter(s) for the constructor or static method become the properties available
* in the builder. For the case of a static method, the return type of the static method becomes the
* class of the instance being created. For static factory methods, this is normally the class containing the
* static method but in general it can be any class.
*
* Note: if using more than one {@code @Builder} annotation, which is only possible when using static method
* or constructor variants, it is up to you to ensure that any generated helper classes or builder methods
* have unique names. E.g. we can modify the previous example to have three builders. At least two of the builders
* in our case will need to set the 'builderClassName' and 'builderMethodName' annotation attributes to ensure
* we have unique names. This is shown in the following example:
*