use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DescrDumper 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 + " && ";
String[] nullCheckAndExpr = new String[] { innerCheck, expr };
atomicExpr.setRewrittenExpression(expr);
return nullCheckAndExpr;
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL6Expressions method andExpression.
// $ANTLR end "exclusiveOrExpression"
// $ANTLR start "andExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:286:1: andExpression returns [BaseDescr result] : left= equalityExpression ( AMPER right= equalityExpression )* ;
public final BaseDescr andExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:287:3: (left= equalityExpression ( AMPER right= equalityExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:287:5: left= equalityExpression ( AMPER right= equalityExpression )*
{
pushFollow(FOLLOW_equalityExpression_in_andExpression1430);
left = equalityExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:288:3: ( AMPER right= equalityExpression )*
loop30: while (true) {
int alt30 = 2;
int LA30_0 = input.LA(1);
if ((LA30_0 == AMPER)) {
alt30 = 1;
}
switch(alt30) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:288:5: AMPER right= equalityExpression
{
match(input, AMPER, FOLLOW_AMPER_in_andExpression1438);
if (state.failed)
return result;
pushFollow(FOLLOW_equalityExpression_in_andExpression1442);
right = equalityExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newIncAnd();
descr.addOrMerge(result);
descr.addOrMerge(right);
result = descr;
}
}
}
break;
default:
break loop30;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL6Expressions method conditionalOrExpression.
// $ANTLR end "annotationArray"
// $ANTLR start "conditionalOrExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:228:1: conditionalOrExpression returns [BaseDescr result] : left= conditionalAndExpression ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )* ;
public final BaseDescr conditionalOrExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
AnnotationDescr args = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:229:3: (left= conditionalAndExpression ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:229:5: left= conditionalAndExpression ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )*
{
pushFollow(FOLLOW_conditionalAndExpression_in_conditionalOrExpression1192);
left = conditionalAndExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:230:3: ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )*
loop25: while (true) {
int alt25 = 2;
int LA25_0 = input.LA(1);
if ((LA25_0 == DOUBLE_PIPE)) {
alt25 = 1;
}
switch(alt25) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:230:5: DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression
{
match(input, DOUBLE_PIPE, FOLLOW_DOUBLE_PIPE_in_conditionalOrExpression1201);
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/DRL6Expressions.g:232:13: (args= fullAnnotation[null] )?
int alt24 = 2;
int LA24_0 = input.LA(1);
if ((LA24_0 == AT)) {
alt24 = 1;
}
switch(alt24) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:232:13: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_conditionalOrExpression1223);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_conditionalAndExpression_in_conditionalOrExpression1229);
right = conditionalAndExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
descr.addOrMerge(result);
descr.addOrMerge(right);
if (args != null) {
descr.addAnnotation(args);
}
result = descr;
}
}
}
break;
default:
break loop25;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL6Expressions method inExpression.
// $ANTLR end "instanceOfExpression"
// $ANTLR start "inExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:325:1: inExpression returns [BaseDescr result] : left= relationalExpression ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )? ;
public final BaseDescr inExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
ParserRuleReturnScope e1 = null;
ParserRuleReturnScope e2 = null;
ConstraintConnectiveDescr descr = null;
BaseDescr leftDescr = null;
BindingDescr binding = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:328:3: (left= relationalExpression ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )? )
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:328:5: left= relationalExpression ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )?
{
pushFollow(FOLLOW_relationalExpression_in_inExpression1615);
left = relationalExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
if (left instanceof BindingDescr) {
binding = (BindingDescr) left;
leftDescr = new AtomicExprDescr(binding.getExpression());
} else {
leftDescr = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:337:5: ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )?
int alt36 = 3;
int LA36_0 = input.LA(1);
if ((LA36_0 == ID)) {
int LA36_1 = input.LA(2);
if ((LA36_1 == ID)) {
int LA36_3 = input.LA(3);
if ((LA36_3 == LEFT_PAREN) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) && synpred8_DRL6Expressions()))) {
alt36 = 1;
}
} else if ((LA36_1 == LEFT_PAREN) && (((helper.validateIdentifierKey(DroolsSoftKeywords.IN))))) {
alt36 = 2;
}
}
switch(alt36) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:337:6: ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN
{
pushFollow(FOLLOW_not_key_in_inExpression1635);
not_key();
state._fsp--;
if (state.failed)
return result;
pushFollow(FOLLOW_in_key_in_inExpression1639);
in_key();
state._fsp--;
if (state.failed)
return result;
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_inExpression1641);
if (state.failed)
return result;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
}
pushFollow(FOLLOW_expression_in_inExpression1663);
e1 = expression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
descr = ConstraintConnectiveDescr.newAnd();
RelationalExprDescr rel = new RelationalExprDescr("!=", false, null, leftDescr, (e1 != null ? ((DRL6Expressions.expression_return) e1).result : null));
descr.addOrMerge(rel);
result = descr;
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:345:7: ( COMMA e2= expression )*
loop34: while (true) {
int alt34 = 2;
int LA34_0 = input.LA(1);
if ((LA34_0 == COMMA)) {
alt34 = 1;
}
switch(alt34) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:345:8: COMMA e2= expression
{
match(input, COMMA, FOLLOW_COMMA_in_inExpression1682);
if (state.failed)
return result;
pushFollow(FOLLOW_expression_in_inExpression1686);
e2 = expression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
RelationalExprDescr rel = new RelationalExprDescr("!=", false, null, leftDescr, (e2 != null ? ((DRL6Expressions.expression_return) e2).result : null));
descr.addOrMerge(rel);
}
}
break;
default:
break loop34;
}
}
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_inExpression1707);
if (state.failed)
return result;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
}
}
break;
case 2:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:351:7: in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN
{
pushFollow(FOLLOW_in_key_in_inExpression1723);
in_key();
state._fsp--;
if (state.failed)
return result;
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_inExpression1725);
if (state.failed)
return result;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
}
pushFollow(FOLLOW_expression_in_inExpression1747);
e1 = expression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
descr = ConstraintConnectiveDescr.newOr();
RelationalExprDescr rel = new RelationalExprDescr("==", false, null, leftDescr, (e1 != null ? ((DRL6Expressions.expression_return) e1).result : null));
descr.addOrMerge(rel);
result = descr;
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:359:7: ( COMMA e2= expression )*
loop35: while (true) {
int alt35 = 2;
int LA35_0 = input.LA(1);
if ((LA35_0 == COMMA)) {
alt35 = 1;
}
switch(alt35) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:359:8: COMMA e2= expression
{
match(input, COMMA, FOLLOW_COMMA_in_inExpression1766);
if (state.failed)
return result;
pushFollow(FOLLOW_expression_in_inExpression1770);
e2 = expression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
RelationalExprDescr rel = new RelationalExprDescr("==", false, null, leftDescr, (e2 != null ? ((DRL6Expressions.expression_return) e2).result : null));
descr.addOrMerge(rel);
}
}
break;
default:
break loop35;
}
}
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_inExpression1791);
if (state.failed)
return result;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
}
}
break;
}
}
if (state.backtracking == 0) {
if (binding != null && descr != null)
descr.addOrMerge(binding);
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DRL6Expressions method orRestriction.
// $ANTLR end "relationalExpression"
// $ANTLR start "orRestriction"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:405:1: orRestriction returns [BaseDescr result] : left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? ;
public final BaseDescr orRestriction() 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/DRL6Expressions.g:406:3: (left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? )
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:406:5: left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )?
{
pushFollow(FOLLOW_andRestriction_in_orRestriction1892);
left = andRestriction();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:5: ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )*
loop39: while (true) {
int alt39 = 2;
int LA39_0 = input.LA(1);
if ((LA39_0 == DOUBLE_PIPE)) {
int LA39_9 = input.LA(2);
if ((synpred10_DRL6Expressions())) {
alt39 = 1;
}
}
switch(alt39) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:7: ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction
{
lop = (Token) match(input, DOUBLE_PIPE, FOLLOW_DOUBLE_PIPE_in_orRestriction1914);
if (state.failed)
return result;
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:79: (args= fullAnnotation[null] )?
int alt38 = 2;
int LA38_0 = input.LA(1);
if ((LA38_0 == AT)) {
alt38 = 1;
}
switch(alt38) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:79: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_orRestriction1918);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_andRestriction_in_orRestriction1924);
right = andRestriction();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
descr.addOrMerge(result);
descr.addOrMerge(right);
if (args != null) {
descr.addAnnotation(args);
}
result = descr;
}
}
}
break;
default:
break loop39;
}
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:416:7: ( EOF )?
int alt40 = 2;
int LA40_0 = input.LA(1);
if ((LA40_0 == EOF)) {
int LA40_1 = input.LA(2);
if ((LA40_1 == EOF)) {
int LA40_3 = input.LA(3);
if ((LA40_3 == EOF)) {
alt40 = 1;
}
} else if (((LA40_1 >= AMPER && LA40_1 <= AND_ASSIGN) || LA40_1 == AT || (LA40_1 >= COLON && LA40_1 <= COMMA) || LA40_1 == DIV_ASSIGN || (LA40_1 >= DOUBLE_AMPER && LA40_1 <= DOUBLE_PIPE) || (LA40_1 >= EQUALS && LA40_1 <= EQUALS_ASSIGN) || (LA40_1 >= GREATER && LA40_1 <= GREATER_EQUALS) || LA40_1 == ID || LA40_1 == LEFT_PAREN || (LA40_1 >= LESS && LA40_1 <= LESS_EQUALS) || LA40_1 == MINUS_ASSIGN || LA40_1 == MOD_ASSIGN || LA40_1 == MULT_ASSIGN || LA40_1 == NOT_EQUALS || LA40_1 == OR_ASSIGN || LA40_1 == PIPE || (LA40_1 >= PLUS_ASSIGN && LA40_1 <= QUESTION) || (LA40_1 >= RIGHT_CURLY && LA40_1 <= SEMICOLON) || LA40_1 == TILDE || (LA40_1 >= XOR && LA40_1 <= XOR_ASSIGN))) {
alt40 = 1;
}
}
switch(alt40) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:416:7: EOF
{
match(input, EOF, FOLLOW_EOF_in_orRestriction1943);
if (state.failed)
return result;
}
break;
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
Aggregations