1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.api.dom.java;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21
22
23
24 public class Parameter {
25 private String name;
26 private FullyQualifiedJavaType type;
27 private boolean isVarargs;
28
29 private List<String> annotations;
30
31 public Parameter(FullyQualifiedJavaType type, String name, boolean isVarargs) {
32 super();
33 this.name = name;
34 this.type = type;
35 this.isVarargs = isVarargs;
36 annotations = new ArrayList<String>();
37 }
38
39 public Parameter(FullyQualifiedJavaType type, String name) {
40 this(type, name, false);
41 }
42
43 public Parameter(FullyQualifiedJavaType type, String name, String annotation) {
44 this(type, name, false);
45 addAnnotation(annotation);
46 }
47
48 public Parameter(FullyQualifiedJavaType type, String name, String annotation, boolean isVarargs) {
49 this(type, name, isVarargs);
50 addAnnotation(annotation);
51 }
52
53
54
55
56 public String getName() {
57 return name;
58 }
59
60
61
62
63 public FullyQualifiedJavaType getType() {
64 return type;
65 }
66
67 public List<String> getAnnotations() {
68 return annotations;
69 }
70
71 public void addAnnotation(String annotation) {
72 annotations.add(annotation);
73 }
74
75 public String getFormattedContent(CompilationUnit compilationUnit) {
76 StringBuilder sb = new StringBuilder();
77
78 for (String annotation : annotations) {
79 sb.append(annotation);
80 sb.append(' ');
81 }
82
83 sb.append(JavaDomUtils.calculateTypeName(compilationUnit, type));
84
85 sb.append(' ');
86 if (isVarargs) {
87 sb.append("... ");
88 }
89 sb.append(name);
90
91 return sb.toString();
92 }
93
94 @Override
95 public String toString() {
96 return getFormattedContent(null);
97 }
98
99 public boolean isVarargs() {
100 return isVarargs;
101 }
102 }