drccrd commented on code in PR #6786:
URL:
https://github.com/apache/incubator-kie-drools/pull/6786#discussion_r3543909752
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/RuleContext.java:
##########
@@ -316,15 +316,15 @@ public Optional<MethodCallExpr> findBindingExpression(
String boundVar ) {
public void addGlobalDeclarations() {
Map<String, java.lang.reflect.Type> globals = getGlobals();
- // also takes globals defined in different packages imported with a
wildcard
- packageModel.getImports().stream()
- .filter( imp -> imp.endsWith(".*") )
- .map( imp -> imp.substring(0, imp.length()-2) )
- .map( imp -> typeDeclarationContext.getPackageRegistry(imp) )
+ // Globals are kbase-wide: include globals declared in any package of
the kbase, not only
+ // those in the current package or in packages imported with a
wildcard. This matches the
+ // classic (non-executable-model) behavior where a global is visible
from every package, so
+ // a constraint can reference a global declared in another DRL without
a wildcard import.
+ typeDeclarationContext.getPackageRegistry().values().stream()
.filter( Objects::nonNull )
- .map( pkgRegistry -> pkgRegistry.getPackage().getGlobals() )
- .forEach( globals::putAll );
-
+ .filter( pkgRegistry -> pkgRegistry.getPackage() != null )
+ .forEach( pkgRegistry -> globals.putAll(
pkgRegistry.getPackage().getGlobals() ) );
+
Review Comment:
@tkobayas great addition - I had tried to find existing methods for
ownership and not point it, but adding the feature is helpful (I have also been
considering something similar for functions - we have a number functions across
packages that need re-declaration (or else get moved into a static method of a
java class) - something like this would partly help in that area too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]