• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / generator / 2212

14 May 2026 03:01PM UTC coverage: 91.803% (-0.04%) from 91.84%
2212

Pull #1514

github

web-flow
Merge f807ae416 into 66161b118
Pull Request #1514: Allow Configuration for the Java Merger

2519 of 3223 branches covered (78.16%)

311 of 325 new or added lines in 24 files covered. (95.69%)

11 existing lines in 4 files now uncovered.

12208 of 13298 relevant lines covered (91.8%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/merge/java/JavaMergerFactory.java
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.merge.java;
17

18
import com.github.javaparser.printer.DefaultPrettyPrinter;
19
import com.github.javaparser.printer.Printer;
20
import com.github.javaparser.printer.configuration.ImportOrderingStrategy;
21
import com.github.javaparser.printer.configuration.Indentation;
22
import com.github.javaparser.printer.configuration.imports.DefaultImportOrderingStrategy;
23
import com.github.javaparser.printer.configuration.imports.EclipseImportOrderingStrategy;
24
import com.github.javaparser.printer.configuration.imports.IntelliJImportOrderingStrategy;
25
import com.github.javaparser.printer.lexicalpreservation.DefaultLexicalPreservingPrinter;
26
import org.mybatis.generator.api.Indenter;
27
import org.mybatis.generator.config.JavaMergeConfiguration;
28

UNCOV
29
public class JavaMergerFactory {
×
30
    public static JavaFileMerger getMerger(JavaMergeConfiguration javaMergeConfiguration, Indenter indenter) {
31
        return switch (javaMergeConfiguration.mergeStrategy()) {
1✔
32
        case MERGE_INTO_NEW -> new MergeIntoNewJavaFileMerger(getPrinter(javaMergeConfiguration, indenter),
1✔
33
                    javaMergeConfiguration.isLexicalPreserving());
1✔
34
        case MERGE_INTO_EXISTING -> new MergeIntoExistingJavaFileMerger(getPrinter(javaMergeConfiguration, indenter),
1✔
35
                    javaMergeConfiguration.isLexicalPreserving());
1✔
36
        };
37
    }
38

39
    private static Printer getPrinter(JavaMergeConfiguration javaMergeConfiguration, Indenter indenter) {
40
        if (javaMergeConfiguration.isLexicalPreserving()) {
1✔
41
            return new DefaultLexicalPreservingPrinter();
1✔
42
        }
43

44
        return new DefaultPrettyPrinter(calculatePrinterConfiguration(javaMergeConfiguration, indenter));
1✔
45
    }
46

47
    private static CustomPrinterConfiguration calculatePrinterConfiguration(
48
            JavaMergeConfiguration javaMergeConfiguration, Indenter indenter) {
49
        ImportOrderingStrategy ios = switch (javaMergeConfiguration.importSortType()) {
1✔
50
        case ECLIPSE -> new EclipseImportOrderingStrategy();
1✔
51
        case INTELLIJ -> new IntelliJImportOrderingStrategy();
1✔
52
        case DEFAULT -> new DefaultImportOrderingStrategy();
1✔
53
        };
54
        ios.setSortImportsAlphabetically(true);
1✔
55

56
        Indentation indentation = switch (indenter.javaIndentType()) {
1✔
57
        case TABS -> new Indentation(Indentation.IndentType.TABS, indenter.javaIndentAmount());
1✔
58
        case SPACES -> new Indentation(Indentation.IndentType.SPACES, indenter.javaIndentAmount());
1✔
59
        };
60

61
        return new CustomPrinterConfiguration.Builder()
1✔
62
                .withImportOrderingStrategy(ios)
1✔
63
                .withIndentation(indentation)
1✔
64
                .build();
1✔
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc