use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class DroolsMvelParserTest method testComplexEnclosedBindVariable.
@Test
public void testComplexEnclosedBindVariable() {
String expr = "($n : name == \"Mario\") && (age > 20)";
DrlxExpression drlxExpression = parseExpression(parser, expr);
Expression bExpr = drlxExpression.getExpr();
assertTrue(bExpr instanceof BinaryExpr);
Node left = ((BinaryExpr) bExpr).getLeft();
assertTrue(left instanceof EnclosedExpr);
Expression inner = ((EnclosedExpr) left).getInner();
assertTrue(inner instanceof DrlxExpression);
DrlxExpression innerDrlxExpression = (DrlxExpression) inner;
SimpleName bind = innerDrlxExpression.getBind();
assertEquals("$n", bind.asString());
Expression expression = innerDrlxExpression.getExpr();
BinaryExpr binaryExpr = ((BinaryExpr) expression);
assertEquals("name", toString(binaryExpr.getLeft()));
assertEquals("\"Mario\"", toString(binaryExpr.getRight()));
assertEquals(Operator.EQUALS, binaryExpr.getOperator());
Node right = ((BinaryExpr) bExpr).getRight();
assertTrue(right instanceof EnclosedExpr);
Expression expression2 = ((EnclosedExpr) right).getInner();
BinaryExpr binaryExpr2 = ((BinaryExpr) expression2);
assertEquals("age", toString(binaryExpr2.getLeft()));
assertEquals("20", toString(binaryExpr2.getRight()));
assertEquals(Operator.GREATER, binaryExpr2.getOperator());
}
use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class SetNodeReferenceHandler method generateSwitchForSubNodes.
private MethodDeclaration generateSwitchForSubNodes(int partitionIndex, List<NetworkNode> subNodes, BlockStmt setNetworkNodeReferenceBody) {
String switchMethodName = "setNetworkNode" + partitionIndex;
BlockStmt callSwitchStatements = StaticJavaParser.parseBlock(switchStatementCall);
callSwitchStatements.findAll(SimpleName.class, ne -> ne.toString().equals("setNetworkResultN")).forEach(n -> n.replace(new SimpleName("setNetworkResult" + partitionIndex)));
callSwitchStatements.findAll(MethodCallExpr.class, mc -> mc.getNameAsString().equals("setNetworkNodeN")).forEach(n -> n.setName(new SimpleName("setNetworkNode" + partitionIndex)));
callSwitchStatements.getStatements().forEach(setNetworkNodeReferenceBody::addStatement);
MethodDeclaration switchMethod = new MethodDeclaration(nodeList(Modifier.privateModifier()), switchMethodName, PrimitiveType.booleanType(), nodeParameter());
BlockStmt switchBodyStatements = switchMethod.getBody().orElseThrow(() -> new RuntimeException("No"));
generateSwitchBody(switchBodyStatements, subNodes);
return switchMethod;
}
use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.
the class InlineFieldReferenceInitHandler method generateInitMethodForPartition.
private MethodDeclaration generateInitMethodForPartition(int partitionIndex, List<NetworkNode> nodeInPartition, BlockStmt setNetworkNodeReferenceBody) {
String initWithIndex = "initNode" + partitionIndex;
CompilationUnit initialisationCompilationUnit = new CompilationUnit();
initialisationCompilationUnit.setPackageDeclaration(ObjectTypeNodeCompiler.PACKAGE_NAME);
initialisationCompilationUnit.addClass(ucFirst(initWithIndex));
partitionedNodeInitialisationClasses.put(partitionIndex, initialisationCompilationUnit);
BlockStmt setFieldStatementCall = StaticJavaParser.parseBlock(statementCall);
setFieldStatementCall.findAll(MethodCallExpr.class, mc -> mc.getNameAsString().equals("initNodeN")).forEach(n -> n.setName(new SimpleName(initWithIndex)));
setFieldStatementCall.getStatements().forEach(setNetworkNodeReferenceBody::addStatement);
MethodDeclaration initMethodWithIndex = new MethodDeclaration(nodeList(Modifier.publicModifier()), new VoidType(), initWithIndex);
BlockStmt initBlockPerPartition = initMethodWithIndex.getBody().orElseThrow(() -> new RuntimeException("No"));
generateInitBody(initBlockPerPartition, nodeInPartition, partitionIndex);
return initMethodWithIndex;
}
use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.
the class NodeTest method findParent.
@Test
public void findParent() {
CompilationUnit cu = parse("class X{int x;}");
SimpleName x = cu.getClassByName("X").get().getMember(0).asFieldDeclaration().getVariables().get(0).getName();
assertEquals("int x;", x.findParent(FieldDeclaration.class).get().toString());
}
use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.
the class AnnotationMemberDeclarationTest method whenSettingNameTheParentOfNameIsAssigned.
@Test
public void whenSettingNameTheParentOfNameIsAssigned() {
AnnotationMemberDeclaration decl = new AnnotationMemberDeclaration();
SimpleName name = new SimpleName("foo");
decl.setName(name);
assertTrue(name.getParentNode().isPresent());
assertTrue(decl == name.getParentNode().get());
}
Aggregations