Module: JavaKlass

Defined in:
lib/ycn/java/java_klass.rb

Instance Method Summary collapse

Instance Method Details

#java_accessorsObject



69
# File 'lib/ycn/java/java_klass.rb', line 69

def java_accessors; java_g_s_etters; end

#java_class_declarationObject



39
40
41
# File 'lib/ycn/java/java_klass.rb', line 39

def java_class_declaration
  "public class #{name}#{" extends #{parent.name}" if parent}"
end

#java_constructorsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ycn/java/java_klass.rb', line 43

def java_constructors
  @construct_params.map { |parameter_set|
    "\n  public #{@name}(" +
    
    parameter_set.map { |parameter|
      type = find_var( parameter ).type
      "#{type} #{styled_var :riki, parameter, :p, type}"
      
    }.join(', ') + ")\n  {\n    " +
    
    parameter_set.map { |parameter|
      type = find_var( parameter ).type
      "set#{camelize parameter}(#{styled_var :riki, parameter, :p, type});"
    }.join("\n    ") +
    
    java_prop_default_overrides
  }.join("\n  }\n") + "\n  }\n"
end

#java_g_s_ettersObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ycn/java/java_klass.rb', line 71

def java_g_s_etters
  text = properties.map { |property|
    unless prop_default_overrides.include? property.name
      type = property.type
      name = property.name
      result = ''
      if configatron.getters; result += <<TEXT
public #{type} get#{camelize name}()
{
  return #{styled_var :riki, name, :g, type };
}
TEXT
      end
      
      if configatron.setters; result += <<TEXT
public void set#{camelize name}(#{type} #{styled_var :riki, name, :p, type})
{
  #{styled_var :riki, name, :g, type } = #{styled_var :riki, name, :p, type}; 
}
TEXT
      end
      result
    end
  }.join
  text
end

#java_headerObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ycn/java/java_klass.rb', line 4

def java_header 
  text = <<HEAD
Programme :    #{configatron.program_name}
Auteur(s) :    #{configatron.author_name}
Date :         #{Time.now.day}/#{Time.now.month}/#{Time.now.year}
Description :  #{configatron.description}
HEAD

  '/*' + text.split("\n").map{ |l|
    "\n *  #{l}"
  }.join + "\n */\n"
end

#java_importsObject



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

def java_imports
  text = properties.map{ |property|
    import = case property.type
      when 'Date'
        "import java.util.Date;"
      when 'Time'
        "import java.util.Time;"
      else
        nil
    end
    import  
  }.compact
  
  if text.size > 0
    text = "\n" + text.join("\n")  + "\n"
  end
end

#java_packageObject



17
18
19
# File 'lib/ycn/java/java_klass.rb', line 17

def java_package
  @package ? "\npackage pcg#{camelize @package};" : ''
end

#java_prop_default_overridesObject



62
63
64
65
66
67
# File 'lib/ycn/java/java_klass.rb', line 62

def java_prop_default_overrides
  prop_default_overrides.map { |property|
    property = find_var( property )
    "\n    super.set#{camelize property.name}(#{property.default_value});"
  }.join("\n")
end