Reviewers: kpreid2,

Description:
This is part 1 of an N-part plan to deprecate com.google.util.List and
related classes

- fix static method used in non-static call.

- delete some unused private static methods.

- use Json.put instead of JSONObject#put to suppress warnings about
  unchecked generics.

- @SuppressWarnings("resource") unfortunately will cause a warning about
  unnecessary @SuppressWarnings if you turn off the flag to warn about
  possible resource leaks. In this case, it's harmless to close.

Please review this at https://codereview.appspot.com/13826049/

Affected files (+12, -55 lines):
  M     src/com/google/caja/service/AbstractCajolingHandler.java
  M     src/com/google/caja/tools/AbstractCajaAntTask.java
  M     tests/com/google/caja/util/RhinoTestBed.java


Index: src/com/google/caja/service/AbstractCajolingHandler.java
===================================================================
--- src/com/google/caja/service/AbstractCajolingHandler.java    (revision 5601)
+++ src/com/google/caja/service/AbstractCajolingHandler.java    (working copy)
@@ -34,20 +34,14 @@
 import com.google.caja.render.JsPrettyPrinter;
 import com.google.caja.reporting.SimpleMessageQueue;
 import com.google.caja.util.ContentType;
+import com.google.caja.util.Json;
 import com.google.caja.util.Maps;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.w3c.dom.Node;

 import com.google.caja.lexer.FetchedData;
-import com.google.caja.lexer.FilePosition;
 import com.google.caja.parser.html.Nodes;
-import com.google.caja.parser.js.ArrayConstructor;
-import com.google.caja.parser.js.Expression;
-import com.google.caja.parser.js.IntegerLiteral;
-import com.google.caja.parser.js.ObjectConstructor;
-import com.google.caja.parser.js.StringLiteral;
-import com.google.caja.parser.js.ValueProperty;
 import com.google.caja.plugin.UriFetcher;
 import com.google.caja.render.Concatenator;
 import com.google.caja.reporting.BuildInfo;
@@ -92,26 +86,6 @@
       MessageQueue mq)
       throws UnsupportedContentTypeException;

-  private static StringLiteral lit(String s) {
-    return StringLiteral.valueOf(FilePosition.UNKNOWN, s);
-  }
-
-  private static IntegerLiteral lit(int i) {
-    return new IntegerLiteral(FilePosition.UNKNOWN, i);
-  }
-
-  private static ArrayConstructor arr(List<? extends Expression> items) {
-    return new ArrayConstructor(FilePosition.UNKNOWN, items);
-  }
-
- private static ObjectConstructor obj(List<? extends ValueProperty> props) {
-    return new ObjectConstructor(FilePosition.UNKNOWN, props);
-  }
-
-  private static ValueProperty prop(String key, Expression e) {
-    return new ValueProperty(FilePosition.UNKNOWN, lit(key), e);
-  }
-
   /**
    * Checks whether a string is a JavaScript Identifier.
    */
@@ -176,17 +150,17 @@
     JSONObject o = new JSONObject();
     JSONArray messages = new JSONArray();

-    if (staticHtml != null) { o.put("html", staticHtml); }
-    if (javascript != null) { o.put("js", javascript); }
-    o.put("messages", messages);
+    if (staticHtml != null) { Json.put(o, "html", staticHtml); }
+    if (javascript != null) { Json.put(o, "js", javascript); }
+    Json.put(o, "messages", messages);

     for (Message m : mq.getMessages()) {
       JSONObject msg = new JSONObject();
-      msg.put("level", m.getMessageLevel().ordinal());
-      msg.put("name", m.getMessageLevel().name());
-      msg.put("type", m.getMessageType().name());
-      msg.put("message", m.toString());
-      messages.add(msg);
+      Json.put(msg, "level", m.getMessageLevel().ordinal());
+      Json.put(msg, "name", m.getMessageLevel().name());
+      Json.put(msg, "type", m.getMessageType().name());
+      Json.put(msg, "message", m.toString());
+      Json.push(messages, msg);
     }

     String rendered = o.toJSONString();
Index: src/com/google/caja/tools/AbstractCajaAntTask.java
===================================================================
--- src/com/google/caja/tools/AbstractCajaAntTask.java  (revision 5601)
+++ src/com/google/caja/tools/AbstractCajaAntTask.java  (working copy)
@@ -85,14 +85,13 @@
       }

       BuildService buildService = getBuildService();
-      @SuppressWarnings("resource")  // Not closed since not newly opened.
       PrintWriter logger = getLogger();
       try {
         for (Output output : outputs) {
output.build(inputFiles, dependees, youngest, buildService, logger);
         }
       } finally {
-        logger.flush();
+        logger.close();
       }
     } catch (RuntimeException ex) {
       ex.printStackTrace();
@@ -130,7 +129,7 @@
             }
           }
           @Override
-          public void close() { /* noop */ }
+          public void close() { flush(); }
         }, true);
   }

Index: tests/com/google/caja/util/RhinoTestBed.java
===================================================================
--- tests/com/google/caja/util/RhinoTestBed.java        (revision 5601)
+++ tests/com/google/caja/util/RhinoTestBed.java        (working copy)
@@ -18,22 +18,15 @@
 import com.google.caja.lexer.CharProducer;
 import com.google.caja.lexer.FilePosition;
 import com.google.caja.lexer.InputSource;
-import com.google.caja.lexer.JsLexer;
-import com.google.caja.lexer.JsTokenQueue;
 import com.google.caja.lexer.ParseException;
 import com.google.caja.parser.html.Namespaces;
 import com.google.caja.parser.html.Nodes;
-import com.google.caja.parser.js.Block;
-import com.google.caja.parser.js.Parser;
 import com.google.caja.parser.js.StringLiteral;
-import com.google.caja.reporting.EchoingMessageQueue;
 import com.google.caja.reporting.MessageContext;
-import com.google.caja.reporting.MessageQueue;
 import com.google.caja.util.Executor.AbnormalExitException;

 import java.io.File;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.io.StringReader;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -112,7 +105,6 @@
     List<Pair<String, InputSource>> scriptContent
         = new ArrayList<Pair<String, InputSource>>();
     MessageContext mc = new MessageContext();
- MessageQueue mq = new EchoingMessageQueue(new PrintWriter(System.err), mc);

     List<Element> scripts = new ArrayList<Element>();
     for (Node root : Nodes.childrenOf(html)) {
@@ -190,14 +182,6 @@
     }
   }

-  private static Block parseJavascript(CharProducer cp, MessageQueue mq)
-      throws ParseException {
-    JsLexer lexer = new JsLexer(cp, false);
-    Parser p = new Parser(
- new JsTokenQueue(lexer, cp.getSourceBreaks(0).source()), mq, false);
-    return p.parse();
-  }
-
   private static CharProducer loadResource(InputSource resource)
       throws IOException {
     File f = new File(resource.getUri());
@@ -264,7 +248,7 @@
       try {
         CajaTestCase t = new CajaTestCase() { { this.setUp(); } };
         return
-            t.render(
+            CajaTestCase.render(
                 t.js(
                     t.fromString(
                         "(" + s + ");",


--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to