Here are the examples of the java api class com.google.caja.parser.js.ObjectConstructor taken from open source projects.
1. ObjectCtorQuasiNode#consumeSpecimens()
Project: caja
File: ObjectCtorQuasiNode.java
File: ObjectCtorQuasiNode.java
@Override protected boolean consumeSpecimens(List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) { if (specimens.isEmpty()) { return false; } ParseTreeNode specimen = specimens.get(0); if (!(specimen instanceof ObjectConstructor)) { return false; } ObjectConstructor obj = (ObjectConstructor) specimen; List<ParseTreeNode> parts = Lists.<ParseTreeNode>newLinkedList(obj.children()); MultiPropertyQuasi hole = null; for (QuasiNode q : getChildren()) { if (q instanceof MultiPropertyQuasi) { hole = (MultiPropertyQuasi) q; } else { if (!q.consumeSpecimens(parts, bindings)) { return false; } } } if (hole != null && !hole.consumeSpecimens(parts, bindings)) { return false; } if (!parts.isEmpty()) { return false; } specimens.remove(0); return true; }
2. CssPropertyPatternsTest#toDigest()
Project: caja
File: CssPropertyPatternsTest.java
File: CssPropertyPatternsTest.java
private String toDigest(String sig, String... ignoreKeys) { CssPropertyPatterns.CssPropertyData data = pp.cssPropertyToData("test", parseSignature(sig)); // CSS // ( foo || bar || <number> || baz(...) )+ // -> // JS // { // literals: ["foo", "bar"], // properties: [ // fns: [], // } final FilePosition unk = FilePosition.UNKNOWN; ObjectConstructor obj = new ObjectConstructor(unk); appendIfNotEmptyOrIgnored(obj, "lits", mapToJsArray(Sets.newTreeSet(data.literals), new Function<String, Expression>() { public Expression apply(String s) { return StringLiteral.valueOf(unk, s); } }), ignoreKeys); appendIfNotEmptyOrIgnored(obj, "props", mapToJsArray(data.properties, new Function<CssPropBit, Expression>() { public Expression apply(CssPropBit bit) { return new Reference(new Identifier(unk, bit.name())); } }), ignoreKeys); appendIfNotEmptyOrIgnored(obj, "fns", mapToJsArray(data.fns, new Function<CssPropertySignature.CallSignature, Expression>() { public Expression apply(CssPropertySignature.CallSignature fn) { return StringLiteral.valueOf(unk, fn.getName()); } }), ignoreKeys); return render(obj); }
3. BuildServiceImplementation#loadEnvJsonFile()
Project: caja
File: BuildServiceImplementation.java
File: BuildServiceImplementation.java
private static void loadEnvJsonFile(File f, JsOptimizer op, MessageQueue mq) { CharProducer cp; try { cp = read(f); } catch (IOException ex) { mq.addMessage(MessageType.IO_ERROR, MessagePart.Factory.valueOf(ex.toString())); return; } ObjectConstructor envJson; try { Parser p = parser(cp, mq); // TODO(mikesamuel): limit to JSON Expression e = p.parseExpression(true); p.getTokenQueue().expectEmpty(); if (!(e instanceof ObjectConstructor)) { mq.addMessage(MessageType.IO_ERROR, MessagePart.Factory.valueOf("Invalid JSON in " + f)); return; } envJson = (ObjectConstructor) e; } catch (ParseException ex) { ex.toMessageQueue(mq); return; } op.setEnvJson(envJson); }