@@ -647,6 +647,7 @@ public void beforeParsing(ParserHelper parserHelper) {
647
647
@ BuildStep
648
648
void validateCheckedFragments (List <CheckedFragmentValidationBuildItem > validations ,
649
649
List <TemplateExpressionMatchesBuildItem > expressionMatches ,
650
+ List <TemplateGlobalBuildItem > templateGlobals ,
650
651
BeanArchiveIndexBuildItem beanArchiveIndex ,
651
652
BuildProducer <ValidationErrorBuildItem > validationErrors ) {
652
653
@@ -657,6 +658,8 @@ void validateCheckedFragments(List<CheckedFragmentValidationBuildItem> validatio
657
658
Map <DotName , AssignableInfo > assignableCache = new HashMap <>();
658
659
String [] hintPrefixes = { LoopSectionHelper .Factory .HINT_PREFIX , WhenSectionHelper .Factory .HINT_PREFIX ,
659
660
SetSectionHelper .Factory .HINT_PREFIX };
661
+ Set <String > globals = templateGlobals .stream ().map (TemplateGlobalBuildItem ::getName )
662
+ .collect (Collectors .toUnmodifiableSet ());
660
663
661
664
for (CheckedFragmentValidationBuildItem validation : validations ) {
662
665
Map <String , Type > paramNamesToTypes = new HashMap <>();
@@ -672,33 +675,40 @@ void validateCheckedFragments(List<CheckedFragmentValidationBuildItem> validatio
672
675
}
673
676
674
677
for (Expression expression : validation .fragmentExpressions ) {
675
- // Note that we ignore literals and expressions with no type info and expressions with a hint referencing an expression from inside the fragment
676
- if (expression .isLiteral ()) {
678
+ // Note that we ignore:
679
+ // - literals,
680
+ // - globals,
681
+ // - expressions with no type info,
682
+ // - loop metadata; e.g. |java.lang.Integer|<loop-metadata>
683
+ // - expressions with a hint referencing an expression from inside the fragment
684
+ if (expression .isLiteral () || globals .contains (expression .getParts ().get (0 ).getName ())) {
677
685
continue ;
678
686
}
679
- if ( expression .hasTypeInfo ()) {
680
- Info info = TypeInfos . create ( expression , index , null ). get ( 0 );
681
- if ( info . isTypeInfo ()) {
682
- // |org.acme.Foo|.name
683
- paramNamesToTypes . put (expression . getParts ( ).get (0 ). getName (), info . asTypeInfo (). resolvedType );
684
- } else if (info .hasHints ()) {
685
- // foo<set#123> .name
686
- hintLoop : for ( String helperHint : info .asHintInfo ().hints ) {
687
- for ( String prefix : hintPrefixes ) {
688
- if ( helperHint . startsWith ( prefix )) {
689
- int generatedId = parseHintId ( helperHint , prefix );
690
- Expression localExpression = findExpression ( generatedId , validation . fragmentExpressions );
691
- if (localExpression == null ) {
692
- Match match = matchResults . getMatch ( generatedId );
693
- if ( match == null ) {
694
- throw new IllegalStateException (
695
- " Match result not found for expression [" + expression . toOriginalString ()
696
- + "] in: "
697
- + validation . templateId );
698
- }
699
- paramNamesToTypes . put ( expression . getParts (). get ( 0 ). getName (), match . type );
700
- break hintLoop ;
687
+ String typeInfo = expression .getParts (). get ( 0 ). getTypeInfo ();
688
+ if ( typeInfo == null || ( typeInfo != null && typeInfo . endsWith ( LoopSectionHelper . Factory . HINT_METADATA ))) {
689
+ continue ;
690
+ }
691
+ Info info = TypeInfos . create (expression , index , null ).get (0 );
692
+ if (info .isTypeInfo ()) {
693
+ // |org.acme.Foo| .name
694
+ paramNamesToTypes . put ( expression . getParts (). get ( 0 ). getName (), info .asTypeInfo ().resolvedType );
695
+ } else if ( info . hasHints () ) {
696
+ // foo<set#123>.name
697
+ hintLoop : for ( String helperHint : info . asHintInfo (). hints ) {
698
+ for ( String prefix : hintPrefixes ) {
699
+ if (helperHint . startsWith ( prefix ) ) {
700
+ int generatedId = parseHintId ( helperHint , prefix );
701
+ Expression localExpression = findExpression ( generatedId , validation . fragmentExpressions );
702
+ if ( localExpression == null ) {
703
+ Match match = matchResults . getMatch ( generatedId );
704
+ if ( match == null ) {
705
+ throw new IllegalStateException (
706
+ "Match result not found for expression [" + expression . toOriginalString ()
707
+ + "] in: "
708
+ + validation . templateId ) ;
701
709
}
710
+ paramNamesToTypes .put (expression .getParts ().get (0 ).getName (), match .type );
711
+ break hintLoop ;
702
712
}
703
713
}
704
714
}
0 commit comments