Search in sources :

Example 6 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class NodeTest method testSerializeProperties_isInferredConstant.

@Test
public void testSerializeProperties_isInferredConstant() {
    Node node = new Node(Token.NAME);
    node.setInferredConstantVar(true);
    EnumSet<NodeProperty> result = node.serializeProperties();
    assertThat(result).containsExactly(NodeProperty.IS_INFERRED_CONSTANT);
}
Also used : NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Example 7 with NodeProperty

use of com.google.javascript.jscomp.serialization.NodeProperty in project closure-compiler by google.

the class Node method deserializeProperties.

public final void deserializeProperties(List<NodeProperty> serializedNodeBooleanPropertyList) {
    if (this.isRoot()) {
        checkState(this.propListHead == null, this.propListHead);
    } else {
        checkState(this.propListHead.propType == Prop.SOURCE_FILE.ordinal(), this.propListHead);
    }
    EnumSet<NodeProperty> propSet = EnumSet.noneOf(NodeProperty.class);
    for (int i = 0; i < serializedNodeBooleanPropertyList.size(); i++) {
        NodeProperty nodeProperty = serializedNodeBooleanPropertyList.get(i);
        checkState(propSet.add(nodeProperty), "Found multiple node property: %s", nodeProperty);
    }
    if (propSet.contains(NodeProperty.IS_DECLARED_CONSTANT) || propSet.contains(NodeProperty.IS_INFERRED_CONSTANT)) {
        int newConstantVarFlags = (propSet.remove(NodeProperty.IS_DECLARED_CONSTANT) ? ConstantVarFlags.DECLARED : 0) | (propSet.remove(NodeProperty.IS_INFERRED_CONSTANT) ? ConstantVarFlags.INFERRED : 0);
        this.propListHead = new IntPropListItem((byte) Prop.CONSTANT_VAR_FLAGS.ordinal(), newConstantVarFlags, this.propListHead);
    }
    for (NodeProperty nodeProperty : propSet) {
        Prop prop = PropTranslator.deserialize(nodeProperty);
        this.propListHead = new IntPropListItem((byte) prop.ordinal(), 1, this.propListHead);
    }
    // Make sure the deserialized properties are valid.
    validateProperties(// triggers warning messages from some code analysis tools.
    errorMessage -> checkState(errorMessage != null, "deserialize error: %s: %s", errorMessage, this));
}
Also used : NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty)

Aggregations

NodeProperty (com.google.javascript.jscomp.serialization.NodeProperty)7 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)5 Test (org.junit.Test)5 Prop (com.google.javascript.rhino.Node.Prop)1 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)1 TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)1