Use real generic syntax instead of comment-based. (#75)
Also, update pubspec to support v2 dev SDKs.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 115fc77..ff768bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 0.5.5
+
+* Use real generic syntax instead of comment-based.
+* Support v2 dev SDKs.
+
## 0.5.4
* Unknown enum values are ignored when parsing JSON, instead of throwing an
diff --git a/lib/src/protobuf/builder_info.dart b/lib/src/protobuf/builder_info.dart
index 8040e0a..f04eee0 100644
--- a/lib/src/protobuf/builder_info.dart
+++ b/lib/src/protobuf/builder_info.dart
@@ -4,9 +4,7 @@
part of protobuf;
-/**
- * Per-message type setup.
- */
+/// Per-message type setup.
class BuilderInfo {
final String messageName;
final Map<int, FieldInfo> fieldInfo = new Map<int, FieldInfo>();
@@ -18,22 +16,17 @@
BuilderInfo(this.messageName);
- void add/*<T>*/(
- int tagNumber,
- String name,
- int fieldType,
- dynamic defaultOrMaker,
- CreateBuilderFunc subBuilder,
- ValueOfFunc valueOf) {
+ void add<T>(int tagNumber, String name, int fieldType, dynamic defaultOrMaker,
+ CreateBuilderFunc subBuilder, ValueOfFunc valueOf) {
var index = fieldInfo.length;
- addField(new FieldInfo/*<T>*/(name, tagNumber, index, fieldType,
- defaultOrMaker, subBuilder, valueOf));
+ addField(new FieldInfo<T>(name, tagNumber, index, fieldType, defaultOrMaker,
+ subBuilder, valueOf));
}
- void addRepeated/*<T>*/(int tagNumber, String name, int fieldType,
+ void addRepeated<T>(int tagNumber, String name, int fieldType,
CheckFunc check, CreateBuilderFunc subBuilder, ValueOfFunc valueOf) {
var index = fieldInfo.length;
- addField(new FieldInfo/*<T>*/ .repeated(
+ addField(new FieldInfo<T>.repeated(
name, tagNumber, index, fieldType, check, subBuilder, valueOf));
}
@@ -43,39 +36,39 @@
byName[fi.name] = fi;
}
- void a/*<T>*/(int tagNumber, String name, int fieldType,
+ void a<T>(int tagNumber, String name, int fieldType,
[dynamic defaultOrMaker,
CreateBuilderFunc subBuilder,
ValueOfFunc valueOf]) {
- add/*<T>*/(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf);
+ add<T>(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf);
}
// Enum.
- void e/*<T>*/(int tagNumber, String name, int fieldType,
- dynamic defaultOrMaker, ValueOfFunc valueOf) {
- add/*<T>*/(tagNumber, name, fieldType, defaultOrMaker, null, valueOf);
+ void e<T>(int tagNumber, String name, int fieldType, dynamic defaultOrMaker,
+ ValueOfFunc valueOf) {
+ add<T>(tagNumber, name, fieldType, defaultOrMaker, null, valueOf);
}
// Repeated message.
// TODO(skybrian): migrate to pp() and remove.
- void m/*<T>*/(int tagNumber, String name, CreateBuilderFunc subBuilder,
+ void m<T>(int tagNumber, String name, CreateBuilderFunc subBuilder,
MakeDefaultFunc makeDefault) {
- add/*<T>*/(tagNumber, name, PbFieldType._REPEATED_MESSAGE, makeDefault,
+ add<T>(tagNumber, name, PbFieldType._REPEATED_MESSAGE, makeDefault,
subBuilder, null);
}
// Repeated, not a message, group, or enum.
- void p/*<T>*/(int tagNumber, String name, int fieldType) {
+ void p<T>(int tagNumber, String name, int fieldType) {
assert(!_isGroupOrMessage(fieldType) && !_isEnum(fieldType));
- addRepeated/*<T>*/(
+ addRepeated<T>(
tagNumber, name, fieldType, getCheckFunction(fieldType), null, null);
}
// Repeated message, group, or enum.
- void pp/*<T>*/(int tagNumber, String name, int fieldType, CheckFunc check,
+ void pp<T>(int tagNumber, String name, int fieldType, CheckFunc check,
[CreateBuilderFunc subBuilder, ValueOfFunc valueOf]) {
assert(_isGroupOrMessage(fieldType) || _isEnum(fieldType));
- addRepeated/*<T>*/(tagNumber, name, fieldType, check, subBuilder, valueOf);
+ addRepeated<T>(tagNumber, name, fieldType, check, subBuilder, valueOf);
}
bool containsTagNumber(int tagNumber) => fieldInfo.containsKey(tagNumber);
diff --git a/lib/src/protobuf/extension.dart b/lib/src/protobuf/extension.dart
index cfed0a4..0348a87 100644
--- a/lib/src/protobuf/extension.dart
+++ b/lib/src/protobuf/extension.dart
@@ -4,9 +4,7 @@
part of protobuf;
-/**
- * An object representing an extension field.
- */
+/// An object representing an extension field.
class Extension<T> extends FieldInfo<T> {
final String extendee;
diff --git a/lib/src/protobuf/extension_field_set.dart b/lib/src/protobuf/extension_field_set.dart
index 8778262..b96e1df 100644
--- a/lib/src/protobuf/extension_field_set.dart
+++ b/lib/src/protobuf/extension_field_set.dart
@@ -38,12 +38,12 @@
///
/// If it doesn't exist, creates the list and saves the extension.
/// Suitable for public API and decoders.
- List/*<T>*/ _ensureRepeatedField/*<T>*/(Extension/*<T>*/ fi) {
+ List<T> _ensureRepeatedField<T>(Extension<T> fi) {
assert(fi.isRepeated);
assert(fi.extendee == _parent._messageName);
var list = _values[fi.tagNumber];
- if (list != null) return list as List/*<T>*/;
+ if (list != null) return list as List<T>;
// Add info and create list.
_validateInfo(fi);
diff --git a/lib/src/protobuf/extension_registry.dart b/lib/src/protobuf/extension_registry.dart
index d94225a..667052d 100644
--- a/lib/src/protobuf/extension_registry.dart
+++ b/lib/src/protobuf/extension_registry.dart
@@ -4,29 +4,23 @@
part of protobuf;
-/**
- * A collection of [Extension] objects, organized by the message type they
- * extend.
- */
+/// A collection of [Extension] objects, organized by the message type they
+/// extend.
class ExtensionRegistry {
final Map<String, Map<int, Extension>> _extensions =
<String, Map<int, Extension>>{};
static const ExtensionRegistry EMPTY = const _EmptyExtensionRegistry();
- /**
- * Store an extension in the registry.
- */
+ /// Stores an [extension] in the registry.
void add(Extension extension) {
var map = _extensions.putIfAbsent(
extension.extendee, () => new Map<int, Extension>());
map[extension.tagNumber] = extension;
}
- /**
- * Retrieve an extension from the registry that adds the given tag
- * number to the given message type.
- */
+ /// Retrieves an extension from the registry that adds tag number [tagNumber]
+ /// to the [messageName] message type.
Extension getExtension(String messageName, int tagNumber) {
var map = _extensions[messageName];
if (map != null) {
@@ -39,7 +33,7 @@
class _EmptyExtensionRegistry implements ExtensionRegistry {
const _EmptyExtensionRegistry();
- // needed to quite missing member warning
+ // Needed to quiet missing member warning.
get _extensions => null;
void add(Extension extension) {
diff --git a/lib/src/protobuf/field_info.dart b/lib/src/protobuf/field_info.dart
index 0c176eb..8e8d08a 100644
--- a/lib/src/protobuf/field_info.dart
+++ b/lib/src/protobuf/field_info.dart
@@ -4,9 +4,7 @@
part of protobuf;
-/**
- * An object representing a protobuf message field.
- */
+/// An object representing a protobuf message field.
class FieldInfo<T> {
final String name;
final int tagNumber;
@@ -127,7 +125,7 @@
/// be overridden by a mixin.
List<T> _createRepeatedField(GeneratedMessage m) {
assert(isRepeated);
- return m.createRepeatedField/*<T>*/(tagNumber, this);
+ return m.createRepeatedField<T>(tagNumber, this);
}
String toString() => name;
diff --git a/lib/src/protobuf/field_set.dart b/lib/src/protobuf/field_set.dart
index 1a45f9e..15e6a25 100644
--- a/lib/src/protobuf/field_set.dart
+++ b/lib/src/protobuf/field_set.dart
@@ -210,14 +210,14 @@
/// Creates and stores the repeated field if it doesn't exist.
/// If it's an extension and the list doesn't exist, validates and stores it.
/// Suitable for decoders.
- List/*<T>*/ _ensureRepeatedField/*<T>*/(FieldInfo/*<T>*/ fi) {
+ List<T> _ensureRepeatedField<T>(FieldInfo<T> fi) {
assert(!_isReadOnly);
assert(fi.isRepeated);
if (fi.index == null) {
return _ensureExtensions()._ensureRepeatedField(fi);
}
var value = _getFieldOrNull(fi);
- if (value != null) return value as List/*<T>*/;
+ if (value != null) return value as List<T>;
var newValue = fi._createRepeatedField(_message);
_setNonExtensionFieldUnchecked(fi, newValue);
@@ -235,12 +235,12 @@
// Generated method implementations
/// The implementation of a generated getter.
- /*=T*/ _$get/*<T>*/(int index, int tagNumber, /*=T*/ defaultValue) {
+ T _$get<T>(int index, int tagNumber, T defaultValue) {
assert(_nonExtensionInfo(tagNumber).index == index);
var value = _values[index];
- if (value != null) return value as dynamic/*=T*/;
+ if (value != null) return value as T;
if (defaultValue != null) return defaultValue;
- return _getDefault(_nonExtensionInfo(tagNumber)) as dynamic/*=T*/;
+ return _getDefault(_nonExtensionInfo(tagNumber)) as T;
}
/// The implementation of a generated has method.
diff --git a/lib/src/protobuf/generated_message.dart b/lib/src/protobuf/generated_message.dart
index e29bf28..e4657e5 100644
--- a/lib/src/protobuf/generated_message.dart
+++ b/lib/src/protobuf/generated_message.dart
@@ -221,8 +221,8 @@
/// that the protobuf can be encoded correctly, the returned List must
/// validate all items added to it. This can most easily be done
/// using the FieldInfo.check function.
- List/*<T>*/ createRepeatedField/*<T>*/(int tagNumber, FieldInfo/*<T>*/ fi) {
- return new PbList/*<T>*/(check: fi.check);
+ List<T> createRepeatedField<T>(int tagNumber, FieldInfo<T> fi) {
+ return new PbList<T>(check: fi.check);
}
/// Returns the value of a field, ignoring any defaults.
@@ -279,8 +279,8 @@
void setField(int tagNumber, value) => _fieldSet._setField(tagNumber, value);
/// For generated code only.
- /*=T*/ $_get/*<T>*/(int index, int tagNumber, /*=T*/ defaultValue) =>
- _fieldSet._$get/*<T>*/(index, tagNumber, defaultValue);
+ T $_get<T>(int index, int tagNumber, T defaultValue) =>
+ _fieldSet._$get<T>(index, tagNumber, defaultValue);
/// For generated code only.
bool $_has(int index, int tagNumber) => _fieldSet._$has(index, tagNumber);
diff --git a/lib/src/protobuf/pb_list.dart b/lib/src/protobuf/pb_list.dart
index b82b363..b4c8a9c 100644
--- a/lib/src/protobuf/pb_list.dart
+++ b/lib/src/protobuf/pb_list.dart
@@ -37,46 +37,34 @@
return hash;
}
- /**
- * Returns an [Iterator] for the list.
- */
+ /// Returns an [Iterator] for the list.
Iterator<E> get iterator => _wrappedList.iterator;
- /**
- * Returns a new lazy [Iterable] with elements that are created by calling `f`
- * on each element of this `PbList` in iteration order.
- */
- Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => _wrappedList.map/*<T>*/(f);
+ /// Returns a new lazy [Iterable] with elements that are created by calling
+ /// `f` on each element of this `PbList` in iteration order.
+ Iterable<T> map<T>(T f(E e)) => _wrappedList.map<T>(f);
- /**
- * Applies the function [f] to each element of this list in iteration order.
- */
+ /// Applies the function [f] to each element of this list in iteration order.
void forEach(void f(E element)) {
_wrappedList.forEach(f);
}
- /**
- * Returns the element at the given [index] in the list or throws
- * an [IndexOutOfRangeException] if [index] is out of bounds.
- */
+ /// Returns the element at the given [index] in the list or throws an
+ /// [IndexOutOfRangeException] if [index] is out of bounds.
E operator [](int index) => _wrappedList[index];
- /**
- * Sets the entry at the given [index] in the list to [value].
- * Throws an [IndexOutOfRangeException] if [index] is out of bounds.
- */
+ /// Sets the entry at the given [index] in the list to [value].
+ /// Throws an [IndexOutOfRangeException] if [index] is out of bounds.
void operator []=(int index, E value) {
_validate(value);
_wrappedList[index] = value;
}
- /**
- * Unsupported -- violated non-null constraint imposed by protobufs.
- *
- * Changes the length of the list. If [newLength] is greater than
- * the current [length], entries are initialized to [:null:]. Throws
- * an [UnsupportedError] if the list is not extendable.
- */
+ /// Unsupported -- violated non-null constraint imposed by protobufs.
+ ///
+ /// Changes the length of the list. If [newLength] is greater than the current
+ /// [length], entries are initialized to [:null:]. Throws an
+ /// [UnsupportedError] if the list is not extendable.
void set length(int newLength) {
if (newLength > length) {
throw new ArgumentError('Extending protobuf lists is not supported');
@@ -84,33 +72,24 @@
_wrappedList.length = newLength;
}
- /**
- * Adds [value] at the end of the list, extending the length by
- * one. Throws an [UnsupportedError] if the list is not
- * extendable.
- */
+ /// Adds [value] at the end of the list, extending the length by one.
+ /// Throws an [UnsupportedError] if the list is not extendable.
void add(E value) {
_validate(value);
_wrappedList.add(value);
}
- /**
- * Appends all elements of the [collection] to the end of list.
- * Extends the length of the list by the length of [collection].
- * Throws an [UnsupportedError] if the list is not
- * extendable.
- */
+ /// Appends all elements of the [collection] to the end of list.
+ /// Extends the length of the list by the length of [collection].
+ /// Throws an [UnsupportedError] if the list is not extendable.
void addAll(Iterable<E> collection) {
collection.forEach(_validate);
_wrappedList.addAll(collection);
}
- /**
- * Copies [:end - start:] elements of the [from] array, starting
- * from [skipCount], into [:this:], starting at [start].
- * Throws an [UnsupportedError] if the list is
- * not extendable.
- */
+ /// Copies [:end - start:] elements of the [from] array, starting from
+ /// [skipCount], into [:this:], starting at [start].
+ /// Throws an [UnsupportedError] if the list is not extendable.
void setRange(int start, int end, Iterable<E> from, [int skipCount = 0]) {
// NOTE: In case `take()` returns less than `end - start` elements, the
// _wrappedList will fail with a `StateError`.
@@ -118,39 +97,31 @@
_wrappedList.setRange(start, end, from, skipCount);
}
- /**
- * Inserts a new element in the list.
- * The element must be valid (and not nullable) for the PbList type.
- */
+ /// Inserts a new element in the list.
+ /// The element must be valid (and not nullable) for the PbList type.
void insert(int index, E element) {
_validate(element);
_wrappedList.insert(index, element);
}
- /**
- * Inserts all elements of [iterable] at position [index] in the list.
- *
- * Elements in [iterable] must be valid and not nullable for the PbList type.
- */
+ /// Inserts all elements of [iterable] at position [index] in the list.
+ ///
+ /// Elements in [iterable] must be valid and not nullable for the PbList type.
void insertAll(int index, Iterable<E> iterable) {
iterable.forEach(_validate);
_wrappedList.insertAll(index, iterable);
}
- /**
- * Overwrites elements of `this` with elements of [iterable] starting at
- * position [index] in the list.
- *
- * Elements in [iterable] must be valid and not nullable for the PbList type.
- */
+ /// Overwrites elements of `this` with elements of [iterable] starting at
+ /// position [index] in the list.
+ ///
+ /// Elements in [iterable] must be valid and not nullable for the PbList type.
void setAll(int index, Iterable<E> iterable) {
iterable.forEach(_validate);
_wrappedList.setAll(index, iterable);
}
- /**
- * Returns the number of elements in this collection.
- */
+ /// Returns the number of elements in this collection.
int get length => _wrappedList.length;
void _validate(E val) {
diff --git a/lib/src/protobuf/readonly_message.dart b/lib/src/protobuf/readonly_message.dart
index 57cf769..b8f03e0 100644
--- a/lib/src/protobuf/readonly_message.dart
+++ b/lib/src/protobuf/readonly_message.dart
@@ -17,7 +17,7 @@
void clearField(int tagNumber) => _readonly("clearField");
- List/*<T>*/ createRepeatedField/*<T>*/(int tagNumber, FieldInfo/*<T>*/ fi) {
+ List<T> createRepeatedField<T>(int tagNumber, FieldInfo<T> fi) {
_readonly("createRepeatedField");
return null; // not reached
}
diff --git a/lib/src/protobuf/utils.dart b/lib/src/protobuf/utils.dart
index a9993e3..fb6ee44 100644
--- a/lib/src/protobuf/utils.dart
+++ b/lib/src/protobuf/utils.dart
@@ -35,4 +35,4 @@
return _areListsEqual(asBytes(lhs), asBytes(rhs));
}
-List/*<T>*/ sorted/*<T>*/(Iterable/*<T>*/ list) => new List.from(list)..sort();
+List<T> sorted<T>(Iterable<T> list) => new List.from(list)..sort();
diff --git a/pubspec.yaml b/pubspec.yaml
index 458317b..48ae1b4 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,10 +1,10 @@
name: protobuf
-version: 0.5.4
+version: 0.5.5
author: Dart Team <misc@dartlang.org>
description: Runtime library for protocol buffers support.
homepage: https://github.com/dart-lang/protobuf
environment:
- sdk: '>=1.13.0 <2.0.0'
+ sdk: '>=1.21.0 <2.0.0-dev.infinity'
dependencies:
fixnum: '>=0.9.0 <0.11.0'
dev_dependencies:
diff --git a/test/coded_buffer_reader_test.dart b/test/coded_buffer_reader_test.dart
index 7a30bee..3e46cec 100755
--- a/test/coded_buffer_reader_test.dart
+++ b/test/coded_buffer_reader_test.dart
@@ -122,11 +122,9 @@
}, throwsInvalidProtocolBufferException);
});
- /**
- * Tests that if we read a string that contains invalid UTF-8, no exception
- * is thrown. Instead, the invalid bytes are replaced with the Unicode
- * 'replacement character' U+FFFD.
- */
+ /// Tests that if we read a string that contains invalid UTF-8, no exception
+ /// is thrown. Instead, the invalid bytes are replaced with the Unicode
+ /// 'replacement character' U+FFFD.
test('testReadInvalidUtf8', () {
CodedBufferReader input = new CodedBufferReader([1, 0x80]);
String text = input.readString();