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.Collection;
20  import java.util.List;
21  import java.util.Objects;
22  import java.util.Optional;
23  import java.util.Set;
24  import java.util.TreeSet;
25  
26  public class KotlinFile {
27      private final String fileName;
28      private final List<String> fileCommentLines = new ArrayList<>();
29      private final Set<String> imports = new TreeSet<>();
30      private String packageDefinition;
31      private final List<KotlinNamedItem> namedItems = new ArrayList<>();
32  
33      public KotlinFile(String fileName) {
34          Objects.requireNonNull(fileName);
35  
36          if (fileName.endsWith(".kt")) { //$NON-NLS-1$
37              this.fileName = fileName;
38          } else {
39              this.fileName = fileName + ".kt"; //$NON-NLS-1$
40          }
41      }
42  
43      public String getFileName() {
44          return fileName;
45      }
46  
47      public List<String> getFileCommentLines() {
48          return fileCommentLines;
49      }
50  
51      public void addFileCommentLine(String fileComentLine) {
52          fileCommentLines.add(fileComentLine);
53      }
54  
55      public Set<String> getImports() {
56          return imports;
57      }
58  
59      public void addImport(String i) {
60          imports.add(i);
61      }
62  
63      public void addImports(Collection<String> imports) {
64          this.imports.addAll(imports);
65      }
66  
67      public Optional<String> getPackage() {
68          return Optional.ofNullable(packageDefinition);
69      }
70  
71      public void setPackage(String p) {
72          this.packageDefinition = p;
73      }
74  
75      public void addNamedItem(KotlinNamedItem namedItem) {
76          namedItems.add(namedItem);
77      }
78  
79      public List<KotlinNamedItem> getNamedItems() {
80          return namedItems;
81      }
82  }