Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/compilable/package.rb,
lib/compilable/interface.rb,
lib/compilable/signature.rb,
lib/compilable/annotation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#package_nameObject (readonly)

Returns the value of attribute package_name.



10
11
12
# File 'lib/compilable/package.rb', line 10

def package_name
  @package_name
end

Instance Method Details

#annotation(name, anno_hash = {}) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/compilable/annotation.rb', line 2

def annotation(name, anno_hash = {})
  name = name.to_s
  annotations[name] ||= {}
  anno_hash.each do |k,v|
    annotations[name][k] = v
  end
end

#annotationsObject



10
11
12
# File 'lib/compilable/annotation.rb', line 10

def annotations
  @annotations ||= {}
end

#interface(*list) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/compilable/interface.rb', line 3

def interface(*list)
  raise ArgumentError, "at least 1 interface needed" if list.empty?
  interfaces.push *list
  interfaces.uniq!
end

#interfacesObject



9
10
11
# File 'lib/compilable/interface.rb', line 9

def interfaces
  @interfaces ||= []
end

#package(*package_name) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
# File 'lib/compilable/package.rb', line 3

def package(*package_name)
  raise ArgumentError, 'too few arguments' if package_name.empty?
  # Should we raise an exception?
  # Only first called is considered.
  @package_name = package_name.map!{|x| x.split('.')}.flatten unless @package_name
end

#signature(name, signature) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/compilable/signature.rb', line 5

def signature(name, signature)
  name = name.to_s
  params = signature.keys.first
  sig = Signature.new(params, signature[params])
  sig_method = instance_method(name) || method(name)
  if sig.fit? *(sig_method.args)
    signatures[name] = [sig]
  else
    raise ArgumentError, "java signature does not fit ruby signature"
  end
end

#signaturesObject



17
18
19
# File 'lib/compilable/signature.rb', line 17

def signatures
  @signatures ||= {}
end

#static_annotation(name, anno_hash = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/compilable/annotation.rb', line 14

def static_annotation(name, anno_hash = {})
  name = name.to_s
  annotations[name] ||= {}
  anno_hash.each do |k,v|
    static_annotations[name][k] = v
  end
end

#static_annotationsObject



22
23
24
# File 'lib/compilable/annotation.rb', line 22

def static_annotations
  @static_annotations ||= {}
end

#static_signature(name, signature) ⇒ Object



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

def static_signature(name, signature)
  name = name.to_s
  params = signature.keys.first
  sig = Signature.new(params, signature[params])
  sig_method = begin
    instance_method(name)
  rescue NameError
    method(name)
  end
  if sig.fit? *(sig_method.args)
    static_signatures[name] = [sig]
  else
    raise ArgumentError, "java signature does not fit ruby signature"
  end
end

#static_signaturesObject



37
38
39
# File 'lib/compilable/signature.rb', line 37

def static_signatures
  @static_signatures ||= {}
end