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.kotlin;
17  
18  import java.util.Objects;
19  import java.util.Optional;
20  
21  public class KotlinProperty extends KotlinNamedItem {
22  
23      private final String dataType;
24      private final String initializationString;
25      private final Type type;
26  
27      public enum Type {
28          VAL("val"), //$NON-NLS-1$
29          VAR("var"); //$NON-NLS-1$
30  
31          private final String value;
32  
33          Type(String value) {
34              this.value = value;
35          }
36  
37          public String getValue() {
38              return value;
39          }
40      }
41  
42      private KotlinProperty(Builder builder) {
43          super(builder);
44          dataType = builder.dataType;
45          initializationString = builder.initializationString;
46          type = Objects.requireNonNull(builder.type);
47      }
48  
49      public Optional<String> getInitializationString() {
50          return Optional.ofNullable(initializationString);
51      }
52  
53      public Optional<String> getDataType() {
54          return Optional.ofNullable(dataType);
55      }
56  
57      public Type getType() {
58          return type;
59      }
60  
61      @Override
62      public <R> R accept(KotlinNamedItemVisitor<R> visitor) {
63          return visitor.visit(this);
64      }
65  
66      public static Builder newVal(String name) {
67          return new Builder(Type.VAL, name);
68      }
69  
70      public static Builder newVar(String name) {
71          return new Builder(Type.VAR, name);
72      }
73  
74      public static class Builder extends AbstractBuilder<Builder> {
75          private String dataType;
76          private String initializationString;
77          private final Type type;
78  
79          private Builder(Type type, String name) {
80              super(name);
81              this.type = type;
82          }
83  
84          public Builder withInitializationString(String initializationString) {
85              this.initializationString = initializationString;
86              return this;
87          }
88  
89          public Builder withDataType(String dataType) {
90              this.dataType = dataType;
91              return this;
92          }
93  
94          public Builder getThis() {
95              return this;
96          }
97  
98          public KotlinProperty build() {
99              return new KotlinProperty(this);
100         }
101     }
102 }