Package org.stjs.generator.writer.expression

Source Code of org.stjs.generator.writer.expression.InstanceofWriter

package org.stjs.generator.writer.expression;

import java.util.Arrays;

import javax.lang.model.type.TypeMirror;

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

import com.sun.source.tree.InstanceOfTree;
import com.sun.source.util.TreePath;

public class InstanceofWriter<JS> implements WriterContributor<InstanceOfTree, JS> {

  @SuppressWarnings("unchecked")
  @Override
  public JS visit(WriterVisitor<JS> visitor, InstanceOfTree tree, GenerationContext<JS> context) {

    // build stjs.isInstanceOf(expr.constructor, type);
    // TODO do I need a check or parenthesis around !?

    TypeMirror type = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getType()));
    JS getConstructor = context.js().property(visitor.scan(tree.getExpression(), context), JavascriptKeywords.CONSTRUCTOR);
    JS targetInst = context.js().property(context.js().name("stjs"), "isInstanceOf");
    JS typeName = context.js().name(context.getNames().getTypeName(context, type));
    return context.js().functionCall(targetInst, Arrays.asList(getConstructor, typeName));
  }
}
TOP

Related Classes of org.stjs.generator.writer.expression.InstanceofWriter

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.