Class: JAVAModelDefinition

Inherits:
ModelDefinition show all
Defined in:
lib/translate2java.rb

Instance Attribute Summary

Attributes inherited from ModelDefinition

#configHash, #context

Instance Method Summary collapse

Methods inherited from ModelDefinition

#class_name, getModelDefinition, #header, #header_template, #implementation, #initialize, #processTranslate, #setcontext, #startTranslate

Constructor Details

This class inherits a constructor from ModelDefinition

Instance Method Details

#finishTranslateObject



72
73
74
# File 'lib/translate2java.rb', line 72

def finishTranslate
    replace_file("#{getDirPath}/#{class_name}.java",implementation)
end

#implementation_body(property) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/translate2java.rb', line 21

def implementation_body(property)
  case property
  when String
    return "decodeString"
  when TrueClass,FalseClass
    return "decodeBoolean"
  when Float
    return "decodeDouble"
  when Fixnum
    return "decodeInt"
  when Bignum
    return "decodeLong"
  else
  end
end

#implementation_templateObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/translate2java.rb', line 53

def implementation_template
    template = "package com.tencent.videobase.videoconfig;\n\nimport com.tencent.videobase.videoconfig.VideoConfigCacheMgr;\n\npublic final class <%= context.class_name %> {\n<% context.properties.each do |prop| -%>\n<%= property_definition(true,prop) %>\n<% end -%>\n\n<% context.properties.each do |prop| -%>\n<%=propterty_getterGenerator(prop) %>\n<% end -%>\n\n}\n"
end

#property_definition(readonly, args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/translate2java.rb', line 6

def property_definition(readonly, args)
  property_value = args[1]
  if String === args[1] 
      property_value = %Q("#{property_value}")
  end
  property_str = "private static #{property_type(args[1])} #{args[0]} = #{property_value}; "
end

#property_type(property) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/translate2java.rb', line 37

def property_type(property)
  case property
  when String
    return "String"
  when TrueClass,FalseClass
    return "boolean"
  when Float
    return "double"
  when Fixnum
    return "int"
  when Bignum
    return "long"
  else
  end
end

#propterty_getterGenerator(args) ⇒ Object



14
15
16
17
18
19
# File 'lib/translate2java.rb', line 14

def propterty_getterGenerator(args)
  argParam = %Q("#{context.class_name}_#{args[0]}")
  getter = "public static #{property_type(args[1])} get#{args[0]}(){
    return VideoConfigCacheMgr.#{implementation_body(args[1])}(#{argParam},#{args[0]});
  } "
end