@@ -672,6 +672,7 @@ public void beforeParsing(ParserHelper parserHelper) {
672
672
@ BuildStep
673
673
void validateCheckedFragments (List <CheckedFragmentValidationBuildItem > validations ,
674
674
List <TemplateExpressionMatchesBuildItem > expressionMatches ,
675
+ List <TemplateGlobalBuildItem > templateGlobals ,
675
676
BeanArchiveIndexBuildItem beanArchiveIndex ,
676
677
BuildProducer <ValidationErrorBuildItem > validationErrors ) {
677
678
@@ -682,6 +683,8 @@ void validateCheckedFragments(List<CheckedFragmentValidationBuildItem> validatio
682
683
Map <DotName , AssignableInfo > assignableCache = new HashMap <>();
683
684
String [] hintPrefixes = { LoopSectionHelper .Factory .HINT_PREFIX , WhenSectionHelper .Factory .HINT_PREFIX ,
684
685
SetSectionHelper .Factory .HINT_PREFIX };
686
+ Set <String > globals = templateGlobals .stream ().map (TemplateGlobalBuildItem ::getName )
687
+ .collect (Collectors .toUnmodifiableSet ());
685
688
686
689
for (CheckedFragmentValidationBuildItem validation : validations ) {
687
690
Map <String , Type > paramNamesToTypes = new HashMap <>();
@@ -697,33 +700,40 @@ void validateCheckedFragments(List<CheckedFragmentValidationBuildItem> validatio
697
700
}
698
701
699
702
for (Expression expression : validation .fragmentExpressions ) {
700
- // Note that we ignore literals and expressions with no type info and expressions with a hint referencing an expression from inside the fragment
701
- if (expression .isLiteral ()) {
703
+ // Note that we ignore:
704
+ // - literals,
705
+ // - globals,
706
+ // - expressions with no type info,
707
+ // - loop metadata; e.g. |java.lang.Integer|<loop-metadata>
708
+ // - expressions with a hint referencing an expression from inside the fragment
709
+ if (expression .isLiteral () || globals .contains (expression .getParts ().get (0 ).getName ())) {
702
710
continue ;
703
711
}
704
- if ( expression .hasTypeInfo ()) {
705
- Info info = TypeInfos . create ( expression , index , null ). get ( 0 );
706
- if ( info . isTypeInfo ()) {
707
- // |org.acme.Foo|.name
708
- paramNamesToTypes . put (expression . getParts ( ).get (0 ). getName (), info . asTypeInfo (). resolvedType );
709
- } else if (info .hasHints ()) {
710
- // foo<set#123> .name
711
- hintLoop : for ( String helperHint : info .asHintInfo ().hints ) {
712
- for ( String prefix : hintPrefixes ) {
713
- if ( helperHint . startsWith ( prefix )) {
714
- int generatedId = parseHintId ( helperHint , prefix );
715
- Expression localExpression = findExpression ( generatedId , validation . fragmentExpressions );
716
- if (localExpression == null ) {
717
- Match match = matchResults . getMatch ( generatedId );
718
- if ( match == null ) {
719
- throw new IllegalStateException (
720
- " Match result not found for expression [" + expression . toOriginalString ()
721
- + "] in: "
722
- + validation . templateId );
723
- }
724
- paramNamesToTypes . put ( expression . getParts (). get ( 0 ). getName (), match . type );
725
- break hintLoop ;
712
+ String typeInfo = expression .getParts (). get ( 0 ). getTypeInfo ();
713
+ if ( typeInfo == null || ( typeInfo != null && typeInfo . endsWith ( LoopSectionHelper . Factory . HINT_METADATA ))) {
714
+ continue ;
715
+ }
716
+ Info info = TypeInfos . create (expression , index , null ).get (0 );
717
+ if (info .isTypeInfo ()) {
718
+ // |org.acme.Foo| .name
719
+ paramNamesToTypes . put ( expression . getParts (). get ( 0 ). getName (), info .asTypeInfo ().resolvedType );
720
+ } else if ( info . hasHints () ) {
721
+ // foo<set#123>.name
722
+ hintLoop : for ( String helperHint : info . asHintInfo (). hints ) {
723
+ for ( String prefix : hintPrefixes ) {
724
+ if (helperHint . startsWith ( prefix ) ) {
725
+ int generatedId = parseHintId ( helperHint , prefix );
726
+ Expression localExpression = findExpression ( generatedId , validation . fragmentExpressions );
727
+ if ( localExpression == null ) {
728
+ Match match = matchResults . getMatch ( generatedId );
729
+ if ( match == null ) {
730
+ throw new IllegalStateException (
731
+ "Match result not found for expression [" + expression . toOriginalString ()
732
+ + "] in: "
733
+ + validation . templateId ) ;
726
734
}
735
+ paramNamesToTypes .put (expression .getParts ().get (0 ).getName (), match .type );
736
+ break hintLoop ;
727
737
}
728
738
}
729
739
}
0 commit comments