#67 Problem with lisp->java interface

closed-fixed
nobody
Lisp (13)
5
2003-11-09
2003-11-09
No

In the current CVS version the following:

CL-USER(1): (java:jmethod "java.sql.Connection"
"createStatement")

yields:

#<JAVAOBJECT java.lang.reflect.Method "public abstract
java.sql.Statement
java.sql.Connection.createStatement(int,int,int) throws
java.sql.SQLException">

It should yield the correct default (no parameters):

#<JAVAOBJECT java.lang.reflect.Method "public abstract
java.sql.Statement java.sql.Connection.createStatement()
throws java.sql.SQLException">

The solution is to modify the jmethod function in Java.java
like so:

// ### jmethod
// jmethod class-ref name &rest parameter-class-names
private static final Primitive JMETHOD = new
Primitive("jmethod", PACKAGE_JAVA)
{
public LispObject execute(LispObject[] args) throws
ConditionThrowable
{
if (args.length < 2)
throw new ConditionThrowable(new
WrongNumberOfArgumentsException(this));
String className = LispString.getValue(args[0]);
String methodName = LispString.getValue(args[1]);
try {
final Class c = Class.forName(className);
int argCount = -1;
if (args.length == 3 && args[2] instanceof
Fixnum) {
argCount = Fixnum.getValue(args[2]);
} else if (args.length > 2) {
Class[] parameterTypes = new
Class[args.length-2];
for (int i = 2; i < args.length; i++) {
className = LispString.getValue(args[i]);
parameterTypes[i-2] =
forName(className);
}
return new
JavaObject(c.getMethod(methodName,
parameterTypes));
}
if (argCount < 0) argCount = 0; // ***FIX***
// Parameter types not explicitly specified.
Method[] methods = c.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals(methodName))
{
if (argCount >= 0) {
Class[] parameterTypes =
method.getParameterTypes();
if (parameterTypes.length == argCount)
return new JavaObject(method);
} else
return new JavaObject(method);
}
}
throw new ConditionThrowable(new LispError("no
such method"));
}
catch (ClassNotFoundException e) {
throw new ConditionThrowable(new
LispError("class not found: " + className));
}
catch (NoSuchMethodException e) {
throw new ConditionThrowable(new LispError("no
such method"));
}
catch (Throwable t) {
throw new ConditionThrowable(new
LispError(getMessage(t)));
}
}
};

Discussion

  • Peter Graves

    Peter Graves - 2003-11-09

    Logged In: YES
    user_id=558172

    Fixed in current CVS. Thanks!

     
  • Peter Graves

    Peter Graves - 2003-11-09
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks