Revision: 5602
Author:   [email protected]
Date:     Tue Sep 24 17:39:42 2013 UTC
Log:      fix some eclipse warnings
https://codereview.appspot.com/13826049

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.

R=kpreid2


http://code.google.com/p/google-caja/source/detail?r=5602

Modified:
 /trunk/src/com/google/caja/service/AbstractCajolingHandler.java
 /trunk/src/com/google/caja/tools/AbstractCajaAntTask.java
 /trunk/tests/com/google/caja/util/RhinoTestBed.java

=======================================
--- /trunk/src/com/google/caja/service/AbstractCajolingHandler.java Sat Sep 21 22:20:38 2013 UTC +++ /trunk/src/com/google/caja/service/AbstractCajolingHandler.java Tue Sep 24 17:39:42 2013 UTC
@@ -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();
=======================================
--- /trunk/src/com/google/caja/tools/AbstractCajaAntTask.java Thu Aug 8 00:39:21 2013 UTC +++ /trunk/src/com/google/caja/tools/AbstractCajaAntTask.java Tue Sep 24 17:39:42 2013 UTC
@@ -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();
@@ -114,7 +113,7 @@
* Wrap {@link Task#log(String)} in a PrintWriter so BuildService doesn't have
    * to know about ANT.
    */
-  PrintWriter getLogger() {
+  private PrintWriter getLogger() {
     return new PrintWriter(
         new Writer() {
           StringBuilder sb = new StringBuilder();
@@ -130,7 +129,7 @@
             }
           }
           @Override
-          public void close() { /* noop */ }
+          public void close() { flush(); }
         }, true);
   }

=======================================
--- /trunk/tests/com/google/caja/util/RhinoTestBed.java Sat Sep 21 22:20:38 2013 UTC +++ /trunk/tests/com/google/caja/util/RhinoTestBed.java Tue Sep 24 17:39:42 2013 UTC
@@ -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)) {
@@ -189,14 +181,6 @@
           "Rhino tests did not pass; title = " + title);
     }
   }
-
-  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 {
@@ -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