forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjava_helper.rb
More file actions
85 lines (76 loc) · 1.58 KB
/
Copy pathjava_helper.rb
File metadata and controls
85 lines (76 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
module JavaHelper
# Transforms an interface name to a Java method name
def self.format_name(name)
return 'equals' if name == 'Equal'
result = name
match = /^([A-Z]+)/.match(name)
result = name.sub(match[1], match[1].downcase) unless match.nil?
result.sub(/_/, '')
end
# Transforms a proto name name to a JNI class name
def self.proto_to_class(name)
parts = name.split('_')
return nil if parts.count < 3 || parts[0] != 'TW'
if parts.count == 3
"wallet.core.jni.proto.Common.#{parts.last}"
else
"wallet.core.jni.proto.#{parts[1]}.#{parts.last}"
end
end
# Transforms an interface name to a Java constant name
def self.format_constant(name)
name.upcase
end
def self.parameters(params)
names = params.map do |param|
"#{type(param.type)} #{param.name || 'value'}"
end
names.join(', ')
end
def self.arguments(params)
params.map do |param|
param.name || 'value'
end.join(', ')
end
def self.type(t)
case t.name
when :void
'void'
when :bool
'boolean'
when :int
'int'
when :uint8
'byte'
when :uint16
'short'
when :uint32
'int'
when :uint64
'long'
when :int8
'byte'
when :int16
'short'
when :int32
'int'
when :int64
'long'
when :size
'int'
when :data
'byte[]'
when 'Data'
'byte[]'
when :string
'String'
else
if t.is_proto
proto_to_class(t.name)
else
t.name
end
end
end
end