diff --git a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java index 463099918..9a5cd30f4 100644 --- a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java +++ b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java @@ -163,8 +163,8 @@ private List evaluateSingleSource( final List> sources = Collections.>singletonList(source); final Iterable iterable = iterables.values().iterator().next(); List list; - if (iterable instanceof List) { - list = (List) iterable; + if (iterable instanceof List list1) { + list = list1; } else { list = IteratorAdapter.asList(iterable.iterator()); } diff --git a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java index b973dcfca..f7bc2ba88 100644 --- a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java +++ b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java @@ -45,8 +45,8 @@ public MultiComparator(Evaluator ev, boolean[] directions, boolean[] n @Override public int compare(T o1, T o2) { - if (o1 instanceof Object[]) { - return innerCompare(ev.evaluate((Object[]) o1), ev.evaluate((Object[]) o2)); + if (o1 instanceof Object[] objects) { + return innerCompare(ev.evaluate(objects), ev.evaluate((Object[]) o2)); } else { return innerCompare(ev.evaluate(o1), ev.evaluate(o2)); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java index a7b1d3edc..681619cd8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java @@ -113,8 +113,8 @@ public BooleanBuilder clone() throws CloneNotSupportedException { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof BooleanBuilder) { - return Objects.equals(((BooleanBuilder) o).getValue(), predicate); + } else if (o instanceof BooleanBuilder builder) { + return Objects.equals(builder.getValue(), predicate); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java index bd5cefe48..5af759876 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java @@ -158,7 +158,7 @@ private void addLastJoin() { public void addJoin(JoinType joinType, Expression expr) { addLastJoin(); if (!exprInJoins.contains(expr)) { - if (expr instanceof Path && ((Path) expr).getMetadata().isRoot()) { + if (expr instanceof Path path && path.getMetadata().isRoot()) { exprInJoins.add(expr); } else { validate(expr); @@ -378,8 +378,7 @@ public void setValidatingVisitor(ValidatingVisitor visitor) { @Override public boolean equals(Object o) { - if (o instanceof QueryMetadata) { - var q = (QueryMetadata) o; + if (o instanceof QueryMetadata q) { return q.getFlags().equals(flags) && q.getGroupBy().equals(groupBy) && Objects.equals(q.getHaving(), having) diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java index 975521d1c..3e817b31e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java @@ -107,8 +107,7 @@ public int hashCode() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof JoinExpression) { - var j = (JoinExpression) o; + } else if (o instanceof JoinExpression j) { return Objects.equals(condition, j.condition) && Objects.equals(target, j.target) && Objects.equals(type, j.type); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java index c24348edd..cd9ece7a0 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java @@ -106,8 +106,8 @@ public int hashCode() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof JoinFlag) { - return ((JoinFlag) obj).flag.equals(flag); + } else if (obj instanceof JoinFlag joinFlag) { + return joinFlag.flag.equals(flag); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java index 4ae16e003..9e7e396c4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java @@ -103,8 +103,7 @@ public int hashCode() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof QueryFlag) { - var other = (QueryFlag) obj; + } else if (obj instanceof QueryFlag other) { return other.position.equals(position) && other.flag.equals(flag); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java index 536141911..ad03f9ca8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java @@ -120,8 +120,7 @@ public List subList(List list) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof QueryModifiers) { - var qm = (QueryModifiers) o; + } else if (o instanceof QueryModifiers qm) { return Objects.equals(qm.getLimit(), limit) && Objects.equals(qm.getOffset(), offset); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java index c17418e84..0165678fc 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java @@ -162,8 +162,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof CollectionPath) { return (CollectionPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (CollectionPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (CollectionPath>) object.__mappedPath(); } else { return (CollectionPath>) current; } @@ -242,8 +242,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof ListPath) { return (ListPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (ListPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (ListPath>) object.__mappedPath(); } else { return (ListPath>) current; } @@ -272,8 +272,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof MapPath) { return (MapPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (MapPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (MapPath>) object.__mappedPath(); } else { return (MapPath>) current; } @@ -291,8 +291,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof SetPath) { return (SetPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (SetPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (SetPath>) object.__mappedPath(); } else { return (SetPath>) current; } @@ -351,8 +351,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof EntityPath) { return (EntityPathBase) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (EntityPathBase) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (EntityPathBase) object.__mappedPath(); } else { return (EntityPathBase) current; } @@ -364,8 +364,8 @@ private static > P getPath(D arg) { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof Path) { return (P) arg; - } else if (arg instanceof ManagedObject) { - return (P) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (P) object.__mappedPath(); } else { return (P) current; } @@ -415,8 +415,8 @@ public static A alias(Class cl, String var) { @SuppressWarnings("unchecked") public static Expression getAny(D arg) { Object current = aliasFactory.getCurrentAndReset(); - if (arg instanceof ManagedObject) { - return (Expression) ((ManagedObject) arg).__mappedPath(); + if (arg instanceof ManagedObject object) { + return (Expression) object.__mappedPath(); } else if (current != null) { return (Expression) current; } else { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java index 63d978569..834a8b825 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java @@ -74,13 +74,12 @@ protected AbstractGroupByTransformer(Expression key, Expression... express projection.add(key); for (Expression expr : expressions) { - if (expr instanceof GroupExpression) { - GroupExpression groupExpr = (GroupExpression) expr; + if (expr instanceof GroupExpression groupExpr) { groupExpressions.add(groupExpr); Expression colExpression = groupExpr.getExpression(); - if (colExpression instanceof Operation - && ((Operation) colExpression).getOperator() == Ops.ALIAS) { - projection.add(((Operation) colExpression).getArg(0)); + if (colExpression instanceof Operation operation + && operation.getOperator() == Ops.ALIAS) { + projection.add(operation.getArg(0)); } else { projection.add(colExpression); } @@ -100,8 +99,8 @@ protected static FactoryExpression withoutGroupExpressions( final FactoryExpression expr) { List> args = new ArrayList<>(expr.getArgs().size()); for (Expression arg : expr.getArgs()) { - if (arg instanceof GroupExpression) { - args.add(((GroupExpression) arg).getExpression()); + if (arg instanceof GroupExpression expression) { + args.add(expression.getExpression()); } else { args.add(arg); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java index 9e813643a..ff39e4224 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java @@ -50,9 +50,8 @@ public GroupImpl(List> columnDefinitions, List collector = coldef.createGroupCollector(); Expression coldefExpr = coldef.getExpression(); groupCollectorMap.put(coldefExpr, collector); - if (coldefExpr instanceof Operation - && ((Operation) coldefExpr).getOperator() == Ops.ALIAS) { - groupCollectorMap.put(((Operation) coldefExpr).getArg(1), collector); + if (coldefExpr instanceof Operation operation && operation.getOperator() == Ops.ALIAS) { + groupCollectorMap.put(operation.getArg(1), collector); } } groupCollectors.add(collector); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java index 674b4d372..3f8b17273 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java @@ -48,8 +48,7 @@ public class CollectionAnyVisitor implements Visitor, Context> { private static Path replaceParent(Path path, Path parent) { var metadata = new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()); - if (path instanceof CollectionExpression) { - CollectionExpression col = (CollectionExpression) path; + if (path instanceof CollectionExpression col) { return Expressions.listPath(col.getParameter(0), SimplePath.class, metadata); } else { return ExpressionUtils.path(path.getType(), metadata); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java index 93b572775..848d42877 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java @@ -50,8 +50,8 @@ public ConstantHidingExpression(FactoryExpression expr) { for (var i = 0; i < template.length; i++) { Expression arg = expr.getArgs().get(i); Expression unwrapped = unwrap(arg); - if (unwrapped instanceof Constant) { - template[i] = ((Constant) unwrapped).getConstant(); + if (unwrapped instanceof Constant constant) { + template[i] = constant.getConstant(); } else if (unwrapped.equals(Expressions.TRUE)) { template[i] = Boolean.TRUE; } else if (unwrapped.equals(Expressions.FALSE)) { @@ -64,8 +64,8 @@ public ConstantHidingExpression(FactoryExpression expr) { private static Expression unwrap(Expression expr) { expr = ExpressionUtils.extract(expr); - if (expr instanceof Operation && ((Operation) expr).getOperator() == Ops.ALIAS) { - return ((Operation) expr).getArg(0); + if (expr instanceof Operation operation && operation.getOperator() == Ops.ALIAS) { + return operation.getArg(0); } return expr; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java index 38c7f0372..f3f8fd1ff 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java @@ -61,8 +61,8 @@ public T newInstance(Object... args) { @SuppressWarnings("unchecked") // The expression type is an enum var rv = (T) Enum.valueOf(getType().asSubclass(Enum.class), args[0].toString()); return rv; - } else if (args[0] instanceof Number) { - return values[((Number) args[0]).intValue()]; + } else if (args[0] instanceof Number number) { + return values[number.intValue()]; } else { @SuppressWarnings("unchecked") var rv = (T) args[0]; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java index c915a094c..603a140f8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java @@ -73,8 +73,7 @@ protected T uniqueResult(CloseableIterator it) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof SubQueryExpression) { - SubQueryExpression s = (SubQueryExpression) o; + } else if (o instanceof SubQueryExpression s) { return s.getMetadata().equals(queryMixin.getMetadata()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java index 527dc207c..dfb5c1e12 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java @@ -68,16 +68,16 @@ public T newInstance(Object... args) { for (var i = 0; i < args.length; i++) { Class type = expr.getArgs().get(i).getType(); if (Enum.class.isAssignableFrom(type) && !type.isInstance(args[i])) { - if (args[i] instanceof String) { - args[i] = Enum.valueOf((Class) type, (String) args[i]); - } else if (args[i] instanceof Number) { - args[i] = getValues((Class) type)[((Number) args[i]).intValue()]; + if (args[i] instanceof String string) { + args[i] = Enum.valueOf((Class) type, string); + } else if (args[i] instanceof Number number) { + args[i] = getValues((Class) type)[number.intValue()]; } - } else if (args[i] instanceof Number && !type.isInstance(args[i])) { + } else if (args[i] instanceof Number number && !type.isInstance(args[i])) { if (type.equals(Boolean.class)) { - args[i] = ((Number) args[i]).intValue() > 0; + args[i] = number.intValue() > 0; } else if (Number.class.isAssignableFrom(type)) { - args[i] = MathUtils.cast((Number) args[i], (Class) type); + args[i] = MathUtils.cast(number, (Class) type); } } } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java index 141cdd0ae..3df31f036 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java @@ -77,8 +77,8 @@ public Void visit(TemplateExpression expr, List> paths) { public Path visit(Collection exprs, List> paths) { for (Object e : exprs) { - if (e instanceof Expression) { - ((Expression) e).accept(this, paths); + if (e instanceof Expression expression) { + expression.accept(this, paths); } } return null; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java index 67eb9fec1..5be6c4dd0 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java @@ -178,8 +178,7 @@ public

Q set(ParamExpression

param, P value) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof QueryBase) { - var q = (QueryBase) o; + } else if (o instanceof QueryBase q) { return q.queryMixin.equals(queryMixin); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java index 0ad21f0fa..e59b016f5 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java @@ -150,14 +150,14 @@ private Path normalizePath(Path expr) { @SuppressWarnings({"rawtypes", "unchecked"}) public Expression convert(Expression expr, Role role) { if (expandAnyPaths) { - if (expr instanceof Path) { - expr = (Expression) normalizePath((Path) expr); + if (expr instanceof Path path) { + expr = (Expression) normalizePath(path); } else if (expr != null) { expr = (Expression) expr.accept(replaceVisitor, null); } } - if (expr instanceof ProjectionRole) { - return convert(((ProjectionRole) expr).getProjection(), role); + if (expr instanceof ProjectionRole pr) { + return convert((pr).getProjection(), role); } else if (expr instanceof FactoryExpression && !(expr instanceof FactoryExpressionAdapter)) { return FactoryExpressionUtils.wrap((FactoryExpression) expr); @@ -437,8 +437,7 @@ public final T where(Predicate... o) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof QueryMixin) { - QueryMixin q = (QueryMixin) o; + } else if (o instanceof QueryMixin q) { return q.metadata.equals(metadata); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java index 082a7e543..0657a2047 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java @@ -39,8 +39,7 @@ public Publisher transform(ReactiveResultTransformer transformer) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof SubQueryExpression) { - SubQueryExpression s = (SubQueryExpression) o; + } else if (o instanceof SubQueryExpression s) { return s.getMetadata().equals(queryMixin.getMetadata()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java index bd4664e23..8d293fbaf 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java @@ -88,8 +88,8 @@ public Expression visit(Path expr, C context) { var metadata = expr.getMetadata(); Path parent = (Path) metadata.getParent().accept(this, context); var element = metadata.getElement(); - if (element instanceof Expression) { - element = ((Expression) element).accept(this, context); + if (element instanceof Expression expression) { + element = expression.accept(this, context); } if (parent.equals(metadata.getParent()) && Objects.equals(element, metadata.getElement())) { return expr; @@ -155,8 +155,8 @@ public Expression visit(SubQueryExpression expr, C context) { public Expression visit(TemplateExpression expr, C context) { ArrayList args = new ArrayList<>(); for (Object arg : expr.getArgs()) { - if (arg instanceof Expression) { - args.add(((Expression) arg).accept(this, context)); + if (arg instanceof Expression expression) { + args.add(expression.accept(this, context)); } else { args.add(arg); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java index 616a92bb0..8af04c3ac 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java @@ -116,8 +116,8 @@ public final S handle(Expression expr) { } public final S handle(Object arg) { - if (arg instanceof Expression) { - ((Expression) arg).accept(this, null); + if (arg instanceof Expression expression) { + expression.accept(this, null); } else { visitConstant(arg); } @@ -146,8 +146,8 @@ public final S handle(final String sep, final List> expr protected void handleTemplate(final Template template, final List args) { for (final Template.Element element : template.getElements()) { final var rv = element.convert(args); - if (rv instanceof Expression) { - ((Expression) rv).accept(this, null); + if (rv instanceof Expression expression) { + expression.accept(this, null); } else if (element.isString()) { builder.append(rv.toString()); } else { @@ -304,10 +304,9 @@ protected void visitOperation( var first = true; for (final Template.Element element : template.getElements()) { final var rv = element.convert(args); - if (rv instanceof Expression) { - final Expression expr = (Expression) rv; - if (precedence > -1 && expr instanceof Operation) { - var op = ((Operation) expr).getOperator(); + if (rv instanceof Expression expr) { + if (precedence > -1 && expr instanceof Operation operation) { + var op = operation.getOperator(); var opPrecedence = templates.getPrecedence(op); if (precedence < opPrecedence) { append("(").handle(expr).append(")"); @@ -328,9 +327,8 @@ protected void visitOperation( } } else if (strict) { throw new IllegalArgumentException( - String.format( - "No pattern found for %s. Make sure to register any custom functions with %s.", - operator, templates.getClass())); + "No pattern found for %s. Make sure to register any custom functions with %s." + .formatted(operator, templates.getClass())); } else { append(operator.toString()); append("("); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java index f322258b6..2636397bd 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java @@ -79,8 +79,7 @@ public List> getArgs() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java index e0654d09f..d5d432513 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java @@ -144,8 +144,8 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Constant) { - return ((Constant) o).getConstant().equals(constant); + } else if (o instanceof Constant constant1) { + return constant1.getConstant().equals(constant); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java index 61fe66bf3..46014baf3 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java @@ -115,8 +115,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof ConstructorExpression) { - ConstructorExpression c = (ConstructorExpression) obj; + } else if (obj instanceof ConstructorExpression c) { return Arrays.equals(parameterTypes, c.parameterTypes) && args.equals(c.args) && getType().equals(c.getType()); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java index 7daab4481..32fa19d86 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java @@ -548,8 +548,7 @@ public static Expression likeToRegex(Expression expr, boolean ma if (!like.equals(rv.toString())) { return ConstantImpl.create(rv.toString()); } - } else if (expr instanceof Operation) { - Operation o = (Operation) expr; + } else if (expr instanceof Operation o) { if (o.getOperator() == Ops.CONCAT) { var lhs = likeToRegex((Expression) o.getArg(0), false); var rhs = likeToRegex((Expression) o.getArg(1), false); @@ -628,8 +627,7 @@ public static Expression regexToLike(Expression expr) { if (!rv.toString().equals(str)) { return ConstantImpl.create(rv.toString()); } - } else if (expr instanceof Operation) { - Operation o = (Operation) expr; + } else if (expr instanceof Operation o) { if (o.getOperator() == Ops.CONCAT) { var lhs = regexToLike((Expression) o.getArg(0)); var rhs = regexToLike((Expression) o.getArg(1)); @@ -820,8 +818,8 @@ public static String createRootVariable(Path path) { * @return converted argument */ public static Expression toExpression(Object o) { - if (o instanceof Expression) { - return (Expression) o; + if (o instanceof Expression expression) { + return expression; } else { return ConstantImpl.create(o); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java index d1f5d9e40..d339ca698 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java @@ -61,8 +61,8 @@ public R accept(Visitor v, @Nullable C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof FactoryExpressionWrapper) { - return expr.equals(((FactoryExpressionWrapper) o).expr); + } else if (o instanceof FactoryExpressionWrapper wrapper) { + return expr.equals(wrapper.expr); } else { return false; } @@ -86,8 +86,8 @@ public FactoryExpression skipNulls() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof FactoryExpression) { - return getClass().equals(o.getClass()) && getArgs().equals(((FactoryExpression) o).getArgs()); + } else if (o instanceof FactoryExpression expression) { + return getClass().equals(o.getClass()) && getArgs().equals(expression.getArgs()); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java index 4b5b49522..904e49e2d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java @@ -71,8 +71,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof FactoryExpression) { - FactoryExpression e = (FactoryExpression) o; + } else if (o instanceof FactoryExpression e) { return args.equals(e.getArgs()) && getType().equals(e.getType()); } else { return false; @@ -99,8 +98,8 @@ public static FactoryExpression wrap( public static FactoryExpression wrap(FactoryExpression expr) { for (Expression arg : expr.getArgs()) { - if (arg instanceof ProjectionRole) { - arg = ((ProjectionRole) arg).getProjection(); + if (arg instanceof ProjectionRole role) { + arg = role.getProjection(); } if (arg instanceof FactoryExpression) { return new FactoryExpressionAdapter<>(expr); @@ -112,11 +111,11 @@ public static FactoryExpression wrap(FactoryExpression expr) { private static List> expand(List> exprs) { List> rv = new ArrayList<>(exprs.size()); for (Expression expr : exprs) { - if (expr instanceof ProjectionRole) { - expr = ((ProjectionRole) expr).getProjection(); + if (expr instanceof ProjectionRole role) { + expr = role.getProjection(); } - if (expr instanceof FactoryExpression) { - rv.addAll(expand(((FactoryExpression) expr).getArgs())); + if (expr instanceof FactoryExpression expression) { + rv.addAll(expand(expression.getArgs())); } else { rv.add(expr); } @@ -127,11 +126,11 @@ private static List> expand(List> exprs) { private static int countArguments(FactoryExpression expr) { var counter = 0; for (Expression arg : expr.getArgs()) { - if (arg instanceof ProjectionRole) { - arg = ((ProjectionRole) arg).getProjection(); + if (arg instanceof ProjectionRole role) { + arg = role.getProjection(); } - if (arg instanceof FactoryExpression) { - counter += countArguments((FactoryExpression) arg); + if (arg instanceof FactoryExpression expression) { + counter += countArguments(expression); } else { counter++; } @@ -144,11 +143,10 @@ private static Object[] compress(List> exprs, Object[] args) { var offset = 0; for (var i = 0; i < exprs.size(); i++) { Expression expr = exprs.get(i); - if (expr instanceof ProjectionRole) { - expr = ((ProjectionRole) expr).getProjection(); + if (expr instanceof ProjectionRole role) { + expr = role.getProjection(); } - if (expr instanceof FactoryExpression) { - FactoryExpression fe = (FactoryExpression) expr; + if (expr instanceof FactoryExpression fe) { var fullArgsLength = countArguments(fe); var compressed = compress(fe.getArgs(), ArrayUtils.subarray(args, offset, offset + fullArgsLength)); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java index 88902cd8f..cab09a78c 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java @@ -69,8 +69,7 @@ public final Operator getOperator() { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Operation) { - Operation op = (Operation) o; + } else if (o instanceof Operation op) { return op.getOperator() == operator && op.getArgs().equals(args) && op.getType().equals(getType()); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java index 8d4b79eb7..bffb4bb3d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java @@ -113,8 +113,7 @@ public String toString() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof OrderSpecifier) { - OrderSpecifier os = (OrderSpecifier) o; + } else if (o instanceof OrderSpecifier os) { return os.order.equals(order) && os.target.equals(target) && os.nullHandling.equals(nullHandling); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java index 5a5622084..f67913643 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java @@ -52,8 +52,7 @@ public final R accept(Visitor v, C context) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ParamExpression) { - ParamExpression other = (ParamExpression) o; + } else if (o instanceof ParamExpression other) { return other.getType().equals(getType()) && other.getName().equals(name) && other.isAnon() == anon; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java index 8e781dba8..157327eb4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java @@ -78,8 +78,8 @@ public Void visit(SubQueryExpression expr, QueryMetadata context) { @Override public Void visit(TemplateExpression expr, QueryMetadata context) { for (Object arg : expr.getArgs()) { - if (arg instanceof Expression) { - ((Expression) arg).accept(this, context); + if (arg instanceof Expression expression) { + expression.accept(this, context); } } return null; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java index 4407d026a..11ddcd94f 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java @@ -63,8 +63,8 @@ public Path visit(TemplateExpression expr, Void context) { private Path visit(List exprs) { for (Object e : exprs) { - if (e instanceof Expression) { - Path path = ((Expression) e).accept(this, null); + if (e instanceof Expression expression) { + Path path = expression.accept(this, null); if (path != null) { return path; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java index d68598132..404e45d52 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java @@ -53,8 +53,8 @@ protected PathImpl(Class type, Path parent, String property) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Path) { - return ((Path) o).getMetadata().equals(metadata); + } else if (o instanceof Path path) { + return path.getMetadata().equals(metadata); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java index ecee9e0c8..aaf2df59f 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java @@ -48,8 +48,7 @@ public PathMetadata(@Nullable Path parent, Object element, PathType type) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof PathMetadata) { - var p = (PathMetadata) obj; + } else if (obj instanceof PathMetadata p) { return element.equals(p.element) && pathType == p.pathType && Objects.equals(parent, p.parent); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java index 57d5b5eed..728c9c973 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java @@ -50,11 +50,9 @@ public class QBean extends FactoryExpressionBase { private static Map> createBindings(Expression... args) { Map> rv = new LinkedHashMap<>(); for (Expression expr : args) { - if (expr instanceof Path) { - Path path = (Path) expr; + if (expr instanceof Path path) { rv.put(path.getMetadata().getName(), expr); - } else if (expr instanceof Operation) { - Operation operation = (Operation) expr; + } else if (expr instanceof Operation operation) { if (operation.getOperator() == Ops.ALIAS && operation.getArg(1) instanceof Path) { Path path = (Path) operation.getArg(1); if (isCompoundExpression(operation.getArg(0))) { @@ -275,8 +273,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof QBean) { - QBean c = (QBean) obj; + } else if (obj instanceof QBean c) { return getArgs().equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java index ec82ca5ce..a45334860 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java @@ -85,8 +85,7 @@ public List> getArgs() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java index 6cec69316..2c1d95e46 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java @@ -97,8 +97,7 @@ public List> getArgs() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java index 7e20b1ce5..c5becc346 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java @@ -58,8 +58,8 @@ private static Map, Integer> createBindings(List> ex Map, Integer> map = new LinkedHashMap<>(); for (var i = 0; i < exprs.size(); i++) { Expression e = exprs.get(i); - if (e instanceof Operation && ((Operation) e).getOperator() == Ops.ALIAS) { - map.put(((Operation) e).getArg(1), i); + if (e instanceof Operation operation && operation.getOperator() == Ops.ALIAS) { + map.put(operation.getArg(1), i); } map.put(e, i); } @@ -107,8 +107,8 @@ public Object[] toArray() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof Tuple) { - return Arrays.equals(a, ((Tuple) obj).toArray()); + } else if (obj instanceof Tuple tuple) { + return Arrays.equals(a, tuple.toArray()); } else { return false; } @@ -180,8 +180,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java index 249ffddb1..1965fb8e2 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java @@ -173,8 +173,8 @@ public ByIndex(int index) { @Override public Object convert(final List args) { final Object arg = args.get(index); - if (arg instanceof Expression) { - return ExpressionUtils.extract((Expression) arg); + if (arg instanceof Expression expression) { + return ExpressionUtils.extract(expression); } else { return arg; } @@ -223,20 +223,19 @@ public Object convert(List args) { Expression expr1 = asExpression(arg1); Expression expr2 = asExpression(arg2); - if (arg2 instanceof Number) { + if (arg2 instanceof Number number) { if (CONVERTIBLES.contains(operator) - && expr1 instanceof com.querydsl.core.types.Operation) { - var operation = (com.querydsl.core.types.Operation) expr1; + && expr1 instanceof com.querydsl.core.types.Operation operation) { if (CONVERTIBLES.contains(operation.getOperator()) && operation.getArg(1) instanceof Constant) { var num1 = ((Constant) operation.getArg(1)).getConstant(); Number num2; if (operator == operation.getOperator()) { - num2 = MathUtils.result(num1, (Number) arg2, Ops.ADD); + num2 = MathUtils.result(num1, number, Ops.ADD); } else if (operator == Ops.ADD) { - num2 = MathUtils.result((Number) arg2, num1, Ops.SUB); + num2 = MathUtils.result(number, num1, Ops.SUB); } else { - num2 = MathUtils.result(num1, (Number) arg2, Ops.SUB); + num2 = MathUtils.result(num1, number, Ops.SUB); } return ExpressionUtils.operation( expr1.getType(), operator, operation.getArg(0), Expressions.constant(num2)); @@ -295,8 +294,8 @@ public Object convert(List args) { } else { Expression expr1 = asExpression(arg1); - if (CONVERTIBLES.contains(operator) && expr1 instanceof com.querydsl.core.types.Operation) { - var operation = (com.querydsl.core.types.Operation) expr1; + if (CONVERTIBLES.contains(operator) + && expr1 instanceof com.querydsl.core.types.Operation operation) { if (CONVERTIBLES.contains(operation.getOperator()) && operation.getArg(1) instanceof Constant) { var num1 = ((Constant) operation.getArg(1)).getConstant(); @@ -350,8 +349,8 @@ public String toString() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Template) { - return ((Template) o).template.equals(template); + } else if (o instanceof Template template1) { + return template1.template.equals(template); } else { return false; } @@ -363,23 +362,22 @@ public int hashCode() { } private static Number asNumber(Object arg) { - if (arg instanceof Number) { - return (Number) arg; - } else if (arg instanceof Constant) { - return (Number) ((Constant) arg).getConstant(); + if (arg instanceof Number number) { + return number; + } else if (arg instanceof Constant constant) { + return (Number) constant.getConstant(); } else { throw new IllegalArgumentException(arg.toString()); } } private static boolean isNumber(Object o) { - return o instanceof Number - || o instanceof Constant && ((Constant) o).getConstant() instanceof Number; + return o instanceof Number || o instanceof Constant c && c.getConstant() instanceof Number; } private static Expression asExpression(Object arg) { - if (arg instanceof Expression) { - return ExpressionUtils.extract((Expression) arg); + if (arg instanceof Expression expression) { + return ExpressionUtils.extract(expression); } else { return Expressions.constant(arg); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java index 6d48e6977..5032e1f09 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java @@ -64,8 +64,7 @@ public final Template getTemplate() { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof TemplateExpression) { - TemplateExpression c = (TemplateExpression) o; + } else if (o instanceof TemplateExpression c) { return c.getTemplate().equals(template) && c.getType().equals(getType()) && c.getArgs().equals(args); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java index 3e07b0b9d..298610663 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java @@ -67,8 +67,8 @@ public class TemplateFactory { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.LOWER, (Expression) arg); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.LOWER, expression); } else { return String.valueOf(arg).toLowerCase(); } @@ -81,8 +81,8 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.UPPER, (Expression) arg); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.UPPER, expression); } else { return String.valueOf(arg).toUpperCase(); } @@ -95,8 +95,8 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.CONCAT, (Expression) arg, PERCENT); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.CONCAT, expression, PERCENT); } else { return escapeForLike(String.valueOf(arg)) + "%"; } @@ -109,9 +109,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, (Expression) arg, PERCENT); + ExpressionUtils.operation(String.class, Ops.CONCAT, expression, PERCENT); return ExpressionUtils.operation(String.class, Ops.LOWER, concatenated); } else { return escapeForLike(String.valueOf(arg).toLowerCase()) + "%"; @@ -125,8 +125,8 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); } else { return "%" + escapeForLike(String.valueOf(arg)); } @@ -139,9 +139,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); return ExpressionUtils.operation(String.class, Ops.LOWER, concatenated); } else { return "%" + escapeForLike(String.valueOf(arg).toLowerCase()); @@ -155,9 +155,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); return ExpressionUtils.operation(String.class, Ops.CONCAT, concatenated, PERCENT); } else { return "%" + escapeForLike(String.valueOf(arg)) + "%"; @@ -171,9 +171,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); concatenated = ExpressionUtils.operation(String.class, Ops.CONCAT, concatenated, PERCENT); return ExpressionUtils.operation(String.class, Ops.LOWER, concatenated); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java index 4a5614c7c..0e4713dbf 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java @@ -57,16 +57,16 @@ public String visit(Operation o, Templates templates) { final var builder = new StringBuilder(); for (Template.Element element : template.getElements()) { final var rv = element.convert(o.getArgs()); - if (rv instanceof Expression) { - if (precedence > -1 && rv instanceof Operation) { - if (precedence < templates.getPrecedence(((Operation) rv).getOperator())) { + if (rv instanceof Expression expression) { + if (precedence > -1 && rv instanceof Operation operation) { + if (precedence < templates.getPrecedence(operation.getOperator())) { builder.append("("); - builder.append(((Expression) rv).accept(this, templates)); + builder.append(operation.accept(this, templates)); builder.append(")"); continue; } } - builder.append(((Expression) rv).accept(this, templates)); + builder.append(expression.accept(this, templates)); } else { builder.append(rv.toString()); } @@ -96,8 +96,8 @@ public String visit(Path p, Templates templates) { final var builder = new StringBuilder(); for (Template.Element element : pattern.getElements()) { var rv = element.convert(args); - if (rv instanceof Expression) { - builder.append(((Expression) rv).accept(this, templates)); + if (rv instanceof Expression expression) { + builder.append(expression.accept(this, templates)); } else { builder.append(rv.toString()); } @@ -121,8 +121,8 @@ public String visit(TemplateExpression expr, Templates templates) { final var builder = new StringBuilder(); for (Template.Element element : expr.getTemplate().getElements()) { var rv = element.convert(expr.getArgs()); - if (rv instanceof Expression) { - builder.append(((Expression) rv).accept(this, templates)); + if (rv instanceof Expression expression) { + builder.append(expression.accept(this, templates)); } else { builder.append(rv.toString()); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java index a706b05d6..29e01ba76 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java @@ -74,7 +74,7 @@ public Set> visit(ParamExpression expr, Set> know @Override public Set> visit(Path expr, Set> known) { if (!known.contains(expr.getRoot())) { - throw new IllegalArgumentException(String.format(errorTemplate, expr.getRoot())); + throw new IllegalArgumentException(errorTemplate.formatted(expr.getRoot())); } return known; } @@ -105,8 +105,8 @@ public Set> visit(SubQueryExpression expr, Set> k @Override public Set> visit(TemplateExpression expr, Set> known) { for (Object arg : expr.getArgs()) { - if (arg instanceof Expression) { - known = ((Expression) arg).accept(this, known); + if (arg instanceof Expression expression) { + known = expression.accept(this, known); } } return known; @@ -115,7 +115,7 @@ public Set> visit(TemplateExpression expr, Set> k private Set> visitJoins(Iterable joins, Set> known) { for (JoinExpression j : joins) { final Expression expr = j.getTarget(); - if (expr instanceof Path && ((Path) expr).getMetadata().isRoot()) { + if (expr instanceof Path path && path.getMetadata().isRoot()) { known = add(known, expr); } else { known = expr.accept(this, known); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java index a6b9ea83e..78bea3359 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java @@ -158,20 +158,20 @@ public Initial(Predicate b) { @SuppressWarnings("unchecked") public Cases> then(Expression expr) { - if (expr instanceof Predicate) { - return (Cases) then((Predicate) expr); - } else if (expr instanceof StringExpression) { - return (Cases) then((StringExpression) expr); - } else if (expr instanceof NumberExpression) { - return then((NumberExpression) expr); - } else if (expr instanceof DateExpression) { - return then((DateExpression) expr); - } else if (expr instanceof DateTimeExpression) { - return then((DateTimeExpression) expr); - } else if (expr instanceof TimeExpression) { - return then((TimeExpression) expr); - } else if (expr instanceof ComparableExpression) { - return then((ComparableExpression) expr); + if (expr instanceof Predicate predicate) { + return (Cases) then(predicate); + } else if (expr instanceof StringExpression se) { + return (Cases) then(se); + } else if (expr instanceof NumberExpression ne) { + return then(ne); + } else if (expr instanceof DateExpression de) { + return then(de); + } else if (expr instanceof DateTimeExpression dte) { + return then(dte); + } else if (expr instanceof TimeExpression te) { + return then(te); + } else if (expr instanceof ComparableExpression ce) { + return then(ce); } else { return thenSimple(expr); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java index 25ac60896..87adfe554 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java @@ -76,20 +76,20 @@ public CaseForEqBuilder(Expression base, Expression other) { } public Cases> then(Expression expr) { - if (expr instanceof Predicate) { - return (Cases) then((Predicate) expr); - } else if (expr instanceof StringExpression) { - return (Cases) then((StringExpression) expr); - } else if (expr instanceof NumberExpression) { - return then((NumberExpression) expr); - } else if (expr instanceof DateExpression) { - return then((DateExpression) expr); - } else if (expr instanceof DateTimeExpression) { - return then((DateTimeExpression) expr); - } else if (expr instanceof TimeExpression) { - return then((TimeExpression) expr); - } else if (expr instanceof ComparableExpression) { - return then((ComparableExpression) expr); + if (expr instanceof Predicate p) { + return (Cases) then(p); + } else if (expr instanceof StringExpression se) { + return (Cases) then(se); + } else if (expr instanceof NumberExpression ne) { + return then(ne); + } else if (expr instanceof DateExpression de) { + return then(de); + } else if (expr instanceof DateTimeExpression dte) { + return then(dte); + } else if (expr instanceof TimeExpression te) { + return then(te); + } else if (expr instanceof ComparableExpression ce) { + return then(ce); } else { return thenSimple(expr); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java index d423015dd..7af91de5b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java @@ -145,8 +145,7 @@ private Expression getExpressionList() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Coalesce) { - Coalesce c = (Coalesce) o; + } else if (o instanceof Coalesce c) { return c.exprs.equals(exprs); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java index f4f6e6507..548f90a31 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java @@ -1580,10 +1580,10 @@ public static BooleanExpression asBoolean(Expression expr) { Expression underlyingMixin = ExpressionUtils.extract(expr); if (underlyingMixin instanceof PathImpl) { return new BooleanPath((PathImpl) underlyingMixin); - } else if (underlyingMixin instanceof PredicateOperation) { - return new BooleanOperation((PredicateOperation) underlyingMixin); - } else if (underlyingMixin instanceof PredicateTemplate) { - return new BooleanTemplate((PredicateTemplate) underlyingMixin); + } else if (underlyingMixin instanceof PredicateOperation operation) { + return new BooleanOperation(operation); + } else if (underlyingMixin instanceof PredicateTemplate template) { + return new BooleanTemplate(template); } else { return new BooleanExpression(underlyingMixin) { @@ -1598,8 +1598,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof BooleanExpression) { - var other = (BooleanExpression) o; + } else if (o instanceof BooleanExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1647,8 +1646,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ComparableExpression) { - var other = (ComparableExpression) o; + } else if (o instanceof ComparableExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1807,8 +1805,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof EnumExpression) { - var other = (EnumExpression) o; + } else if (o instanceof EnumExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1857,8 +1854,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof NumberExpression) { - var other = (NumberExpression) o; + } else if (o instanceof NumberExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1906,8 +1902,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof StringExpression) { - var other = (StringExpression) o; + } else if (o instanceof StringExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/MathUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/MathUtils.java index d17416075..c7b1cfadb 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/MathUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/MathUtils.java @@ -75,21 +75,21 @@ public static D cast(Number num, Class type) { } else if (type.equals(BigDecimal.class)) { rv = type.cast(new BigDecimal(num.toString())); } else if (type.equals(BigInteger.class)) { - if (num instanceof BigDecimal) { - rv = type.cast(((BigDecimal) num).toBigInteger()); + if (num instanceof BigDecimal decimal) { + rv = type.cast(decimal.toBigInteger()); } else { rv = type.cast(new BigInteger(num.toString())); } } else { throw new IllegalArgumentException( - String.format("Unsupported target type : %s", type.getSimpleName())); + "Unsupported target type : %s".formatted(type.getSimpleName())); } return rv; } private static BigDecimal toBigDecimal(Number num) { - if (num instanceof BigDecimal) { - return (BigDecimal) num; + if (num instanceof BigDecimal decimal) { + return decimal; } else { return new BigDecimal(num.toString()); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/ReflectionUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/ReflectionUtils.java index 32315f422..f4266a534 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/ReflectionUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/ReflectionUtils.java @@ -92,10 +92,10 @@ public static Method getGetterOrNull(Class beanClass, String name, Class t } public static int getTypeParameterCount(java.lang.reflect.Type type) { - if (type instanceof ParameterizedType) { - return ((ParameterizedType) type).getActualTypeArguments().length; - } else if (type instanceof TypeVariable) { - return getTypeParameterCount(((TypeVariable) type).getBounds()[0]); + if (type instanceof ParameterizedType parameterizedType) { + return parameterizedType.getActualTypeArguments().length; + } else if (type instanceof TypeVariable variable) { + return getTypeParameterCount(variable.getBounds()[0]); } else { return 0; } @@ -112,34 +112,33 @@ public static Class getTypeParameterAsClass(java.lang.reflect.Type type, int @Nullable public static Type getTypeParameter(java.lang.reflect.Type type, int index) { - if (type instanceof ParameterizedType) { - return ((ParameterizedType) type).getActualTypeArguments()[index]; - } else if (type instanceof TypeVariable) { - return getTypeParameter(((TypeVariable) type).getBounds()[0], index); + if (type instanceof ParameterizedType parameterizedType) { + return parameterizedType.getActualTypeArguments()[index]; + } else if (type instanceof TypeVariable variable) { + return getTypeParameter(variable.getBounds()[0], index); } else { return null; } } private static Class asClass(Type type) { - if (type instanceof WildcardType) { - var wildcardType = (WildcardType) type; - if (wildcardType.getUpperBounds()[0] instanceof Class) { - return (Class) wildcardType.getUpperBounds()[0]; - } else if (wildcardType.getUpperBounds()[0] instanceof ParameterizedType) { - return (Class) ((ParameterizedType) wildcardType.getUpperBounds()[0]).getRawType(); + if (type instanceof WildcardType wildcardType) { + if (wildcardType.getUpperBounds()[0] instanceof Class class1) { + return class1; + } else if (wildcardType.getUpperBounds()[0] instanceof ParameterizedType parameterizedType) { + return (Class) parameterizedType.getRawType(); } else { return Object.class; } - } else if (type instanceof TypeVariable) { - return asClass(((TypeVariable) type).getBounds()[0]); - } else if (type instanceof ParameterizedType) { - return (Class) ((ParameterizedType) type).getRawType(); - } else if (type instanceof GenericArrayType) { - var component = ((GenericArrayType) type).getGenericComponentType(); + } else if (type instanceof TypeVariable variable) { + return asClass(variable.getBounds()[0]); + } else if (type instanceof ParameterizedType parameterizedType) { + return (Class) parameterizedType.getRawType(); + } else if (type instanceof GenericArrayType arrayType) { + var component = arrayType.getGenericComponentType(); return Array.newInstance(asClass(component), 0).getClass(); - } else if (type instanceof Class) { - return (Class) type; + } else if (type instanceof Class class1) { + return class1; } else { throw new IllegalArgumentException(type.getClass().toString()); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/TupleUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/TupleUtils.java index 86ef005d2..5f133bb25 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/TupleUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/TupleUtils.java @@ -10,12 +10,12 @@ public final class TupleUtils { public static Tuple toTuple(Object next, Expression[] expressions) { // workaround from https://github.com/querydsl/querydsl/issues/3264 Tuple tuple; - if (next instanceof Tuple) { - tuple = (Tuple) next; - } else if (next instanceof Object[]) { - tuple = Projections.tuple(expressions).newInstance((Object[]) next); + if (next instanceof Tuple tuple1) { + tuple = tuple1; + } else if (next instanceof Object[] objects) { + tuple = Projections.tuple(expressions).newInstance(objects); } else { - throw new IllegalArgumentException(String.format("Could not translate %s into tuple", next)); + throw new IllegalArgumentException("Could not translate %s into tuple".formatted(next)); } return tuple; } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java index d780470bd..b1c80c0bb 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java @@ -384,10 +384,10 @@ private void serializeSources(boolean forCountRow, List joins) { @Override public void visitConstant(Object constant) { if (inCaseOperation && templates.isCaseWithLiterals()) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : (Collection) constant) { + for (Object o : collection) { if (!first) { append(", "); } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java index 8f0d3e73b..dbb89a0ff 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java @@ -212,8 +212,8 @@ public String asLiteral(Object constant) { return constant.toString(); } else if (constant instanceof String) { return "'" + escapeLiteral(constant.toString()) + "'"; - } else if (constant instanceof Enum) { - return constant.getClass().getName() + "." + ((Enum) constant).name(); + } else if (constant instanceof Enum enum1) { + return constant.getClass().getName() + "." + enum1.name(); } else { return "'" + constant.toString() + "'"; } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java index 5f6aa5c19..a97948db5 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java @@ -205,10 +205,10 @@ private static ArrayList createArrayList(Object key) { @Override public void visitConstant(Object constant) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object element : ((Collection) constant)) { + for (Object element : collection) { if (!first) { append(", "); } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java index b90fb534b..76e013cf2 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java @@ -37,7 +37,7 @@ public class TransformingIterator implements CloseableIterator { public TransformingIterator(Iterator iterator, FactoryExpression projection) { this.iterator = iterator; this.projection = projection; - this.closeable = iterator instanceof Closeable ? (Closeable) iterator : null; + this.closeable = iterator instanceof Closeable c ? c : null; } public TransformingIterator( diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java index f8eb6dea3..1f7007b79 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java @@ -108,10 +108,10 @@ public static void setConstants( private static void setValueWithNumberedLabel( org.hibernate.query.Query query, Integer key, Object val) { - if (val instanceof Collection) { - query.setParameterList(key, (Collection) val); - } else if (val instanceof Object[] && !BUILT_IN.contains(val.getClass())) { - query.setParameterList(key, (Object[]) val); + if (val instanceof Collection collection) { + query.setParameterList(key, collection); + } else if (val instanceof Object[] objects && !BUILT_IN.contains(val.getClass())) { + query.setParameterList(key, objects); } else if (val instanceof Number && TYPES.containsKey(val.getClass())) { query.setParameter(key, val, getType(val.getClass())); } else { diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java index b3e4719f6..adacb516c 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java @@ -50,8 +50,8 @@ public static void setConstants( Parameter parameter = query.getParameter(i + 1); var parameterType = parameter != null ? parameter.getParameterType() : null; if (parameterType != null && !parameterType.isInstance(val)) { - if (val instanceof Number && Number.class.isAssignableFrom(parameterType)) { - val = MathUtils.cast((Number) val, parameterType); + if (val instanceof Number number && Number.class.isAssignableFrom(parameterType)) { + val = MathUtils.cast(number, parameterType); } } } diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java index d7fccd1bd..cdc67e684 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java @@ -816,10 +816,10 @@ public void serializeUnion(Expression union, QueryMetadata metadata, boolean @Override public void visitConstant(Object constant) { if (useLiterals) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -830,10 +830,10 @@ public void visitConstant(Object constant) { } else { append(configuration.asLiteral(constant)); } - } else if (constant instanceof Collection) { + } else if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -846,7 +846,7 @@ public void visitConstant(Object constant) { } append(")"); - var size = ((Collection) constant).size() - 1; + var size = collection.size() - 1; Path lastPath = constantPaths.peekLast(); for (var i = 0; i < size; i++) { constantPaths.add(lastPath); diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java index 952034206..905e31e9f 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java @@ -34,8 +34,8 @@ public CharacterType(int type) { @Override public Character getValue(Row row, int startIndex) { var val = row.get(startIndex); - if (val instanceof Character) { - return (Character) val; + if (val instanceof Character character) { + return character; } return val == null ? null : ((String) val).charAt(0); diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java index 37565256c..46280287d 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java @@ -58,12 +58,12 @@ protected LocalDate toDbValue(Date value) { @Override protected Date fromDbValue(Temporal value) { - if (value instanceof LocalDate) { - return Date.valueOf((LocalDate) value); + if (value instanceof LocalDate date) { + return Date.valueOf(date); } - if (value instanceof LocalDateTime) { - return Date.valueOf(((LocalDateTime) value).toLocalDate()); + if (value instanceof LocalDateTime time) { + return Date.valueOf(time.toLocalDate()); } // mysql // if (String.class.isAssignableFrom(value.getClass())) { diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java index 0b84e8ed2..c874178e7 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java @@ -38,8 +38,8 @@ public StringAsObjectType(int type) { @Override public String getValue(Row row, int startIndex) { var o = row.get(startIndex); - if (o instanceof String) { - return (String) o; + if (o instanceof String string) { + return string; // } else if (o instanceof Clob) { // Clob clob = (Clob) o; // return clob.stream(); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java index 283abcfb5..16208d07f 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java @@ -518,8 +518,8 @@ public QueryResults fetchResults() { } long total; if (!results.isEmpty()) { - if (lastCell instanceof Number) { - total = ((Number) lastCell).longValue(); + if (lastCell instanceof Number number) { + total = number.longValue(); } else { throw new IllegalStateException("Unsupported lastCell instance " + lastCell); } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java index b9b0af225..16c0d8ace 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java @@ -31,8 +31,8 @@ public static ColumnMetadata getColumnMetadata(Path path) { Path parent = path.getMetadata().getParent(); if (parent instanceof EntityPath) { var columnMetadata = ((EntityPath) parent).getMetadata(path); - if (columnMetadata instanceof ColumnMetadata) { - return (ColumnMetadata) columnMetadata; + if (columnMetadata instanceof ColumnMetadata metadata) { + return metadata; } } return ColumnMetadata.named(path.getMetadata().getName()); @@ -49,8 +49,8 @@ public static String getName(Path path) { Path parent = path.getMetadata().getParent(); if (parent instanceof EntityPath) { var columnMetadata = ((EntityPath) parent).getMetadata(path); - if (columnMetadata instanceof ColumnMetadata) { - return ((ColumnMetadata) columnMetadata).getName(); + if (columnMetadata instanceof ColumnMetadata metadata) { + return metadata.getName(); } } return path.getMetadata().getName(); @@ -161,8 +161,7 @@ public ColumnMetadata withDigits(int decimalDigits) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ColumnMetadata) { - var md = (ColumnMetadata) o; + } else if (o instanceof ColumnMetadata md) { return name.equals(md.name) && Objects.equals(jdbcType, md.jdbcType) && nullable == md.nullable diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java index e096ca305..f983a1339 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java @@ -142,8 +142,8 @@ public NumberExpression countDistinct() { */ @Override public BooleanExpression eq(T right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.EQ, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.EQ, primaryKey, path.getPrimaryKey()); } else { return super.eq(right); } @@ -157,8 +157,8 @@ public BooleanExpression eq(T right) { */ @Override public BooleanExpression eq(Expression right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.EQ, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.EQ, primaryKey, path.getPrimaryKey()); } else { return super.eq(right); } @@ -172,8 +172,8 @@ public BooleanExpression eq(Expression right) { */ @Override public BooleanExpression ne(T right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.NE, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.NE, primaryKey, path.getPrimaryKey()); } else { return super.ne(right); } @@ -187,8 +187,8 @@ public BooleanExpression ne(T right) { */ @Override public BooleanExpression ne(Expression right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.NE, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.NE, primaryKey, path.getPrimaryKey()); } else { return super.ne(right); } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java index efb9eacdc..a624addc0 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java @@ -95,8 +95,8 @@ public Set> visit(ParamExpression expr, Set> visit(Path expr, Set> known) { if (expr.getMetadata().isRoot()) { - if (expr instanceof RelationalPath) { - known = add(known, (RelationalPath) expr); + if (expr instanceof RelationalPath path) { + known = add(known, path); } } else { known = expr.getMetadata().getParent().accept(this, known); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java index 762ac694f..2a7e44367 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java @@ -35,8 +35,7 @@ class SQLListenerAdapter implements SQLDetailedListener { private final SQLDetailedListener detailedListener; SQLListenerAdapter(final SQLListener sqlListener) { - this.detailedListener = - sqlListener instanceof SQLDetailedListener ? (SQLDetailedListener) sqlListener : null; + this.detailedListener = sqlListener instanceof SQLDetailedListener sqldl ? sqldl : null; this.sqlListener = sqlListener; } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java index 40dc38986..3a4067715 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java @@ -50,12 +50,12 @@ public SQLListeners() { } public void add(SQLListener listener) { - if (listener instanceof SQLListeners) { - for (SQLListener l : ((SQLListeners) listener).listeners) { + if (listener instanceof SQLListeners lListeners) { + for (SQLListener l : lListeners.listeners) { add(l); } - } else if (listener instanceof SQLDetailedListener) { - listeners.add((SQLDetailedListener) listener); + } else if (listener instanceof SQLDetailedListener detailedListener) { + listeners.add(detailedListener); } else { listeners.add(new SQLListenerAdapter(listener)); } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java index 033692a21..967258067 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java @@ -607,14 +607,12 @@ public void serializeForMergeUsing( append("\nusing "); // A hacky way to allow merging table to table directly - if (usingExpression instanceof RelationalPath) { + if (usingExpression instanceof RelationalPath path) { dmlWithSchema = true; // If table has an alias, handle both original table name and alias - if (!((RelationalPath) usingExpression) - .getTableName() - .equals(ColumnMetadata.getName((RelationalPath) usingExpression))) { + if (!path.getTableName().equals(ColumnMetadata.getName(path))) { RelationalPath originalEntity = this.entity; - this.entity = (RelationalPath) usingExpression; + this.entity = path; handle(usingExpression); append(" "); this.entity = originalEntity; @@ -936,10 +934,10 @@ public void serializeUnion(Expression union, QueryMetadata metadata, boolean @Override public void visitConstant(Object constant) { if (useLiterals) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -950,10 +948,10 @@ public void visitConstant(Object constant) { } else { append(configuration.asLiteral(constant)); } - } else if (constant instanceof Collection) { + } else if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -966,7 +964,7 @@ public void visitConstant(Object constant) { } append(")"); - var size = ((Collection) constant).size() - 1; + var size = collection.size() - 1; Path lastPath = constantPaths.peekLast(); for (var i = 0; i < size; i++) { constantPaths.add(lastPath); @@ -1007,8 +1005,8 @@ protected void serializeConstant(int parameterIndex, String constantLabel) { @Override public Void visit(Path path, Void context) { if (dml) { - if (path.equals(entity) && path instanceof RelationalPath) { - var schemaAndTable = getSchemaAndTable((RelationalPath) path); + if (path.equals(entity) && path instanceof RelationalPath relationalPath) { + var schemaAndTable = getSchemaAndTable(relationalPath); boolean precededByDot; if (dmlWithSchema && templates.isPrintSchema()) { appendSchemaName(schemaAndTable.getSchema()); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java index 7907d5068..b0f3a771a 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java @@ -38,8 +38,7 @@ public String getTable() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof SchemaAndTable) { - var st = (SchemaAndTable) o; + } else if (o instanceof SchemaAndTable st) { return Objects.equals(st.schema, schema) && Objects.equals(st.table, table); } else { return false; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java index 91864c784..bb9d11442 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java @@ -121,8 +121,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof WindowFunction) { - WindowFunction so = (WindowFunction) o; + } else if (o instanceof WindowFunction so) { return so.target.equals(target) && so.partitionBy.equals(partitionBy) && so.orderBy.equals(orderBy); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java index a97b943a2..cb1268e92 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java @@ -39,10 +39,9 @@ public StringAsObjectType(int type) { @Override public String getValue(ResultSet rs, int startIndex) throws SQLException { var o = rs.getObject(startIndex); - if (o instanceof String) { - return (String) o; - } else if (o instanceof Clob) { - var clob = (Clob) o; + if (o instanceof String string) { + return string; + } else if (o instanceof Clob clob) { return clob.getSubString(1, (int) clob.length()); } else if (o != null) { return o.toString(); diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java index e03d74a4c..c30ac8264 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java @@ -248,8 +248,8 @@ protected Set collectElements() { // from class annotations for (Class annotation : conf.getEntityAnnotations()) { for (Element element : getElements(annotation)) { - if (element instanceof TypeElement) { - elements.add((TypeElement) element); + if (element instanceof TypeElement typeElement) { + elements.add(typeElement); } } } @@ -402,8 +402,8 @@ private void handleEmbeddedType(Element element, Set elements) { private Set getTypeFromProperties(Set parents) { Set elements = new HashSet<>(); for (Element element : parents) { - if (element instanceof TypeElement) { - processFromProperties((TypeElement) element, elements); + if (element instanceof TypeElement typeElement) { + processFromProperties(typeElement, elements); } } @@ -470,10 +470,10 @@ private void addSupertypeFields(EntityType model, Set handled) { private void processExclusions() { for (Element element : getElements(QueryExclude.class)) { - if (element instanceof PackageElement) { - conf.addExcludedPackage(((PackageElement) element).getQualifiedName().toString()); - } else if (element instanceof TypeElement) { - conf.addExcludedClass(((TypeElement) element).getQualifiedName().toString()); + if (element instanceof PackageElement packageElement) { + conf.addExcludedPackage(packageElement.getQualifiedName().toString()); + } else if (element instanceof TypeElement typeElement) { + conf.addExcludedClass(typeElement.getQualifiedName().toString()); } else { throw new IllegalArgumentException(element.toString()); } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java index d1e4db720..a8c0b56db 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java @@ -222,11 +222,9 @@ public DefaultConfiguration( for (Element element : roundEnv.getElementsAnnotatedWith(Config.class)) { var querydslConfig = element.getAnnotation(Config.class); var config = SimpleSerializerConfig.getConfig(querydslConfig); - if (element instanceof PackageElement) { - var packageElement = (PackageElement) element; + if (element instanceof PackageElement packageElement) { packageToConfig.put(packageElement.getQualifiedName().toString(), config); - } else if (element instanceof TypeElement) { - var typeElement = (TypeElement) element; + } else if (element instanceof TypeElement typeElement) { typeToConfig.put(typeElement.getQualifiedName().toString(), config); } } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java index 5bd1e5c9e..a7b4adc0a 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java @@ -447,8 +447,8 @@ && isAssignable(typeElement.asType(), comparableType)) { } } typeElement = (TypeElement) env.getTypeUtils().asElement(type); - if (type instanceof DeclaredType) { - arguments = ((DeclaredType) type).getTypeArguments(); + if (type instanceof DeclaredType declaredType1) { + arguments = declaredType1.getTypeArguments(); } } @@ -456,8 +456,8 @@ && isAssignable(typeElement.asType(), comparableType)) { var superType = typeElement.getSuperclass(); TypeElement superTypeElement = null; - if (superType instanceof DeclaredType) { - superTypeElement = (TypeElement) ((DeclaredType) superType).asElement(); + if (superType instanceof DeclaredType declaredType1) { + superTypeElement = (TypeElement) declaredType1.asElement(); } // entity type @@ -624,8 +624,8 @@ private Set getSupertypes(TypeMirror typeMirror, boolean deep) { if (e.getKind() == ElementKind.CLASS) { if (e.getSuperclass().getKind() != TypeKind.NONE) { var supertype = normalize(e.getSuperclass()); - if (supertype instanceof DeclaredType - && ((DeclaredType) supertype).asElement().getAnnotation(QueryExclude.class) != null) { + if (supertype instanceof DeclaredType type + && type.asElement().getAnnotation(QueryExclude.class) != null) { return Collections.emptySet(); } else { Type superClass = getType(supertype, deep); diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java index 88059338e..6d0f98cbf 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java @@ -168,8 +168,8 @@ private TypeMirror getRealElementType(Element element) { if (mirror != null) { var typeArg = TypeUtils.getAnnotationValueAsTypeMirror(mirror, "targetEntity"); TypeMirror erasure; - if (element instanceof ExecutableElement) { - erasure = ((ExecutableElement) element).getReturnType(); + if (element instanceof ExecutableElement executableElement) { + erasure = executableElement.getReturnType(); } else { erasure = types.erasure(element.asType()); } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java index ab6fd14a5..904ba0200 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java @@ -309,8 +309,8 @@ public void acceptResult(CompilationResult result) { // not one of our checked exceptions boxed as unchecked; just rethrow var cause = ex.getCause(); if (cause != null) { - if (cause instanceof IOException) { - throw (IOException) cause; + if (cause instanceof IOException exception) { + throw exception; } else if (cause instanceof ClassFormatException) { throw new IOException(cause); } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java index 944b0068b..a1fd8e57b 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java @@ -144,12 +144,11 @@ private void annotationConstant(Object value) throws IOException { first = false; } append("}"); - } else if (value instanceof Class) { - appendType((Class) value).append(".class"); + } else if (value instanceof Class class1) { + appendType(class1).append(".class"); } else if (value instanceof Number || value instanceof Boolean) { append(value.toString()); - } else if (value instanceof Enum) { - Enum enumValue = (Enum) value; + } else if (value instanceof Enum enumValue) { if (classes.contains(enumValue.getClass().getName()) || packages.contains(enumValue.getClass().getPackage().getName())) { append(enumValue.name()); diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java index 44e314276..0a5ad65aa 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java @@ -36,8 +36,7 @@ public LocationAndKind(Location location, Kind kind) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof LocationAndKind) { - var other = (LocationAndKind) obj; + } else if (obj instanceof LocationAndKind other) { return location.equals(other.location) && kind.equals(other.kind); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java index dcf7c06b0..2f6cee4ae 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java @@ -168,14 +168,13 @@ private void annotationConstant(Object value) throws IOException { first = false; } append(")"); - } else if (value instanceof Class) { + } else if (value instanceof Class class1) { append("classOf["); - appendType((Class) value); + appendType(class1); append("]"); } else if (value instanceof Number || value instanceof Boolean) { append(value.toString()); - } else if (value instanceof Enum) { - Enum enumValue = (Enum) value; + } else if (value instanceof Enum enumValue) { if (classes.contains(enumValue.getClass().getName()) || packages.contains(enumValue.getClass().getPackage().getName())) { append(enumValue.name()); diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java index f960a95e1..a408aa075 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java @@ -74,8 +74,7 @@ public Type asArrayType() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Type) { - var t = (Type) o; + } else if (o instanceof Type t) { return t.getFullName().equals(className) && t.getParameters().equals(parameters); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java index a30f086f1..aca49f4b7 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java @@ -30,8 +30,8 @@ public Constructor(Collection params) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Constructor) { - return ((Constructor) o).parameters.equals(parameters); + } else if (o instanceof Constructor constructor) { + return constructor.parameters.equals(parameters); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java index 61bace515..6b0426ad3 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java @@ -33,8 +33,7 @@ public Parameter(String name, Type type) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Parameter) { - var t = (Parameter) o; + } else if (o instanceof Parameter t) { return type.equals(t.type) && name.equals(t.name); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java index be74b8427..cf8767bad 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java @@ -156,8 +156,7 @@ public Type asArrayType() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Type) { - var t = (Type) o; + } else if (o instanceof Type t) { return t.getFullName().equals(fullName) && t.getParameters().equals(parameters); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java index 18928094b..e70d9a3d6 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java @@ -62,9 +62,8 @@ public String getVarName() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof TypeExtends) { - return Objects.equals(((TypeExtends) o).varName, varName) - && ((TypeExtends) o).type.equals(type); + } else if (o instanceof TypeExtends extends1) { + return Objects.equals(extends1.varName, varName) && extends1.type.equals(type); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java index 0890c1618..ca2728e68 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java @@ -68,9 +68,8 @@ public String getVarName() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof TypeSuper) { - return Objects.equals(((TypeSuper) o).varName, varName) - && ((TypeSuper) o).superType.equals(superType); + } else if (o instanceof TypeSuper super1) { + return Objects.equals(super1.varName, varName) && super1.superType.equals(superType); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java index 6b5fa1504..1d0d78d83 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java @@ -48,8 +48,7 @@ public Delegate( public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Delegate) { - var m = (Delegate) o; + } else if (o instanceof Delegate m) { return m.name.equals(name) && m.parameters.equals(parameters); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java index 223ff9d9c..5e7a0586e 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java @@ -496,11 +496,11 @@ private Type getPropertyType( } if (propertyType == null) { propertyType = typeFactory.get(type, annotated, genericType); - if (propertyType instanceof EntityType + if (propertyType instanceof EntityType entityType && !allTypes.containsKey(ClassUtils.getFullName(type))) { var fullName = ClassUtils.getFullName(type); if (!allTypes.containsKey(fullName)) { - allTypes.put(fullName, (EntityType) propertyType); + allTypes.put(fullName, entityType); } } } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java index e9b139028..e4208003c 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java @@ -53,8 +53,7 @@ public Type getOwnerType() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ParameterizedTypeImpl) { - var other = (ParameterizedTypeImpl) o; + } else if (o instanceof ParameterizedTypeImpl other) { return other.rawType.equals(rawType) && Arrays.equals(other.arguments, arguments); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java index d1d3f9557..1415feee3 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java @@ -126,8 +126,7 @@ public int hashCode() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Property) { - var p = (Property) o; + } else if (o instanceof Property p) { return p.name.equals(name) && p.type.equals(type); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java index 82c744cda..30b151d38 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java @@ -59,8 +59,8 @@ public int hashCode() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Supertype) { - return ((Supertype) o).type.equals(type); + } else if (o instanceof Supertype supertype) { + return supertype.type.equals(type); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java index 85c193f21..e4c7f83b4 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java @@ -172,8 +172,7 @@ private Type create( value = createOther(cl, entity, annotationHelper, annotation, parameters); } - if (genericType instanceof TypeVariable) { - var tv = (TypeVariable) genericType; + if (genericType instanceof TypeVariable tv) { if (tv.getBounds().length == 1 && tv.getBounds()[0].equals(Object.class)) { value = new TypeSuper(tv.getName(), value); } else { @@ -248,13 +247,12 @@ private Type[] getGenericParameters( @SuppressWarnings("rawtypes") private Type getGenericParameter(Class cl, java.lang.reflect.Type genericType, int i) { java.lang.reflect.Type parameter = ReflectionUtils.getTypeParameter(genericType, i); - if (parameter instanceof TypeVariable) { - var variable = (TypeVariable) parameter; + if (parameter instanceof TypeVariable variable) { var rv = get(ReflectionUtils.getTypeParameterAsClass(genericType, i), null, parameter); return new TypeExtends(variable.getName(), rv); - } else if (parameter instanceof WildcardType - && ((WildcardType) parameter).getUpperBounds()[0].equals(Object.class) - && ((WildcardType) parameter).getLowerBounds().length == 0) { + } else if (parameter instanceof WildcardType type + && type.getUpperBounds()[0].equals(Object.class) + && type.getLowerBounds().length == 0) { return ANY; } else { var rv = get(ReflectionUtils.getTypeParameterAsClass(genericType, i), null, parameter); @@ -280,8 +278,8 @@ public void extendTypes() { var entityType = (EntityType) entry.getValue(); if (entityType.getProperties().isEmpty()) { for (Type type : cache.values()) { - if (type.getFullName().equals(entityType.getFullName()) && type instanceof EntityType) { - var base = (EntityType) type; + if (type.getFullName().equals(entityType.getFullName()) + && type instanceof EntityType base) { for (Property property : base.getProperties()) { entityType.addProperty(property); } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java index ae1c1ddd7..ee8c17eb3 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java @@ -46,9 +46,9 @@ public static Type resolve(Type type, Type declaringType, EntityType context) { } // rewrap entity type - if (type instanceof EntityType) { + if (type instanceof EntityType entityType) { if (!unwrap(type).equals(resolved)) { - resolved = new EntityType(resolved, ((EntityType) type).getSuperTypes()); + resolved = new EntityType(resolved, entityType.getSuperTypes()); } else { // reset to original type resolved = type; @@ -116,8 +116,8 @@ private static String getVarName(Type type) { } private static Type unwrap(Type type) { - if (type instanceof EntityType) { - return ((EntityType) type).getInnerType(); + if (type instanceof EntityType entityType) { + return entityType.getInnerType(); } else { return type; }