1717 */
1818package org .aavso .tools .vstar .vela ;
1919
20- import java .lang .reflect .InvocationTargetException ;
2120import java .lang .reflect .Method ;
2221import java .lang .reflect .Modifier ;
2322import java .util .ArrayList ;
@@ -66,7 +65,7 @@ public Optional<Operand> apply(List<Operand> operands) throws VeLaEvalError {
6665 }
6766
6867 private Optional <Operand > invokeJavaMethod (Method method , List <Operand > operands , Optional <Type > retType ) {
69- Operand result = null ;
68+ Optional < Operand > retVal = null ;
7069
7170 try {
7271 // obj is null for static methods
@@ -76,7 +75,8 @@ private Optional<Operand> invokeJavaMethod(Method method, List<Operand> operands
7675 // For non-static methods, if instance is null, assume the first
7776 // operand is an object instance.
7877 if (instance == null ) {
79- obj = operands .get (0 ).toObject (method .getClass ());
78+ Operand op = operands .get (0 );
79+ obj = operands .get (0 ).toObject (Type .vela2Java (op .getType ()));
8080 operands .remove (0 );
8181 } else {
8282 // ...otherwise, use what's been passed in.
@@ -93,23 +93,21 @@ private Optional<Operand> invokeJavaMethod(Method method, List<Operand> operands
9393 paramIndex ++;
9494 }
9595
96- result = Operand .object2Operand (retType .get (), method .invoke (obj , objParams ));
96+ Operand result = Operand .object2Operand (retType .get (), method .invoke (obj , objParams ));
9797
98- Optional < Operand > retVal = null ;
98+ retVal = null ;
9999
100100 if (result != null ) {
101101 retVal = Optional .of (result );
102102 } else {
103103 retVal = Optional .of (Operand .NO_VALUE );
104104 }
105105
106- return retVal ;
107-
108- } catch (InvocationTargetException e ) {
109- throw new VeLaEvalError (e .getLocalizedMessage ());
110- } catch (IllegalAccessException e ) {
111- throw new VeLaEvalError (e .getLocalizedMessage ());
106+ } catch (Exception e ) {
107+ throwVeLaEvalError (e );
112108 }
109+
110+ return retVal ;
113111 }
114112
115113 @ Override
@@ -122,7 +120,7 @@ protected String getParametersString() {
122120 StringBuffer paramsBuf = new StringBuffer ();
123121
124122 for (int i = 0 ; i < parameterTypes .size (); i ++) {
125- // Note: when we can get real names from Javadoc, re-enable
123+ // Note: when we can get real names from Javadoc, re-enable this
126124// paramsBuf.append(parameterNames.get(i - 1));
127125// paramsBuf.append(":");
128126 paramsBuf .append (parameterTypes .get (i ));
@@ -134,4 +132,17 @@ protected String getParametersString() {
134132
135133 return paramsStr ;
136134 }
135+
136+ // Helpers
137+
138+ private void throwVeLaEvalError (Exception e ) throws VeLaEvalError {
139+ String msg = e .getLocalizedMessage ();
140+ if (msg == null ) {
141+ msg = "Intrinsic function invocation error" ;
142+ if (funcName .isPresent ()) {
143+ msg += ": " + funcName .get ();
144+ }
145+ }
146+ throw new VeLaEvalError (msg );
147+ }
137148}
0 commit comments