Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into incubator-kie-issues#…
Browse files Browse the repository at this point in the history
…1209
  • Loading branch information
Gabriele-Cardosi committed May 16, 2024
2 parents ff79e4b + 6645110 commit a08c841
Show file tree
Hide file tree
Showing 26 changed files with 467 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ void replaceDeclaration(Declaration oldDecl,
*/
boolean isTemporal();

default BitMask getListenedPropertyMask(ObjectType objectType, List<String> settableProperties ) {
return getListenedPropertyMask(Optional.empty(), objectType, settableProperties);
}

/**
* Returns property reactivity BitMask of this constraint.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
package org.drools.core.reteoo;

import java.util.List;
import java.util.Optional;

import org.drools.base.base.ObjectType;
import org.drools.base.common.NetworkNode;
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.reteoo.BaseTerminalNode;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.Pattern;
import org.drools.base.rule.constraint.AlphaNodeFieldConstraint;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.common.InternalWorkingMemory;
Expand Down Expand Up @@ -309,8 +311,8 @@ public NetworkNode[] getSinks() {
}
}

public BitMask calculateDeclaredMask(ObjectType objectType, List<String> settableProperties) {
return constraint.getListenedPropertyMask(objectType, settableProperties);
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType objectType, List<String> settableProperties) {
return constraint.getListenedPropertyMask(Optional.ofNullable(pattern), objectType, settableProperties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.EntryPointId;
import org.drools.base.rule.Pattern;
import org.drools.core.WorkingMemoryEntryPoint;
import org.drools.core.common.BaseNode;
import org.drools.core.common.DefaultEventHandle;
Expand Down Expand Up @@ -418,7 +419,7 @@ public void byPassModifyToBetaNode(InternalFactHandle factHandle,
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.drools.base.base.ObjectType;
import org.drools.base.common.NetworkNode;
Expand Down Expand Up @@ -182,7 +183,7 @@ protected Pattern getLeftInputPattern( BuildContext context ) {
@Override
protected BitMask setNodeConstraintsPropertyReactiveMask( BitMask mask, ObjectType objectType, List<String> accessibleProperties) {
for (int i = 0; i < alphaConstraints.length; i++) {
mask = mask.setAll(alphaConstraints[i].getListenedPropertyMask(objectType, accessibleProperties));
mask = mask.setAll(alphaConstraints[i].getListenedPropertyMask(Optional.empty(), objectType, accessibleProperties));
}
return mask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public void initDeclaredMask(BuildContext context) {

if ( isPropertyReactive(context.getRuleBase(), objectType) ) {
List<String> settableProperties = getAccessibleProperties( context.getRuleBase(), objectType );
declaredMask = calculateDeclaredMask(objectType, settableProperties);
declaredMask = calculateDeclaredMask(pattern, objectType, settableProperties);
} else {
// if property specific is not on, then accept all modification propagations
declaredMask = AllSetBitMask.get();
}
}

public abstract BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties);
public abstract BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties);

public void resetInferredMask() {
this.inferredMask = EmptyBitMask.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.EntryPointId;
import org.drools.base.rule.Pattern;
import org.drools.base.time.JobHandle;
import org.drools.core.common.DefaultFactHandle;
import org.drools.core.common.InternalFactHandle;
Expand Down Expand Up @@ -169,7 +170,7 @@ public RuleBasePartitionId getPartitionId() {
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
return EmptyBitMask.get();
}

Expand Down
3 changes: 2 additions & 1 deletion drools-core/src/main/java/org/drools/core/reteoo/Rete.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.EntryPointId;
import org.drools.base.rule.Pattern;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.common.PropagationContext;
Expand Down Expand Up @@ -215,7 +216,7 @@ public void byPassModifyToBetaNode(InternalFactHandle factHandle,
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.drools.base.common.NetworkNode;
import org.drools.base.definitions.rule.impl.RuleImpl;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.Pattern;
import org.drools.core.RuleBaseConfiguration;
import org.drools.core.common.ActivationsManager;
import org.drools.core.common.InternalFactHandle;
Expand Down Expand Up @@ -290,7 +291,7 @@ public void setLeftInputOtnId(ObjectTypeNodeId leftInputOtnId) {
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.drools.base.base.ObjectType;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.EntryPointId;
import org.drools.base.rule.Pattern;
import org.drools.base.rule.constraint.AlphaNodeFieldConstraint;
import org.drools.core.RuleBaseConfiguration;
import org.drools.core.common.DefaultEventHandle;
Expand Down Expand Up @@ -300,7 +301,7 @@ public EntryPointId getEntryPoint() {
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.reteoo.BaseTerminalNode;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.rule.Pattern;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.common.PropagationContext;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void retractRightTuple(final TupleImpl rightTuple,
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.drools.base.base.ObjectType;
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.rule.Pattern;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.common.PropagationContext;
Expand Down Expand Up @@ -89,7 +90,7 @@ public int getType() {
}

@Override
public BitMask calculateDeclaredMask(ObjectType modifiedType, List<String> settableProperties) {
public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List<String> settableProperties) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.PATTERN_CALL;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.isDslTopLevelNamespace;
import static org.drools.model.codegen.execmodel.generator.expressiontyper.ExpressionTyper.findLeftLeafOfNameExprTraversingParent;
import static org.drools.util.ClassUtils.actualTypeFromGenerics;
import static org.drools.util.ClassUtils.toRawClass;
import static org.drools.util.MethodUtils.findMethod;

Expand Down Expand Up @@ -161,7 +162,7 @@ public static TypedExpression nameExprToMethodCallExpr(String name, java.lang.re
Method accessor = getAccessor(clazz, name, context);
if (accessor != null) {
MethodCallExpr body = new MethodCallExpr( scope, accessor.getName() );
return new TypedExpression( body, accessor.getGenericReturnType() );
return new TypedExpression( body, actualTypeFromGenerics( type, accessor.getGenericReturnType() ) );
} else {
// try parse it as inner class
for (Class<?> declaredClass : clazz.getClasses()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ String getMethodName(BinaryExpr.Operator operator) {

static SpecialComparisonCase specialComparisonFactory(TypedExpression left, TypedExpression right) {
if (isNumber(left) && !isObject(right.getRawClass()) || isNumber(right) && !isObject(left.getRawClass())) { // Don't coerce Object yet. EvaluationUtil will handle it dynamically later
Optional<Class<?>> leftCast = typeNeedsCast(left.getType());
Optional<Class<?>> rightCast = typeNeedsCast(right.getType());
if (leftCast.isPresent() || rightCast.isPresent()) {
if (typeNeedsCast(left.getType()) || typeNeedsCast(right.getType())) {
return new ComparisonWithCast(true, left, right, of(Number.class), of(Number.class));
} else {
return new NumberComparisonWithoutCast(left, right);
Expand All @@ -67,13 +65,8 @@ static SpecialComparisonCase specialComparisonFactory(TypedExpression left, Type
return new PlainEvaluation(left, right);
}

private static Optional<Class<?>> typeNeedsCast(Type t) {
boolean needCast = isObject((Class<?>)t) || isMap((Class<?>) t) || isList((Class<?>) t);
if (needCast) {
return of((Class<?>) t);
} else {
return Optional.empty();
}
private static boolean typeNeedsCast(Type t) {
return t instanceof Class && ( isObject((Class<?>)t) || isMap((Class<?>) t) || isList((Class<?>) t) );
}

private static boolean isList(Class<?> t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -94,6 +93,7 @@
import org.drools.mvelcompiler.CompiledExpressionResult;
import org.drools.mvelcompiler.ConstraintCompiler;
import org.drools.mvelcompiler.util.BigDecimalArgumentCoercion;
import org.drools.util.ClassUtils;
import org.drools.util.MethodUtils;
import org.drools.util.Pair;
import org.drools.util.TypeResolver;
Expand Down Expand Up @@ -125,6 +125,7 @@
import static org.drools.mvel.parser.MvelParser.parseType;
import static org.drools.mvel.parser.printer.PrintUtil.printNode;
import static org.drools.util.ClassUtils.extractGenericType;
import static org.drools.util.ClassUtils.actualTypeFromGenerics;
import static org.drools.util.ClassUtils.getTypeArgument;
import static org.drools.util.ClassUtils.getter2property;
import static org.drools.util.ClassUtils.toRawClass;
Expand Down Expand Up @@ -922,16 +923,7 @@ private TypedExpressionCursor parseMethodCallExpr(MethodCallExpr methodCallExpr,
return new TypedExpressionCursor(methodCallExpr, ((ParameterizedType) originalTypeCursor).getActualTypeArguments()[0]);
}

java.lang.reflect.Type genericReturnType = m.getGenericReturnType();
if (genericReturnType instanceof TypeVariable) {
if (originalTypeCursor instanceof ParameterizedType) {
return new TypedExpressionCursor( methodCallExpr, getActualType( rawClassCursor, ( ParameterizedType ) originalTypeCursor, ( TypeVariable ) genericReturnType ) );
} else {
return new TypedExpressionCursor(methodCallExpr, Object.class);
}
} else {
return new TypedExpressionCursor(methodCallExpr, genericReturnType);
}
return new TypedExpressionCursor(methodCallExpr, actualTypeFromGenerics(originalTypeCursor, m.getGenericReturnType(), rawClassCursor));
}

private void promoteBigDecimalParameters(MethodCallExpr methodCallExpr, Class[] argsType, Class<?>[] actualArgumentTypes) {
Expand Down Expand Up @@ -967,17 +959,6 @@ private Optional<TypedExpressionCursor> checkStartsWithMVEL(MethodCallExpr metho
}
}

private java.lang.reflect.Type getActualType(Class<?> rawClassCursor, ParameterizedType originalTypeCursor, TypeVariable genericReturnType) {
int genericPos = 0;
for (TypeVariable typeVar : rawClassCursor.getTypeParameters()) {
if (typeVar.equals( genericReturnType )) {
return originalTypeCursor.getActualTypeArguments()[genericPos];
}
genericPos++;
}
throw new RuntimeException( "Unknonw generic type " + genericReturnType + " for type " + originalTypeCursor );
}

private TypedExpressionCursor objectCreationExpr(ObjectCreationExpr objectCreationExpr) {
parseNodeArguments( objectCreationExpr );
return new TypedExpressionCursor(objectCreationExpr, getClassFromType(ruleContext.getTypeResolver(), objectCreationExpr.getType()));
Expand Down Expand Up @@ -1163,7 +1144,7 @@ private Optional<TypedExpressionCursor> drlNameExpr(Expression drlxExpr, DrlName
return of(new TypedExpressionCursor(addCastToExpression(typeWithoutDollar, fieldAccessor, false), typeOfFirstAccessor ) );
}

return of(new TypedExpressionCursor(fieldAccessor, firstAccessor.getGenericReturnType() ) );
return of( new TypedExpressionCursor(fieldAccessor, ClassUtils.actualTypeFromGenerics(originalTypeCursor, firstAccessor.getGenericReturnType()) ) );
}

Field field = DrlxParseUtil.getField( classCursor, firstName );
Expand Down
Loading

0 comments on commit a08c841

Please sign in to comment.