Discussion:
branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt
Richard Dale
2005-10-06 11:35:46 UTC
Permalink
SVN commit 467774 by rdale:

* This check via reflection to tell if an event method had been
overriden was insufficiently herioc - I just love those java
apis ;). This should fix the bug reported by Jochen Becher

CCBUGS: 112409
CCMAIL: kde-***@kde.org



M +8 -4 Invocation.java


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #467773:467774
@@ -442,11 +442,15 @@
Object onThis = qtjava.objectForQtKey(target, "org.kde.qt.QObject", false);

try {
- // Assume that an event handler is a protected method, so use getDeclaredMethod()
- method = onThis.getClass().getDeclaredMethod(methodName, parameterType);
+ method = onThis.getClass().getMethod(methodName, parameterType);
method.setAccessible(true);
- } catch (NoSuchMethodException e) {
- return false;
+ } catch (NoSuchMethodException e1) {
+ try {
+ method = onThis.getClass().getDeclaredMethod(methodName, parameterType);
+ method.setAccessible(true);
+ } catch (NoSuchMethodException e2) {
+ return true;
+ }
}

// Ignore any native code event handling methods
Richard Dale
2005-10-06 11:44:13 UTC
Permalink
SVN commit 467777 by rdale:

* Oops, the last commit solved the wrong problem. Instead of
two nested exception handlers, which would get both
protected and public methods, but not inherited ones.
A loop is needed to look for inherited event methods, going
up the class heirarchy.

CCBUGS: 112409
CCMAIL: kde-***@kde.org



M +8 -7 Invocation.java


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #467776:467777
@@ -440,18 +440,19 @@
Class[] parameterType = new Class[1];
parameterType[0] = Class.forName(qtjava.toFullyQualifiedClassName(argClass));
Object onThis = qtjava.objectForQtKey(target, "org.kde.qt.QObject", false);
+
+ Class targetClass = onThis.getClass();

- try {
- method = onThis.getClass().getMethod(methodName, parameterType);
- method.setAccessible(true);
- } catch (NoSuchMethodException e1) {
+ do {
try {
- method = onThis.getClass().getDeclaredMethod(methodName, parameterType);
+ method = targetClass.getDeclaredMethod(methodName, parameterType);
method.setAccessible(true);
- } catch (NoSuchMethodException e2) {
+ } catch (NoSuchMethodException e1) {
return true;
}
- }
+
+ targetClass = targetClass.getSuperclass();
+ } while (targetClass != null);

// Ignore any native code event handling methods
if ((method.getModifiers() & Modifier.NATIVE) != 0) {
Richard Dale
2005-10-07 13:52:20 UTC
Permalink
SVN commit 468238 by rdale:

* Still trying to fix bug #112409 - fourth attempt, feeling lucky

CCBUGS: 112409
CCMAIL: kde-***@kde.org



M +6 -2 Invocation.java


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #468237:468238
@@ -436,7 +436,7 @@
if the method was successfully invoked, otherwise false.
Used for event handling callbacks */
public static boolean invoke(long target, long arg, String argClass, String methodName) throws NoSuchMethodException, ClassNotFoundException {
- Method method;
+ Method method = null;
Class[] parameterType = new Class[1];
parameterType[0] = Class.forName(qtjava.toFullyQualifiedClassName(argClass));
Object onThis = qtjava.objectForQtKey(target, "org.kde.qt.QObject", false);
@@ -447,13 +447,17 @@
try {
method = targetClass.getDeclaredMethod(methodName, parameterType);
method.setAccessible(true);
+ break;
} catch (NoSuchMethodException e1) {
- return false;
}

targetClass = targetClass.getSuperclass();
} while (targetClass != null);

+ if (targetClass == null) {
+ return false;
+ }
+
// Ignore any native code event handling methods
if ((method.getModifiers() & Modifier.NATIVE) != 0) {
return false;

Loading...