Skip to content

Commit f569d53

Browse files
committed
Apply formatter for mybatis rule
Fixes gh-15
1 parent 9bac280 commit f569d53

23 files changed

+458
-374
lines changed

format.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2018-2019 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE Format>
20+
<Format>
21+
<!-- Dummy format file -->
22+
</Format>

src/main/java/org/mybatis/scripting/thymeleaf/MyBatisBindingContext.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ public class MyBatisBindingContext {
4040
/**
4141
* Load instance from {@link IContext} provided by Thymeleaf.
4242
*
43-
* @param context a context of thymeleaf template processing
43+
* @param context
44+
* a context of thymeleaf template processing
4445
* @return instance of this class
4546
*/
4647
public static MyBatisBindingContext load(IContext context) {
47-
return (MyBatisBindingContext)context.getVariable(CONTEXT_VARIABLE_NAME);
48+
return (MyBatisBindingContext) context.getVariable(CONTEXT_VARIABLE_NAME);
4849
}
4950

5051
/**
5152
* Constructor.
5253
*
53-
* @param fallbackParameterObject whether use fallback parameter object when parameter is value object
54+
* @param fallbackParameterObject
55+
* whether use fallback parameter object when parameter is value object
5456
*/
5557
MyBatisBindingContext(boolean fallbackParameterObject) {
5658
this.fallbackParameterObject = fallbackParameterObject;
@@ -68,29 +70,34 @@ Map<String, Object> getCustomBindVariables() {
6870
/**
6971
* Set a value into custom bind variable.
7072
*
71-
* @param name variable name
72-
* @param value variable value
73+
* @param name
74+
* variable name
75+
* @param value
76+
* variable value
7377
*/
7478
public void setCustomBindVariable(String name, Object value) {
7579
customBindVariables.put(name, value);
7680
}
7781

7882
/**
7983
* Return whether contains specified variable into custom bind variables.
80-
* @param name variable name
84+
*
85+
* @param name
86+
* variable name
8187
* @return If specified variable exists, return {@code true}
8288
*/
8389
public boolean containsCustomBindVariable(String name) {
8490
return customBindVariables.containsKey(name);
8591
}
8692

8793
/**
88-
* Generate an unique variable name per iteration object.
89-
* <br>
94+
* Generate an unique variable name per iteration object. <br>
9095
* Variable name rule is {@code {objectName}_{status list index}_{status.getIndex()}}.
9196
*
92-
* @param objectName base object name
93-
* @param status iteration status object
97+
* @param objectName
98+
* base object name
99+
* @param status
100+
* iteration status object
94101
* @return an unique variable name per iteration object
95102
*/
96103
public String generateUniqueName(String objectName, IterationStatusVar status) {

src/main/java/org/mybatis/scripting/thymeleaf/MyBatisDialect.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
import org.thymeleaf.templatemode.TemplateMode;
3333

3434
/**
35-
* The Dialect for integrating with MyBatis.
36-
* <br>
35+
* The Dialect for integrating with MyBatis. <br>
3736
* This dialect provides following features. This dialect prefix is {@code "mb"} by default.
3837
*
3938
* <ul>
40-
* <li>{@code #likes} expression : {@link Likes}</li>
41-
* <li>{@code mb:p} attribute tag: {@link MyBatisParamTagProcessor}</li>
42-
* <li>{@code mb:bind} attribute tag : {@link MyBatisBindTagProcessor}</li>
39+
* <li>{@code #likes} expression : {@link Likes}</li>
40+
* <li>{@code mb:p} attribute tag: {@link MyBatisParamTagProcessor}</li>
41+
* <li>{@code mb:bind} attribute tag : {@link MyBatisBindTagProcessor}</li>
4342
* </ul>
4443
*
4544
* @author Kazuki Shimizu
@@ -61,16 +60,18 @@ public MyBatisDialect() {
6160
/**
6261
* Constructor that can be specified the dialect prefix.
6362
*
64-
* @param prefix A dialect prefix
63+
* @param prefix
64+
* A dialect prefix
6565
*/
6666
public MyBatisDialect(String prefix) {
6767
super("MyBatis Dialect", prefix, StandardDialect.PROCESSOR_PRECEDENCE);
6868
}
6969

7070
/**
71-
* Set an expression utility object that provide helper method for like feature.
72-
* <br>
73-
* @param likes An expression utility object that provide helper method for like feature
71+
* Set an expression utility object that provide helper method for like feature. <br>
72+
*
73+
* @param likes
74+
* An expression utility object that provide helper method for like feature
7475
*/
7576
public void setLikes(Likes likes) {
7677
this.likes = likes;
@@ -81,12 +82,10 @@ public void setLikes(Likes likes) {
8182
*/
8283
@Override
8384
public Set<IProcessor> getProcessors(String dialectPrefix) {
84-
return new HashSet<>(Arrays.asList(
85-
new MyBatisBindTagProcessor(TemplateMode.TEXT, dialectPrefix),
85+
return new HashSet<>(Arrays.asList(new MyBatisBindTagProcessor(TemplateMode.TEXT, dialectPrefix),
8686
new MyBatisBindTagProcessor(TemplateMode.CSS, dialectPrefix),
8787
new MyBatisParamTagProcessor(TemplateMode.TEXT, dialectPrefix),
88-
new MyBatisParamTagProcessor(TemplateMode.CSS, dialectPrefix)
89-
));
88+
new MyBatisParamTagProcessor(TemplateMode.CSS, dialectPrefix)));
9089
}
9190

9291
/**

src/main/java/org/mybatis/scripting/thymeleaf/MyBatisIntegratingEngineContextFactory.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class MyBatisIntegratingEngineContextFactory implements IEngineContextFac
3838
/**
3939
* Constructor.
4040
*
41-
* @param delegate A target context factory for delegating
41+
* @param delegate
42+
* A target context factory for delegating
4243
*/
4344
public MyBatisIntegratingEngineContextFactory(IEngineContextFactory delegate) {
4445
this.delegate = delegate;
@@ -49,18 +50,18 @@ public MyBatisIntegratingEngineContextFactory(IEngineContextFactory delegate) {
4950
*/
5051
@Override
5152
public IEngineContext createEngineContext(IEngineConfiguration configuration, TemplateData templateData,
52-
Map<String, Object> templateResolutionAttributes, IContext context) {
53-
IEngineContext engineContext =
54-
delegate.createEngineContext(configuration, templateData, templateResolutionAttributes, context);
55-
return (IEngineContext) Proxy.newProxyInstance(classLoader, new Class[]{IEngineContext.class},
53+
Map<String, Object> templateResolutionAttributes, IContext context) {
54+
IEngineContext engineContext = delegate.createEngineContext(configuration, templateData,
55+
templateResolutionAttributes, context);
56+
return (IEngineContext) Proxy.newProxyInstance(classLoader, new Class[] { IEngineContext.class },
5657
(proxy, method, args) -> {
5758
if (method.getName().equals("getVariable")) {
5859
String name = (String) args[0];
5960
Object value;
6061
MyBatisBindingContext bindingContext = MyBatisBindingContext.load(engineContext);
6162
if (bindingContext.isFallbackParameterObject()) {
62-
value = engineContext.containsVariable(name)
63-
? engineContext.getVariable(name) : engineContext.getVariable(DynamicContext.PARAMETER_OBJECT_KEY);
63+
value = engineContext.containsVariable(name) ? engineContext.getVariable(name)
64+
: engineContext.getVariable(DynamicContext.PARAMETER_OBJECT_KEY);
6465
} else {
6566
value = engineContext.getVariable(name);
6667
}

src/main/java/org/mybatis/scripting/thymeleaf/TemplateEngineCustomizer.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,26 @@
2222
import org.thymeleaf.templateresolver.ITemplateResolver;
2323

2424
/**
25-
* The interface for customizing a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf.
26-
* <br>
27-
* If you want to customize a default {@code TemplateEngine},
28-
* you implements class of this interface and you need to specify
29-
* the 'customizer' property of mybatis-thymeleaf.properties.
30-
* <br>
25+
* The interface for customizing a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf. <br>
26+
* If you want to customize a default {@code TemplateEngine}, you implements class of this interface and you need to
27+
* specify the 'customizer' property of mybatis-thymeleaf.properties. <br>
3128
* e.g.) Implementation class:
29+
*
3230
* <pre>
3331
* package com.example;
32+
*
3433
* // ...
3534
* public class MyTemplateEngineCustomizer implements TemplateEngineCustomizer {
3635
* public void customize(TemplateEngine defaultTemplateEngine) {
3736
* // ...
3837
* }
3938
* }
4039
* </pre>
40+
*
4141
* e.g.) Configuration file (mybatis-thymeleaf.properties):
42+
*
4243
* <pre>
43-
* customizer=com.example.MyTemplateEngineCustomizer
44+
* customizer = com.example.MyTemplateEngineCustomizer
4445
* </pre>
4546
*
4647
* @author Kazuki Shimizu
@@ -51,6 +52,7 @@ public interface TemplateEngineCustomizer extends Consumer<TemplateEngine> {
5152

5253
/**
5354
* {@inheritDoc}
55+
*
5456
* @see #customize(TemplateEngine)
5557
*/
5658
@Override
@@ -61,22 +63,25 @@ default void accept(TemplateEngine templateEngine) {
6163
/**
6264
* Customize a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf.
6365
*
64-
* @param defaultTemplateEngine a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf
66+
* @param defaultTemplateEngine
67+
* a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf
6568
*/
6669
void customize(TemplateEngine defaultTemplateEngine);
6770

6871
/**
6972
* Utility method to extract a {@code ITemplateResolver} that implements specified type.
7073
*
71-
* @param templateEngine A target {@code TemplateEngine}
72-
* @param type A target type for extracting instance
73-
* @param <T> A type that implements the {@code ITemplateResolver}
74+
* @param templateEngine
75+
* A target {@code TemplateEngine}
76+
* @param type
77+
* A target type for extracting instance
78+
* @param <T>
79+
* A type that implements the {@code ITemplateResolver}
7480
* @return A {@code ITemplateResolver} instance that implements specified type
7581
*/
76-
static <T extends ITemplateResolver> Optional<T> extractTemplateResolver(
77-
TemplateEngine templateEngine, Class<T> type) {
78-
return templateEngine.getTemplateResolvers().stream()
79-
.filter(type::isInstance).map(type::cast).findFirst();
82+
static <T extends ITemplateResolver> Optional<T> extractTemplateResolver(TemplateEngine templateEngine,
83+
Class<T> type) {
84+
return templateEngine.getTemplateResolvers().stream().filter(type::isInstance).map(type::cast).findFirst();
8085
}
8186

8287
/**

src/main/java/org/mybatis/scripting/thymeleaf/ThymeleafLanguageDriver.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public ThymeleafLanguageDriver() {
5555
/**
5656
* Constructor for creating instance with user specified {@code Properties}.
5757
*
58-
* @param config A user defined {@code ITemplateEngine} instance
58+
* @param config
59+
* A user defined {@code ITemplateEngine} instance
5960
*/
6061
public ThymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
6162
this.templateEngine = createDefaultTemplateEngine(config);
@@ -64,28 +65,27 @@ public ThymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
6465
/**
6566
* Constructor for creating instance with user defined {@code ITemplateEngine}.
6667
*
67-
* @param templateEngine A user defined {@code ITemplateEngine} instance
68+
* @param templateEngine
69+
* A user defined {@code ITemplateEngine} instance
6870
*/
6971
public ThymeleafLanguageDriver(ITemplateEngine templateEngine) {
7072
this.templateEngine = templateEngine;
7173
}
7274

7375
private ITemplateEngine createDefaultTemplateEngine(ThymeleafLanguageDriverConfig config) {
7476
MyBatisDialect dialect = new MyBatisDialect(config.getDialect().getPrefix());
75-
Likes likes = Likes.newBuilder()
76-
.escapeChar(config.getDialect().getLikeEscapeChar())
77+
Likes likes = Likes.newBuilder().escapeChar(config.getDialect().getLikeEscapeChar())
7778
.escapeClauseFormat(config.getDialect().getLikeEscapeClauseFormat())
78-
.additionalEscapeTargetChars(config.getDialect().getLikeAdditionalEscapeTargetChars())
79-
.build();
79+
.additionalEscapeTargetChars(config.getDialect().getLikeAdditionalEscapeTargetChars()).build();
8080
dialect.setLikes(likes);
8181

8282
// Create an ClassLoaderTemplateResolver instance
8383
ClassLoaderTemplateResolver classLoaderTemplateResolver = new ClassLoaderTemplateResolver();
8484
TemplateMode mode = config.isUse2way() ? TemplateMode.CSS : TemplateMode.TEXT;
8585
classLoaderTemplateResolver.setOrder(1);
8686
classLoaderTemplateResolver.setTemplateMode(mode);
87-
classLoaderTemplateResolver.setResolvablePatterns(
88-
Arrays.stream(config.getTemplateFile().getPatterns()).collect(Collectors.toSet()));
87+
classLoaderTemplateResolver
88+
.setResolvablePatterns(Arrays.stream(config.getTemplateFile().getPatterns()).collect(Collectors.toSet()));
8989
classLoaderTemplateResolver.setCharacterEncoding(config.getTemplateFile().getEncoding().name());
9090
classLoaderTemplateResolver.setCacheable(config.getTemplateFile().isCacheEnabled());
9191
classLoaderTemplateResolver.setCacheTTLMs(config.getTemplateFile().getCacheTtl());
@@ -105,15 +105,13 @@ private ITemplateEngine createDefaultTemplateEngine(ThymeleafLanguageDriverConfi
105105
new MyBatisIntegratingEngineContextFactory(targetTemplateEngine.getEngineContextFactory()));
106106

107107
// Create an TemplateEngineCustomizer instance and apply
108-
final TemplateEngineCustomizer customizer = Optional.ofNullable(config.getCustomizer())
109-
.map(v -> {
110-
try {
111-
return v.getConstructor().newInstance();
112-
} catch (InstantiationException | IllegalAccessException
113-
| InvocationTargetException | NoSuchMethodException e) {
114-
throw new IllegalStateException("Cannot create an instance for class: " + v, e);
115-
}
116-
}).map(TemplateEngineCustomizer.class::cast).orElse(TemplateEngineCustomizer.BuiltIn.DO_NOTHING);
108+
final TemplateEngineCustomizer customizer = Optional.ofNullable(config.getCustomizer()).map(v -> {
109+
try {
110+
return v.getConstructor().newInstance();
111+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
112+
throw new IllegalStateException("Cannot create an instance for class: " + v, e);
113+
}
114+
}).map(TemplateEngineCustomizer.class::cast).orElse(TemplateEngineCustomizer.BuiltIn.DO_NOTHING);
117115
customizer.accept(targetTemplateEngine);
118116

119117
return targetTemplateEngine;
@@ -123,8 +121,8 @@ private ITemplateEngine createDefaultTemplateEngine(ThymeleafLanguageDriverConfi
123121
* {@inheritDoc}
124122
*/
125123
@Override
126-
public ParameterHandler createParameterHandler(
127-
MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
124+
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
125+
BoundSql boundSql) {
128126
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
129127
}
130128

0 commit comments

Comments
 (0)