com.google.caja.parser.js.ObjProperty

Here are the examples of the java api class com.google.caja.parser.js.ObjProperty taken from open source projects.

1. JsOptimizer#setEnvJson()

Project: caja
Source File: JsOptimizer.java
View license
/**
   * Sets the environment file to use during optimization.
   * The environment file contains facts about the environment in which the
   * optimized output is expected to run, so allows for interpreter-specific
   * optimization.
   */
public JsOptimizer setEnvJson(ObjectConstructor envJson) {
    if (optimizer == null) {
        optimizer = new ParseTreeKB();
    }
    List<? extends ObjProperty> props = envJson.children();
    for (ObjProperty prop : props) {
        // JSON had better not have getters
        ValueProperty vprop = (ValueProperty) prop;
        // fold negative nums
        Expression value = vprop.getValueExpr().fold(false);
        if (!(value instanceof Literal)) {
            // True for "*useragent*" property inserted by JSKB.
            continue;
        }
        StringLiteral sl = vprop.getPropertyNameNode();
        String rawExpr = sl.getValue();
        rawExpr = " " + rawExpr.substring(1, rawExpr.length() - 1) + " ";
        CharProducer valueCp = CharProducer.Factory.fromJsString(CharProducer.Factory.fromString(rawExpr, sl.getFilePosition()));
        try {
            Expression expr = jsExpr(valueCp, DevNullMessageQueue.singleton());
            optimizer.addFact(expr, Fact.is((Literal) value));
        } catch (ParseException ex) {
            continue;
        }
    }
    return this;
}

2. ObjectCtorQuasiNode#createSubstitutes()

Project: caja
Source File: ObjectCtorQuasiNode.java
View license
@Override
protected boolean createSubstitutes(List<ParseTreeNode> substitutes, Map<String, ParseTreeNode> bindings) {
    List<ParseTreeNode> props = Lists.newArrayList();
    for (QuasiNode q : getChildren()) {
        if (!q.createSubstitutes(props, bindings)) {
            return false;
        }
    }
    ObjProperty[] propArr = new ObjProperty[props.size()];
    props.toArray(propArr);
    substitutes.add(new ObjectConstructor(FilePosition.UNKNOWN, Arrays.asList(propArr)));
    return true;
}

3. ConstLocalOptimization#areSinglyInlineableProps()

Project: caja
Source File: ConstLocalOptimization.java
View license
private static boolean areSinglyInlineableProps(List<? extends ObjProperty> props) {
    for (ObjProperty prop : props) {
        if (prop instanceof ValueProperty && !isSinglyInlineable(((ValueProperty) prop).getValueExpr())) {
            return false;
        }
    // getters and setters are inlineable.
    }
    return true;
}

4. QuasiBuilder#buildObjectConstructorNode()

Project: caja
Source File: QuasiBuilder.java
View license
private static QuasiNode buildObjectConstructorNode(ObjectConstructor obj) {
    List<QuasiNode> propQuasis = Lists.newArrayList();
    for (ObjProperty prop : obj.children()) {
        StringLiteral key = prop.getPropertyNameNode();
        if (prop instanceof ValueProperty) {
            Expression value = ((ValueProperty) prop).getValueExpr();
            String keyIdent = quasiIdent(key);
            if (value instanceof Reference) {
                String valueStr = ((Reference) value).getIdentifierName();
                if (keyIdent != null && keyIdent.endsWith("*") && valueStr.startsWith("@") && valueStr.endsWith("*")) {
                    propQuasis.add(new MultiPropertyQuasi(keyIdent.substring(1, keyIdent.length() - 1), valueStr.substring(1, valueStr.length() - 1)));
                    continue;
                }
            }
            QuasiNode keyQuasi = build(keyIdent != null ? new Reference(new Identifier(FilePosition.UNKNOWN, keyIdent)) : key);
            propQuasis.add(new SinglePropertyQuasi(keyQuasi, build(value)));
        } else {
            // TODO: support getters and setters in object quasis
            throw new UnsupportedOperationException(prop.getClass().getName());
        }
    }
    return new ObjectCtorQuasiNode(propQuasis.toArray(new QuasiNode[0]));
}