use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class MVELDumper method processConstraint.
private void processConstraint(StringBuilder sbuilder, ExprConstraintDescr base, boolean isInsideRelCons, MVELDumperContext context) {
DrlExprParser expr = new DrlExprParser(context.getRuleContext().getConfiguration().getLanguageLevel());
ConstraintConnectiveDescr result = expr.parse(base.getExpression());
if (result.getDescrs().size() == 1) {
dump(sbuilder, result.getDescrs().get(0), 0, isInsideRelCons, context);
} else {
dump(sbuilder, result, 0, isInsideRelCons, context);
}
}
use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class MVELDumper method processNullSafeDereferencing.
private String[] processNullSafeDereferencing(String expr, AtomicExprDescr atomicExpr, ConstraintConnectiveDescr ccd, int nullSafePos, int parentIdx, int childIdx) {
// convert "field1!.field2" in ["field1 != null && ", "field1.field2"]
String field1 = expr.substring(0, nullSafePos).trim();
expr = field1 + "." + expr.substring(nullSafePos + 2).trim();
RelationalExprDescr check = new RelationalExprDescr("!=", false, null, new AtomicExprDescr(getPreconditionsToAppend(field1)), new AtomicExprDescr("null"));
if (ccd.getConnective() == ConnectiveType.AND || ccd.getConnective() == ConnectiveType.INC_AND) {
ccd.getDescrs().add(childIdx, check);
} else {
BaseDescr desc = ccd.getDescrs().get(parentIdx);
if (desc instanceof ConstraintConnectiveDescr) {
((ConstraintConnectiveDescr) desc).getDescrs().add(childIdx, check);
} else {
ConstraintConnectiveDescr localAnd = new ConstraintConnectiveDescr(ConnectiveType.AND);
BaseDescr original = ccd.getDescrs().remove(parentIdx);
localAnd.getDescrs().add(check);
localAnd.getDescrs().add(original);
ccd.getDescrs().add(parentIdx, localAnd);
}
}
String innerCheck = check.toString() + " && ";
String[] nullCheckAndExpr = new String[] { innerCheck, expr };
atomicExpr.setRewrittenExpression(expr);
return nullCheckAndExpr;
}
use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL5Expressions method andRestriction.
// $ANTLR end "orRestriction"
// $ANTLR start "andRestriction"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:405:1: andRestriction returns [BaseDescr result] : left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )* ;
public final BaseDescr andRestriction() throws RecognitionException {
BaseDescr result = null;
Token lop = null;
BaseDescr left = null;
AnnotationDescr args = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:406:3: (left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:406:5: left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )*
{
pushFollow(FOLLOW_singleRestriction_in_andRestriction1881);
left = singleRestriction();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:407:3: ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )*
loop42: while (true) {
int alt42 = 2;
int LA42_0 = input.LA(1);
if ((LA42_0 == DOUBLE_AMPER)) {
int LA42_9 = input.LA(2);
if ((synpred10_DRL5Expressions())) {
alt42 = 1;
}
}
switch(alt42) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:407:5: ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction
{
lop = (Token) match(input, DOUBLE_AMPER, FOLLOW_DOUBLE_AMPER_in_andRestriction1901);
if (state.failed)
return result;
if (state.backtracking == 0) {
if (isNotEOF())
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:409:13: (args= fullAnnotation[null] )?
int alt41 = 2;
int LA41_0 = input.LA(1);
if ((LA41_0 == AT)) {
alt41 = 1;
}
switch(alt41) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:409:13: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_andRestriction1922);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_singleRestriction_in_andRestriction1927);
right = singleRestriction();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newAnd();
descr.addOrMerge(result);
descr.addOrMerge(right);
if (args != null) {
descr.addAnnotation(args);
}
result = descr;
}
}
}
break;
default:
break loop42;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL5Expressions method exclusiveOrExpression.
// $ANTLR end "inclusiveOrExpression"
// $ANTLR start "exclusiveOrExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:259:1: exclusiveOrExpression returns [BaseDescr result] : left= andExpression ( XOR right= andExpression )* ;
public final BaseDescr exclusiveOrExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:260:3: (left= andExpression ( XOR right= andExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:260:5: left= andExpression ( XOR right= andExpression )*
{
pushFollow(FOLLOW_andExpression_in_exclusiveOrExpression1301);
left = andExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:261:3: ( XOR right= andExpression )*
loop29: while (true) {
int alt29 = 2;
int LA29_0 = input.LA(1);
if ((LA29_0 == XOR)) {
alt29 = 1;
}
switch(alt29) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:261:5: XOR right= andExpression
{
match(input, XOR, FOLLOW_XOR_in_exclusiveOrExpression1309);
if (state.failed)
return result;
pushFollow(FOLLOW_andExpression_in_exclusiveOrExpression1313);
right = andExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newXor();
descr.addOrMerge(result);
descr.addOrMerge(right);
result = descr;
}
}
}
break;
default:
break loop29;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL5Expressions method inclusiveOrExpression.
// $ANTLR end "conditionalAndExpression"
// $ANTLR start "inclusiveOrExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:246:1: inclusiveOrExpression returns [BaseDescr result] : left= exclusiveOrExpression ( PIPE right= exclusiveOrExpression )* ;
public final BaseDescr inclusiveOrExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:247:3: (left= exclusiveOrExpression ( PIPE right= exclusiveOrExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:247:5: left= exclusiveOrExpression ( PIPE right= exclusiveOrExpression )*
{
pushFollow(FOLLOW_exclusiveOrExpression_in_inclusiveOrExpression1254);
left = exclusiveOrExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:248:3: ( PIPE right= exclusiveOrExpression )*
loop28: while (true) {
int alt28 = 2;
int LA28_0 = input.LA(1);
if ((LA28_0 == PIPE)) {
alt28 = 1;
}
switch(alt28) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:248:5: PIPE right= exclusiveOrExpression
{
match(input, PIPE, FOLLOW_PIPE_in_inclusiveOrExpression1262);
if (state.failed)
return result;
pushFollow(FOLLOW_exclusiveOrExpression_in_inclusiveOrExpression1266);
right = exclusiveOrExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newIncOr();
descr.addOrMerge(result);
descr.addOrMerge(right);
result = descr;
}
}
}
break;
default:
break loop28;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
Aggregations