View Javadoc
1   /*
2    *    Copyright 2006-2026 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  import java.util.Optional;
21  
22  import org.jspecify.annotations.Nullable;
23  
24  public class Field extends JavaElement {
25      private FullyQualifiedJavaType type;
26      private String name;
27      private @Nullable String initializationString;
28      private boolean isTransient;
29      private boolean isVolatile;
30      private boolean isFinal;
31  
32      private final List<String> typeAnnotations = new ArrayList<>();
33  
34      public Field(String name, FullyQualifiedJavaType type) {
35          this.name = name;
36          this.type = type;
37      }
38  
39      public Field(Field field) {
40          super(field);
41          this.type = field.type;
42          this.name = field.name;
43          this.initializationString = field.initializationString;
44          this.isTransient = field.isTransient;
45          this.isVolatile = field.isVolatile;
46          this.isFinal = field.isFinal;
47      }
48  
49      public String getName() {
50          return name;
51      }
52  
53      public void setName(String name) {
54          this.name = name;
55      }
56  
57      public FullyQualifiedJavaType getType() {
58          return type;
59      }
60  
61      public void setType(FullyQualifiedJavaType type) {
62          this.type = type;
63      }
64  
65      public Optional<String> getInitializationString() {
66          return Optional.ofNullable(initializationString);
67      }
68  
69      public void setInitializationString(String initializationString) {
70          this.initializationString = initializationString;
71      }
72  
73      public boolean isTransient() {
74          return isTransient;
75      }
76  
77      public void setTransient(boolean isTransient) {
78          this.isTransient = isTransient;
79      }
80  
81      public boolean isVolatile() {
82          return isVolatile;
83      }
84  
85      public void setVolatile(boolean isVolatile) {
86          this.isVolatile = isVolatile;
87      }
88  
89      public boolean isFinal() {
90          return isFinal;
91      }
92  
93      public void setFinal(boolean isFinal) {
94          this.isFinal = isFinal;
95      }
96  
97      public List<String> getTypeAnnotations() {
98          return typeAnnotations;
99      }
100 
101     public void addTypeAnnotation(String annotation) {
102         typeAnnotations.add(annotation);
103     }
104 }