Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0a8141c
Add some functions for Java object introspection
ctrueden Mar 26, 2025
7b8a6c4
Update methods() functionality
ian-coccimiglio Mar 27, 2025
fe0bfe3
Make progress on introspection methods
ian-coccimiglio Mar 27, 2025
25d769e
Make linter happy
ian-coccimiglio Mar 27, 2025
1a0fd71
Add source code reporting to methods() function
ian-coccimiglio Mar 27, 2025
640d57d
Implement fields introspection function
ian-coccimiglio Mar 27, 2025
aa3996c
Add partials, refactor, add java_source function
ian-coccimiglio Mar 28, 2025
9352ff6
Refactor introspection code
ian-coccimiglio Mar 28, 2025
fe60217
Add test cases for introspection functions
ian-coccimiglio Mar 28, 2025
7293d23
Lint code
ian-coccimiglio Mar 28, 2025
4123078
Improve introspection function documentation
ian-coccimiglio Mar 31, 2025
3533446
Add docstring to test_introspection.py
ian-coccimiglio Mar 31, 2025
9516a72
Wrap long line
ctrueden Apr 2, 2025
6520223
Increment minor version digit
ctrueden Apr 2, 2025
363e7bc
Alphabetize introspection imports
ctrueden Apr 2, 2025
c8afba4
Shorten introspection to introspect
ctrueden Apr 2, 2025
6bfec82
Add toplevel docstrings to test files
ctrueden Apr 2, 2025
37bd92e
Fix naming of versions test file
ctrueden Apr 2, 2025
5f883f1
Fix type hints to work with Python 3.8
ctrueden Apr 2, 2025
6282d8c
CI: test Python 3.13 support
ctrueden Apr 2, 2025
bded14f
Rename find_java function to jreflect
ctrueden Apr 2, 2025
0778a89
Add missing is_j* type methods to README
ctrueden Apr 2, 2025
21ffae9
Use imperative tense for function docstrings
ctrueden Apr 2, 2025
bb06ed1
Wrap >88 lines, and make quoting more consistent
ctrueden Apr 2, 2025
553d552
Add introspection functions to the README
ctrueden Apr 2, 2025
bf2ee82
Improve get_version method
ctrueden Apr 24, 2025
2d44fed
Test a little further into the GitHub source paths
ctrueden Apr 24, 2025
8846ce5
Tweak management of multiple endpoints
ctrueden Apr 24, 2025
a31701b
Rename java_source method to jsource
ctrueden Apr 24, 2025
2713b6c
Make jreflect function more powerful
ctrueden Apr 24, 2025
92d7fb1
Split pretty-print functions to own subpackage
ctrueden Apr 25, 2025
30bd4d3
Hide non-public scijava.config attrs
ctrueden Apr 25, 2025
a537c00
Hide non-public scyjava.inspect attrs
ctrueden Apr 25, 2025
cea10cd
Use jimport naming convention for Java types
ctrueden Apr 25, 2025
3a46f1b
Make output writer configurable
ctrueden Apr 25, 2025
5fe1461
Replace print statements with logger calls
ctrueden Apr 25, 2025
2f11f0d
Add unit test for inspect.members function
ctrueden Apr 25, 2025
f4266c4
Ensure submodules are directly available
ctrueden Apr 25, 2025
1d9b507
Let jsource also find Java library source code
ctrueden Apr 25, 2025
5c06747
Be less aggressive with source code detection
ctrueden Apr 25, 2025
e5e9cab
Add test for jreflect constructors
ctrueden Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement fields introspection function
  • Loading branch information
ian-coccimiglio authored and ctrueden committed Apr 2, 2025
commit 640d57deb7393407fe6edcced2d728186133e3bb
5 changes: 4 additions & 1 deletion src/scyjava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@
jclass,
jinstance,
jstacktrace,
methods,
find_java_methods,
find_java_fields,
methods,
fields,
attrs,
numeric_bounds,
)
from ._versions import compare_version, get_version, is_version_at_least
Expand Down
67 changes: 39 additions & 28 deletions src/scyjava/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,11 @@ def find_java_fields(data) -> list[dict[str, Any]]:

for f in fields:
name = f.getName()
table.append(name)
ftype = f.getType().getName()
table.append({"name": name, "type": ftype})
sorted_table = sorted(table, key=lambda d: d["name"])

return table
return sorted_table


def _map_syntax(base_type):
Expand Down Expand Up @@ -441,39 +443,18 @@ def _make_pretty_string(entry, offset):
obj_name = f"{entry['name']}"
modifier = f"{'*':>4}" if entry["static"] else f"{'':>4}"

# Handle fields
if entry["arguments"] is None:
return f"{return_val} = {obj_name}\n"

# Handle methods with no arguments
if not entry["arguments"]:
if len(entry["arguments"]) == 0:
return f"{return_val} {modifier} = {obj_name}()\n"
else:
arg_string = ", ".join([r.__str__() for r in entry["arguments"]])
return f"{return_val} {modifier} = {obj_name}({arg_string})\n"


# TODO
def fields(data) -> str:
"""
Writes data to a printed field names with the field value.
:param data: The object or class to inspect.
"""
# table = find_java_fields(data)

all_fields = ""
################
# FILL THIS IN #
################

print(all_fields)


# TODO
def attrs(data):
"""
Writes data to a printed field names with the field value. Alias for `fields(data)`.
:param data: The object or class to inspect.
"""
fields(data)


def get_source_code(data):
"""
Tries to find the source code using Scijava's SourceFinder'
Expand All @@ -496,6 +477,36 @@ def get_source_code(data):
return f"Unexpected {err=}, {type(err)=}"


def fields(data) -> str:
"""
Writes data to a printed field names with the field value.
:param data: The object or class to inspect.
"""
table = find_java_fields(data)
if len(table) == 0:
print("No fields found")
return

all_fields = ""
offset = max(list(map(lambda entry: len(entry["type"]), table)))
for entry in table:
entry["returns"] = _map_syntax(entry["type"])
entry["static"] = False
entry["arguments"] = None
entry_string = _make_pretty_string(entry, offset)
all_fields += entry_string

print(all_fields)


def attrs(data):
"""
Writes data to a printed field names with the field value. Alias for `fields(data)`.
:param data: The object or class to inspect.
"""
fields(data)


def methods(data, static: bool | None = None, source: bool = True) -> str:
"""
Writes data to a printed string of class methods with inputs, static modifier, arguments, and return values.
Expand Down