Skip to content

Commit 7f16cc3

Browse files
committed
[ci] Cleanup if statement breaks / return logic
1 parent abe66e1 commit 7f16cc3

File tree

63 files changed

+471
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+471
-538
lines changed

src/main/java/org/apache/ibatis/binding/MapperMethod.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ private <E> Object executeForMany(SqlSession sqlSession, Object[] args) {
150150
if (!method.getReturnType().isAssignableFrom(result.getClass())) {
151151
if (method.getReturnType().isArray()) {
152152
return convertToArray(result);
153-
} else {
154-
return convertToDeclaredCollection(sqlSession.getConfiguration(), result);
155153
}
154+
return convertToDeclaredCollection(sqlSession.getConfiguration(), result);
156155
}
157156
return result;
158157
}
@@ -180,14 +179,13 @@ private <E> Object convertToDeclaredCollection(Configuration config, List<E> lis
180179
private <E> Object convertToArray(List<E> list) {
181180
Class<?> arrayComponentType = method.getReturnType().getComponentType();
182181
Object array = Array.newInstance(arrayComponentType, list.size());
183-
if (arrayComponentType.isPrimitive()) {
184-
for (int i = 0; i < list.size(); i++) {
185-
Array.set(array, i, list.get(i));
186-
}
187-
return array;
188-
} else {
182+
if (!arrayComponentType.isPrimitive()) {
189183
return list.toArray((E[]) array);
190184
}
185+
for (int i = 0; i < list.size(); i++) {
186+
Array.set(array, i, list.get(i));
187+
}
188+
return array;
191189
}
192190

193191
private <K, V> Map<K, V> executeForMap(SqlSession sqlSession, Object[] args) {
@@ -226,13 +224,12 @@ public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method
226224
final Class<?> declaringClass = method.getDeclaringClass();
227225
MappedStatement ms = resolveMappedStatement(mapperInterface, methodName, declaringClass, configuration);
228226
if (ms == null) {
229-
if (method.getAnnotation(Flush.class) != null) {
230-
name = null;
231-
type = SqlCommandType.FLUSH;
232-
} else {
227+
if (method.getAnnotation(Flush.class) == null) {
233228
throw new BindingException(
234229
"Invalid bound statement (not found): " + mapperInterface.getName() + "." + methodName);
235230
}
231+
name = null;
232+
type = SqlCommandType.FLUSH;
236233
} else {
237234
name = ms.getId();
238235
type = ms.getSqlCommandType();
@@ -255,7 +252,8 @@ private MappedStatement resolveMappedStatement(Class<?> mapperInterface, String
255252
String statementId = mapperInterface.getName() + "." + methodName;
256253
if (configuration.hasStatement(statementId)) {
257254
return configuration.getMappedStatement(statementId);
258-
} else if (mapperInterface.equals(declaringClass)) {
255+
}
256+
if (mapperInterface.equals(declaringClass)) {
259257
return null;
260258
}
261259
for (Class<?> superInterface : mapperInterface.getInterfaces()) {
@@ -359,12 +357,11 @@ private Integer getUniqueParamIndex(Method method, Class<?> paramType) {
359357
final Class<?>[] argTypes = method.getParameterTypes();
360358
for (int i = 0; i < argTypes.length; i++) {
361359
if (paramType.isAssignableFrom(argTypes[i])) {
362-
if (index == null) {
363-
index = i;
364-
} else {
360+
if (index != null) {
365361
throw new BindingException(
366362
method.getName() + " cannot have multiple " + paramType.getSimpleName() + " parameters");
367363
}
364+
index = i;
368365
}
369366
}
370367
return index;

src/main/java/org/apache/ibatis/binding/MapperProxy.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,9 +82,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
8282
try {
8383
if (Object.class.equals(method.getDeclaringClass())) {
8484
return method.invoke(this, args);
85-
} else {
86-
return cachedInvoker(method).invoke(proxy, method, args, sqlSession);
8785
}
86+
return cachedInvoker(method).invoke(proxy, method, args, sqlSession);
8887
} catch (Throwable t) {
8988
throw ExceptionUtil.unwrapThrowable(t);
9089
}
@@ -93,20 +92,19 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
9392
private MapperMethodInvoker cachedInvoker(Method method) throws Throwable {
9493
try {
9594
return MapUtil.computeIfAbsent(methodCache, method, m -> {
96-
if (m.isDefault()) {
97-
try {
98-
if (privateLookupInMethod == null) {
99-
return new DefaultMethodInvoker(getMethodHandleJava8(method));
100-
} else {
101-
return new DefaultMethodInvoker(getMethodHandleJava9(method));
102-
}
103-
} catch (IllegalAccessException | InstantiationException | InvocationTargetException
104-
| NoSuchMethodException e) {
105-
throw new RuntimeException(e);
106-
}
107-
} else {
95+
if (!m.isDefault()) {
10896
return new PlainMethodInvoker(new MapperMethod(mapperInterface, method, sqlSession.getConfiguration()));
10997
}
98+
try {
99+
if (privateLookupInMethod == null) {
100+
return new DefaultMethodInvoker(getMethodHandleJava8(method));
101+
} else {
102+
return new DefaultMethodInvoker(getMethodHandleJava9(method));
103+
}
104+
} catch (IllegalAccessException | InstantiationException | InvocationTargetException
105+
| NoSuchMethodException e) {
106+
throw new RuntimeException(e);
107+
}
110108
});
111109
} catch (RuntimeException re) {
112110
Throwable cause = re.getCause();

src/main/java/org/apache/ibatis/builder/ParameterExpression.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,11 +106,10 @@ private void jdbcTypeOpt(String expression, int p) {
106106
private void jdbcType(String expression, int p) {
107107
int left = skipWS(expression, p);
108108
int right = skipUntil(expression, left, ",");
109-
if (right > left) {
110-
put("jdbcType", trimmedStr(expression, left, right));
111-
} else {
109+
if (right <= left) {
112110
throw new BuilderException("Parsing error in {" + expression + "} in position " + p);
113111
}
112+
put("jdbcType", trimmedStr(expression, left, right));
114113
option(expression, right + 1);
115114
}
116115

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ private SqlSource buildSqlSource(Annotation annotation, Class<?> parameterType,
590590
Method method) {
591591
if (annotation instanceof Select) {
592592
return buildSqlSourceFromStrings(((Select) annotation).value(), parameterType, languageDriver);
593-
} else if (annotation instanceof Update) {
593+
}
594+
if (annotation instanceof Update) {
594595
return buildSqlSourceFromStrings(((Update) annotation).value(), parameterType, languageDriver);
595596
} else if (annotation instanceof Insert) {
596597
return buildSqlSourceFromStrings(((Insert) annotation).value(), parameterType, languageDriver);

src/main/java/org/apache/ibatis/builder/annotation/ProviderMethodResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ default Method resolveMethod(ProviderContext context) {
6767
if (targetMethods.isEmpty()) {
6868
throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
6969
+ "' does not return the CharSequence or its subclass in SqlProvider '" + getClass().getName() + "'.");
70-
} else {
71-
throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
72-
+ "' is found multiple in SqlProvider '" + getClass().getName() + "'.");
7370
}
71+
throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
72+
+ "' is found multiple in SqlProvider '" + getClass().getName() + "'.");
7473
}
7574

7675
}

src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,26 @@ private SqlSource createSqlSource(Object parameterObject) {
180180
Map<String, Object> params = (Map<String, Object>) parameterObject;
181181
sql = invokeProviderMethod(extractProviderMethodArguments(params, providerMethodArgumentNames));
182182
}
183-
} else if (providerMethodParameterTypes.length == 0) {
184-
sql = invokeProviderMethod();
185-
} else if (providerMethodParameterTypes.length == 1) {
186-
if (providerContext == null) {
187-
sql = invokeProviderMethod(parameterObject);
188-
} else {
189-
sql = invokeProviderMethod(providerContext);
183+
} else
184+
switch (providerMethodParameterTypes.length) {
185+
case 0:
186+
sql = invokeProviderMethod();
187+
break;
188+
case 1:
189+
if (providerContext == null) {
190+
sql = invokeProviderMethod(parameterObject);
191+
} else {
192+
sql = invokeProviderMethod(providerContext);
193+
}
194+
break;
195+
case 2:
196+
sql = invokeProviderMethod(extractProviderMethodArguments(parameterObject));
197+
break;
198+
default:
199+
throw new BuilderException("Cannot invoke SqlProvider method '" + providerMethod
200+
+ "' with specify parameter '" + (parameterObject == null ? null : parameterObject.getClass())
201+
+ "' because SqlProvider method arguments for '" + mapperMethod + "' is an invalid combination.");
190202
}
191-
} else if (providerMethodParameterTypes.length == 2) {
192-
sql = invokeProviderMethod(extractProviderMethodArguments(parameterObject));
193-
} else {
194-
throw new BuilderException("Cannot invoke SqlProvider method '" + providerMethod + "' with specify parameter '"
195-
+ (parameterObject == null ? null : parameterObject.getClass())
196-
+ "' because SqlProvider method arguments for '" + mapperMethod + "' is an invalid combination.");
197-
}
198203
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
199204
return languageDriver.createSqlSource(configuration, sql, parameterType);
200205
} catch (BuilderException e) {
@@ -219,9 +224,8 @@ private Object[] extractProviderMethodArguments(Object parameterObject) {
219224
args[providerContextIndex == 0 ? 1 : 0] = parameterObject;
220225
args[providerContextIndex] = providerContext;
221226
return args;
222-
} else {
223-
return new Object[] { parameterObject };
224227
}
228+
return new Object[] { parameterObject };
225229
}
226230

227231
private Object[] extractProviderMethodArguments(Map<String, Object> params, String[] argumentNames) {

src/main/java/org/apache/ibatis/builder/xml/XMLIncludeTransformer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ private Properties getVariablesContext(Node node, Properties inheritedVariablesC
135135
}
136136
if (declaredProperties == null) {
137137
return inheritedVariablesContext;
138-
} else {
139-
Properties newProperties = new Properties();
140-
newProperties.putAll(inheritedVariablesContext);
141-
newProperties.putAll(declaredProperties);
142-
return newProperties;
143138
}
139+
Properties newProperties = new Properties();
140+
newProperties.putAll(inheritedVariablesContext);
141+
newProperties.putAll(declaredProperties);
142+
return newProperties;
144143
}
145144
}

src/main/java/org/apache/ibatis/builder/xml/XMLMapperEntityResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc
6060
String lowerCaseSystemId = systemId.toLowerCase(Locale.ENGLISH);
6161
if (lowerCaseSystemId.contains(MYBATIS_CONFIG_SYSTEM) || lowerCaseSystemId.contains(IBATIS_CONFIG_SYSTEM)) {
6262
return getInputSource(MYBATIS_CONFIG_DTD, publicId, systemId);
63-
} else if (lowerCaseSystemId.contains(MYBATIS_MAPPER_SYSTEM)
64-
|| lowerCaseSystemId.contains(IBATIS_MAPPER_SYSTEM)) {
63+
}
64+
if (lowerCaseSystemId.contains(MYBATIS_MAPPER_SYSTEM) || lowerCaseSystemId.contains(IBATIS_MAPPER_SYSTEM)) {
6565
return getInputSource(MYBATIS_MAPPER_DTD, publicId, systemId);
6666
}
6767
}

src/main/java/org/apache/ibatis/cache/CacheKey.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,13 +98,7 @@ public boolean equals(Object object) {
9898

9999
final CacheKey cacheKey = (CacheKey) object;
100100

101-
if (hashcode != cacheKey.hashcode) {
102-
return false;
103-
}
104-
if (checksum != cacheKey.checksum) {
105-
return false;
106-
}
107-
if (count != cacheKey.count) {
101+
if ((hashcode != cacheKey.hashcode) || (checksum != cacheKey.checksum) || (count != cacheKey.count)) {
108102
return false;
109103
}
110104

src/main/java/org/apache/ibatis/cache/decorators/SerializedCache.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,11 +52,10 @@ public int getSize() {
5252

5353
@Override
5454
public void putObject(Object key, Object object) {
55-
if (object == null || object instanceof Serializable) {
56-
delegate.putObject(key, serialize((Serializable) object));
57-
} else {
55+
if ((object != null) && !(object instanceof Serializable)) {
5856
throw new CacheException("SharedCache failed to make a copy of a non-serializable object: " + object);
5957
}
58+
delegate.putObject(key, serialize((Serializable) object));
6059
}
6160

6261
@Override

0 commit comments

Comments
 (0)