@Test public void prependTest() { final Expression expr = StaticJavaParser.parseExpression("getAddressName().startsWith(\"M\")"); final NameExpr nameExpr = new NameExpr(THIS_PLACEHOLDER); final Expression concatenated = DrlxParseUtil.prepend(nameExpr, expr); assertEquals(THIS_PLACEHOLDER + ".getAddressName().startsWith(\"M\")", concatenated.toString()); }
public static Expression prepend(Expression scope, Expression expr) { final Optional<Expression> rootNode = findRootNodeViaScope(expr); if (rootNode.isPresent()) { if(rootNode.get() instanceof ThisExpr) { rootNode.get().replace(scope); } else if (rootNode.get() instanceof NodeWithOptionalScope<?>) { ((NodeWithOptionalScope) rootNode.get()).setScope(scope); } return expr; } else { throw new IllegalStateException("No root node was found!"); } }
DrlxParseUtil { public static Expression prepend(Expression scope, Expression expr) { final Optional<Expression> rootNode = findRootNodeViaScope(expr); if (rootNode.isPresent()) { if(rootNode.get() instanceof ThisExpr) { rootNode.get().replace(scope); } else if (rootNode.get() instanceof NodeWithOptionalScope<?>) { ((NodeWithOptionalScope) rootNode.get()).setScope(scope); } return expr; } else { throw new IllegalStateException("No root node was found!"); } } }
DrlxParseUtil { public static Expression prepend(Expression scope, Expression expr) { final Optional<Expression> rootNode = findRootNodeViaScope(expr); if (rootNode.isPresent()) { if(rootNode.get() instanceof ThisExpr) { rootNode.get().replace(scope); } else if (rootNode.get() instanceof NodeWithOptionalScope<?>) { ((NodeWithOptionalScope) rootNode.get()).setScope(scope); } return expr; } else { throw new IllegalStateException("No root node was found!"); } } private  DrlxParseUtil(); }
DrlxParseUtil { public static Expression prepend(Expression scope, Expression expr) { final Optional<Expression> rootNode = findRootNodeViaScope(expr); if (rootNode.isPresent()) { if(rootNode.get() instanceof ThisExpr) { rootNode.get().replace(scope); } else if (rootNode.get() instanceof NodeWithOptionalScope<?>) { ((NodeWithOptionalScope) rootNode.get()).setScope(scope); } return expr; } else { throw new IllegalStateException("No root node was found!"); } } private  DrlxParseUtil(); static boolean isThisExpression( Node expr ); static Index.ConstraintType toConstraintType( Operator operator); static TypedExpression nameExprToMethodCallExprWithCast(String name, java.lang.reflect.Type type, Expression scope, Type castType); static TypedExpression nameExprToMethodCallExpr(String name, java.lang.reflect.Type type, Expression scope); static java.lang.reflect.Type returnTypeOfMethodCallExpr(RuleContext context, TypeResolver typeResolver, MethodCallExpr methodCallExpr, java.lang.reflect.Type clazz, Collection<String> usedDeclarations); static java.lang.reflect.Type getExpressionType(RuleContext context, TypeResolver typeResolver, Expression expr, Collection<String> usedDeclarations); static boolean canCoerceLiteralNumberExpr(Class<?> type); static Class<?> getLiteralExpressionType( LiteralExpr expr ); static Expression prepend(Expression scope, Expression expr); static Optional<Node> findRootNodeViaParent(Node expr); static Node replaceAllHalfBinaryChildren(Node parent); static Expression trasformHalfBinaryToBinary(Expression drlxExpr); static MethodCallExpr findLastMethodInChain(MethodCallExpr expr); static RemoveRootNodeResult findRemoveRootNodeViaScope(Expression expr); static Optional<Expression> findRootNodeViaScope(Expression expr); static RemoveRootNodeResult removeRootNode(Expression expr); static String fromVar(String key); static BlockStmt parseBlock(String ruleConsequenceAsBlock); static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations, Expression expr); static Expression generateLambdaWithoutParameters(Expression expr); static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations,
                                                             Expression expr,
                                                             boolean skipFirstParamAsThis,
                                                             Optional<Class<?>> patternClass); static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations,
                                                             Expression expr,
                                                             boolean skipFirstParamAsThis,
                                                             Optional<Class<?>> patternClass,
                                                             RuleContext ruleContext); static Type classToReferenceType(Class<?> declClass); static Type classNameToReferenceType(String className); static Type toType(Class<?> declClass); static ClassOrInterfaceType toClassOrInterfaceType( Class<?> declClass ); static ClassOrInterfaceType toClassOrInterfaceType( String className ); static Optional<String> findBindingIdFromDotExpression(String expression); static Optional<Expression> findViaScopeWithPredicate(Expression expr, Predicate<Expression> predicate); static DrlxExpression parseExpression(String expression); static Class<?> getClassFromType(TypeResolver typeResolver, Type type); static Class<?> getClassFromContext(TypeResolver typeResolver, String className); static boolean isPrimitiveExpression(Expression expr); static void forceCastForName(String nameRef, Type type, Expression expression); static void rescopeNamesToNewScope(Expression newScope, List<String> names, Expression e); static List<String> getPatternListenedProperties( PatternDescr pattern); static Optional<MethodCallExpr> findLastPattern(List<Expression> expressions); static boolean isNameExprWithName(Node expression, String name); static List<Node> findAllChildrenRecursive(Expression e); static String toVar(String key); static Optional<InvalidExpressionErrorResult> validateDuplicateBindings(String ruleName, List<String> allBindings); static Method getAccessor( Class<?> clazz, String name ); static void clearAccessorCache(); static Field getField( Class<?> clazz, String name ); static T transformDrlNameExprToNameExpr(T e); static String addCurlyBracesToBlock(String blockString); static String addSemicolon(String block); static Expression uncastExpr(Expression e); static Collection<String> collectUsedDeclarationsInExpression(Expression expr); static Optional<java.lang.reflect.Type> safeResolveType(TypeResolver typeResolver, String typeName); }
