Package org.stjs.generator.writer.statement

Source Code of org.stjs.generator.writer.statement.SwitchWriter

package org.stjs.generator.writer.statement;

import java.util.ArrayList;
import java.util.List;

import org.stjs.generator.GenerationContext;
import org.stjs.generator.writer.WriterContributor;
import org.stjs.generator.writer.WriterVisitor;

import com.sun.source.tree.ParenthesizedTree;
import com.sun.source.tree.SwitchTree;
import com.sun.source.tree.Tree;

/**
* switch
*
* @author acraciun
*/
public class SwitchWriter<JS> implements WriterContributor<SwitchTree, JS> {

  @Override
  public JS visit(WriterVisitor<JS> visitor, SwitchTree tree, GenerationContext<JS> context) {
    Tree expr = tree.getExpression();
    if (expr instanceof ParenthesizedTree) {
      // remove the parans
      expr = ((ParenthesizedTree) expr).getExpression();
    }
    JS jsExpr = visitor.scan(expr, context);
    List<JS> cases = new ArrayList<JS>();
    for (Tree c : tree.getCases()) {
      cases.add(visitor.scan(c, context));
    }

    return context.withPosition(tree, context.js().switchStatement(jsExpr, cases));
  }
}
TOP

Related Classes of org.stjs.generator.writer.statement.SwitchWriter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.