OLD | NEW |
| (Empty) |
1 /* | |
2 Copyright 2010 Google Inc | |
3 | |
4 Licensed under the Apache License, Version 2.0 (the "License"); | |
5 you may not use this file except in compliance with the License. | |
6 You may obtain a copy of the License at | |
7 | |
8 http://www.apache.org/licenses/LICENSE-2.0 | |
9 | |
10 Unless required by applicable law or agreed to in writing, software | |
11 distributed under the License is distributed on an "AS IS" BASIS, | |
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 See the License for the specific language governing permissions and | |
14 limitations under the License. | |
15 */ | |
16 | |
17 using System.CodeDom; | |
18 using System.Collections.Generic; | |
19 using Google.Apis.Discovery.Schema; | |
20 using Google.Apis.Logging; | |
21 using Google.Apis.Testing; | |
22 using Google.Apis.Tools.CodeGen.Generator; | |
23 using Google.Apis.Util; | |
24 using Newtonsoft.Json.Schema; | |
25 | |
26 namespace Google.Apis.Tools.CodeGen.Decorator.SchemaDecorator | |
27 { | |
28 /// <summary> | |
29 /// Decorator which adds comments to schemas | |
30 /// </summary> | |
31 public class StandardSchemaCommentDecorator : ISchemaDecorator, INestedClass
SchemaDecorator, IPropertyDecorator | |
32 { | |
33 private static readonly ILogger logger = ApplicationContext.Logger.ForTy
pe<StandardSchemaCommentDecorator>(); | |
34 | |
35 #region INestedClassSchemaDecorator Members | |
36 | |
37 public void DecorateInternalClass(CodeTypeDeclaration typeDeclaration, | |
38 string name, | |
39 JsonSchema schema, | |
40 IDictionary<JsonSchema, SchemaImplemen
tationDetails> implDetails, | |
41 INestedClassProvider internalClassProv
ider) | |
42 { | |
43 typeDeclaration.ThrowIfNull("typeDeclaration"); | |
44 schema.ThrowIfNull("schema"); | |
45 implDetails.ThrowIfNull("details"); | |
46 internalClassProvider.ThrowIfNull("internalClassProvider"); | |
47 | |
48 typeDeclaration.Comments.AddRange(CreateComment(schema)); | |
49 } | |
50 | |
51 #endregion | |
52 | |
53 #region ISchemaDecorator Members | |
54 | |
55 public void DecorateClass(CodeTypeDeclaration typeDeclaration, | |
56 ISchema schema, | |
57 IDictionary<JsonSchema, SchemaImplementationDe
tails> implDetails, | |
58 INestedClassProvider internalClassProvider) | |
59 { | |
60 typeDeclaration.ThrowIfNull("typeDeclaration"); | |
61 schema.ThrowIfNull("schema"); | |
62 implDetails.ThrowIfNull("implDetails"); | |
63 internalClassProvider.ThrowIfNull("internalClassProvider"); | |
64 schema.SchemaDetails.ThrowIfNull("schema.SchemaDetails"); | |
65 | |
66 typeDeclaration.Comments.AddRange(CreateComment(schema.SchemaDetails
)); | |
67 } | |
68 | |
69 #endregion | |
70 | |
71 #region IPropertyDecorator Members | |
72 | |
73 public void DecorateProperty(CodeMemberProperty propertyDefinition, KeyV
aluePair<string, JsonSchema> propertyPair) | |
74 { | |
75 propertyDefinition.ThrowIfNull("propertyDefinition"); | |
76 propertyPair.ThrowIfNull("propertyPair"); | |
77 | |
78 propertyDefinition.Comments.AddRange(CreateComment(propertyPair.Valu
e)); | |
79 } | |
80 | |
81 #endregion | |
82 | |
83 [VisibleForTestOnly] | |
84 internal CodeCommentStatementCollection CreateComment(JsonSchema schema) | |
85 { | |
86 schema.ThrowIfNull("schema"); | |
87 | |
88 return DecoratorUtil.CreateSummaryComment(schema.Description); | |
89 } | |
90 } | |
91 } | |
OLD | NEW |