All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.stjs.generator.writer.statement.SwitchWriter Maven / Gradle / Ivy

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 implements WriterContributor {

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy