private void processRelationalExpression(StringBuilder sbuilder, RelationalExprDescr red, ConstraintConnectiveDescr parent, MVELDumperContext context) { // maximum precedence, so wrap any child connective in parenthesis int idx = parent.getDescrs().indexOf( red ); StringBuilder left = dump(new StringBuilder(), red.getLeft(), parent, idx, Integer.MAX_VALUE, true, context); StringBuilder right = red.getRight() instanceof AtomicExprDescr ? processRightAtomicExpr(left, (AtomicExprDescr)red.getRight(), parent, idx, context) : dump( new StringBuilder(), red.getRight(), parent, idx, Integer.MAX_VALUE, true, context); processRestriction( context, sbuilder, left.toString(), red.getOperatorDescr(), right.toString() );// maximum precedence, so wrap any child connective in parenthesis }
@Override public String toString() { return this.left + (isNegated() ? " not " : " ") + getOperator() + (getParameters() != null ? getParameters().toString() + " " : " ") + this.right; } }
protected boolean isSimpleExpr( final RelationalExprDescr relDescr ) { boolean simple = false; if ( relDescr != null ) { if ( (relDescr.getLeft() instanceof AtomicExprDescr || relDescr.getLeft() instanceof BindingDescr) && (relDescr.getRight() instanceof AtomicExprDescr || relDescr.getRight() instanceof BindingDescr) ) { simple = true; } } return simple; }
private Declaration[] getDeclarationsForReturnValue(RuleBuildContext context, RelationalExprDescr relDescr, String operator, String value2) { Pattern pattern = (Pattern) context.getBuildStack().peek(); ReturnValueRestrictionDescr returnValueRestrictionDescr = new ReturnValueRestrictionDescr( operator, relDescr.isNegated(), relDescr.getParametersText(), value2 );
RelationalExprDescr check = new RelationalExprDescr( "instanceof", false, null, innerCheck = check.toString() + " && ";
protected LiteralRestrictionDescr buildLiteralRestrictionDescr(RuleBuildContext context, RelationalExprDescr exprDescr, String rightValue, String operator, boolean isRightLiteral) { // is it a literal? Does not include enums if ( isRightLiteral ) { return new LiteralRestrictionDescr(operator, exprDescr.isNegated(), exprDescr.getParameters(), rightValue, LiteralRestrictionDescr.TYPE_STRING); } // is it an enum? int dotPos = rightValue.lastIndexOf( '.' ); if ( dotPos >= 0 ) { final String mainPart = rightValue.substring( 0, dotPos ); String lastPart = rightValue.substring( dotPos + 1 ); try { context.getDialect().getTypeResolver().resolveType( mainPart ); if ( lastPart.indexOf( '(' ) < 0 && lastPart.indexOf( '.' ) < 0 && lastPart.indexOf( '[' ) < 0 ) { return new LiteralRestrictionDescr(operator, exprDescr.isNegated(), exprDescr.getParameters(), rightValue, LiteralRestrictionDescr.TYPE_STRING ); } } catch ( ClassNotFoundException e ) { // do nothing as this is just probing to see if it was a class, which we now know it isn't :) } } return null; }
String operator = relDescr.getOperator().trim(); LiteralRestrictionDescr restrictionDescr = buildLiteralRestrictionDescr(context, relDescr, value2, operator, isConstant); pattern.addConstraint( getConstraintBuilder( context ).buildVariableConstraint(context, pattern, expr, declarations, value1, relDescr.getOperatorDescr(), value2, extractor, declr, relDescr) ); return true;
if ( state.backtracking==0 ) { if( buildDescr ) { result = new RelationalExprDescr( (op!=null?op.getText():null), false, null, left, right );
public void copyParameters( BaseDescr base ) { if ( base instanceof RelationalExprDescr ) { setParameters( ((RelationalExprDescr) base).getParameters() ); } } }
private boolean findExpressionValues(RelationalExprDescr relDescr, String[] values) { boolean usesThisRef; if ( relDescr.getRight() instanceof AtomicExprDescr ) { AtomicExprDescr rdescr = ((AtomicExprDescr) relDescr.getRight()); values[1] = rdescr.getRewrittenExpression().trim(); usesThisRef = "this".equals( values[1] ) || values[1].startsWith("this."); } else { BindingDescr rdescr = ((BindingDescr) relDescr.getRight()); values[1] = rdescr.getExpression().trim(); usesThisRef = "this".equals( values[1] ) || values[1].startsWith("this."); } if ( relDescr.getLeft() instanceof AtomicExprDescr ) { AtomicExprDescr ldescr = (AtomicExprDescr) relDescr.getLeft(); values[0] = ldescr.getRewrittenExpression(); usesThisRef = usesThisRef || "this".equals( values[0] ) || values[0].startsWith("this."); } else { values[0] = ((BindingDescr) relDescr.getLeft()).getExpression(); usesThisRef = usesThisRef || "this".equals( values[0] ) || values[0].startsWith("this."); } return usesThisRef; }
extractor.getValueType(), operatorDescr.getOperator(), relDescr.isNegated(), relDescr.getParametersText(), left, right );
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" ) ); String innerCheck = ""; 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 ); } } innerCheck = check.toString() + " && "; String[] nullCheckAndExpr = new String[] { innerCheck, expr }; atomicExpr.setRewrittenExpression( expr ); return nullCheckAndExpr; }
if ( state.backtracking==0 ) { if( buildDescr ) { result = new RelationalExprDescr( (op!=null?input.toString(op.start,op.stop):null), false, null, left, new AtomicExprDescr((right!=null?input.toString(right.start,right.stop):null)) );
} else { ValueType vtype = extractor.getValueType(); LiteralRestrictionDescr restrictionDescr = new LiteralRestrictionDescr( relDescr.getOperator(), relDescr.isNegated(), relDescr.getParameters(), values[1], LiteralRestrictionDescr.TYPE_STRING ); subExprs[i++], values[0], relDescr.getOperator(), values[1], restrictionDescr );
(value!=null?value.result:null) : new AtomicExprDescr( (value!=null?input.toString(value.start,value.stop):null) ) ; result = new RelationalExprDescr( (op!=null?op.opr:null), (op!=null?op.negated:false), sa, ((relationalExpression_scope)relationalExpression_stack.peek()).lsd, descr ); if( ((relationalExpression_scope)relationalExpression_stack.peek()).lsd instanceof BindingDescr ) { ((relationalExpression_scope)relationalExpression_stack.peek()).lsd = new AtomicExprDescr( ((BindingDescr)((relationalExpression_scope)relationalExpression_stack.peek()).lsd).getExpression() );
if ( state.backtracking==0 ) { descr = ConstraintConnectiveDescr.newAnd(); RelationalExprDescr rel = new RelationalExprDescr( "!=", false, null, leftDescr, (e1!=null?e1.result:null) ); descr.addOrMerge( rel ); result = descr; if (state.failed) return result; if ( state.backtracking==0 ) { RelationalExprDescr rel = new RelationalExprDescr( "!=", false, null, leftDescr, (e2!=null?e2.result:null) ); descr.addOrMerge( rel ); if ( state.backtracking==0 ) { descr = ConstraintConnectiveDescr.newOr(); RelationalExprDescr rel = new RelationalExprDescr( "==", false, null, leftDescr, (e1!=null?e1.result:null) ); descr.addOrMerge( rel ); result = descr; if (state.failed) return result; if ( state.backtracking==0 ) { RelationalExprDescr rel = new RelationalExprDescr( "==", false, null, leftDescr, (e2!=null?e2.result:null) ); descr.addOrMerge( rel );