use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class ConstraintUtil method inverseMethodCallExpr.
private static void inverseMethodCallExpr(MethodCallExpr mcExpr) {
String mcExprName = mcExpr.getName().asString();
String methodName = mcExprName.substring(CLASS_NAME.length(), mcExprName.length());
NodeList<Expression> arguments = mcExpr.getArguments();
if (methodName.startsWith(GREATER_THAN_PREFIX)) {
methodName = methodName.replaceFirst(GREATER_THAN_PREFIX, LESS_THAN_PREFIX);
} else if (methodName.startsWith(GREATER_OR_EQUAL_PREFIX)) {
methodName = methodName.replaceFirst(GREATER_OR_EQUAL_PREFIX, LESS_OR_EQUAL_PREFIX);
} else if (methodName.startsWith(LESS_THAN_PREFIX)) {
methodName = methodName.replaceFirst(LESS_THAN_PREFIX, GREATER_THAN_PREFIX);
} else if (methodName.startsWith(LESS_OR_EQUAL_PREFIX)) {
methodName = methodName.replaceFirst(LESS_OR_EQUAL_PREFIX, GREATER_OR_EQUAL_PREFIX);
}
mcExpr.setName(new SimpleName(CLASS_NAME + methodName));
Expression firstArg = arguments.get(0);
mcExpr.setArgument(0, arguments.get(1));
mcExpr.setArgument(1, firstArg);
}
use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class ConsequenceGenerator method replaceGenericType.
private static void replaceGenericType(int arity, ClassOrInterfaceDeclaration clone, ConstructorDeclaration constructor) {
List<TypeParameter> genericTypeParameterList = genericTypeStream(arity, ConsequenceGenerator::createTypeParameter).collect(Collectors.toList());
clone.setTypeParameters(nodeList(genericTypeParameterList));
List<Type> genericTypeList = genericTypeStream(arity, ConsequenceGenerator::parseType).collect(Collectors.toList());
ClassOrInterfaceType extendTypeParameter = toClassOrInterfaceType(arityName(arity));
extendTypeParameter.setTypeArguments(nodeList(genericTypeList));
ClassOrInterfaceType extendedType = new ClassOrInterfaceType(null, new SimpleName("AbstractValidBuilder"), nodeList(extendTypeParameter));
clone.findAll(MethodDeclaration.class, mc -> mc.getType().asString().equals(arityName(arity))).forEach(c -> c.setType(extendTypeParameter));
clone.setExtendedTypes(nodeList(extendedType));
List<Parameter> parameters = genericTypeStream(arity, genericTypeIndex -> {
ClassOrInterfaceType type = toClassOrInterfaceType(String.format("Variable<%s>", argumentTypeName(genericTypeIndex)));
return new Parameter(type, argName(genericTypeIndex));
}).collect(Collectors.toList());
constructor.setParameters(nodeList(parameters));
constructorBody(arity, constructor);
ClassOrInterfaceType arityBlockType = toClassOrInterfaceType("Block" + arity);
arityBlockType.setTypeArguments(nodeList(genericTypeList));
ClassOrInterfaceType arityBlockTypePlusOne = toClassOrInterfaceType("Block" + (arity + 1));
List<Type> genericTypeListPlusDrools = new ArrayList<>(genericTypeList);
genericTypeListPlusDrools.add(0, toClassOrInterfaceType("Drools"));
arityBlockTypePlusOne.setTypeArguments(nodeList(genericTypeListPlusDrools));
clone.findAll(ClassOrInterfaceType.class, findNodeWithNameArityClassName(ARITY_CLASS_BLOCK)).forEach(oldType -> oldType.replace(arityBlockType));
clone.findAll(ClassOrInterfaceType.class, findNodeWithNameArityClassName(ARITY_CLASS_BLOCK_PLUS_ONE)).forEach(oldType -> oldType.replace(arityBlockTypePlusOne));
}
use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class DroolsMvelParserTest method testBindVariable.
@Test
public void testBindVariable() {
String expr = "$n : name == \"Mark\"";
DrlxExpression drlxExpression = parseExpression(parser, expr);
SimpleName bind = drlxExpression.getBind();
assertEquals("$n", bind.asString());
Expression expression = drlxExpression.getExpr();
BinaryExpr binaryExpr = ((BinaryExpr) expression);
assertEquals("name", toString(binaryExpr.getLeft()));
assertEquals("\"Mark\"", toString(binaryExpr.getRight()));
assertEquals(Operator.EQUALS, binaryExpr.getOperator());
}
use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class AstUtils method parseBindingAfterAnd.
public static DrlxExpression parseBindingAfterAnd(TokenRange tokenRange, DrlxExpression leftExpr, Expression rightExpr) {
if (leftExpr.getExpr() instanceof BinaryExpr && ((BinaryExpr) leftExpr.getExpr()).getOperator() == BinaryExpr.Operator.AND) {
if (((BinaryExpr) leftExpr.getExpr()).getRight() instanceof NameExpr) {
DrlxExpression newLeft = new DrlxExpression(leftExpr.getBind(), ((BinaryExpr) leftExpr.getExpr()).getLeft());
SimpleName rightName = ((NameExpr) ((BinaryExpr) leftExpr.getExpr()).getRight()).getName();
DrlxExpression newRight = new DrlxExpression(rightName, rightExpr);
return new DrlxExpression(null, new BinaryExpr(tokenRange, newLeft, newRight, BinaryExpr.Operator.AND));
}
if (((BinaryExpr) leftExpr.getExpr()).getRight() instanceof DrlxExpression) {
Expression first = ((BinaryExpr) leftExpr.getExpr()).getLeft();
DrlxExpression innerRight = parseBindingAfterAnd(tokenRange, (DrlxExpression) ((BinaryExpr) leftExpr.getExpr()).getRight(), rightExpr);
Expression second = ((BinaryExpr) innerRight.getExpr()).getLeft();
Expression third = ((BinaryExpr) innerRight.getExpr()).getRight();
return new DrlxExpression(null, new BinaryExpr(tokenRange, new BinaryExpr(tokenRange, first, second, BinaryExpr.Operator.AND), third, BinaryExpr.Operator.AND));
}
}
throw new IllegalStateException();
}
Aggregations