Polishing

This commit is contained in:
Sam Brannen
2024-02-16 13:37:39 +01:00
parent 6791ea94a0
commit 7c07c43201
16 changed files with 120 additions and 124 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -47,19 +47,19 @@ import org.springframework.util.ObjectUtils;
public abstract class ValueCodeGeneratorDelegates {
/**
* Return the {@link Delegate} implementations for common value types.
* These are:
* A list of {@link Delegate} implementations for the following common value
* types.
* <ul>
* <li>Primitive types,</li>
* <li>String,</li>
* <li>Charset,</li>
* <li>Enum,</li>
* <li>Class,</li>
* <li>{@link ResolvableType},</li>
* <li>Array,</li>
* <li>List via {@code List.of},</li>
* <li>Set via {@code Set.of} and support of {@link LinkedHashSet},</li>
* <li>Map via {@code Map.of} or {@code Map.ofEntries}.</li>
* <li>Primitive types</li>
* <li>String</li>
* <li>Charset</li>
* <li>Enum</li>
* <li>Class</li>
* <li>{@link ResolvableType}</li>
* <li>Array</li>
* <li>List via {@code List.of}</li>
* <li>Set via {@code Set.of} and support for {@link LinkedHashSet}</li>
* <li>Map via {@code Map.of} or {@code Map.ofEntries}</li>
* </ul>
* Those implementations do not require the {@link ValueCodeGenerator} to be
* {@linkplain ValueCodeGenerator#scoped(GeneratedMethods) scoped}.

View File

@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -123,9 +122,7 @@ public final class TypeHint implements ConditionalHint {
@Override
public String toString() {
return new StringJoiner(", ", TypeHint.class.getSimpleName() + "[", "]")
.add("type=" + this.type)
.toString();
return TypeHint.class.getSimpleName() + "[type=" + this.type + "]";
}
/**

View File

@@ -1169,7 +1169,8 @@ public class ResolvableType implements Serializable {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(generics, "Generics array must not be null");
TypeVariable<?>[] variables = clazz.getTypeParameters();
Assert.isTrue(variables.length == generics.length, () -> "Mismatched number of generics specified for " + clazz.toGenericString());
Assert.isTrue(variables.length == generics.length,
() -> "Mismatched number of generics specified for " + clazz.toGenericString());
Type[] arguments = new Type[generics.length];
for (int i = 0; i < generics.length; i++) {

View File

@@ -1019,10 +1019,10 @@ public abstract class ClassUtils {
}
Class<?> clazz = value.getClass();
if (Proxy.isProxyClass(clazz)) {
String prefix = clazz.getName() + " implementing ";
String prefix = clazz.getTypeName() + " implementing ";
StringJoiner result = new StringJoiner(",", prefix, "");
for (Class<?> ifc : clazz.getInterfaces()) {
result.add(ifc.getName());
result.add(ifc.getTypeName());
}
return result.toString();
}

View File

@@ -46,13 +46,13 @@ import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
* a given key can involve the resolution of nested placeholders. Default values
* can also have placeholders.
*
* <p>For situations where the syntax of a valid placeholder match a String that
* <p>For situations where the syntax of a valid placeholder matches a String that
* must be rendered as is, the placeholder can be escaped using an {@code escape}
* character. For instance {@code \${name}} resolves as {@code ${name}}.
*
* <p>The prefix, suffix, separator, and escape characters are configurable. Only
* the prefix and suffix are mandatory and the support of default values or
* escaping are conditional on providing a non-null value for them.
* the prefix and suffix are mandatory, and the support for default values or
* escaping is conditional on providing non-null values for them.
*
* <p>This parser makes sure to resolves placeholders as lazily as possible.
*
@@ -64,7 +64,11 @@ final class PlaceholderParser {
private static final Log logger = LogFactory.getLog(PlaceholderParser.class);
private static final Map<String, String> wellKnownSimplePrefixes = Map.of(
"}", "{", "]", "[", ")", "(");
"}", "{",
"]", "[",
")", "("
);
private final String prefix;
@@ -80,9 +84,9 @@ final class PlaceholderParser {
@Nullable
private final Character escape;
/**
* Create an instance using the specified input for the parser.
*
* @param prefix the prefix that denotes the start of a placeholder
* @param suffix the suffix that denotes the end of a placeholder
* @param ignoreUnresolvablePlaceholders whether unresolvable placeholders
@@ -90,7 +94,7 @@ final class PlaceholderParser {
* @param separator the separating character between the placeholder
* variable and the associated default value, if any
* @param escape the character to use at the beginning of a placeholder
* to escape it and render it as is
* prefix or separator to escape it and render it as is
*/
PlaceholderParser(String prefix, String suffix, boolean ignoreUnresolvablePlaceholders,
@Nullable String separator, @Nullable Character escape) {
@@ -109,7 +113,7 @@ final class PlaceholderParser {
}
/**
* Replaces all placeholders of format {@code ${name}} with the value returned
* Replace all placeholders of format {@code ${name}} with the value returned
* from the supplied {@link PlaceholderResolver}.
* @param value the value containing the placeholders to be replaced
* @param placeholderResolver the {@code PlaceholderResolver} to use for replacement
@@ -138,8 +142,7 @@ final class PlaceholderParser {
LinkedList<Part> parts = new LinkedList<>();
int startIndex = nextStartPrefix(value, 0);
if (startIndex == -1) {
Part part = inPlaceholder ? createSimplePlaceholderPart(value)
: new TextPart(value);
Part part = (inPlaceholder ? createSimplePlaceholderPart(value) : new TextPart(value));
parts.add(part);
return parts;
}
@@ -168,13 +171,13 @@ final class PlaceholderParser {
}
// Add rest of text if necessary
addText(value, position, value.length(), parts);
return inPlaceholder ? List.of(createNestedPlaceholderPart(value, parts)) : parts;
return (inPlaceholder ? List.of(createNestedPlaceholderPart(value, parts)) : parts);
}
private SimplePlaceholderPart createSimplePlaceholderPart(String text) {
String[] keyAndDefault = splitKeyAndDefault(text);
return (keyAndDefault != null) ? new SimplePlaceholderPart(text, keyAndDefault[0], keyAndDefault[1])
: new SimplePlaceholderPart(text, text, null);
return ((keyAndDefault != null) ? new SimplePlaceholderPart(text, keyAndDefault[0], keyAndDefault[1]) :
new SimplePlaceholderPart(text, text, null));
}
private NestedPlaceholderPart createNestedPlaceholderPart(String text, List<Part> parts) {
@@ -291,7 +294,7 @@ final class PlaceholderParser {
}
/**
* Provide the necessary to handle and resolve underlying placeholders.
* Provide the necessary context to handle and resolve underlying placeholders.
*/
static class PartResolutionContext implements PlaceholderResolver {
@@ -308,6 +311,7 @@ final class PlaceholderParser {
@Nullable
private Set<String> visitedPlaceholders;
PartResolutionContext(PlaceholderResolver resolver, String prefix, String suffix,
boolean ignoreUnresolvablePlaceholders, Function<String, List<Part>> parser) {
this.prefix = prefix;

View File

@@ -22,7 +22,8 @@ import org.springframework.lang.Nullable;
/**
* Utility class for working with Strings that have placeholder values in them.
* A placeholder takes the form {@code ${name}}. Using {@code PropertyPlaceholderHelper}
*
* <p>A placeholder takes the form {@code ${name}}. Using {@code PropertyPlaceholderHelper}
* these placeholders can be substituted for user-supplied values.
*
* <p>Values for substitution can be supplied using a {@link Properties} instance or
@@ -39,7 +40,7 @@ public class PropertyPlaceholderHelper {
/**
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* Create a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* Unresolvable placeholders are ignored.
* @param placeholderPrefix the prefix that denotes the start of a placeholder
* @param placeholderSuffix the suffix that denotes the end of a placeholder
@@ -49,14 +50,15 @@ public class PropertyPlaceholderHelper {
}
/**
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* Create a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* @param placeholderPrefix the prefix that denotes the start of a placeholder
* @param placeholderSuffix the suffix that denotes the end of a placeholder
* @param valueSeparator the separating character between the placeholder variable
* and the associated default value, if any
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
* be ignored ({@code true}) or cause an exception ({@code false})
* @deprecated in favor of {@link PropertyPlaceholderHelper#PropertyPlaceholderHelper(String, String, String, boolean, Character)}
* @deprecated as of 6.2, in favor of
* {@link PropertyPlaceholderHelper#PropertyPlaceholderHelper(String, String, String, Character, boolean)}
*/
@Deprecated(since = "6.2", forRemoval = true)
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix,
@@ -66,7 +68,7 @@ public class PropertyPlaceholderHelper {
}
/**
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* Create a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* @param placeholderPrefix the prefix that denotes the start of a placeholder
* @param placeholderSuffix the suffix that denotes the end of a placeholder
* @param valueSeparator the separating character between the placeholder variable
@@ -89,7 +91,7 @@ public class PropertyPlaceholderHelper {
/**
* Replaces all placeholders of format {@code ${name}} with the corresponding
* Replace all placeholders of format {@code ${name}} with the corresponding
* property from the supplied {@link Properties}.
* @param value the value containing the placeholders to be replaced
* @param properties the {@code Properties} to use for replacement
@@ -101,7 +103,7 @@ public class PropertyPlaceholderHelper {
}
/**
* Replaces all placeholders of format {@code ${name}} with the value returned
* Replace all placeholders of format {@code ${name}} with the value returned
* from the supplied {@link PlaceholderResolver}.
* @param value the value containing the placeholders to be replaced
* @param placeholderResolver the {@code PlaceholderResolver} to use for replacement

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.

View File

@@ -336,7 +336,7 @@ class PlaceholderParserTests {
if (pairs.length % 2 == 1) {
throw new IllegalArgumentException("size must be even, it is a set of key=value pairs");
}
PlaceholderResolver resolver = mock(PlaceholderResolver.class);
PlaceholderResolver resolver = mock();
for (int i = 0; i < pairs.length; i += 2) {
String key = pairs[i];
String value = pairs[i + 1];