-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
79 lines (65 loc) · 1.18 KB
/
utils.go
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
package bytecode
import (
"fmt"
"reflect"
)
func countParameters(descriptor string) uint16 {
parameters := 0
foundReference := false
for _, char := range descriptor {
if char == '(' || char == '[' {
continue
}
if char == ')' {
break
}
if char == 'L' {
foundReference = true
}
if foundReference {
if char == ';' {
foundReference = false
parameters++
}
continue
}
parameters++
}
return uint16(parameters)
}
func AsJavaType(value interface{}) JavaType {
if _, ok := value.(int); ok {
return Type_Char
}
switch value.(type) {
case int8:
return Type_Byte
case int16:
return Type_Short
case int:
return Type_Int
case int32:
return Type_Int
case int64:
return Type_Long
case float32:
return Type_Float
case float64:
return Type_Double
case bool:
return Type_Boolean
case string:
return Type_Reference
}
panic("could not get JavaType of " + reflect.TypeOf(value).Name())
}
func Ternary(expresion bool, whenTrue interface{}, whenFalse interface{}) interface{} {
if expresion {
return whenTrue
} else {
return whenFalse
}
}
func Log(message string, values ...interface{}) {
fmt.Printf(message+"\n", values...)
}