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.api.dom.java;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.mybatis.generator.api.dom.java.render.ParameterRenderer;
22  
23  public class Parameter {
24      private final String name;
25      private final FullyQualifiedJavaType type;
26      private final boolean isVarargs;
27  
28      private final List<String> annotations = new ArrayList<>();
29  
30      public Parameter(FullyQualifiedJavaType type, String name, boolean isVarargs) {
31          this.name = name;
32          this.type = type;
33          this.isVarargs = isVarargs;
34      }
35  
36      public Parameter(FullyQualifiedJavaType type, String name) {
37          this(type, name, false);
38      }
39  
40      public Parameter(FullyQualifiedJavaType type, String name, String annotation) {
41          this(type, name, false);
42          addAnnotation(annotation);
43      }
44  
45      public Parameter(FullyQualifiedJavaType type, String name, String annotation, boolean isVarargs) {
46          this(type, name, isVarargs);
47          addAnnotation(annotation);
48      }
49  
50      public String getName() {
51          return name;
52      }
53  
54      public FullyQualifiedJavaType getType() {
55          return type;
56      }
57  
58      public List<String> getAnnotations() {
59          return annotations;
60      }
61  
62      public void addAnnotation(String annotation) {
63          annotations.add(annotation);
64      }
65  
66      @Override
67      public String toString() {
68          return new ParameterRenderer().render(this, null);
69      }
70  
71      public boolean isVarargs() {
72          return isVarargs;
73      }
74  }