Skip to content

Commit 3de0623

Browse files
committed
Update code and fix styles
1 parent 6d247da commit 3de0623

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaUtil.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.Set;
2525
import java.util.function.Predicate;
2626
import java.util.function.Supplier;
27+
import java.util.regex.Matcher;
28+
import java.util.regex.Pattern;
2729
import java.util.stream.Collectors;
2830
import java.util.stream.IntStream;
2931
import java.util.stream.Stream;
@@ -685,19 +687,26 @@ public static String optionalExpression(
685687
codeGenerationConfig.importTracker().importExplicit( Optional.class );
686688
codeGenerationConfig.importTracker().importExplicit( DatatypeConstants.class );
687689

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+
+ ")";
697708
}
698709

699-
// Default case - use ofNullable with empty check
700-
return "Optional.ofNullable(" + expression + ")" +
701-
".filter(v -> v != null)";
710+
return expression;
702711
}
703712
}

0 commit comments

Comments
 (0)