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;
17
18 import org.mybatis.generator.api.dom.java.CompilationUnit;
19
20 public class GeneratedJavaFile extends GeneratedFile {
21 private final CompilationUnit compilationUnit;
22 private final boolean isMergeable;
23
24 public GeneratedJavaFile(CompilationUnit compilationUnit, String targetProject) {
25 this(compilationUnit, targetProject, true);
26 }
27
28 public GeneratedJavaFile(CompilationUnit compilationUnit, String targetProject, boolean isMergeable) {
29 super(targetProject);
30 this.compilationUnit = compilationUnit;
31 this.isMergeable = isMergeable;
32 }
33
34 @Override
35 public String getFileName() {
36 return compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"; //$NON-NLS-1$
37 }
38
39 @Override
40 public String getTargetPackage() {
41 return compilationUnit.getType().getPackageName();
42 }
43
44 /**
45 * Return the compilation unit created for this file. The compilation unit will be run through the
46 * Java formatter before it is written to disk.
47 *
48 * @return the CompilationUnit associated with this file.
49 */
50 public CompilationUnit getCompilationUnit() {
51 return compilationUnit;
52 }
53
54 /**
55 * A Java file is mergeable if the getCompilationUnit() method returns a valid compilation unit.
56 *
57 * @return true if this file is mergeable
58 */
59 @Override
60 public boolean isMergeable() {
61 return isMergeable;
62 }
63 }