1 /**
2 * Copyright 2006-2016 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 * http://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.OutputUtilities;
22
23 /**
24 * The Class JavaElement.
25 *
26 * @author Jeff Butler
27 */
28 public abstract class JavaElement {
29
30 /** The java doc lines. */
31 private List<String> javaDocLines;
32
33 /** The visibility. */
34 private JavaVisibility visibility = JavaVisibility.DEFAULT;
35
36 /** The is static. */
37 private boolean isStatic;
38
39 /** The is final. */
40 private boolean isFinal;
41
42 /** The annotations. */
43 private List<String> annotations;
44
45 /**
46 * Instantiates a new java element.
47 */
48 public JavaElement() {
49 super();
50 javaDocLines = new ArrayList<String>();
51 annotations = new ArrayList<String>();
52 }
53
54 /**
55 * Copy Constructor.
56 *
57 * @param original
58 * the original
59 */
60 public JavaElement(JavaElement original) {
61 this();
62 this.annotations.addAll(original.annotations);
63 this.isFinal = original.isFinal;
64 this.isStatic = original.isFinal;
65 this.javaDocLines.addAll(original.javaDocLines);
66 this.visibility = original.visibility;
67 }
68
69 /**
70 * Gets the java doc lines.
71 *
72 * @return Returns the javaDocLines.
73 */
74 public List<String> getJavaDocLines() {
75 return javaDocLines;
76 }
77
78 /**
79 * Adds the java doc line.
80 *
81 * @param javaDocLine
82 * the java doc line
83 */
84 public void addJavaDocLine(String javaDocLine) {
85 javaDocLines.add(javaDocLine);
86 }
87
88 /**
89 * Gets the annotations.
90 *
91 * @return the annotations
92 */
93 public List<String> getAnnotations() {
94 return annotations;
95 }
96
97 /**
98 * Adds the annotation.
99 *
100 * @param annotation
101 * the annotation
102 */
103 public void addAnnotation(String annotation) {
104 annotations.add(annotation);
105 }
106
107 /**
108 * Gets the visibility.
109 *
110 * @return Returns the visibility.
111 */
112 public JavaVisibility getVisibility() {
113 return visibility;
114 }
115
116 /**
117 * Sets the visibility.
118 *
119 * @param visibility
120 * The visibility to set.
121 */
122 public void setVisibility(JavaVisibility visibility) {
123 this.visibility = visibility;
124 }
125
126 /**
127 * Adds the suppress type warnings annotation.
128 */
129 public void addSuppressTypeWarningsAnnotation() {
130 addAnnotation("@SuppressWarnings(\"unchecked\")"); //$NON-NLS-1$
131 }
132
133 /**
134 * Adds the formatted javadoc.
135 *
136 * @param sb
137 * the sb
138 * @param indentLevel
139 * the indent level
140 */
141 public void addFormattedJavadoc(StringBuilder sb, int indentLevel) {
142 for (String javaDocLine : javaDocLines) {
143 OutputUtilities.javaIndent(sb, indentLevel);
144 sb.append(javaDocLine);
145 OutputUtilities.newLine(sb);
146 }
147 }
148
149 /**
150 * Adds the formatted annotations.
151 *
152 * @param sb
153 * the sb
154 * @param indentLevel
155 * the indent level
156 */
157 public void addFormattedAnnotations(StringBuilder sb, int indentLevel) {
158 for (String annotation : annotations) {
159 OutputUtilities.javaIndent(sb, indentLevel);
160 sb.append(annotation);
161 OutputUtilities.newLine(sb);
162 }
163 }
164
165 /**
166 * Checks if is final.
167 *
168 * @return true, if is final
169 */
170 public boolean isFinal() {
171 return isFinal;
172 }
173
174 /**
175 * Sets the final.
176 *
177 * @param isFinal
178 * the new final
179 */
180 public void setFinal(boolean isFinal) {
181 this.isFinal = isFinal;
182 }
183
184 /**
185 * Checks if is static.
186 *
187 * @return true, if is static
188 */
189 public boolean isStatic() {
190 return isStatic;
191 }
192
193 /**
194 * Sets the static.
195 *
196 * @param isStatic
197 * the new static
198 */
199 public void setStatic(boolean isStatic) {
200 this.isStatic = isStatic;
201 }
202 }