talk 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47ce5983a7162f33cd2b2ede78b20d5e2a456047
4
- data.tar.gz: afe02ff186a9e44749bc746147521b7af2537205
3
+ metadata.gz: f1f1b965faec105c8139b2c31c25093ad3f7a07d
4
+ data.tar.gz: 65ad8dfa35eca34ccf71e9348760e42fb68cd639
5
5
  SHA512:
6
- metadata.gz: bc2872575d0307819fa67a7ad2cb498a09ed87c5fa199d2c33f2cc49a42a2f7f6a9879f83f4c4057e5a5eb5292897cd682cf833c2a3b6892a756e5be9407484e
7
- data.tar.gz: 76ad99b4fdbc1efe914eb12ac0ecc8bc1a1586656181ec1396d75ad0982d5191e2adf6ee67bdfcc5a1553f1f7c8b187a07edcaa01db79257584aa185e0b8dea1
6
+ metadata.gz: 09583344d986efe5ff4d06b71c54dabcbee808d27586dd623a79d5c1451ce3e4f4e967a7096286fdbc7f9df77fe47e6e718359b402509b11cadf7191a5df8831
7
+ data.tar.gz: e4501266f0041de42d2c9b4556a04a98645318b850b68d2c9cc031413d5f4fb0bc838ad1a749430d86c006c8bdafa387c81055fa1564c37dcdc273f48449ab1b
@@ -9,6 +9,10 @@ def make_source
9
9
  generate_template(filename_for_entity(@current), type.to_s+".java.erb")
10
10
  end
11
11
  end
12
+ @base[:protocol].each do |current|
13
+ @current = current
14
+ generate_template("com/acres4/common/protocol/#{current[:name]}.java", "TalkProtocol.java.erb")
15
+ end
12
16
  end
13
17
 
14
18
  def filename_for_entity(name)
@@ -43,13 +47,31 @@ def list_references_for_class(cls)
43
47
  references = Set.new
44
48
  cls[:field].each do |field|
45
49
  unless is_primitive?(field[:type].first) then
46
- references.add(field[:type])
50
+ references.add(class_named(field[:type][0], @base[:class])[:name])
47
51
  end
48
52
  end
49
53
 
54
+ references.add("java.math.BigDecimal") if class_has_bigdec(cls)
55
+ references.add("java.util.Map") if class_has_map(cls)
50
56
  references.to_a
51
57
  end
52
58
 
59
+ def class_has_bigdec(cls)
60
+ cls[:field].each do |f|
61
+ return true if f[:type][0] == "uint64"
62
+ end
63
+
64
+ false
65
+ end
66
+
67
+ def class_has_map(cls)
68
+ cls[:field].each do |f|
69
+ return true if f[:type].include? "{}"
70
+ end
71
+
72
+ false
73
+ end
74
+
53
75
  def import_classes
54
76
  (list_references_for_class(@current).map { |name| "import #{name};"}).join("\n")
55
77
  end
@@ -57,7 +79,7 @@ end
57
79
  def comment_block(tag, indent_level=0)
58
80
  lines = []
59
81
  indent = "\t" * indent_level
60
- lines.push(indent + "/*!")
82
+ lines.push(indent + "/**")
61
83
  lines.push(wrap_text_to_width(tag[:description], 80, indent + " * ")) unless tag[:description].nil?
62
84
  lines.push(indent + " * ")
63
85
  lines.push(indent + " * " + definition_reference(tag))
@@ -80,14 +102,31 @@ def field_datatype_rec(field, stack)
80
102
 
81
103
  r = field_datatype_rec(field, stack[0 .. -2])
82
104
  if is_array? t then
83
- "[]"
105
+ "#{r}[]"
84
106
  elsif is_dict? t then
85
- "Map<String, #{r}>"
107
+ "Map<String, #{convert_field_for_map(r)}>"
86
108
  else
87
109
  nil
88
110
  end
89
111
  end
90
112
 
113
+ def convert_field_for_map(field)
114
+ case field
115
+ when "byte"
116
+ "Byte"
117
+ when "short"
118
+ "Short"
119
+ when "int"
120
+ "Integer"
121
+ when "long"
122
+ "Long"
123
+ when "double"
124
+ "Double"
125
+ else
126
+ field
127
+ end
128
+ end
129
+
91
130
  def field_datatype_basic(field, type)
