Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Code for the doma-core module #578

Merged
merged 78 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
2a471ad
Remove unused instance fields
nakamura-to Sep 19, 2020
165052d
Remove "unused" suppression
nakamura-to Sep 19, 2020
3609466
Remove unnecessary `private`
nakamura-to Sep 19, 2020
c889e0f
Remove unnecessary `static`, `public`, and `abstract`
nakamura-to Sep 19, 2020
8a16365
Replace with 'StandardCharsets.UTF_8'
nakamura-to Sep 19, 2020
b3c1a0e
Remove redundant if statements
nakamura-to Sep 19, 2020
4c91e19
Replace with 'String.join'
nakamura-to Sep 19, 2020
f57215a
Replace with enhanced 'for'
nakamura-to Sep 19, 2020
182293e
Specify type parameter
nakamura-to Sep 19, 2020
31f8621
Remove boxing
nakamura-to Sep 19, 2020
95e7e20
Remove unboxing
nakamura-to Sep 19, 2020
a8542b8
Replace with <>
nakamura-to Sep 19, 2020
541bf45
Collapse 'catch' blocks
nakamura-to Sep 19, 2020
0557a18
Replace with 'contains()'
nakamura-to Sep 19, 2020
c2547c0
Replace with lambda
nakamura-to Sep 19, 2020
7613d12
Replace lambda with method reference
nakamura-to Sep 19, 2020
30b5602
Replace with expression lambda
nakamura-to Sep 19, 2020
0729cc4
Make `static`
nakamura-to Sep 19, 2020
61c7a78
Avoid unpredictable BigDecimal constructor call
nakamura-to Sep 19, 2020
e2aa92d
Replace with 'Collections.singleList()'
nakamura-to Sep 19, 2020
1a9ce56
Suppress 'AssertBetweenInconvertibleTypes'
nakamura-to Sep 19, 2020
b8fdcda
Simplify assertion
nakamura-to Sep 19, 2020
a09fb43
Remove explicit String creation
nakamura-to Sep 19, 2020
e941cca
Remove explicit Array creation
nakamura-to Sep 19, 2020
a8ff3e8
Remove type arguments
nakamura-to Sep 19, 2020
4960b8b
Suppress unnecessary 'continue' and 'return'
nakamura-to Sep 19, 2020
cdafae9
Replace StringBuilder with String
nakamura-to Sep 19, 2020
f7ab7ca
Remove redundant suppression
nakamura-to Sep 19, 2020
98714a9
Remove redundant suppression
nakamura-to Sep 19, 2020
6cc44ea
Suppress SameReturnValue
nakamura-to Sep 19, 2020
64a79a8
Make final
nakamura-to Sep 19, 2020
aa92f07
Suppress CStyleArrayDeclaration
nakamura-to Sep 19, 2020
3baa07f
Remove unnecessary semicolon
nakamura-to Sep 19, 2020
9b22d20
Print a message instead of an exception
nakamura-to Sep 19, 2020
e906c52
Replace with 'while'
nakamura-to Sep 19, 2020
23f803a
Replace with 'if'
nakamura-to Sep 19, 2020
66ed256
Inline variable
nakamura-to Sep 19, 2020
6b0de00
Suppress BooleanMethodIsAlwaysInverted
nakamura-to Sep 19, 2020
7eac0ec
Remove redundant 'extends Object'
nakamura-to Sep 19, 2020
c529f2c
Suppress OptionalUsedAsFieldOrParameterType
nakamura-to Sep 19, 2020
ff1a9df
Rename exception parameter name
nakamura-to Sep 19, 2020
fbd45c2
Replace with expression lambda
nakamura-to Sep 19, 2020
32d7bb5
Make 'static'
nakamura-to Sep 19, 2020
1266abd
Suppress DuplicateBranchesInSwitch
nakamura-to Sep 19, 2020
76dd18e
Remove redundant initializer
nakamura-to Sep 19, 2020
9d4a40b
Suppress ImplicitArrayToString
nakamura-to Sep 19, 2020
c8f13f6
Suppress OptionalGetWithoutIsPresent
nakamura-to Sep 19, 2020
376c2a9
Suppress ResultOfMethodCallIgnored
nakamura-to Sep 19, 2020
298c46b
Replace with 'while'
nakamura-to Sep 19, 2020
6bcda11
Suppress UnusedAssignment
nakamura-to Sep 19, 2020
e7922ff
Suppress SuspiciousInvocationHandlerImplementation
nakamura-to Sep 19, 2020
3bc4c29
Remove unnecessary test class
nakamura-to Sep 19, 2020
1d41932
Suppress EmptyMethod
nakamura-to Sep 19, 2020
5e1bddf
Convert octal literal to decimal literal
nakamura-to Sep 19, 2020
e88a9e1
Remove unnecessary condition
nakamura-to Sep 19, 2020
135b561
Make 'final'
nakamura-to Sep 19, 2020
da352ae
Suppress SameParameterValue
nakamura-to Sep 19, 2020
07d838e
Replace with 'BigDecimal.valueOf'
nakamura-to Sep 19, 2020
2d1964b
Suppress BigDecimalMethodWithoutRoundingCalled
nakamura-to Sep 19, 2020
fde7a5c
Suppress MismatchedQueryAndUpdateOfCollection
nakamura-to Sep 19, 2020
d0b6c10
Suppress CopyConstructorMissesField
nakamura-to Sep 19, 2020
a067e6e
Suppress SameReturnValue
nakamura-to Sep 19, 2020
2a9ff86
Suppress NullableProblems
nakamura-to Sep 19, 2020
7ec627b
Replace with 'null'
nakamura-to Sep 19, 2020
b9bfab4
Suppress ConstantConditions
nakamura-to Sep 19, 2020
a3dbe14
Remove redundant assignment
nakamura-to Sep 19, 2020
7fc401b
Remove redundant if statement
nakamura-to Sep 19, 2020
303a045
Split exception creation and exception throwing
nakamura-to Sep 19, 2020
de9fbea
Use 'new HashSet()' instead of 'Collections.emptySet()' because the S…
nakamura-to Sep 19, 2020
e5b40c7
Remove unnecessary 'throws' declarations
nakamura-to Sep 19, 2020
f08512d
Remove unnecessary assertion
nakamura-to Sep 19, 2020
9b5d8c3
Fix typo
nakamura-to Sep 19, 2020
c8f6914
Avoid possible NullPointerException
nakamura-to Sep 19, 2020
bf825b7
Suppress MagicConstant
nakamura-to Sep 19, 2020
df2ed3e
Suppress RedundantThrows
nakamura-to Sep 19, 2020
1405d80
Remove unnecessary 'throws' declarations
nakamura-to Sep 19, 2020
221d03c
Remove redundant suppression
nakamura-to Sep 19, 2020
18537c6
Extract common part
nakamura-to Sep 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion doma-core/src/main/java/org/seasar/doma/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
*
* @return the entity listener class
*/
@SuppressWarnings("rawtypes")
Class<? extends EntityListener> listener() default NullEntityListener.class;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static String getVersion() {
return VERSION;
}

