Merge branch 'feature/WAVE-439-support-java-8-compilation' of https://github.com/vega113/incubator-wave
diff --git a/pst/build.gradle b/pst/build.gradle
index b49cd85..d32385a 100644
--- a/pst/build.gradle
+++ b/pst/build.gradle
@@ -28,8 +28,8 @@
 // Project Level Settings
 //=============================================================================
 version = 0.1
-sourceCompatibility = 1.7
-targetCompatibility = 1.7
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
 def title = 'Apache Wave PST Compiler'
 def vendor = 'The Apache Software Foundation'
 
diff --git a/wave/build.gradle b/wave/build.gradle
index f09b059..8e7b6e4 100644
--- a/wave/build.gradle
+++ b/wave/build.gradle
@@ -38,8 +38,8 @@
         "-Djava.util.logging.config.file=config/wiab-logging.conf",
         "-Djava.security.auth.login.config=config/jaas.config"
 ]
-sourceCompatibility = 1.7
-targetCompatibility = 1.7
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
 compileJava {
     options.incremental = true
 }
diff --git a/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchProfilesServlet.java b/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchProfilesServlet.java
index 0033ff5..3118372 100644
--- a/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchProfilesServlet.java
+++ b/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchProfilesServlet.java
@@ -24,6 +24,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.google.inject.name.Named;
+import com.google.protobuf.Message;
 import com.google.protobuf.MessageLite;
 import com.google.wave.api.FetchProfilesRequest;
 import com.google.wave.api.FetchProfilesResult;
@@ -183,7 +184,7 @@
   /**
    * Writes the json with profile results to Response.
    */
