File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
extensions/src/main/java/org/mapstruct/extensions/spring/converter Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 1111import java .util .List ;
1212import java .util .Locale ;
1313import java .util .Optional ;
14+ import java .util .regex .Pattern ;
1415import java .util .stream .Stream ;
1516
1617public class ConversionServiceAdapterGenerator extends AdapterRelatedGenerator {
@@ -25,6 +26,7 @@ public class ConversionServiceAdapterGenerator extends AdapterRelatedGenerator {
2526 ClassName .get ("org.springframework.core.convert" , "TypeDescriptor" );
2627 private static final ClassName COMPONENT_ANNOTATION_CLASS_NAME =
2728 ClassName .get ("org.springframework.stereotype" , "Component" );
29+ private static final Pattern NON_WORD_PATTERN = Pattern .compile ("\\ W" );
2830
2931 public ConversionServiceAdapterGenerator (final Clock clock ) {
3032 super (clock );
@@ -58,13 +60,12 @@ private List<FieldSpec> buildTypeDescriptorFields(ConversionServiceAdapterDescri
5860 }
5961
6062 private String fieldName (TypeName typeName ) {
61- String fieldName = "TYPE_DESCRIPTOR_" + typeName .toString ()
62- .replace ('.' , '_' )
63- .replace ('<' , '_' )
64- .replace ('>' , '_' )
65- .replace ("[]" , "_ARRAY" )
63+ String fieldName = "TYPE_DESCRIPTOR_" + NON_WORD_PATTERN .matcher (typeName .toString ())
64+ .replaceAll ("_" )
6665 .toUpperCase (Locale .ROOT );
66+
6767 if (fieldName .lastIndexOf ('_' ) == fieldName .length () - 1 ) {
68+ // drop trailing underscore
6869 return fieldName .substring (0 , fieldName .length () - 1 );
6970 } else {
7071 return fieldName ;
You can’t perform that action at this time.
0 commit comments