Search in sources :

Example 11 with SwitchEntry

use of com.github.javaparser.ast.stmt.SwitchEntry in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitCase.

@Override
public Void visitCase(CaseTree javacTree, Node javaParserNode) {
    SwitchEntry node = castNode(SwitchEntry.class, javaParserNode, javacTree);
    processCase(javacTree, node);
    // Java 12 introduced multiple label cases:
    List<Expression> labels = node.getLabels();
    List<? extends ExpressionTree> treeExpressions = org.checkerframework.javacutil.TreeUtils.caseTreeGetExpressions(javacTree);
    assert node.getLabels().size() == treeExpressions.size() : String.format("node.getLabels() = %s, treeExpressions = %s", node.getLabels(), treeExpressions);
    for (int i = 0; i < treeExpressions.size(); i++) {
        treeExpressions.get(i).accept(this, labels.get(i));
    }
    if (javacTree.getStatements() == null) {
        Tree javacBody = TreeUtils.caseTreeGetBody(javacTree);
        Statement nodeBody = node.getStatement(0);
        if (javacBody.getKind() == Kind.EXPRESSION_STATEMENT) {
            javacBody.accept(this, node.getStatement(0));
        } else if (nodeBody.isExpressionStmt()) {
            javacBody.accept(this, nodeBody.asExpressionStmt().getExpression());
        } else {
            javacBody.accept(this, nodeBody);
        }
    } else {
        processStatements(javacTree.getStatements(), node.getStatements());
    }
    return null;
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) Statement(com.github.javaparser.ast.stmt.Statement) CompoundAssignmentTree(com.sun.source.tree.CompoundAssignmentTree) LiteralTree(com.sun.source.tree.LiteralTree) ExportsTree(com.sun.source.tree.ExportsTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) TypeCastTree(com.sun.source.tree.TypeCastTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ForLoopTree(com.sun.source.tree.ForLoopTree) InstanceOfTree(com.sun.source.tree.InstanceOfTree) ModuleTree(com.sun.source.tree.ModuleTree) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) OpensTree(com.sun.source.tree.OpensTree) MemberSelectTree(com.sun.source.tree.MemberSelectTree) ExpressionStatementTree(com.sun.source.tree.ExpressionStatementTree) ThrowTree(com.sun.source.tree.ThrowTree) BlockTree(com.sun.source.tree.BlockTree) EnhancedForLoopTree(com.sun.source.tree.EnhancedForLoopTree) ReturnTree(com.sun.source.tree.ReturnTree) ArrayTypeTree(com.sun.source.tree.ArrayTypeTree) LabeledStatementTree(com.sun.source.tree.LabeledStatementTree) UnaryTree(com.sun.source.tree.UnaryTree) VariableTree(com.sun.source.tree.VariableTree) TypeParameterTree(com.sun.source.tree.TypeParameterTree) NewClassTree(com.sun.source.tree.NewClassTree) ParameterizedTypeTree(com.sun.source.tree.ParameterizedTypeTree) BreakTree(com.sun.source.tree.BreakTree) ImportTree(com.sun.source.tree.ImportTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) IntersectionTypeTree(com.sun.source.tree.IntersectionTypeTree) WildcardTree(com.sun.source.tree.WildcardTree) RequiresTree(com.sun.source.tree.RequiresTree) UnionTypeTree(com.sun.source.tree.UnionTypeTree) ArrayAccessTree(com.sun.source.tree.ArrayAccessTree) AnnotatedTypeTree(com.sun.source.tree.AnnotatedTypeTree) PackageTree(com.sun.source.tree.PackageTree) IdentifierTree(com.sun.source.tree.IdentifierTree) CatchTree(com.sun.source.tree.CatchTree) NewArrayTree(com.sun.source.tree.NewArrayTree) ContinueTree(com.sun.source.tree.ContinueTree) UsesTree(com.sun.source.tree.UsesTree) CaseTree(com.sun.source.tree.CaseTree) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) SwitchTree(com.sun.source.tree.SwitchTree) PrimitiveTypeTree(com.sun.source.tree.PrimitiveTypeTree) SynchronizedTree(com.sun.source.tree.SynchronizedTree) AssertTree(com.sun.source.tree.AssertTree) StatementTree(com.sun.source.tree.StatementTree) ModifiersTree(com.sun.source.tree.ModifiersTree) WhileLoopTree(com.sun.source.tree.WhileLoopTree) AnnotationTree(com.sun.source.tree.AnnotationTree) MethodTree(com.sun.source.tree.MethodTree) BinaryTree(com.sun.source.tree.BinaryTree) EmptyStatementTree(com.sun.source.tree.EmptyStatementTree) ClassTree(com.sun.source.tree.ClassTree) IfTree(com.sun.source.tree.IfTree) ProvidesTree(com.sun.source.tree.ProvidesTree) MemberReferenceTree(com.sun.source.tree.MemberReferenceTree) ErroneousTree(com.sun.source.tree.ErroneousTree) DoWhileLoopTree(com.sun.source.tree.DoWhileLoopTree) TryTree(com.sun.source.tree.TryTree) SwitchEntry(com.github.javaparser.ast.stmt.SwitchEntry)

Example 12 with SwitchEntry

use of com.github.javaparser.ast.stmt.SwitchEntry in project checker-framework by typetools.

the class DoubleJavaParserVisitor method visit.

@Override
public void visit(final SwitchEntry node1, final Node other) {
    SwitchEntry node2 = (SwitchEntry) other;
    defaultAction(node1, node2);
    visitLists(node1.getLabels(), node2.getLabels());
    visitLists(node1.getStatements(), node2.getStatements());
}
Also used : SwitchEntry(com.github.javaparser.ast.stmt.SwitchEntry)

Aggregations

SwitchEntry (com.github.javaparser.ast.stmt.SwitchEntry)12 SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)5 Expression (com.github.javaparser.ast.expr.Expression)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)4 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)4 Statement (com.github.javaparser.ast.stmt.Statement)4 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 ThisExpr (com.github.javaparser.ast.expr.ThisExpr)3 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)3 NodeList (com.github.javaparser.ast.NodeList)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 CastExpr (com.github.javaparser.ast.expr.CastExpr)2 NameExpr (com.github.javaparser.ast.expr.NameExpr)2 StaticJavaParser (com.github.javaparser.StaticJavaParser)1 StaticJavaParser.parseExpression (com.github.javaparser.StaticJavaParser.parseExpression)1 StaticJavaParser.parseStatement (com.github.javaparser.StaticJavaParser.parseStatement)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 NodeList.nodeList (com.github.javaparser.ast.NodeList.nodeList)1