Skip to content

Commit cf40eb4

Browse files
authored
Merge pull request #540 from AAVSO/457-operandtoobject-should-call-operandconvert-for-list-elements
457 operandtoobject should call operandconvert for list elements
2 parents b85bbef + fbbd950 commit cf40eb4

File tree

6 files changed

+579
-203
lines changed

6 files changed

+579
-203
lines changed

src/org/aavso/tools/vstar/ui/vela/VeLaDialog.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,27 @@ public void keyTyped(KeyEvent e) {
182182
if (escapeMode) {
183183
switch (ch) {
184184
case 'b':
185+
case 'B':
185186
// Boolean set
186187
newCh = "\uD835\uDD39";
187188
break;
188189
case 'l':
190+
case 'L':
189191
// lambda
190192
newCh = "\u03BB";
191193
break;
192194
case 'p':
195+
case 'P':
193196
// pi
194197
newCh = "\u03C0";
195198
break;
196199
case 'r':
200+
case 'R':
197201
// real number set
198202
newCh = "\u211D";
199203
break;
200204
case 'z':
205+
case 'Z':
201206
// integer number set
202207
newCh = "\u2124";
203208
break;
@@ -266,10 +271,14 @@ private void execute() {
266271
output += result.get().toHumanReadableString();
267272
}
268273
} catch (Exception e) {
274+
// e.printStackTrace();
275+
269276
// Show error in text area.
270277
String msg = e.getLocalizedMessage();
271278
if (msg != null) {
272279
error = msg;
280+
} else {
281+
error = "Error";
273282
}
274283

275284
if (msg != null && !msg.equals(errStream.toString())) {

src/org/aavso/tools/vstar/vela/JavaMethodExecutor.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package org.aavso.tools.vstar.vela;
1919

20-
import java.lang.reflect.InvocationTargetException;
2120
import java.lang.reflect.Method;
2221
import java.lang.reflect.Modifier;
2322
import 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

Comments
 (0)