@@ -2094,7 +2094,13 @@ public Function<FieldInfo, String> apply(ClassInfo clazz) {
2094
2094
}
2095
2095
2096
2096
if (!templateGlobals .isEmpty ()) {
2097
- TemplateGlobalGenerator globalGenerator = new TemplateGlobalGenerator (classOutput , GLOBAL_NAMESPACE , -1000 , index );
2097
+ Set <String > generatedGlobals = new HashSet <>();
2098
+ // The initial priority is increased during live reload so that priorities of non-application globals
2099
+ // do not conflict with priorities of application globals
2100
+ int initialPriority = -1000 + existingValueResolvers .globals .size ();
2101
+
2102
+ TemplateGlobalGenerator globalGenerator = new TemplateGlobalGenerator (classOutput , GLOBAL_NAMESPACE ,
2103
+ initialPriority , index );
2098
2104
2099
2105
Map <DotName , Map <String , AnnotationTarget >> classToTargets = new HashMap <>();
2100
2106
Map <DotName , List <TemplateGlobalBuildItem >> classToGlobals = templateGlobals .stream ()
@@ -2105,12 +2111,19 @@ public Function<FieldInfo, String> apply(ClassInfo clazz) {
2105
2111
}
2106
2112
2107
2113
for (Entry <DotName , Map <String , AnnotationTarget >> e : classToTargets .entrySet ()) {
2108
- globalGenerator .generate (index .getClassByName (e .getKey ()), e .getValue ());
2114
+ String generatedClass = existingValueResolvers .getGeneratedGlobalClass (e .getKey ());
2115
+ if (generatedClass != null ) {
2116
+ generatedGlobals .add (generatedClass );
2117
+ } else {
2118
+ generatedClass = globalGenerator .generate (index .getClassByName (e .getKey ()), e .getValue ());
2119
+ existingValueResolvers .addGlobal (e .getKey (), generatedClass , applicationClassPredicate );
2120
+ }
2109
2121
}
2122
+ generatedGlobals .addAll (globalGenerator .getGeneratedTypes ());
2110
2123
2111
- for (String generatedType : globalGenerator . getGeneratedTypes () ) {
2112
- globalProviders .produce (new TemplateGlobalProviderBuildItem (generatedType ));
2113
- reflectiveClass .produce (ReflectiveClassBuildItem .builder (generatedType ).build ());
2124
+ for (String globalType : generatedGlobals ) {
2125
+ globalProviders .produce (new TemplateGlobalProviderBuildItem (globalType ));
2126
+ reflectiveClass .produce (ReflectiveClassBuildItem .builder (globalType ).build ());
2114
2127
}
2115
2128
}
2116
2129
}
@@ -2122,12 +2135,18 @@ public Function<FieldInfo, String> apply(ClassInfo clazz) {
2122
2135
static class ExistingValueResolvers {
2123
2136
2124
2137
final Map <String , String > identifiersToGeneratedClass = new HashMap <>();
2138
+ // class declaring globals -> generated type
2139
+ final Map <String , String > globals = new HashMap <>();
2125
2140
2126
2141
boolean contains (MethodInfo extensionMethod ) {
2127
2142
return identifiersToGeneratedClass
2128
2143
.containsKey (toKey (extensionMethod ));
2129
2144
}
2130
2145
2146
+ String getGeneratedGlobalClass (DotName declaringClassName ) {
2147
+ return globals .get (declaringClassName .toString ());
2148
+ }
2149
+
2131
2150
String getGeneratedClass (MethodInfo extensionMethod ) {
2132
2151
return identifiersToGeneratedClass .get (toKey (extensionMethod ));
2133
2152
}
@@ -2138,6 +2157,12 @@ void add(MethodInfo extensionMethod, String className, Predicate<DotName> applic
2138
2157
}
2139
2158
}
2140
2159
2160
+ void addGlobal (DotName declaringClassName , String generatedClassName , Predicate <DotName > applicationClassPredicate ) {
2161
+ if (!applicationClassPredicate .test (declaringClassName )) {
2162
+ globals .put (declaringClassName .toString (), generatedClassName );
2163
+ }
2164
+ }
2165
+
2141
2166
private String toKey (MethodInfo extensionMethod ) {
2142
2167
return extensionMethod .declaringClass ().toString () + "#" + extensionMethod .toString ();
2143
2168
}
0 commit comments