Search in sources :

Example 11 with ThisExpr

use of com.github.javaparser.ast.expr.ThisExpr in project drools by kiegroup.

the class FEELPropertyAccessibleImplementation method toGetPropertySwitchEntry.

private SwitchEntry toGetPropertySwitchEntry(DMNDeclaredField fieldDefinition) {
    ReturnStmt returnStmt = new ReturnStmt();
    MethodCallExpr mc = StaticJavaParser.parseExpression(EvalHelper.PropertyValueResult.class.getCanonicalName() + ".ofValue()");
    String accessorName = fieldDefinition.overriddenGetterName().orElse(getAccessorName(fieldDefinition, "get"));
    mc.addArgument(new MethodCallExpr(new ThisExpr(), accessorName));
    returnStmt.setExpression(mc);
    return new SwitchEntry(nodeList(new StringLiteralExpr(fieldDefinition.getOriginalMapKey())), SwitchEntry.Type.STATEMENT_GROUP, nodeList(returnStmt));
}
Also used : EvalHelper(org.kie.dmn.feel.util.EvalHelper) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) SwitchEntry(com.github.javaparser.ast.stmt.SwitchEntry) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 12 with ThisExpr

use of com.github.javaparser.ast.expr.ThisExpr in project drools by kiegroup.

the class FEELPropertyAccessibleImplementation method toSetPropertySwitchEntry.

private SwitchEntry toSetPropertySwitchEntry(DMNDeclaredField fieldDefinition) {
    String accessorName = fieldDefinition.overriddenSetterName().orElse(getAccessorName(fieldDefinition, "set"));
    MethodCallExpr setMethod = new MethodCallExpr(new ThisExpr(), accessorName);
    setMethod.addArgument(new CastExpr(StaticJavaParser.parseType(fieldDefinition.getObjectType()), new NameExpr("value")));
    ExpressionStmt setStatement = new ExpressionStmt();
    setStatement.setExpression(setMethod);
    NodeList<Expression> labels = nodeList(new StringLiteralExpr(fieldDefinition.getOriginalMapKey()));
    NodeList<Statement> statements = nodeList(setStatement, new ReturnStmt());
    return new SwitchEntry(labels, SwitchEntry.Type.STATEMENT_GROUP, statements);
}
Also used : Statement(com.github.javaparser.ast.stmt.Statement) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) Expression(com.github.javaparser.ast.expr.Expression) CastExpr(com.github.javaparser.ast.expr.CastExpr) SwitchEntry(com.github.javaparser.ast.stmt.SwitchEntry) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 13 with ThisExpr

use of com.github.javaparser.ast.expr.ThisExpr in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitMemberSelect.

@Override
public Void visitMemberSelect(MemberSelectTree javacTree, Node javaParserNode) {
    if (javaParserNode instanceof FieldAccessExpr) {
        FieldAccessExpr node = (FieldAccessExpr) javaParserNode;
        processMemberSelect(javacTree, node);
        javacTree.getExpression().accept(this, node.getScope());
    } else if (javaParserNode instanceof Name) {
        Name node = (Name) javaParserNode;
        processMemberSelect(javacTree, node);
        assert node.getQualifier().isPresent();
        javacTree.getExpression().accept(this, node.getQualifier().get());
    } else if (javaParserNode instanceof ClassOrInterfaceType) {
        ClassOrInterfaceType node = (ClassOrInterfaceType) javaParserNode;
        processMemberSelect(javacTree, node);
        assert node.getScope().isPresent();
        javacTree.getExpression().accept(this, node.getScope().get());
    } else if (javaParserNode instanceof ClassExpr) {
        ClassExpr node = (ClassExpr) javaParserNode;
        processMemberSelect(javacTree, node);
        javacTree.getExpression().accept(this, node.getType());
    } else if (javaParserNode instanceof ThisExpr) {
        ThisExpr node = (ThisExpr) javaParserNode;
        processMemberSelect(javacTree, node);
        assert node.getTypeName().isPresent();
        javacTree.getExpression().accept(this, node.getTypeName().get());
    } else if (javaParserNode instanceof SuperExpr) {
        SuperExpr node = (SuperExpr) javaParserNode;
        processMemberSelect(javacTree, node);
        assert node.getTypeName().isPresent();
        javacTree.getExpression().accept(this, node.getTypeName().get());
    } else {
        throwUnexpectedNodeType(javacTree, javaParserNode);
    }
    return null;
}
Also used : SuperExpr(com.github.javaparser.ast.expr.SuperExpr) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) ClassExpr(com.github.javaparser.ast.expr.ClassExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) SimpleName(com.github.javaparser.ast.expr.SimpleName) Name(com.github.javaparser.ast.expr.Name)

Example 14 with ThisExpr

use of com.github.javaparser.ast.expr.ThisExpr in project checker-framework by typetools.

the class DoubleJavaParserVisitor method visit.

@Override
public void visit(final ThisExpr node1, final Node other) {
    ThisExpr node2 = (ThisExpr) other;
    defaultAction(node1, node2);
    node1.getTypeName().ifPresent(l -> l.accept(this, node2.getTypeName().get()));
}
Also used : ThisExpr(com.github.javaparser.ast.expr.ThisExpr)

Aggregations

ThisExpr (com.github.javaparser.ast.expr.ThisExpr)14 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)9 NameExpr (com.github.javaparser.ast.expr.NameExpr)9 Expression (com.github.javaparser.ast.expr.Expression)8 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)7 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)5 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)5 CastExpr (com.github.javaparser.ast.expr.CastExpr)5 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)5 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)5 SimpleName (com.github.javaparser.ast.expr.SimpleName)5 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)5 Node (com.github.javaparser.ast.Node)4 NodeList (com.github.javaparser.ast.NodeList)4 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)4 DoubleLiteralExpr (com.github.javaparser.ast.expr.DoubleLiteralExpr)4 Arrays (java.util.Arrays)4 HashMap (java.util.HashMap)4 List (java.util.List)4