7
7
from scyjava import _introspect
8
8
9
9
10
- def members (data , writer = None ):
10
+ def members (data , static : bool | None = None , source : bool | None = None , writer = None ):
11
11
"""
12
12
Print all the members (constructors, fields, and methods)
13
13
for a Java class, object, or class name.
14
14
15
15
:param data: The Java class, object, or fully qualified class name as string.
16
16
:param writer: Function to which output will be sent, sys.stdout.write by default.
17
17
"""
18
- _print_data (data , aspect = "all" , writer = writer )
18
+ _print_data (data , aspect = "all" , static = static , source = source , writer = writer )
19
19
20
20
21
- def constructors (data , writer = None ):
21
+ def constructors (
22
+ data , static : bool | None = None , source : bool | None = None , writer = None
23
+ ):
22
24
"""
23
25
Print the constructors for a Java class, object, or class name.
24
26
25
27
:param data: The Java class, object, or fully qualified class name as string.
26
28
:param writer: Function to which output will be sent, sys.stdout.write by default.
27
29
"""
28
- _print_data (data , aspect = "constructors" , writer = writer )
30
+ _print_data (
31
+ data , aspect = "constructors" , static = static , source = source , writer = writer
32
+ )
29
33
30
34
31
- def fields (data , writer = None ):
35
+ def fields (data , static : bool | None = None , source : bool | None = None , writer = None ):
32
36
"""
33
37
Print the fields for a Java class, object, or class name.
34
38
35
39
:param data: The Java class, object, or fully qualified class name as string.
36
40
:param writer: Function to which output will be sent, sys.stdout.write by default.
37
41
"""
38
- _print_data (data , aspect = "fields" , writer = writer )
42
+ _print_data (data , aspect = "fields" , static = static , source = source , writer = writer )
39
43
40
44
41
- def methods (data , writer = None ):
45
+ def methods (data , static : bool | None = None , source : bool | None = None , writer = None ):
42
46
"""
43
47
Print the methods for a Java class, object, or class name.
44
48
@@ -115,7 +119,7 @@ def _pretty_string(entry, offset):
115
119
116
120
117
121
def _print_data (
118
- data , aspect , static : bool | None = None , source : bool = True , writer = None
122
+ data , aspect , static : bool | None = None , source : bool | None = None , writer = None
119
123
):
120
124
"""
121
125
Write data to a printed table with inputs, static modifier,
@@ -125,7 +129,11 @@ def _print_data(
125
129
:param static:
126
130
Boolean filter on Static or Instance methods.
127
131
Optional, default is None (prints all).
128
- :param source: Whether to print any available source code. Default True.
132
+ :param source:
133
+ Whether to discern and report a URL to the relevant source code.
134
+ Requires org.scijava:scijava-search to be on the classpath.
135
+ When set to None (the default), autodetects whether scijava-search
136
+ is available, reporting source URL if so, or leaving it out if not.
129
137
"""
130
138
writer = writer or _stdout .write
131
139
table = _introspect .jreflect (data , aspect )
@@ -136,9 +144,15 @@ def _print_data(
136
144
# Print source code
137
145
offset = max (list (map (lambda entry : len (entry ["returns" ] or "void" ), table )))
138
146
all_methods = ""
139
- if source :
140
- urlstring = _introspect .jsource (data )
141
- writer (f"Source code URL: { urlstring } \n " )
147
+ if source or source is None :
148
+ try :
149
+ urlstring = _introspect .jsource (data )
150
+ writer (f"Source code URL: { urlstring } \n " )
151
+ except TypeError :
152
+ if source :
153
+ writer (
154
+ "Classpath lacks scijava-search; no source code URL detection is available.\n "
155
+ )
142
156
143
157
# Print methods
144
158
for entry in table :
0 commit comments