Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class ConversionServiceAdapterGenerator extends AdapterRelatedGenerator {
Expand All @@ -25,6 +26,7 @@ public class ConversionServiceAdapterGenerator extends AdapterRelatedGenerator {
ClassName.get("org.springframework.core.convert", "TypeDescriptor");
private static final ClassName COMPONENT_ANNOTATION_CLASS_NAME =
ClassName.get("org.springframework.stereotype", "Component");
private static final Pattern NON_WORD_PATTERN = Pattern.compile("\\W");

public ConversionServiceAdapterGenerator(final Clock clock) {
super(clock);
Expand Down Expand Up @@ -58,13 +60,12 @@ private List<FieldSpec> buildTypeDescriptorFields(ConversionServiceAdapterDescri
}

private String fieldName(TypeName typeName) {
String fieldName = "TYPE_DESCRIPTOR_" + typeName.toString()
.replace('.', '_')
.replace('<', '_')
.replace('>', '_')
.replace("[]", "_ARRAY")
String fieldName = "TYPE_DESCRIPTOR_" + NON_WORD_PATTERN.matcher(typeName.toString())
.replaceAll("_")
.toUpperCase(Locale.ROOT);

if (fieldName.lastIndexOf('_') == fieldName.length() - 1) {
// drop trailing underscore
return fieldName.substring(0, fieldName.length() - 1);
} else {
return fieldName;
Expand Down