r2269 - trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding
Author: tchemit Date: 2011-04-21 17:23:08 +0200 (Thu, 21 Apr 2011) New Revision: 2269 Url: http://nuiton.org/repositories/revision/jaxx/2269 Log: try to obtain method return type with a fallback while finding bindings Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2011-04-21 15:15:55 UTC (rev 2268) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2011-04-21 15:23:08 UTC (rev 2269) @@ -368,7 +368,7 @@ if (log.isTraceEnabled()) { log.trace("method found = " + method); } - return method.getReturnType(); + return getMethodReturnType(contextClass, method); } catch (NoSuchMethodException e) { if (showLog()) { log.info("Could not find method " + methodName + ", code : " + code + " on : " + contextClass); @@ -852,4 +852,34 @@ // return prefix + "removePropertyChangeListener(" + propertyChangeListenerCode + ");\n"; // } } + + /** + * Given a method from a given context class, try to obtain his method + * return type. + * + * Sometimes, the return type is unknown (generics can not be bind for + * example). As a fallback, we try if the context class is exactly the + * root context class of the compiler, replace it by the script method with + * same name on which we can have more chance to obtain a return type... + * + * @param contextClass the context class of the method + * @param method the method + * @return the method return type + * @since 2.4.2 + */ + protected ClassDescriptor getMethodReturnType(ClassDescriptor contextClass, + MethodDescriptor method) { + ClassDescriptor returnType = method.getReturnType(); + if (returnType == null && + contextClass.equals(compiler.getRootObject().getObjectClass())) { + + // special case to deal with generics (we need to + // have the concrete type)... + method = compiler.getScriptMethod(method.getName()); + if (method != null) { + returnType = method.getReturnType(); + } + } + return returnType; + } } \ No newline at end of file
participants (1)
-
tchemit@users.nuiton.org