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  /**
25   * This class encapsulates the idea of an inner class - it has methods that make it easy to generate inner classes.
26   *
27   * @author Jeff Butler
28   */
29  public class InnerClass extends AbstractJavaType {
30  
31      private final List<TypeParameter> typeParameters = new ArrayList<>();
32  
33      private @Nullable FullyQualifiedJavaType superClass;
34  
35      private boolean isAbstract;
36  
37      private final List<InitializationBlock> initializationBlocks = new ArrayList<>();
38  
39      private boolean isFinal;
40  
41      public InnerClass(FullyQualifiedJavaType type) {
42          super(type);
43      }
44  
45      public InnerClass(String type) {
46          super(type);
47      }
48  
49      public Optional<FullyQualifiedJavaType> getSuperClass() {
50          return Optional.ofNullable(superClass);
51      }
52  
53      public void setSuperClass(FullyQualifiedJavaType superClass) {
54          this.superClass = superClass;
55      }
56  
57      public void setSuperClass(String superClassType) {
58          this.superClass = new FullyQualifiedJavaType(superClassType);
59      }
60  
61      public List<TypeParameter> getTypeParameters() {
62          return this.typeParameters;
63      }
64  
65      public void addTypeParameter(TypeParameter typeParameter) {
66          this.typeParameters.add(typeParameter);
67      }
68  
69      public List<InitializationBlock> getInitializationBlocks() {
70          return initializationBlocks;
71      }
72  
73      public void addInitializationBlock(InitializationBlock initializationBlock) {
74          initializationBlocks.add(initializationBlock);
75      }
76  
77      public boolean isAbstract() {
78          return isAbstract;
79      }
80  
81      public void setAbstract(boolean isAbstract) {
82          this.isAbstract = isAbstract;
83      }
84  
85      public boolean isFinal() {
86          return isFinal;
87      }
88  
89      public void setFinal(boolean isFinal) {
90          this.isFinal = isFinal;
91      }
92  
93      public Method generateBasicConstructor() {
94          Method method = new Method(getType().getShortName());
95          method.setVisibility(JavaVisibility.PUBLIC);
96          method.setConstructor(true);
97          method.addBodyLine("super();"); //$NON-NLS-1$
98          return method;
99      }
100 }