summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Davidson <jpd@google.com>2015-04-06 17:08:27 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-06 17:08:27 +0000
commit001035d84dec844eac16037ac512ad9d35023ac9 (patch)
treec69326ca86ecb487a6b6ee1b7335f04accdbd42d
parentbd87b5ee4a3a8715784a6e12e97c898eff303e68 (diff)
parenteff5d5b33b3ef8b655ce43e9f64578a8c8e4e482 (diff)
downloadexternal_protobuf-001035d84dec844eac16037ac512ad9d35023ac9.zip
external_protobuf-001035d84dec844eac16037ac512ad9d35023ac9.tar.gz
external_protobuf-001035d84dec844eac16037ac512ad9d35023ac9.tar.bz2
am eff5d5b3: am 1d4b8b9f: am ff882b40: Merge "Generate a CREATOR for each Parcelable message."
* commit 'eff5d5b33b3ef8b655ce43e9f64578a8c8e4e482': Generate a CREATOR for each Parcelable message.
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java17
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java17
-rw-r--r--java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNanoCreator.java (renamed from java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java)25
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc11
4 files changed, 34 insertions, 36 deletions
diff --git a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java
index f3b82ed..739ff18 100644
--- a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableExtendableMessageNano.java
@@ -42,21 +42,6 @@ import com.google.protobuf.nano.ExtendableMessageNano;
public abstract class ParcelableExtendableMessageNano<M extends ExtendableMessageNano<M>>
extends ExtendableMessageNano<M> implements Parcelable {
- // Used by Parcelable
- @SuppressWarnings({"unused"})
- public static final Creator<ParcelableExtendableMessageNano<?>> CREATOR =
- new Creator<ParcelableExtendableMessageNano<?>>() {
- @Override
- public ParcelableExtendableMessageNano<?> createFromParcel(Parcel in) {
- return ParcelingUtil.createFromParcel(in);
- }
-
- @Override
- public ParcelableExtendableMessageNano<?>[] newArray(int size) {
- return new ParcelableExtendableMessageNano<?>[size];
- }
- };
-
@Override
public int describeContents() {
return 0;
@@ -64,6 +49,6 @@ public abstract class ParcelableExtendableMessageNano<M extends ExtendableMessag
@Override
public void writeToParcel(Parcel out, int flags) {
- ParcelingUtil.writeToParcel(getClass(), this, out);
+ ParcelableMessageNanoCreator.writeToParcel(getClass(), this, out);
}
}
diff --git a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java
index b07f1d6..83f973d 100644
--- a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNano.java
@@ -40,21 +40,6 @@ import com.google.protobuf.nano.MessageNano;
*/
public abstract class ParcelableMessageNano extends MessageNano implements Parcelable {
- // Used by Parcelable
- @SuppressWarnings("unused")
- public static final Creator<ParcelableMessageNano> CREATOR =
- new Creator<ParcelableMessageNano>() {
- @Override
- public ParcelableMessageNano createFromParcel(Parcel in) {
- return ParcelingUtil.createFromParcel(in);
- }
-
- @Override
- public ParcelableMessageNano[] newArray(int size) {
- return new ParcelableMessageNano[size];
- }
- };
-
@Override
public int describeContents() {
return 0;
@@ -62,6 +47,6 @@ public abstract class ParcelableMessageNano extends MessageNano implements Parce
@Override
public void writeToParcel(Parcel out, int flags) {
- ParcelingUtil.writeToParcel(getClass(), this, out);
+ ParcelableMessageNanoCreator.writeToParcel(getClass(), this, out);
}
}
diff --git a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNanoCreator.java
index 1eb84ee..5a4b70c 100644
--- a/java/src/device/main/java/com/google/protobuf/nano/android/ParcelingUtil.java
+++ b/java/src/device/main/java/com/google/protobuf/nano/android/ParcelableMessageNanoCreator.java
@@ -1,5 +1,5 @@
// Protocol Buffers - Google's data interchange format
-// Copyright 2014 Google Inc. All rights reserved.
+// Copyright 2015 Google Inc. All rights reserved.
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
@@ -31,16 +31,27 @@
package com.google.protobuf.nano.android;
import android.os.Parcel;
+import android.os.Parcelable;
import android.util.Log;
import com.google.protobuf.nano.InvalidProtocolBufferNanoException;
import com.google.protobuf.nano.MessageNano;
-final class ParcelingUtil {
- private static final String TAG = "ParcelingUtil";
+import java.lang.reflect.Array;
+
+public final class ParcelableMessageNanoCreator<T extends MessageNano>
+ implements Parcelable.Creator<T> {
+ private static final String TAG = "PMNCreator";
+
+ private final Class<T> mClazz;
+
+ public ParcelableMessageNanoCreator(Class<T> clazz) {
+ mClazz = clazz;
+ }
@SuppressWarnings("unchecked")
- static <T extends MessageNano> T createFromParcel(Parcel in) {
+ @Override
+ public T createFromParcel(Parcel in) {
String className = in.readString();
byte[] data = in.createByteArray();
@@ -64,6 +75,12 @@ final class ParcelingUtil {
return proto;
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public T[] newArray(int i) {
+ return (T[]) Array.newInstance(mClazz, i);
+ }
+
static <T extends MessageNano> void writeToParcel(Class<T> clazz, MessageNano message,
Parcel out) {
out.writeString(clazz.getName());
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc
index dcfb870..dd6ef91 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -154,6 +154,17 @@ void MessageGenerator::Generate(io::Printer* printer) {
}
printer->Indent();
+ if (params_.parcelable_messages()) {
+ printer->Print(
+ "\n"
+ "// Used by Parcelable\n"
+ "@SuppressWarnings({\"unused\"})\n"
+ "public static final android.os.Parcelable.Creator<$classname$> CREATOR =\n"
+ " new com.google.protobuf.nano.android.ParcelableMessageNanoCreator<\n"
+ " $classname$>($classname$.class);\n",
+ "classname", descriptor_->name());
+ }
+
// Nested types and extensions
for (int i = 0; i < descriptor_->extension_count(); i++) {
ExtensionGenerator(descriptor_->extension(i), params_).Generate(printer);