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.ArrayList;
19  import java.util.List;
20  
21  public abstract class KotlinNamedItem {
22      private final String name;
23      private final List<KotlinModifier> modifiers = new ArrayList<>();
24      private final List<String> annotations = new ArrayList<>();
25  
26      protected KotlinNamedItem(AbstractBuilder<?> builder) {
27          name = builder.name;
28          modifiers.addAll(builder.modifiers);
29          annotations.addAll(builder.annotations);
30      }
31  
32      public String getName() {
33          return name;
34      }
35  
36      public List<KotlinModifier> getModifiers() {
37          return modifiers;
38      }
39  
40      public void addAnnotation(String annotation) {
41          annotations.add(annotation);
42      }
43  
44      public List<String> getAnnotations() {
45          return annotations;
46      }
47  
48      public abstract <R> R accept(KotlinNamedItemVisitor<R> visitor);
49  
50      public abstract static class AbstractBuilder<T extends AbstractBuilder<T>> {
51          private final String name;
52          private final List<KotlinModifier> modifiers = new ArrayList<>();
53          private final List<String> annotations = new ArrayList<>();
54  
55          protected AbstractBuilder(String name) {
56              this.name = name;
57          }
58  
59          public T withModifier(KotlinModifier modifier) {
60              modifiers.add(modifier);
61              return getThis();
62          }
63  
64          public T withAnnotation(String annotation) {
65              annotations.add(annotation);
66              return getThis();
67          }
68  
69          protected abstract T getThis();
70      }
71  }