ToMethodCall { public TypedExpression toMethodCallWithClassCheck(Expression expr, String bindingId, Class<?> clazz) { Deque<ParsedMethod> createExpressionCallLeftToRight = createExpressionCallLeftToRight(expr); previousClass = clazz; for (ParsedMethod e : createExpressionCallLeftToRight) { if (e.expression instanceof EnclosedExpr) { setCursorForEnclosedExpr(e); } else if (e.expression instanceof MethodCallExpr) { setCursorForMethodCall(e); } else { convertNameToMethod(bindingId, e); } } return new TypedExpression(previousScope, previousClass); } ToMethodCall(RuleContext context);  ToMethodCall(TypeResolver typeResolver); TypedExpression toMethodCallWithClassCheck(Expression expr, String bindingId, Class<?> clazz); Optional<Expression> getImplicitCastExpression();  }
@Test public void transformMethodExpressionToMethodCallExpressionTypeSafe() { final Expression expr = StaticJavaParser.parseExpression("address.city.startsWith(\"M\")"); final Expression expr1 = StaticJavaParser.parseExpression("getAddress().city.startsWith(\"M\")"); final Expression expr2 = StaticJavaParser.parseExpression("address.getCity().startsWith(\"M\")"); final MethodCallExpr expected = StaticJavaParser.parseExpression("getAddress().getCity().startsWith(\"M\")"); assertEquals(expected.toString(), new ToMethodCall(typeResolver).toMethodCallWithClassCheck(expr, null, Person.class).getExpression().toString()); assertEquals(expected.toString(), new ToMethodCall(typeResolver).toMethodCallWithClassCheck(expr1, null, Person.class).getExpression().toString()); assertEquals(expected.toString(), new ToMethodCall(typeResolver).toMethodCallWithClassCheck(expr2, null, Person.class).getExpression().toString()); }
@Test public void transformMethodExpressionToMethodCallWithInlineCast() { typeResolver.addImport("org.drools.modelcompiler.domain.InternationalAddress"); final DrlxExpression expr = DrlxParseUtil.parseExpression("address#InternationalAddress.state"); final MethodCallExpr expected = StaticJavaParser.parseExpression("((InternationalAddress)getAddress()).getState()"); assertEquals(expected.toString(), new ToMethodCall(typeResolver).toMethodCallWithClassCheck(expr.getExpr(), null, Person.class).getExpression().toString()); }