diff options
author | csharptest <roger@csharptest.net> | 2011-09-09 15:53:10 -0500 |
---|---|---|
committer | rogerk <devnull@localhost> | 2011-09-09 15:53:10 -0500 |
commit | 4a594cac938258c6fc5150a7b99530bed9df483e (patch) | |
tree | 12f285f82937a7651c1edc8b117da4cf6cd5800b /src/ProtoGen | |
parent | 8f0dcf3df1548a1eff0bed54a9b992f55b8f72d5 (diff) | |
download | protobuf-4a594cac938258c6fc5150a7b99530bed9df483e.tar.gz protobuf-4a594cac938258c6fc5150a7b99530bed9df483e.tar.bz2 protobuf-4a594cac938258c6fc5150a7b99530bed9df483e.zip |
Implemented [Obsolete] attribute for deprecated fields
Diffstat (limited to 'src/ProtoGen')
-rw-r--r-- | src/ProtoGen/EnumFieldGenerator.cs | 9 | ||||
-rw-r--r-- | src/ProtoGen/FieldGeneratorBase.cs | 19 | ||||
-rw-r--r-- | src/ProtoGen/MessageFieldGenerator.cs | 8 | ||||
-rw-r--r-- | src/ProtoGen/PrimitiveFieldGenerator.cs | 9 | ||||
-rw-r--r-- | src/ProtoGen/RepeatedEnumFieldGenerator.cs | 10 | ||||
-rw-r--r-- | src/ProtoGen/RepeatedMessageFieldGenerator.cs | 12 | ||||
-rw-r--r-- | src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs | 17 | ||||
-rw-r--r-- | src/ProtoGen/UmbrellaClassGenerator.cs | 4 |
8 files changed, 73 insertions, 15 deletions
diff --git a/src/ProtoGen/EnumFieldGenerator.cs b/src/ProtoGen/EnumFieldGenerator.cs index 8b56b9e9..78384fdd 100644 --- a/src/ProtoGen/EnumFieldGenerator.cs +++ b/src/ProtoGen/EnumFieldGenerator.cs @@ -49,10 +49,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("private bool has{0};", PropertyName);
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue);
+ AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}");
@@ -60,20 +61,22 @@ namespace Google.ProtocolBuffers.ProtoGen public void GenerateBuilderMembers(TextGenerator writer)
{
+ AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
diff --git a/src/ProtoGen/FieldGeneratorBase.cs b/src/ProtoGen/FieldGeneratorBase.cs index 54294196..93aee6ca 100644 --- a/src/ProtoGen/FieldGeneratorBase.cs +++ b/src/ProtoGen/FieldGeneratorBase.cs @@ -251,6 +251,12 @@ namespace Google.ProtocolBuffers.ProtoGen }
}
+ protected void AddPublicMemberAttributes(TextGenerator writer)
+ {
+ AddDeprecatedFlag(writer);
+ AddClsComplianceCheck(writer);
+ }
+
protected void AddClsComplianceCheck(TextGenerator writer)
{
if (!Descriptor.IsCLSCompliant && Descriptor.File.CSharpOptions.ClsCompliance)
@@ -259,6 +265,19 @@ namespace Google.ProtocolBuffers.ProtoGen }
}
+ protected bool IsObsolete { get { return Descriptor.Options.Deprecated; } }
+
+ /// <summary>
+ /// Writes [global::System.ObsoleteAttribute()] if the member is obsolete
+ /// </summary>
+ protected void AddDeprecatedFlag(TextGenerator writer)
+ {
+ if (IsObsolete)
+ {
+ writer.WriteLine("[global::System.ObsoleteAttribute()]");
+ }
+ }
+
/// <summary>
/// For encodings with fixed sizes, returns that size in bytes. Otherwise
/// returns -1. TODO(jonskeet): Make this less ugly.
diff --git a/src/ProtoGen/MessageFieldGenerator.cs b/src/ProtoGen/MessageFieldGenerator.cs index b86f2c9a..8e4bef5b 100644 --- a/src/ProtoGen/MessageFieldGenerator.cs +++ b/src/ProtoGen/MessageFieldGenerator.cs @@ -49,9 +49,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("private bool has{0};", PropertyName);
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue);
+ AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}");
@@ -59,25 +61,30 @@ namespace Google.ProtocolBuffers.ProtoGen public void GenerateBuilderMembers(TextGenerator writer)
{
+ AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue");
writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" if (result.has{0} &&", PropertyName);
@@ -90,6 +97,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
diff --git a/src/ProtoGen/PrimitiveFieldGenerator.cs b/src/ProtoGen/PrimitiveFieldGenerator.cs index e945bf87..0904ce22 100644 --- a/src/ProtoGen/PrimitiveFieldGenerator.cs +++ b/src/ProtoGen/PrimitiveFieldGenerator.cs @@ -50,10 +50,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("private bool has{0};", PropertyName);
writer.WriteLine("private {0} {1}_{2};", TypeName, Name, HasDefaultValue ? " = " + DefaultValue : "");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}");
@@ -61,21 +62,23 @@ namespace Google.ProtocolBuffers.ProtoGen public void GenerateBuilderMembers(TextGenerator writer)
{
+ AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
diff --git a/src/ProtoGen/RepeatedEnumFieldGenerator.cs b/src/ProtoGen/RepeatedEnumFieldGenerator.cs index 5880390b..de3fe5e1 100644 --- a/src/ProtoGen/RepeatedEnumFieldGenerator.cs +++ b/src/ProtoGen/RepeatedEnumFieldGenerator.cs @@ -52,15 +52,18 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("private int {0}MemoizedSerializedSize;", Name);
}
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
+ AddDeprecatedFlag(writer);
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name);
writer.WriteLine("}");
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
+ AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return {0}_[index];", Name);
writer.WriteLine("}");
@@ -70,27 +73,34 @@ namespace Google.ProtocolBuffers.ProtoGen {
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
+ AddDeprecatedFlag(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}_; }}", Name);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;");
diff --git a/src/ProtoGen/RepeatedMessageFieldGenerator.cs b/src/ProtoGen/RepeatedMessageFieldGenerator.cs index bfa0763f..61b6b6b5 100644 --- a/src/ProtoGen/RepeatedMessageFieldGenerator.cs +++ b/src/ProtoGen/RepeatedMessageFieldGenerator.cs @@ -48,15 +48,18 @@ namespace Google.ProtocolBuffers.ProtoGen public void GenerateMembers(TextGenerator writer)
{
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
+ AddDeprecatedFlag(writer);
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}");
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
+ AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return {0}_[index];", Name);
writer.WriteLine("}");
@@ -66,41 +69,50 @@ namespace Google.ProtocolBuffers.ProtoGen {
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
+ AddDeprecatedFlag(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}_; }}", Name);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
// Extra overload for builder (just on messages)
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue");
writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;");
writer.WriteLine("}");
// Extra overload for builder (just on messages)
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue");
writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;");
diff --git a/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs b/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs index 9e7f5f64..d499011c 100644 --- a/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs +++ b/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs @@ -52,17 +52,18 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("private int {0}MemoizedSerializedSize;", Name);
}
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name);
writer.WriteLine("}");
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
+ AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return {0}_[index];", Name);
writer.WriteLine("}");
@@ -72,34 +73,36 @@ namespace Google.ProtocolBuffers.ProtoGen {
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}_; }}", Name);
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;");
writer.WriteLine("}");
- AddClsComplianceCheck(writer);
+ AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
+ AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;");
diff --git a/src/ProtoGen/UmbrellaClassGenerator.cs b/src/ProtoGen/UmbrellaClassGenerator.cs index 57a7844b..e4250458 100644 --- a/src/ProtoGen/UmbrellaClassGenerator.cs +++ b/src/ProtoGen/UmbrellaClassGenerator.cs @@ -138,8 +138,8 @@ namespace Google.ProtocolBuffers.ProtoGen private void WriteIntroduction(TextGenerator writer) { - writer.WriteLine("// Generated by {0}. DO NOT EDIT!", this.GetType().Assembly.FullName); - writer.WriteLine("#pragma warning disable 1591"); + writer.WriteLine("// Generated by {0}. DO NOT EDIT!", this.GetType().Assembly.FullName);
+ writer.WriteLine("#pragma warning disable 1591, 0612"); writer.WriteLine("#region Designer generated code"); writer.WriteLine(); |