Skip to content

Commit

Permalink
Changed JavaBuilderScope to not make any assumptions about method sig…
Browse files Browse the repository at this point in the history
…natures (fixes #161)
  • Loading branch information
jwharm committed Dec 7, 2024
1 parent 523bb93 commit a8ae098
Showing 1 changed file with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.lang.foreign.MemorySegment;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.function.BooleanSupplier;

import static io.github.jwharm.javagi.Constants.LOG_DOMAIN;

Expand Down Expand Up @@ -115,36 +114,7 @@ public Closure createClosure(GtkBuilder builder,
// Find method with the right name
Class<? extends GObject> cls = currentObject.getClass();
Method method = getMethodForName(cls, function);

// Signal that returns boolean
if (method.getReturnType().equals(Boolean.TYPE)) {
return new JavaClosure((BooleanSupplier) () -> {
try {
return (boolean) method.invoke(currentObject);
} catch (Exception e) {
GLib.log(LOG_DOMAIN, LogLevelFlags.LEVEL_CRITICAL,
"Cannot invoke method %s in class %s: %s\n",
function,
currentObject.getClass().getName(),
e.getMessage());
return false;
}
});

// Signal that returns void
} else {
return new JavaClosure((Runnable) () -> {
try {
method.invoke(currentObject);
} catch (Exception e) {
GLib.log(LOG_DOMAIN, LogLevelFlags.LEVEL_CRITICAL,
"Cannot invoke method %s in class %s: %s\n",
function,
currentObject.getClass().getName(),
e.getMessage());
}
});
}
return new JavaClosure(currentObject, method);
} catch (NoSuchMethodException e) {
GLib.log(LOG_DOMAIN, LogLevelFlags.LEVEL_CRITICAL,
"Cannot find method %s in class %s\n",
Expand Down

0 comments on commit a8ae098

Please sign in to comment.