This is an automated email from the ASF dual-hosted git repository.
tkobayas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-docs.git
The following commit(s) were added to refs/heads/main by this push:
new 0e9bed96c Docs 6779 declared type extends java (#4594)
0e9bed96c is described below
commit 0e9bed96c47ef75073bdb436741490d3109061e2
Author: Daniel Clark <[email protected]>
AuthorDate: Thu Jul 9 02:03:17 2026 +0200
Docs 6779 declared type extends java (#4594)
* Document type extension from Java classes in the executable model
A DRL-declared type that extends a Java class now generates a
full-argument constructor that also includes the parent class's
@Position fields (forwarded via super(...)), or only the subtype's own
fields with a no-arg super() when the parent declares none. Document
this in the Extended type declarations section of the Rule Language
Reference.
Also un-comment the previously excluded @position metadata tag reference
so it is rendered and the added cross-reference resolves; @position
works in Drools (it was originally excluded as "TBD in Kogito").
Ref: apache/incubator-kie-drools#6779 (implemented in
apache/incubator-kie-drools#6780)
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* Correct inaccurate @position claims in the metadata tags reference
The @position tag applies to the fields of DRL-declared types, not only
to classes already on the classpath: reword the "only for fields in
classes on the classpath" sentence, which is contradicted by the tag's
own DRL declare examples and by the Drools tests (test_Extends.drl /
ExtendsTest, functional/query.drl). Also fix the garbled "interfaces of
methods" to "interfaces or methods".
Ref: apache/incubator-kie-drools#6779
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* add note to disambiguate against legacy model
* correct note regarding legacy model
---------
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
---
.../ROOT/pages/language-reference/_drl-rules.adoc | 63 ++++++++++++++++++++--
1 file changed, 59 insertions(+), 4 deletions(-)
diff --git
a/drools-docs/src/modules/ROOT/pages/language-reference/_drl-rules.adoc
b/drools-docs/src/modules/ROOT/pages/language-reference/_drl-rules.adoc
index fc2ba2f80..bbc5fbd7b 100644
--- a/drools-docs/src/modules/ROOT/pages/language-reference/_drl-rules.adoc
+++ b/drools-docs/src/modules/ROOT/pages/language-reference/_drl-rules.adoc
@@ -429,6 +429,64 @@ declare LongTermStudent extends Student
end
----
+When a declared subtype extends a type defined in Java, the {RULE_ENGINE} can
generate a constructor for the subtype that also includes the inherited fields
of the Java parent class, so that you can create a fully populated instance of
the subtype in a rule consequence with a single constructor call.
+The inherited fields that are added to this constructor are the fields of the
Java parent class that are annotated with `@Position`, ordered by their
position value and placed before the fields that are declared in the subtype.
These inherited arguments are forwarded to the parent class through a `super()`
call, so the Java parent class must provide a constructor that accepts its
`@Position` fields in the same order. If the Java parent class does not declare
any `@Position` fields, the g [...]
+
+For example, consider the following Java class whose fields are annotated with
`@Position`:
+
+.Example Java parent class with positional fields
+[source,java]
+----
+import org.kie.api.definition.type.Position;
+
+public class Person {
+
+ @Position(0)
+ private String name;
+
+ @Position(1)
+ private int age;
+
+ public Person() { }
+
+ public Person(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ // Other constructors, getters, and setters
+}
+----
+
+The following declaration extends the `Person` Java class with an additional
`department` field:
+
+.Example extended type declaration from a Java class
+[source,drools]
+----
+import org.example.Person
+
+declare Person end
+
+declare Employee extends Person
+ department : String
+end
+----
+
+For this example, the {RULE_ENGINE} generates an `Employee(String name, int
age, String department)` constructor that you can use directly in a rule
consequence:
+
+.Example instantiation of the extended type in a rule consequence
+[source,drools]
+----
+insertLogical( new Employee( "Mario", 40, "Sales" ) );
+----
+
+[NOTE]
+====
+Extending a Java class with a declared type is supported in both the
executable model and the traditional model. The signature of the generated-type
constructor can differ between the two models because the traditional model
derives the inherited constructor arguments from the fields of the Java class
with getters and setters, while the exeuctable model uses _only_ the ordered
`@Position` annotated fields to contribute to the constructor.
+====
+
+For more information about the `@position` annotation and positional
arguments, see the xref:ref-drl-declarations-metadata-tags_{context}[metadata
tags for declarations].
+
[id="con-drl-declarations-with-metadata_{context}"]
=== Type declarations with metadata in DRL
@@ -680,10 +738,8 @@ Person person = new Person( "John", "Doe" );
----
--
-//@comment Currently TBD in Kogito, so excluding for now. (Stetson 7 Apr 2020)
-////
@position::
-This tag determines the position of a declared fact type attribute or field in
a positional argument, overriding the default declared order of attributes. You
can use this tag to modify positional constraints in patterns while maintaining
a consistent format in your type declarations and positional arguments. You can
use this tag only for fields in classes on the classpath. If some fields in a
single class use this tag and some do not, the attributes without this tag are
positioned last, [...]
+This tag determines the position of a declared fact type attribute or field in
a positional argument, overriding the default declared order of attributes. You
can use this tag to modify positional constraints in patterns while maintaining
a consistent format in your type declarations and positional arguments. You can
use this tag for the fields of DRL-declared types and for fields of Java
classes on the classpath. If some fields in a single class use this tag and
some do not, the attribu [...]
+
--
Default parameter: None
@@ -762,7 +818,6 @@ In this example, the attributes are prioritized in
positional arguments in the f
. `occupation` (first field with no position annotation)
. `graduationDate` (second field with no position annotation)
--
-////
[id="con-drl-queries_{context}"]
== Queries in DRL
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]