77from scyjava import _introspect
88
99
10- def members (data , writer = None ):
10+ def members (data , static : bool | None = None , source : bool | None = None , writer = None ):
1111 """
1212 Print all the members (constructors, fields, and methods)
1313 for a Java class, object, or class name.
1414
1515 :param data: The Java class, object, or fully qualified class name as string.
1616 :param writer: Function to which output will be sent, sys.stdout.write by default.
1717 """
18- _print_data (data , aspect = "all" , writer = writer )
18+ _print_data (data , aspect = "all" , static = static , source = source , writer = writer )
1919
2020
21- def constructors (data , writer = None ):
21+ def constructors (
22+ data , static : bool | None = None , source : bool | None = None , writer = None
23+ ):
2224 """
2325 Print the constructors for a Java class, object, or class name.
2426
2527 :param data: The Java class, object, or fully qualified class name as string.
2628 :param writer: Function to which output will be sent, sys.stdout.write by default.
2729 """
28- _print_data (data , aspect = "constructors" , writer = writer )
30+ _print_data (
31+ data , aspect = "constructors" , static = static , source = source , writer = writer
32+ )
2933
3034
31- def fields (data , writer = None ):
35+ def fields (data , static : bool | None = None , source : bool | None = None , writer = None ):
3236 """
3337 Print the fields for a Java class, object, or class name.
3438
3539 :param data: The Java class, object, or fully qualified class name as string.
3640 :param writer: Function to which output will be sent, sys.stdout.write by default.
3741 """
38- _print_data (data , aspect = "fields" , writer = writer )
42+ _print_data (data , aspect = "fields" , static = static , source = source , writer = writer )
3943
4044
41- def methods (data , writer = None ):
45+ def methods (data , static : bool | None = None , source : bool | None = None , writer = None ):
4246 """
4347 Print the methods for a Java class, object, or class name.
4448
@@ -115,7 +119,7 @@ def _pretty_string(entry, offset):
115119
116120
117121def _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
119123):
120124 """
121125 Write data to a printed string of class methods with inputs, static modifier,
@@ -125,7 +129,11 @@ def _print_data(
125129 :param static:
126130 Boolean filter on Static or Instance methods.
127131 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.
129137 """
130138 writer = writer or _stdout .write
131139 table = _introspect .jreflect (data , aspect )
@@ -136,9 +144,15 @@ def _print_data(
136144 # Print source code
137145 offset = max (list (map (lambda entry : len (entry ["returns" ] or "void" ), table )))
138146 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+ )
142156
143157 # Print methods
144158 for entry in table :
0 commit comments