DrlxParseUtil { public static Expression prepend(Expression scope, Expression expr) { final Optional<Expression> rootNode = findRootNodeViaScope(expr); if (rootNode.isPresent()) { if(rootNode.get() instanceof ThisExpr) { rootNode.get().replace(scope); } else if (rootNode.get() instanceof NodeWithOptionalScope<?>) { ((NodeWithOptionalScope) rootNode.get()).setScope(scope); } return expr; } else { throw new IllegalStateException("No root node was found!"); } } private  DrlxParseUtil(); static boolean isThisExpression( Node expr ); static Index.ConstraintType toConstraintType( Operator operator); static TypedExpression nameExprToMethodCallExprWithCast(String name, java.lang.reflect.Type type, Expression scope, Type castType); static TypedExpression nameExprToMethodCallExpr(String name, java.lang.reflect.Type type, Expression scope); static java.lang.reflect.Type returnTypeOfMethodCallExpr(RuleContext context, TypeResolver typeResolver, MethodCallExpr methodCallExpr, java.lang.reflect.Type clazz, Collection<String> usedDeclarations); static java.lang.reflect.Type getExpressionType(RuleContext context, TypeResolver typeResolver, Expression expr, Collection<String> usedDeclarations); static boolean canCoerceLiteralNumberExpr(Class<?> type); static Class<?> getLiteralExpressionType( LiteralExpr expr ); static Expression prepend(Expression scope, Expression expr); static Optional<Node> findRootNodeViaParent(Node expr); static Node replaceAllHalfBinaryChildren(Node parent); static Expression trasformHalfBinaryToBinary(Expression drlxExpr); static MethodCallExpr findLastMethodInChain(MethodCallExpr expr); static RemoveRootNodeResult findRemoveRootNodeViaScope(Expression expr); static Optional<Expression> findRootNodeViaScope(Expression expr); static RemoveRootNodeResult removeRootNode(Expression expr); static String fromVar(String key); static BlockStmt parseBlock(String ruleConsequenceAsBlock); static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations, Expression expr); static Expression generateLambdaWithoutParameters(Expression expr); static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations,
                                                             Expression expr,
                                                             boolean skipFirstParamAsThis,
                                                             Optional<Class<?>> patternClass); static Expression generateLambdaWithoutParameters(Collection<String> usedDeclarations,
                                                             Expression expr,
                                                             boolean skipFirstParamAsThis,
                                                             Optional<Class<?>> patternClass,
                                                             RuleContext ruleContext); static Type classToReferenceType(Class<?> declClass); static Type classNameToReferenceType(String className); static Type toType(Class<?> declClass); static ClassOrInterfaceType toClassOrInterfaceType( Class<?> declClass ); static ClassOrInterfaceType toClassOrInterfaceType( String className ); static Optional<String> findBindingIdFromDotExpression(String expression); static Optional<Expression> findViaScopeWithPredicate(Expression expr, Predicate<Expression> predicate); static DrlxExpression parseExpression(String expression); static Class<?> getClassFromType(TypeResolver typeResolver, Type type); static Class<?> getClassFromContext(TypeResolver typeResolver, String className); static boolean isPrimitiveExpression(Expression expr); static void forceCastForName(String nameRef, Type type, Expression expression); static void rescopeNamesToNewScope(Expression newScope, List<String> names, Expression e); static List<String> getPatternListenedProperties( PatternDescr pattern); static Optional<MethodCallExpr> findLastPattern(List<Expression> expressions); static boolean isNameExprWithName(Node expression, String name); static List<Node> findAllChildrenRecursive(Expression e); static String toVar(String key); static Optional<InvalidExpressionErrorResult> validateDuplicateBindings(String ruleName, List<String> allBindings); static Method getAccessor( Class<?> clazz, String name ); static void clearAccessorCache(); static Field getField( Class<?> clazz, String name ); static T transformDrlNameExprToNameExpr(T e); static String addCurlyBracesToBlock(String blockString); static String addSemicolon(String block); static Expression uncastExpr(Expression e); static Collection<String> collectUsedDeclarationsInExpression(Expression expr); static Optional<java.lang.reflect.Type> safeResolveType(TypeResolver typeResolver, String typeName); static final String THIS_PLACEHOLDER; }