1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.codegen;
17
18 import java.util.List;
19 import java.util.Objects;
20
21 import org.jspecify.annotations.Nullable;
22 import org.mybatis.generator.api.CommentGenerator;
23 import org.mybatis.generator.api.IntrospectedTable;
24 import org.mybatis.generator.api.ProgressCallback;
25 import org.mybatis.generator.config.Context;
26 import org.mybatis.generator.internal.PluginAggregator;
27
28 public abstract class AbstractGenerator {
29 protected final Context context;
30 protected final IntrospectedTable introspectedTable;
31 protected final List<String> warnings;
32 protected final ProgressCallback progressCallback;
33 protected final CommentGenerator commentGenerator;
34 protected final PluginAggregator pluginAggregator;
35
36 protected AbstractGenerator(AbstractGeneratorBuilder<?> builder) {
37 this.context = Objects.requireNonNull(builder.context);
38 this.introspectedTable = Objects.requireNonNull(builder.introspectedTable);
39 this.warnings = Objects.requireNonNull(builder.warnings);
40 this.progressCallback = Objects.requireNonNull(builder.progressCallback);
41 this.commentGenerator = Objects.requireNonNull(builder.commentGenerator);
42 this.pluginAggregator = Objects.requireNonNull(builder.pluginAggregator);
43 }
44
45 protected <T extends AbstractGeneratorBuilder<T>> T initializeSubBuilder(T builder) {
46 return builder.withContext(context)
47 .withIntrospectedTable(introspectedTable)
48 .withWarnings(warnings)
49 .withProgressCallback(progressCallback)
50 .withCommentGenerator(commentGenerator)
51 .withPluginAggregator(pluginAggregator);
52 }
53
54 public abstract static class AbstractGeneratorBuilder<T extends AbstractGeneratorBuilder<T>> {
55 private @Nullable Context context;
56 private @Nullable IntrospectedTable introspectedTable;
57 private @Nullable List<String> warnings;
58 private @Nullable ProgressCallback progressCallback;
59 private @Nullable CommentGenerator commentGenerator;
60 private @Nullable PluginAggregator pluginAggregator;
61
62 public T withContext(Context context) {
63 this.context = context;
64 return getThis();
65 }
66
67 public T withIntrospectedTable(IntrospectedTable introspectedTable) {
68 this.introspectedTable = introspectedTable;
69 return getThis();
70 }
71
72 public T withWarnings(List<String> warnings) {
73 this.warnings = warnings;
74 return getThis();
75 }
76
77 public T withProgressCallback(ProgressCallback progressCallback) {
78 this.progressCallback = progressCallback;
79 return getThis();
80 }
81
82 public T withCommentGenerator(CommentGenerator commentGenerator) {
83 this.commentGenerator = commentGenerator;
84 return getThis();
85 }
86
87 public T withPluginAggregator(PluginAggregator pluginAggregator) {
88 this.pluginAggregator = pluginAggregator;
89 return getThis();
90 }
91
92 protected abstract T getThis();
93 }
94 }