Commits

Anonymous committed 87cbfdf

added suport for lists with enums, added SuppressWarnings(unused) annotation to generated packets

Comments (0)

Files changed (1)

maven/protocol-generator-plugin/src/main/scripts/java_generator.rb

       visitable_tag = ', Visitable'
     end
     
+    wi("@SuppressWarnings(\"unused\")")
     wi("public#{static_tag} final class #{camelcasetype(name)}#{parent_tag}#{visitable_tag} {")
     @indent_level += 1
     if !class_id.to_s.empty?
   
   def member_list(list)
     type = jtype(list.obj_type)
-    
     # uint8 array *is* a byte-array
     if(list.obj_type == "uint8")
       wi("public byte[] #{camelcase(list.name)} = new byte[0];")
   
   def save_list(list)
     name = camelcase(list.name)
+    ltype = jtype(list.obj_type)
     
-    if(builtin?(list.obj_type))
+    
+    if enum?(list.obj_type)
+      wi("if (#{name} == null) {")
+      @indent_level += 1
+      wi("ps.saveInt(0);")
+      @indent_level -= 1
+      wi("} else {")
+      @indent_level += 1
+      wi("ps.saveInt(#{name}.size());")
+      wi("for(int i = 0; i != #{name}.size(); ++i) {")
+      wi("ps.saveInt(#{name}.get(i).ordinal());",1)
+      wi("}")
+      @indent_level -= 1
+      wi("}")
+      
+    elsif(builtin?(list.obj_type))
       # Save as array
       wi("ps.saveInt(#{name}.length);")
       wi("ps.saveArray(#{name});")
     name = camelcase(list.name)
     ltype = jtype(list.obj_type)
     
+    
     if(UNSIGNED_TYPES.has_key?(ltype))
       ltype = UNSIGNED_TYPES[ltype]
     end
     
-    # Array of uint8 *is* byte
     if(list.obj_type == "uint8")
+      # Array of uint8 *is* byte
       wi("int #{name}Count = ps.loadInt();")
       wi("#{name} = new byte[#{name}Count];")
       wi("ps.loadByteArray(#{name});")
       wi("for(int i = 0; i != #{name}Count; ++i) {")
       if(builtin?(list.obj_type))
         wi("#{name}.add(ps.load#{ltype}());",1)
+      elsif(enum?(list.obj_type))
+        wi("int ordinal = ps.loadInt();",1)
+        wi("#{ltype} _tmp = Enums.make#{ltype}(ordinal);",1)
+        wi("status.add(_tmp);",1)
       else
         wi("#{ltype} _tmp = new #{ltype}();",1)
         wi("_tmp.load(ps);",1)
 import java.util.ArrayList;
 import java.io.IOException;
 
+import #{package}.Enums.*;
+
+
+
 HEADER_END
   end
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.