Apply "instanceof pattern matching" in additional locations
Closes gh-27696
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,8 +70,7 @@ public final class Conventions {
|
||||
valueClass = value.getClass().getComponentType();
|
||||
pluralize = true;
|
||||
}
|
||||
else if (value instanceof Collection) {
|
||||
Collection<?> collection = (Collection<?>) value;
|
||||
else if (value instanceof Collection<?> collection) {
|
||||
if (collection.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot generate variable name for an empty Collection");
|
||||
@@ -188,11 +187,10 @@ public final class Conventions {
|
||||
else if (Collection.class.isAssignableFrom(resolvedType)) {
|
||||
valueClass = ResolvableType.forMethodReturnType(method).asCollection().resolveGeneric();
|
||||
if (valueClass == null) {
|
||||
if (!(value instanceof Collection)) {
|
||||
if (!(value instanceof Collection<?> collection)) {
|
||||
throw new IllegalArgumentException("Cannot generate variable name " +
|
||||
"for non-typed Collection return type and a non-Collection value");
|
||||
}
|
||||
Collection<?> collection = (Collection<?>) value;
|
||||
if (collection.isEmpty()) {
|
||||
throw new IllegalArgumentException("Cannot generate variable name " +
|
||||
"for non-typed Collection return type and an empty Collection value");
|
||||
|
||||
Reference in New Issue
Block a user