-  private void printJson(MessageLite message, HttpServletResponse resp)
+  private <P extends Message> void printJson(P message, HttpServletResponse resp)
       throws IOException {
     if (message == null) {
       resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
diff --git a/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchServlet.java b/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchServlet.java
index 303915c..b23fa29 100644
--- a/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchServlet.java
+++ b/wave/src/main/java/org/waveprotocol/box/server/rpc/FetchServlet.java
@@ -21,6 +21,7 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.inject.Inject;
+import com.google.protobuf.Message;
 import com.google.protobuf.MessageLite;
 
 import org.waveprotocol.box.common.comms.WaveClientRpc.DocumentSnapshot;
@@ -103,7 +104,7 @@
     renderSnapshot(waveref, user, response);
   }
 
-  private void serializeObjectToServlet(MessageLite message, HttpServletResponse dest)
+  private <P extends Message> void serializeObjectToServlet(P message, HttpServletResponse dest)
       throws IOException {
     if (message == null) {
       // Snapshot is null. It would be nice to 404 here, but we can't let
diff --git a/wave/src/main/java/org/waveprotocol/box/server/rpc/ProtoSerializer.java b/wave/src/main/java/org/waveprotocol/box/server/rpc/ProtoSerializer.java
index 07b8bba..2599fde 100644
--- a/wave/src/main/java/org/waveprotocol/box/server/rpc/ProtoSerializer.java
+++ b/wave/src/main/java/org/waveprotocol/box/server/rpc/ProtoSerializer.java
@@ -178,12 +178,12 @@
    * @throws SerializationException if there is no serializer for
    *         {@code protoClass}.
    */
-  private <P> ProtoImplSerializer<? extends P, ?> getSerializer(Class<P> protoClass)
+  private <P extends Message, D extends ProtoWrapper<P> & GsonSerializable> ProtoImplSerializer<P, D> getSerializer(Class<P> protoClass)
       throws SerializationException {
     @SuppressWarnings("unchecked")
     // use of serializers map is safe.
-    ProtoImplSerializer<? extends P, ?> serializer =
-        (ProtoImplSerializer<? extends P, ?>) byClass.get(protoClass);
+    ProtoImplSerializer<P, D> serializer =
+        (ProtoImplSerializer<P, D>) byClass.get(protoClass);
     if (serializer == null) {
       throw new SerializationException("Unknown proto class: " + protoClass.getName());
     }
@@ -214,7 +214,7 @@
    * @throws SerializationException if the class of {@code message} has not been
    *         registered.
    */
-  public JsonElement toJson(MessageLite message) throws SerializationException {
+  public <P extends Message>JsonElement toJson(P message) throws SerializationException {
     return getSerializer(message.getClass()).toGson(message, null, gson);
   }
 
diff --git a/wave/src/main/java/org/waveprotocol/box/server/rpc/SearchServlet.java b/wave/src/main/java/org/waveprotocol/box/server/rpc/SearchServlet.java
index b4c1252..cf875b1 100644
--- a/wave/src/main/java/org/waveprotocol/box/server/rpc/SearchServlet.java
+++ b/wave/src/main/java/org/waveprotocol/box/server/rpc/SearchServlet.java
@@ -23,6 +23,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.google.inject.name.Named;
+import com.google.protobuf.Message;
 import com.google.protobuf.MessageLite;
 import com.google.wave.api.SearchResult;
 import com.google.wave.api.SearchResult.Digest;
@@ -157,7 +158,7 @@
   /**
    * Writes the json with search results to Response.
    */
-  private void serializeObjectToServlet(MessageLite message, HttpServletResponse resp)
+  private <P extends Message> void serializeObjectToServlet(P message, HttpServletResponse resp)
       throws IOException {
     if (message == null) {
       resp.sendError(HttpServletResponse.SC_FORBIDDEN);
diff --git a/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/render/ImageThumbnailWrapper.java b/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/render/ImageThumbnailWrapper.java
index 1c4d6be..a91012b 100644
--- a/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/render/ImageThumbnailWrapper.java
+++ b/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/render/ImageThumbnailWrapper.java
@@ -23,6 +23,7 @@
 import org.waveprotocol.wave.client.editor.content.CMutableDocument;
 import org.waveprotocol.wave.client.editor.content.ContentElement;
 import org.waveprotocol.wave.client.editor.content.ContentNode;
+import org.waveprotocol.wave.client.editor.content.ContentTextNode;
 import org.waveprotocol.wave.client.editor.content.misc.Caption;
 import org.waveprotocol.wave.media.model.Attachment;
 import org.waveprotocol.wave.model.document.util.DocHelper;
@@ -118,8 +119,8 @@
    *                 or null if this wrapper should produce a builder
    * @return resulting XML builder.
    */
-  public XmlStringBuilderDoc<? super ContentElement, ContentElement, ?>
-      appendInto(XmlStringBuilderDoc<? super ContentElement, ContentElement, ?> builder) {
+  public XmlStringBuilderDoc<ContentNode, ContentElement, ContentTextNode> appendInto
+    (XmlStringBuilderDoc<ContentNode, ContentElement, ContentTextNode> builder) {
     if (builder == null) {
       builder = XmlStringBuilderDoc.createEmpty(element.getMutableDoc());
     }
diff --git a/wave/src/main/java/org/waveprotocol/wave/client/doodad/selection/SelectionAnnotationHandler.java b/wave/src/main/java/org/waveprotocol/wave/client/doodad/selection/SelectionAnnotationHandler.java
index b34cfe5..60ff785 100644
--- a/wave/src/main/java/org/waveprotocol/wave/client/doodad/selection/SelectionAnnotationHandler.java
+++ b/wave/src/main/java/org/waveprotocol/wave/client/doodad/selection/SelectionAnnotationHandler.java
@@ -576,7 +576,7 @@
     final String profileAddress = profile.getAddress();
     sessions.each(new ProcV<SessionData>() {
       @Override
-      public void apply(String _, SessionData value) {
+      public void apply(String s, SessionData value) {
         if (value.address.equals(profileAddress) && !value.isStale()) {
           value.replaceName(profile);
         }
diff --git a/wave/src/main/java/org/waveprotocol/wave/client/wavepanel/render/LiveConversationViewRenderer.java b/wave/src/main/java/org/waveprotocol/wave/client/wavepanel/render/LiveConversationViewRenderer.java
index 8e6b56f..c64794f 100644
--- a/wave/src/main/java/org/waveprotocol/wave/client/wavepanel/render/LiveConversationViewRenderer.java
+++ b/wave/src/main/java/org/waveprotocol/wave/client/wavepanel/render/LiveConversationViewRenderer.java
@@ -302,7 +302,7 @@
     wave.removeListener(this);
     conversationRenderers.each(new ProcV<Conversation, LiveConversationRenderer>() {
       @Override
-      public void apply(Conversation _, LiveConversationRenderer value) {
+      public void apply(Conversation c, LiveConversationRenderer value) {
         value.destroy();
       }
     });
diff --git a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicMapTest.java b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicMapTest.java
index bac6fa2..dbfb743 100644
--- a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicMapTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicMapTest.java
@@ -204,9 +204,11 @@
    * @param values list of entries to include in the document state
    * @return a map-context view of the document state
    */
-  private static ValueContext<?, ?> substrate(ListBuilder<String, Integer> values) {
-    return substrate(BasicFactories.observableDocumentProvider().create("data",
-        Collections.<String, String>emptyMap()), values);
+  @SuppressWarnings("unchecked")
+  private static <N, E extends N>  ValueContext<N, E> substrate(ListBuilder<String, Integer> values) {
+    ObservableMutableDocument doc =
+      BasicFactories.observableDocumentProvider().create("data",Collections.<String, String>emptyMap());
+    return substrate(doc, values);
   }
 
   /**
@@ -214,8 +216,8 @@
    *
    * @return a map-context view of the document state.
    */
-  private static <N, E extends N> ValueContext<N, E> substrate(
-      ObservableMutableDocument<N, E, ?> doc,
+  private static <N, E extends N, T extends N> ValueContext<N, E> substrate(
+      ObservableMutableDocument<N, E, T> doc,
       ListBuilder<String, Integer> values) {
     // Insert container element
     E container = doc.createChildElement(doc.getDocumentElement(), CONTAINER_TAG,
diff --git a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicSetTest.java b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicSetTest.java
index 33fd9b9..ca6cece 100644
--- a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicSetTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicSetTest.java
@@ -121,9 +121,11 @@
    * @param value list of entries to include in the document state
    * @return a map-context view of the document state
    */
-  private static ValueContext<?, ?> substrate(int ... value) {
-    return substrate(BasicFactories.observableDocumentProvider().create("data",
-        Collections.<String, String>emptyMap()), value);
+  @SuppressWarnings("unchecked")
+  private static <N, E extends N>  ValueContext<N, E> substrate(int ... value) {
+    ObservableMutableDocument doc =
+      BasicFactories.observableDocumentProvider().create("data",Collections.<String, String>emptyMap());
+    return substrate(doc, value);
   }
 
   /**
@@ -131,8 +133,8 @@
    *
    * @return a map-context view of the document state.
    */
-  private static <N, E extends N> ValueContext<N, E> substrate(
-      ObservableMutableDocument<N, E, ?> doc,
+  private static <N, E extends N, T extends N> ValueContext<N, E> substrate(
+      ObservableMutableDocument<N, E, T> doc,
       int ... values) {
     // Insert container element
     E container = doc.createChildElement(doc.getDocumentElement(), CONTAINER_TAG,
diff --git a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicValueTest.java b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicValueTest.java
index 61b6b3e..a975c6e 100644
--- a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicValueTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedBasicValueTest.java
@@ -116,9 +116,11 @@
    * @param value list of entries to include in the document state
    * @return a map-context view of the document state
    */
-  private static ValueContext<?, ?> substrate(int value) {
-    return substrate(BasicFactories.observableDocumentProvider().create("data",
-        Collections.<String, String>emptyMap()), value);
+  @SuppressWarnings("unchecked")
+  private static <N, E extends N> ValueContext<N, E>substrate(int value) {
+    ObservableMutableDocument doc =
+      BasicFactories.observableDocumentProvider().create("data",Collections.<String, String>emptyMap());
+    return substrate(doc, value);
   }
 
   /**
diff --git a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicMapTest.java b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicMapTest.java
index ca05075..1f1a15d 100644
--- a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicMapTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicMapTest.java
@@ -187,9 +187,11 @@
    * @param values list of entries to include in the document state
    * @return a map-context view of the document state
    */
-  private static ValueContext<?, ?> substrate(ListBuilder<String, Integer> values) {
-    return substrate(BasicFactories.observableDocumentProvider().create("data",
-        Collections.<String, String>emptyMap()), values);
+  @SuppressWarnings("unchecked")
+  private static <N, E extends N> ValueContext<N, E> substrate(ListBuilder<String, Integer> values) {
+    ObservableMutableDocument doc =
+      BasicFactories.observableDocumentProvider().create("data",Collections.<String, String>emptyMap());
+    return substrate(doc, values);
   }
 
   /**
diff --git a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicValueTest.java b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicValueTest.java
index 304b97d..b3a99fa 100644
--- a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicValueTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedMonotonicValueTest.java
@@ -162,10 +162,12 @@
    * @param values list of entries to include in the document state
    * @return a map-context view of the document state
    */
-  private static ValueContext<?, ?> substrate(Integer ... values) {
-    return substrate(BasicFactories.observableDocumentProvider().create("data",
-        Collections.<String, String>emptyMap()),
-        values);
+  @SuppressWarnings("unchecked")
+  private static <N, E extends N> ValueContext<N, E>  substrate(Integer ... values) {
+    ObservableMutableDocument doc =
+      BasicFactories.observableDocumentProvider().create("data",Collections.<String, String>emptyMap());
+
+    return substrate(doc, values);
   }
 
   /**
diff --git a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedStructuredValueTest.java b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedStructuredValueTest.java
index a5c0008..96fd674 100644
--- a/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedStructuredValueTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/model/adt/docbased/DocumentBasedStructuredValueTest.java
@@ -272,9 +272,11 @@
    *
    * @return a map-context view of the document state
    */
-  private static ValueContext<?, ?> substrate(Map<Key, Integer> values) {
-    return substrate(BasicFactories.observableDocumentProvider().create("tagname",
-        Collections.<String, String>emptyMap()), values);
+  @SuppressWarnings("unchecked")
+  private static <N, E extends N> ValueContext<N, E> substrate(Map<Key, Integer> values) {
+    ObservableMutableDocument doc =
+      BasicFactories.observableDocumentProvider().create("tagname",Collections.<String, String>emptyMap());
+    return substrate(doc, values);
   }
 
   /**
@@ -282,8 +284,8 @@
    *
    * @return a map-context view of the document state.
    */
-  private static <N, E extends N> ValueContext<N, E> substrate(
-      ObservableMutableDocument<N, E, ?> doc, Map<Key, Integer> values) {
+  private static <N, E extends N, T extends N> ValueContext<N, E> substrate(
+      ObservableMutableDocument<N, E, T> doc, Map<Key, Integer> values) {
     // Insert container element.
     E container = doc.createChildElement(doc.getDocumentElement(), CONTAINER_TAG,
         Collections.<String,String>emptyMap());