Skip to content

Commit 56f832f

Browse files
committed
Work on interface
1 parent 9fae367 commit 56f832f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1802
-581
lines changed

native/jpype_module/src/main/java/org/jpype/JPypeContext.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
* contents of JPJni.
6565
*
6666
*
67-
*
68-
* @author nelson85
6967
*/
7068
public class JPypeContext
7169
{

native/jpype_module/src/main/java/org/jpype/JPypeKeywords.java

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,103 @@
2020
import java.util.Set;
2121

2222
/**
23+
* Utility class for handling reserved keywords in JPype.
2324
*
24-
* @author nelson85
25+
* This class provides methods to manage a set of reserved keywords and offers
26+
* functionality to wrap and unwrap names to avoid conflicts with these
27+
* keywords. It also includes a method to safely process package names
28+
* containing underscores.
2529
*/
2630
public class JPypeKeywords
2731
{
2832

33+
/**
34+
* A set of reserved keywords.
35+
*
36+
* This set contains keywords that need special handling to avoid conflicts.
37+
* Keywords can be added dynamically using the {@link #setKeywords(String[])}
38+
* method.
39+
*/
2940
final public static Set<String> keywords = new HashSet<>();
3041

42+
/**
43+
* Adds keywords to the reserved keywords set.
44+
*
45+
* This method allows dynamic addition of keywords to the {@link #keywords}
46+
* set.
47+
*
48+
* @param s An array of strings representing the keywords to add.
49+
*/
3150
public static void setKeywords(String[] s)
3251
{
3352
keywords.addAll(Arrays.asList(s));
3453
}
3554

55+
/**
56+
* Wraps a name if it matches a reserved keyword.
57+
*
58+
* If the given name is a reserved keyword, this method appends an underscore
59+
* (`_`) to the name to avoid conflicts. Otherwise, it returns the name
60+
* unchanged.
61+
*
62+
* @param name The name to check and wrap if necessary.
63+
* @return The wrapped name if it is a keyword, otherwise the original name.
64+
*/
3665
public static String wrap(String name)
3766
{
3867
if (keywords.contains(name))
68+
{
3969
return name + "_";
70+
}
4071
return name;
4172
}
4273

74+
/**
75+
* Unwraps a name that ends with an underscore (`_`).
76+
*
77+
* If the given name ends with an underscore and matches a reserved keyword
78+
* (after removing the underscore), this method returns the original keyword.
79+
* Otherwise, it returns the name unchanged.
80+
*
81+
* @param name The name to check and unwrap if necessary.
82+
* @return The unwrapped name if it ends with an underscore and matches a
83+
* keyword, otherwise the original name.
84+
*/
4385
public static String unwrap(String name)
4486
{
4587
if (!name.endsWith("_"))
88+
{
4689
return name;
90+
}
4791
String name2 = name.substring(0, name.length() - 1);
4892
if (keywords.contains(name2))
49-
return name2;;
93+
{
94+
return name2;
95+
}
5096
return name;
5197
}
5298

99+
/**
100+
* Safely processes a package name by unwrapping parts containing underscores.
101+
*
102+
* This method splits the package name into its components (separated by
103+
* dots), unwraps each part, and then reassembles the package name. It ensures
104+
* that underscores are handled properly for each part of the package name.
105+
*
106+
* @param s The package name to process.
107+
* @return The processed package name with unwrapped parts.
108+
*/
53109
static String safepkg(String s)
54110
{
55111
if (!s.contains("_"))
112+
{
56113
return s;
114+
}
57115
String[] parts = s.split("\\.");
58116
for (int i = 0; i < parts.length; ++i)
117+
{
59118
parts[i] = unwrap(parts[i]);
119+
}
60120
return String.join(".", parts);
61121
}
62122
}

native/jpype_module/src/main/java/org/jpype/JPypeReflector.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
import java.lang.reflect.Method;
44

55
/**
6+
* Interface for invoking methods using reflection in JPype.
67
*
7-
* @author nelson85
8+
* The {@code JPypeReflector} interface provides a mechanism to call methods
9+
* dynamically using Java reflection. This is particularly useful for invoking
10+
* caller-sensitive methods while ensuring proper stack frame creation for
11+
* execution.
812
*/
913
public interface JPypeReflector
1014
{
1115

1216
/**
13-
* Call a method using reflection.
17+
* Invokes a method using reflection.
1418
*
15-
* This method creates a stackframe so that caller sensitive methods will
16-
* execute properly.
19+
* This method dynamically calls the specified method on the provided object
20+
* (or class, if the method is static) using reflection. It ensures that
21+
* caller-sensitive methods execute correctly by creating the appropriate
22+
* stack frame during invocation.
1723
*
1824
* @param method is the method to call.
1925
* @param obj is the object to operate on, it will be null if the method is
@@ -23,6 +29,5 @@ public interface JPypeReflector
2329
* @throws java.lang.Throwable throws whatever type the called method
2430
* produces.
2531
*/
26-
public Object callMethod(Method method, Object obj, Object[] args)
27-
throws Throwable;
32+
public Object callMethod(Method method, Object obj, Object[] args) throws Throwable;
2833
}

native/jpype_module/src/main/java/org/jpype/PyExceptionProxy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/**
44
*
5-
* @author nelson85
65
*/
76
public class PyExceptionProxy extends RuntimeException
87
{

0 commit comments

Comments
 (0)