|
24 | 24 | import java.util.Set;
|
25 | 25 | import java.util.function.Predicate;
|
26 | 26 | import java.util.function.Supplier;
|
| 27 | +import java.util.regex.Matcher; |
| 28 | +import java.util.regex.Pattern; |
27 | 29 | import java.util.stream.Collectors;
|
28 | 30 | import java.util.stream.IntStream;
|
29 | 31 | import java.util.stream.Stream;
|
@@ -685,19 +687,26 @@ public static String optionalExpression(
|
685 | 687 | codeGenerationConfig.importTracker().importExplicit( Optional.class );
|
686 | 688 | codeGenerationConfig.importTracker().importExplicit( DatatypeConstants.class );
|
687 | 689 |
|
688 |
| - // Check if this is for XMLGregorianCalendar date handling |
689 |
| - if ( expression.contains( "matcher.group(1)" ) && expression.contains( "XMLGregorianCalendarDate" ) ) { |
690 |
| - return "Optional.ofNullable(matcher.group(1))" + |
691 |
| - ".filter(v -> v != null)" + |
692 |
| - ".map(v -> Integer.valueOf(v))" + |
693 |
| - ".map(v -> _datatypeFactory.newXMLGregorianCalendarDate(v, " + |
694 |
| - "DatatypeConstants.FIELD_UNDEFINED, " + |
695 |
| - "DatatypeConstants.FIELD_UNDEFINED, " + |
696 |
| - "DatatypeConstants.FIELD_UNDEFINED))"; |
| 690 | + final Pattern pattern = java.util.regex.Pattern.compile( |
| 691 | + "Integer\\s*\\.\\s*valueOf\\s*\\(\\s*matcher\\s*\\.\\s*group\\s*\\(\\s*(\\d+)\\s*\\)\\s*\\)" |
| 692 | + ); |
| 693 | + Matcher matcher = pattern.matcher( expression ); |
| 694 | + matcher.reset(); |
| 695 | + boolean hasMatch = matcher.find(); |
| 696 | + |
| 697 | + if ( hasMatch ) { |
| 698 | + final String groupNum = matcher.group( 1 ).trim(); // Trim any captured whitespace |
| 699 | + final String target = matcher.group( 0 ); // The entire matched string |
| 700 | + final String modifiedExpression = expression.replace( target, "v" ); |
| 701 | + |
| 702 | + return "Optional.ofNullable(matcher.group(" + groupNum + "))" |
| 703 | + + ".filter(v -> v != null)" |
| 704 | + + ".map(v -> Integer.valueOf(v))" |
| 705 | + + ".map(v -> " |
| 706 | + + modifiedExpression |
| 707 | + + ")"; |
697 | 708 | }
|
698 | 709 |
|
699 |
| - // Default case - use ofNullable with empty check |
700 |
| - return "Optional.ofNullable(" + expression + ")" + |
701 |
| - ".filter(v -> v != null)"; |
| 710 | + return expression; |
702 | 711 | }
|
703 | 712 | }
|
0 commit comments