Skip to content

Commit 2673123

Browse files
authored
Merge pull request #67 from JuliaInterop/listmethods-for-types
listmethods() for types
2 parents 7b1f719 + 275231e commit 2673123

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/reflect.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ function listmethods(obj::JavaObject)
7979
jcall(cls, "getMethods", Vector{JMethod}, ())
8080
end
8181

82+
function listmethods{C}(::Type{JavaObject{C}})
83+
cls = classforname(string(C))
84+
jcall(cls, "getMethods", Vector{JMethod}, ())
85+
end
86+
87+
function listmethods(cls::JClass)
88+
jcall(cls, "getMethods", Vector{JMethod}, ())
89+
end
90+
91+
8292
"""
8393
```
8494
listmethods(obj::JavaObject, name::AbstractString)
@@ -92,7 +102,7 @@ Lists the methods that are available on the java object passed. The methods are
92102
### Returns
93103
List of methods available on the java object and matching the name passed
94104
"""
95-
function listmethods(obj::JavaObject, name::AbstractString)
105+
function listmethods{C}(obj::Union{JavaObject{C}, Type{JavaObject{C}}}, name::AbstractString)
96106
allmethods = listmethods(obj)
97107
filter(m -> getname(m) == name, allmethods)
98108
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ end
142142

143143
@test length(listmethods(JString("test"))) >= 72
144144
@test length(listmethods(JString("test"), "indexOf")) >= 3
145+
# the same for the type
146+
@test length(listmethods(JString)) >= 72
147+
@test length(listmethods(JString, "indexOf")) >= 3
148+
# the same for class
149+
@test length(listmethods(getclass(JString("test")))) >= 72
150+
@test length(listmethods(getclass(JString("test")), "indexOf")) >= 3
145151
m = listmethods(JString("test"), "indexOf")[1]
146152
@test getname(getreturntype(m)) == "int"
147153
@test [getname(typ) for typ in getparametertypes(m)] == ["java.lang.String", "int"]

0 commit comments

Comments
 (0)