92
131
  if is_primitive? type then
93
132
  case type
@@ -100,22 +139,23 @@ def field_datatype_basic(field, type)
100
139
  when "object"
101
140
  "Object"
102
141
  when "talkobject"
103
- "TalkObject"
104
- else
105
- size = integer_size(type)
106
- size *= 2 if is_unsigned? type # java has no unsigned type; just use the next size up
107
- case
108
- when 8
109
- "byte"
110
- when 16
111
- "short"
112
- when 32
113
- "int"
114
- when 64
115
- "long"
116
- when 128
117
- "BigDecimal"
118
- end
142
+ rootclass
143
+ when "int8"
144
+ "byte"
145
+ when "uint8"
146
+ "short"
147
+ when "int16"
148
+ "short"
149
+ when "uint16"
150
+ "int"
151
+ when "int32"
152
+ "int"
153
+ when "uint32"
154
+ "long"
155
+ when "int64"
156
+ "long"
157
+ when "uint64"
158
+ "BigDecimal"
119
159
  end
120
160
  else
121
161
  truncated_name type
@@ -133,13 +173,33 @@ def field_variable(field)
133
173
  lines.join("\n")
134
174
  end
135
175
 
176
+ def setter_name(field)
177
+ "set#{field[:name].sub(/^(\w)/) {|s| s.capitalize}}"
178
+ end
179
+
180
+ def getter_name(field)
181
+ "get#{field[:name].sub(/^(\w)/) {|s| s.capitalize}}"
182
+ end
183
+
136
184
  def field_accessors(field)
137
- lines.push wrap_text(field[:description], " * ", 1)
138
- lines.push field[:deprecated] if field.has_key? :deprecated
139
- lines.push definition_reference(field)
140
- lines.push " * @param #{field[:name]} #{field[:description]}"
185
+ lines = []
186
+ lines.push "\t/**"
187
+ lines.push "\t#{wrap_text_to_width(field[:description])}"
188
+ lines.push "\t#{field[:deprecated] if field.has_key? :deprecated}"
189
+ lines.push "\t#{definition_reference(field)}"
190
+ lines.push "\t@param #{field[:name]} #{field[:description]}"
191
+ lines.push "\t*/"
141
192
  lines.push "\tpublic void #{setter_name(field)}(#{field_datatype(field)} #{field[:name]}) {"
142
- lines.push "\t\tthis.#{field[:name]} = #{field[:name]}"
193
+ lines.push "\t\tthis.#{field[:name]} = #{field[:name]};"
194
+ lines.push "\t}"
195
+ lines.push "\t/**"
196
+ lines.push "\t#{wrap_text_to_width(field[:description])}"
197
+ lines.push "\t#{field[:deprecated] if field.has_key? :deprecated}"
198
+ lines.push "\t#{definition_reference(field)}"
199
+ lines.push "\t@return #{field[:name]} #{field[:description]}"
200
+ lines.push "\t*/"
201
+ lines.push "\tpublic #{field_datatype(field)} #{getter_name(field)}() {"
202
+ lines.push "\t\treturn this.#{field[:name]};"
143
203
  lines.push "\t}"
144
204
  lines.join "\n"
145
205
  end
@@ -0,0 +1,10 @@
1
+ <%= autogenerated_warning %>
2
+ package com.acres4.common.protocol;
3
+ public class <%= truncated_name(@current[:name]) %> {
4
+ <% @current[:method].each do |method| %>
5
+ /**
6
+ <%= method[:description] %>
7
+ */
8
+ public static final String <%= method[:name].sub(/^(\w)/) {|s| s.capitalize} %> = "<%= method[:name] %>";
9
+ <% end %>
10
+ }
@@ -5,17 +5,16 @@ package <%= class_package(@current) %>;
5
5
  <%= comment_block(@current) %>
6
6
  public class <%= truncated_name(@current) %> extends <%= superclass(@current) %>
