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.java;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Set;
21  import java.util.TreeSet;
22  
23  public class TopLevelEnumeration extends InnerEnum implements CompilationUnit {
24  
25      private final Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>();
26  
27      private final Set<String> staticImports = new TreeSet<>();
28  
29      private final List<String> fileCommentLines = new ArrayList<>();
30  
31      public TopLevelEnumeration(FullyQualifiedJavaType type) {
32          super(type);
33      }
34  
35      public TopLevelEnumeration(String type) {
36          super(type);
37      }
38  
39      @Override
40      public Set<FullyQualifiedJavaType> getImportedTypes() {
41          return importedTypes;
42      }
43  
44      @Override
45      public void addImportedType(FullyQualifiedJavaType importedType) {
46          if (importedType.isExplicitlyImported()
47                  && !importedType.getPackageName().equals(
48                          getType().getPackageName())) {
49              importedTypes.add(importedType);
50          }
51      }
52  
53      @Override
54      public void addFileCommentLine(String commentLine) {
55          fileCommentLines.add(commentLine);
56      }
57  
58      @Override
59      public List<String> getFileCommentLines() {
60          return fileCommentLines;
61      }
62  
63      @Override
64      public void addImportedTypes(Set<FullyQualifiedJavaType> importedTypes) {
65          this.importedTypes.addAll(importedTypes);
66      }
67  
68      @Override
69      public Set<String> getStaticImports() {
70          return staticImports;
71      }
72  
73      @Override
74      public void addStaticImport(String staticImport) {
75          staticImports.add(staticImport);
76      }
77  
78      @Override
79      public void addStaticImports(Set<String> staticImports) {
80          this.staticImports.addAll(staticImports);
81      }
82  
83      @Override
84      public <R> R accept(CompilationUnitVisitor<R> visitor) {
85          return visitor.visit(this);
86      }
87  }