Search in sources :

Example 6 with NameValue

use of org.stjs.generator.javascript.NameValue in project st-js by st-js.

the class MultipleVariableWriter method visit.

public JS visit(WriterVisitor<JS> visitor, List<VariableTree> trees, GenerationContext<JS> context, boolean isStatement) {
    if (trees.isEmpty()) {
        return context.js().emptyStatement();
    }
    List<NameValue<JS>> vars = new ArrayList<NameValue<JS>>();
    for (VariableTree tree : trees) {
        JS init = null;
        if (tree.getInitializer() != null) {
            init = visitor.scan(tree.getInitializer(), context);
        }
        vars.add(NameValue.of(tree.getName(), init));
    }
    return context.withPosition(trees.get(0), context.js().variableDeclaration(isStatement, vars));
}
Also used : NameValue(org.stjs.generator.javascript.NameValue) ArrayList(java.util.ArrayList) VariableTree(com.sun.source.tree.VariableTree)

Aggregations

ArrayList (java.util.ArrayList)6 NameValue (org.stjs.generator.javascript.NameValue)6 AssignmentTree (com.sun.source.tree.AssignmentTree)3 ExpressionTree (com.sun.source.tree.ExpressionTree)3 AnnotationTree (com.sun.source.tree.AnnotationTree)2 BlockTree (com.sun.source.tree.BlockTree)2 VariableTree (com.sun.source.tree.VariableTree)2 ClassTree (com.sun.source.tree.ClassTree)1 ExpressionStatementTree (com.sun.source.tree.ExpressionStatementTree)1 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 MethodTree (com.sun.source.tree.MethodTree)1 NewArrayTree (com.sun.source.tree.NewArrayTree)1 NewClassTree (com.sun.source.tree.NewClassTree)1 StatementTree (com.sun.source.tree.StatementTree)1 Tree (com.sun.source.tree.Tree)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 TypeVariable (javax.lang.model.type.TypeVariable)1