View Javadoc
1   /*
2    *    Copyright 2006-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.runtime.kotlin.elements;
17  
18  import java.util.ArrayList;
19  import java.util.HashSet;
20  import java.util.List;
21  import java.util.Set;
22  
23  import org.mybatis.generator.api.dom.kotlin.KotlinArg;
24  
25  public class KotlinFunctionParts {
26  
27      private final List<String> annotations;
28      private final List<String> codeLines;
29      private final Set<String> imports;
30      private final List<KotlinArg> arguments;
31  
32      private KotlinFunctionParts(Builder builder) {
33          imports = builder.imports;
34          codeLines = builder.codeLines;
35          arguments = builder.arguments;
36          annotations = builder.annotations;
37      }
38  
39      public Set<String> getImports() {
40          return imports;
41      }
42  
43      public List<String> getAnnotations() {
44          return annotations;
45      }
46  
47      public List<String> getCodeLines() {
48          return codeLines;
49      }
50  
51      public List<KotlinArg> getArguments() {
52          return arguments;
53      }
54  
55      public static class Builder {
56          private final List<String> codeLines = new ArrayList<>();
57          private final Set<String> imports = new HashSet<>();
58          private final List<KotlinArg> arguments = new ArrayList<>();
59          private final List<String> annotations = new ArrayList<>();
60  
61          public Builder withAnnotation(String annotation) {
62              annotations.add(annotation);
63              return this;
64          }
65  
66          public Builder withCodeLine(String codeLine) {
67              this.codeLines.add(codeLine);
68              return this;
69          }
70  
71          public Builder withImport(String im) {
72              this.imports.add(im);
73              return this;
74          }
75  
76          public Builder withImports(Set<String> imports) {
77              this.imports.addAll(imports);
78              return this;
79          }
80  
81          public Builder withArgument(KotlinArg argument) {
82              arguments.add(argument);
83              return this;
84          }
85  
86          public KotlinFunctionParts build() {
87              return new KotlinFunctionParts(this);
88          }
89      }
90  }