public static void validateVersion(String generationtimeVersion) {
if (!VERSION.equals(generationtimeVersion)) {
throw new DomaException(Message.DOMA0003, VERSION, generationtimeVersion);
public static void validateVersion(String compileTimeVersion) {
if (!VERSION.equals(compileTimeVersion)) {
throw new DomaException(Message.DOMA0003, VERSION, compileTimeVersion);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.seasar.doma.internal;

import java.util.Objects;
import org.seasar.doma.internal.util.ClassUtil;

public class ClassName implements CharSequence {

private final String qualifiedName;

public ClassName(String qualifiedName) {
this.qualifiedName = qualifiedName;
this.qualifiedName = Objects.requireNonNull(qualifiedName);
}

public String getPackageName() {
Expand All @@ -33,6 +34,7 @@ public CharSequence subSequence(int start, int end) {
return qualifiedName.subSequence(start, end);
}

@SuppressWarnings("NullableProblems")
@Override
public String toString() {
return qualifiedName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.seasar.doma.internal;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public final class Constants {

public static final String ROWNUMBER_COLUMN_NAME = "doma_rownumber_";

public static final Charset UTF_8 = Charset.forName("UTF-8");
public static final Charset UTF_8 = StandardCharsets.UTF_8;

public static final String SQL_PATH_PREFIX = "META-INF/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Object getValue() {

public boolean getBooleanValue() {
if (value instanceof Boolean) {
return ((Boolean) value).booleanValue();
return (Boolean) value;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public ExpressionEvaluator() {
}

public ExpressionEvaluator(ExpressionFunctions expressionFunctions, ClassHelper classHelper) {
this(Collections.<String, Value>emptyMap(), expressionFunctions, classHelper);
this(Collections.emptyMap(), expressionFunctions, classHelper);
}

public ExpressionEvaluator(
Map<String, Value> variableValues,
ExpressionFunctions expressionFunctions,
ClassHelper classHelper) {
assertNotNull(variableValues, expressionFunctions, classHelper);
this.variableValues = new HashMap<String, Value>(variableValues);
this.variableValues = new HashMap<>(variableValues);
this.expressionFunctions = expressionFunctions;
this.classHelper = classHelper;
}
Expand All @@ -100,9 +100,9 @@ public Value removeValue(String variableName) {
return variableValues.remove(variableName);
}

public void add(String varialbeName, Value value) {
assertNotNull(varialbeName, value);
variableValues.put(varialbeName, value);
public void add(String variableName, Value value) {
assertNotNull(variableName, value);
variableValues.put(variableName, value);
}

public EvaluationResult evaluate(ExpressionNode node) {
Expand Down Expand Up @@ -253,21 +253,21 @@ public EvaluationResult visitAddOperatorNode(AddOperatorNode node, Void p) {

Number leftNumber = createNumber(node, leftNode, leftResult);
if (leftNumber == null) {
throwNotNumberException(node, leftNode, leftResult);
throw newNotNumberException(node, leftNode, leftResult);
}
Number rightNumber = createNumber(node, rightNode, rightResult);
if (rightNumber == null) {
throwNotNumberException(node, rightNode, rightResult);
throw newNotNumberException(node, rightNode, rightResult);
}
return leftNumber.add(rightNumber);
}

protected Text createText(
OperatorNode operatoNode, ExpressionNode operandNode, EvaluationResult evaluationResult) {
OperatorNode operatorNode, ExpressionNode operandNode, EvaluationResult evaluationResult) {
if (!Text.isAcceptable(evaluationResult.getValueClass())) {
return null;
}
return new Text(operatoNode, evaluationResult.getValue(), evaluationResult.getValueClass());
return new Text(operatorNode, evaluationResult.getValue(), evaluationResult.getValueClass());
}

protected void throwNotTextException(
Expand All @@ -290,11 +290,11 @@ public EvaluationResult visitSubtractOperatorNode(SubtractOperatorNode node, Voi
EvaluationResult rightResult = evaluateNotNullableOperandNode(node, rightNode, p);
Number leftNumber = createNumber(node, leftNode, leftResult);
if (leftNumber == null) {
throwNotNumberException(node, leftNode, leftResult);
throw newNotNumberException(node, leftNode, leftResult);
}
Number rightNumber = createNumber(node, rightNode, rightResult);
if (rightNumber == null) {
throwNotNumberException(node, rightNode, rightResult);
throw newNotNumberException(node, rightNode, rightResult);
}
return leftNumber.subtract(rightNumber);
}
Expand All @@ -307,11 +307,11 @@ public EvaluationResult visitMultiplyOperatorNode(MultiplyOperatorNode node, Voi
EvaluationResult rightResult = evaluateNotNullableOperandNode(node, rightNode, p);
Number leftNumber = createNumber(node, leftNode, leftResult);
if (leftNumber == null) {
throwNotNumberException(node, leftNode, leftResult);
throw newNotNumberException(node, leftNode, leftResult);
}
Number rightNumber = createNumber(node, rightNode, rightResult);
if (rightNumber == null) {
throwNotNumberException(node, rightNode, rightResult);
throw newNotNumberException(node, rightNode, rightResult);
}
return leftNumber.multiply(rightNumber);
}
Expand All @@ -324,11 +324,11 @@ public EvaluationResult visitDivideOperatorNode(DivideOperatorNode node, Void p)
EvaluationResult rightResult = evaluateNotNullableOperandNode(node, rightNode, p);
Number leftNumber = createNumber(node, leftNode, leftResult);
if (leftNumber == null) {
throwNotNumberException(node, leftNode, leftResult);
throw newNotNumberException(node, leftNode, leftResult);
}
Number rightNumber = createNumber(node, rightNode, rightResult);
if (rightNumber == null) {
throwNotNumberException(node, rightNode, rightResult);
throw newNotNumberException(node, rightNode, rightResult);
}
return leftNumber.divide(rightNumber);
}
Expand All @@ -341,31 +341,31 @@ public EvaluationResult visitModOperatorNode(ModOperatorNode node, Void p) {
EvaluationResult rightResult = evaluateNotNullableOperandNode(node, rightNode, p);
Number leftNumber = createNumber(node, leftNode, leftResult);
if (leftNumber == null) {
throwNotNumberException(node, leftNode, leftResult);
throw newNotNumberException(node, leftNode, leftResult);
}
Number rightNumber = createNumber(node, rightNode, rightResult);
if (rightNumber == null) {
throwNotNumberException(node, rightNode, rightResult);
throw newNotNumberException(node, rightNode, rightResult);
}
return leftNumber.mod(rightNumber);
}

protected Number createNumber(
ArithmeticOperatorNode operatoNode,
ArithmeticOperatorNode operatorNode,
ExpressionNode operandNode,
EvaluationResult evaluationResult) {
if (!Number.isAcceptable(evaluationResult.getValueClass())) {
return null;
}
return new Number(operatoNode, evaluationResult.getValue(), evaluationResult.getValueClass());
return new Number(operatorNode, evaluationResult.getValue(), evaluationResult.getValueClass());
}

protected void throwNotNumberException(
protected ExpressionException newNotNumberException(
ArithmeticOperatorNode operatorNode,
ExpressionNode operandNode,
EvaluationResult evaluationResult) {
ExpressionLocation location = operandNode.getLocation();
throw new ExpressionException(
return new ExpressionException(
Message.DOMA3013,
location.getExpression(),
location.getPosition(),
Expand Down Expand Up @@ -449,7 +449,7 @@ protected Constructor<?> findConstructor(

protected EvaluationResult invokeConstructor(
ExpressionLocation location, Class<?> clazz, Constructor<?> constructor, Object... params) {
Object value = null;
Object value;
try {
value = ConstructorUtil.newInstance(constructor, params);
} catch (WrapException e) {
Expand Down Expand Up @@ -531,7 +531,7 @@ protected Method findMethod(

protected Method findMethodFromInterfaces(
String methodName, Object target, Class<?> targetClass, Class<?>[] paramTypes) {
LinkedList<Method> methods = new LinkedList<Method>();
LinkedList<Method> methods = new LinkedList<>();
for (Class<?> clazz = targetClass;
clazz != null && clazz != Object.class;
clazz = clazz.getSuperclass()) {
Expand All @@ -548,7 +548,7 @@ protected Method findMethodFromInterfaces(

protected Method findMethodFromClasses(
String methodName, Object target, Class<?> targetClass, Class<?>[] paramTypes) {
LinkedList<Method> methods = new LinkedList<Method>();
LinkedList<Method> methods = new LinkedList<>();
for (Class<?> clazz = targetClass;
clazz != null && clazz != Object.class;
clazz = clazz.getSuperclass()) {
Expand All @@ -561,26 +561,27 @@ protected Method findMethodFromClasses(
return findSuiteMethod(methods, target, targetClass, paramTypes);
}

@SuppressWarnings("CStyleArrayDeclaration")
protected Method findSuiteMethod(
List<Method> methods, Object target, Class<?> targetClass, Class<?>[] argTypes) {
CandidateMethod candidate = null;
outer:
for (Method method : methods) {
Class<?> paramTypes[] = method.getParameterTypes();
if (paramTypes.length == argTypes.length) {
int degreeOfcoincidence = 0;
int degreeOfCoincidence = 0;
for (int i = 0; i < paramTypes.length; i++) {
int difference = calculateHierarchyDifference(paramTypes[i], argTypes[i], 0);
if (difference == -1) {
continue outer;
}
degreeOfcoincidence += difference;
degreeOfCoincidence += difference;
}
if (degreeOfcoincidence == 0) {
if (degreeOfCoincidence == 0) {
return method;
}
if (candidate == null || degreeOfcoincidence < candidate.degreeOfcoincidence) {
candidate = new CandidateMethod(degreeOfcoincidence, method);
if (candidate == null || degreeOfCoincidence < candidate.degreeOfCoincidence) {
candidate = new CandidateMethod(degreeOfCoincidence, method);
}
}
}
Expand Down Expand Up @@ -762,11 +763,11 @@ protected EvaluationResult createEvaluationResult(
return new EvaluationResult(nullable, Integer.class);
} else if (value instanceof OptionalLong) {
OptionalLong optional = (OptionalLong) value;
Long nullable = optional.isPresent() ? Long.valueOf(optional.getAsLong()) : null;
Long nullable = optional.isPresent() ? optional.getAsLong() : null;
return new EvaluationResult(nullable, Long.class);
} else if (value instanceof OptionalDouble) {
OptionalDouble optional = (OptionalDouble) value;
Double nullable = optional.isPresent() ? Double.valueOf(optional.getAsDouble()) : null;
Double nullable = optional.isPresent() ? optional.getAsDouble() : null;
return new EvaluationResult(nullable, Double.class);
}
if (target != null) {
Expand Down Expand Up @@ -831,7 +832,7 @@ protected EvaluationResult concat(Text other) {

protected static class Number {

protected static final Map<Class<?>, Integer> priorityMap = new HashMap<Class<?>, Integer>();
protected static final Map<Class<?>, Integer> priorityMap = new HashMap<>();

static {
priorityMap.put(BigDecimal.class, 80);
Expand Down Expand Up @@ -954,6 +955,7 @@ protected EvaluationResult multiply(Number other) {
protected EvaluationResult divide(Number other) {
BigDecimal newValue = null;
try {
//noinspection BigDecimalMethodWithoutRoundingCalled
newValue = numberValue.divide(other.numberValue);
} catch (ArithmeticException e) {
handleArithmeticException(e);
Expand Down Expand Up @@ -993,7 +995,7 @@ protected class ParameterCollector
implements ExpressionNodeVisitor<Void, List<EvaluationResult>> {

public ParameterCollection collect(ExpressionNode node) {
List<EvaluationResult> evaluationResults = new ArrayList<EvaluationResult>();
List<EvaluationResult> evaluationResults = new ArrayList<>();
node.accept(this, evaluationResults);
return new ParameterCollection(evaluationResults);
}
Expand Down Expand Up @@ -1186,11 +1188,11 @@ public Class<?>[] getParamTypes() {
}

protected static class CandidateMethod {
final int degreeOfcoincidence;
final int degreeOfCoincidence;
final Method method;

CandidateMethod(int degreeOfcoincidence, Method method) {
this.degreeOfcoincidence = degreeOfcoincidence;
CandidateMethod(int degreeOfCoincidence, Method method) {
this.degreeOfCoincidence = degreeOfCoincidence;
this.method = method;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

public class ExpressionParser {

protected final Deque<ExpressionNode> expressionNodes = new LinkedList<ExpressionNode>();
protected final Deque<ExpressionNode> expressionNodes = new LinkedList<>();

protected final Deque<OperatorNode> operatorNodes = new LinkedList<OperatorNode>();
protected final Deque<OperatorNode> operatorNodes = new LinkedList<>();

protected final ExpressionReducer expressionReducer = new ExpressionReducer();

Expand Down Expand Up @@ -255,6 +255,7 @@ public ExpressionNode parse() {
Message.DOMA3011, location.getExpression(), location.getPosition(), token);
}
case EOE:
//noinspection DuplicateBranchesInSwitch
{
break outer;
}
Expand Down Expand Up @@ -412,7 +413,7 @@ protected void parseStaticFieldOperand() {

protected void parseNewOperand() {
StringBuilder buf = new StringBuilder();
for (; tokenizer.next() != OPENED_PARENS; ) {
while (tokenizer.next() != OPENED_PARENS) {
if (tokenType != WHITESPACE) {
buf.append(tokenizer.getToken());
}
Expand All @@ -423,22 +424,19 @@ protected void parseNewOperand() {
}

protected void parseOperator(OperatorNode currentNode) {
if (operatorNodes.peek() == null) {
operatorNodes.push(currentNode);
} else {
if (currentNode.getPriority() > operatorNodes.peek().getPriority()) {
operatorNodes.push(currentNode);
} else {
OperatorNode first = operatorNodes.peek();
if (first != null) {
if (currentNode.getPriority() <= first.getPriority()) {
for (Iterator<OperatorNode> it = operatorNodes.iterator(); it.hasNext(); ) {
OperatorNode operatorNode = it.next();
if (operatorNode.getPriority() > currentNode.getPriority()) {
reduce(operatorNode);
it.remove();
}
}
operatorNodes.push(currentNode);
}
}
operatorNodes.push(currentNode);
}

protected void reduceAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ public enum ExpressionTokenType {

OTHER,

EOE;
EOE
}
Loading