Skip to content

Commit c69c3da

Browse files
committed
Change the argument order to definition(String, ::Method)
1 parent 5c01d70 commit c69c3da

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ julia> definition(m)
4949
c.r
5050
end)
5151

52-
julia> definition(m, String)
53-
"red(c::AbstractRGB ) = c.r\n"
52+
julia> str, line1 = definition(String, m)
53+
("red(c::AbstractRGB ) = c.r\n", 14)
5454
```
5555

5656
or to find the method-signatures at a particular location:

src/CodeTracking.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,16 @@ function signatures_at(id::PkgId, relpath::AbstractString, line::Integer)
175175
end
176176

177177
"""
178-
src, line1 = definition(method::Method, String)
178+
src, line1 = definition(String, method::Method)
179179
180180
Return a string with the code that defines `method`. Also return the first line of the
181-
definition, including the signature.
181+
definition, including the signature (which may not be the same line number returned
182+
by `whereis`).
182183
183184
Note this may not be terribly useful for methods that are defined inside `@eval` statements;
184-
see [`definition(method::Method, Expr)`](@ref) instead.
185+
see [`definition(Expr, method::Method)`](@ref) instead.
185186
"""
186-
function definition(method::Method, ::Type{String})
187+
function definition(::Type{String}, method::Method)
187188
file, line = whereis(method)
188189
src = read(file, String)
189190
eol = isequal('\n')
@@ -209,12 +210,12 @@ function definition(method::Method, ::Type{String})
209210
end
210211

211212
"""
212-
ex = definition(method::Method, Expr)
213+
ex = definition(Expr, method::Method)
213214
ex = definition(method::Method)
214215
215216
Return an expression that defines `method`.
216217
"""
217-
function definition(method::Method, ::Type{Expr})
218+
function definition(::Type{Expr}, method::Method)
218219
def = get(method_info, method.sig, nothing)
219220
if def === nothing
220221
f = method_lookup_callback[]
@@ -229,7 +230,7 @@ function definition(method::Method, ::Type{Expr})
229230
return def === nothing || ismissing(def) ? nothing : copy(def[2])
230231
end
231232

232-
definition(method::Method) = definition(method, Expr)
233+
definition(method::Method) = definition(Expr, method)
233234

234235
"""
235236
info = pkgfiles(name::AbstractString)

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
2020
@test whereis(trace[2]) == (scriptpath, 11)
2121
@test whereis(trace[3]) === nothing
2222

23-
src, line = definition(m, String)
23+
src, line = definition(String, m)
2424
@test src == """
2525
function f1(x, y)
2626
# A comment
@@ -30,7 +30,7 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
3030
@test line == 2
3131

3232
m = first(methods(f2))
33-
src, line = definition(m, String)
33+
src, line = definition(String, m)
3434
@test src == """
3535
f2(x, y) = x + y
3636
"""

0 commit comments

Comments
 (0)