Package com.google.caja.parser.js

Source Code of com.google.caja.parser.js.ValueProperty

package com.google.caja.parser.js;

import com.google.caja.lexer.FilePosition;
import com.google.caja.lexer.TokenConsumer;
import com.google.caja.reporting.RenderContext;
import com.google.javascript.jscomp.jsonml.JsonML;
import com.google.javascript.jscomp.jsonml.TagAttr;
import com.google.javascript.jscomp.jsonml.TagType;

import java.util.List;

/**
* The most common type of object property, a name and a value expression.
*
* @author mikesamuel@gmail.com
*/
public class ValueProperty extends ObjProperty {
  private static final long serialVersionUID = -8361603805798322752L;

  public ValueProperty(StringLiteral name, Expression value) {
    super(name, value);
  }

  public ValueProperty(FilePosition pos, StringLiteral name, Expression value) {
    super(pos, name, value);
  }

  /**
   * Provided for reflection.
   * @param value unused
   */
  @ReflectiveCtor
  public ValueProperty(
      FilePosition pos, Void value, List<? extends Expression> children) {
    super(pos, (StringLiteral) children.get(0), children.get(1));
  }

  public Expression getValueExpr() { return children().get(1); }

  public void render(RenderContext rc) {
    Expression value = children().get(1);
    TokenConsumer out = rc.getOut();
    renderPropertyName(rc, false);
    out.consume(":");
    if (!Operation.is(value, Operator.COMMA)) {
      value.render(rc);
    } else {
      out.mark(value.getFilePosition());
      out.consume("(");
      value.render(rc);
      out.consume(")");
    }
  }

  public JsonML toJsonML() {
    return JsonMLBuilder.builder(TagType.DataProp, getFilePosition())
        .setAttribute(TagAttr.NAME, this.getPropertyName())
        .addChild(getValueExpr())
        .build();
  }
}
TOP

Related Classes of com.google.caja.parser.js.ValueProperty

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.