Search in sources :

Example 6 with ParenthesizedTree

use of com.sun.source.tree.ParenthesizedTree in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitSwitchExpression17.

/**
 * Visit a switch expression.
 *
 * @param javacTree switch expression tree
 * @param javaParserNode java parser node
 * @return null
 */
public Void visitSwitchExpression17(Tree javacTree, Node javaParserNode) {
    SwitchExpr node = castNode(SwitchExpr.class, javaParserNode, javacTree);
    processSwitchExpression(javacTree, node);
    // Switch expressions are always parenthesized in javac but never in JavaParser.
    ExpressionTree expression = ((ParenthesizedTree) TreeUtils.switchExpressionTreeGetExpression(javacTree)).getExpression();
    expression.accept(this, node.getSelector());
    visitLists(TreeUtils.switchExpressionTreeGetCases(javacTree), node.getEntries());
    return null;
}
Also used : SwitchExpr(com.github.javaparser.ast.expr.SwitchExpr) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) ExpressionTree(com.sun.source.tree.ExpressionTree)

Example 7 with ParenthesizedTree

use of com.sun.source.tree.ParenthesizedTree in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitIf.

@Override
public Void visitIf(IfTree javacTree, Node javaParserNode) {
    IfStmt node = castNode(IfStmt.class, javaParserNode, javacTree);
    processIf(javacTree, node);
    assert javacTree.getCondition().getKind() == Tree.Kind.PARENTHESIZED;
    ExpressionTree condition = ((ParenthesizedTree) javacTree.getCondition()).getExpression();
    condition.accept(this, node.getCondition());
    javacTree.getThenStatement().accept(this, node.getThenStmt());
    visitOptional(javacTree.getElseStatement(), node.getElseStmt());
    return null;
}
Also used : IfStmt(com.github.javaparser.ast.stmt.IfStmt) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) ExpressionTree(com.sun.source.tree.ExpressionTree)

Example 8 with ParenthesizedTree

use of com.sun.source.tree.ParenthesizedTree in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitSwitch.

@Override
public Void visitSwitch(SwitchTree javacTree, Node javaParserNode) {
    SwitchStmt node = castNode(SwitchStmt.class, javaParserNode, javacTree);
    processSwitch(javacTree, node);
    // Switch expressions are always parenthesized in javac but never in JavaParser.
    ExpressionTree expression = ((ParenthesizedTree) javacTree.getExpression()).getExpression();
    expression.accept(this, node.getSelector());
    visitLists(javacTree.getCases(), node.getEntries());
    return null;
}
Also used : SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) ExpressionTree(com.sun.source.tree.ExpressionTree)

Example 9 with ParenthesizedTree

use of com.sun.source.tree.ParenthesizedTree in project checker-framework by typetools.

the class GuiEffectTypeFactory method getAnnotatedType.

@Override
public AnnotatedTypeMirror getAnnotatedType(Tree tree) {
    AnnotatedTypeMirror typeMirror = super.getAnnotatedType(tree);
    if (typeMirror.hasAnnotation(UI.class)) {
        return typeMirror;
    }
    // containing such class/lambda
    if (isDirectlyMarkedUIThroughInference(tree)) {
        typeMirror.replaceAnnotation(AnnotationBuilder.fromClass(elements, UI.class));
    } else if (tree.getKind() == Tree.Kind.PARENTHESIZED) {
        ParenthesizedTree parenthesizedTree = (ParenthesizedTree) tree;
        return this.getAnnotatedType(parenthesizedTree.getExpression());
    } else if (tree.getKind() == Tree.Kind.CONDITIONAL_EXPRESSION) {
        ConditionalExpressionTree cet = (ConditionalExpressionTree) tree;
        boolean isTrueOperandUI = (cet.getTrueExpression() != null && this.getAnnotatedType(cet.getTrueExpression()).hasAnnotation(UI.class));
        boolean isFalseOperandUI = (cet.getFalseExpression() != null && this.getAnnotatedType(cet.getFalseExpression()).hasAnnotation(UI.class));
        if (isTrueOperandUI || isFalseOperandUI) {
            typeMirror.replaceAnnotation(AnnotationBuilder.fromClass(elements, UI.class));
        }
    }
    // (i.e. are there any other operators that take new or lambda expressions as operands)
    return typeMirror;
}
Also used : PolyUI(org.checkerframework.checker.guieffect.qual.PolyUI) UI(org.checkerframework.checker.guieffect.qual.UI) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Aggregations

ParenthesizedTree (com.sun.source.tree.ParenthesizedTree)9 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)8 ExpressionTree (com.sun.source.tree.ExpressionTree)7 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)5 ArrayAccessTree (com.sun.source.tree.ArrayAccessTree)2 AssignmentTree (com.sun.source.tree.AssignmentTree)2 BinaryTree (com.sun.source.tree.BinaryTree)2 BlockTree (com.sun.source.tree.BlockTree)2 ClassTree (com.sun.source.tree.ClassTree)2 CompoundAssignmentTree (com.sun.source.tree.CompoundAssignmentTree)2 ExpressionStatementTree (com.sun.source.tree.ExpressionStatementTree)2 IdentifierTree (com.sun.source.tree.IdentifierTree)2 LiteralTree (com.sun.source.tree.LiteralTree)2 MemberSelectTree (com.sun.source.tree.MemberSelectTree)2 Tree (com.sun.source.tree.Tree)2 SwitchExpr (com.github.javaparser.ast.expr.SwitchExpr)1 DoStmt (com.github.javaparser.ast.stmt.DoStmt)1 IfStmt (com.github.javaparser.ast.stmt.IfStmt)1 SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)1 WhileStmt (com.github.javaparser.ast.stmt.WhileStmt)1