7
7
  {
8
- <%= detail_comment_block(@current) %>
9
8
  /**
10
9
  * <%= truncated_name @current %> - Default Constructor
11
- *
12
10
  */
13
11
  public <%= truncated_name @current %>() {}
14
12
  <%=
15
13
  (@current[:field].map do |f|
16
14
  field_variable(f)
17
15
  end).join("\n")
18
-
16
+ %>
17
+ <%=
19
18
  (@current[:field].map do |f|
20
19
  field_accessors(f)
21
20
  end).join("\n")
@@ -3,8 +3,8 @@ package <%= class_package(@current) %>;
3
3
 
4
4
  <%= comment_block(@current) %>
5
5
  public class <%= truncated_name(@current) %> extends <%= rootclass %>
6
- {<% @current[:field].each do |field| %>
7
- // <%= field[:description] %>
8
- @TalkDescription(description = "<%= field[:description] %>")
9
- public final static int <%= field[:name] %> = <%= field[:value] %>;
10
- <%= end %>}
6
+ {<% @current[:constant].each do |field| %>
7
+ /** <%= field[:description] %> */
8
+ @TalkDescription(description = <%= (field[:description] ? field[:description].inspect : "\"nil\"") %>)
9
+ public final static int <%= field[:name] %> = <%= field[:value].to_i %>;
10
+ <% end %>}
@@ -3,6 +3,6 @@ package <%= class_package(@current) %>;
3
3
 
4
4
  <%= comment_block(@current) %>
5
5
  public class <%= truncated_name(@current) %>
6
- {<%= @current[:field].each do |field| %>
6
+ {<% @current[:term].each do |field| %>
7
7
  public final static String <%= field[:name] %> = "<%= field[:value] %>";<% end %>
8
8
  }
@@ -13,6 +13,35 @@ def is_primitive?(type)
13
13
  primitives.include? type
14
14
  end
15
15
 
16
+ def rootclass
17
+ @target[:rootclass] || "TalkObject"
18
+ end
19
+
20
+ def superclass(cls)
21
+ cls[:inherits] || rootclass
22
+ end
23
+
24
+ def is_native?(type)
25
+ type != "talkobject" and is_primitive?(type)
26
+ end
27
+
28
+ def is_array?(type)
29
+ type == "[]"
30
+ end
31
+
32
+ def is_dict?(type)
33
+ type == "{}"
34
+ end
35
+
36
+ def class_named(name, classes)
37
+ name_elements = name.split(".")
38
+ classes.each do |defn|
39
+ return defn if defn[:name].end_with?(name)
40
+ end
41
+
42
+ nil
43
+ end
44
+
16
45
  module Talk
17
46
  class Language
18
47
  attr_reader :supported_languages
@@ -59,26 +59,6 @@ def definition_reference(tag)
59
59
  "@talkFile #{tag[:__meta][:file]}:#{tag[:__meta][:line]}"
60
60
  end
61
61
 
62
- def rootclass
63
- @target[:rootclass] || "TalkObject"
64
- end
65
-
66
- def superclass(cls)
67
- cls[:inherits] || rootclass
68
- end
69
-
70
- def is_native?(type)
71
- type != "talkobject" and is_primitive?(type)
72
- end
73
-
74
- def is_array?(type)
75
- type == "[]"
76
- end
77
-
78
- def is_dict?(type)
79
- type == "{}"
80
- end
81
-
82
62
  def mapped_name(container_name, object_name, type, name_key=:name)
83
63
  object_name = object_name[:name] if object_name.is_a? Hash
84
64
  container_name = container_name[:name] if container_name.is_a? Hash
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'talk'
3
3
  s.executables << 'talk'
4
- s.version = '2.0.4'
5
- s.date = '2014-05-16'
4
+ s.version = '2.0.5'
5
+ s.date = '2014-05-30'
6
6
  s.summary = "Compile-to-source protocol contract specification language"
7
7
  s.description = "A lightweight language for specifying protocol contracts. Compiles to source in Java, Javascript, ObjC and Ruby."
8
8
  s.authors = ["Jonas Acres"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Acres
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A lightweight language for specifying protocol contracts. Compiles to
14
14
  source in Java, Javascript, ObjC and Ruby.
@@ -58,6 +58,7 @@ files:
58
58
  - lib/contexts/target.rb
59
59
  - lib/contexts/term.rb
60
60
  - lib/languages/java/java.rb
61
+ - lib/languages/java/templates/TalkProtocol.java.erb
61
62
  - lib/languages/java/templates/class.java.erb
62
63
  - lib/languages/java/templates/enumeration.java.erb
63
64
  - lib/languages/java/templates/glossary.java.erb