diff --git a/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/interpreter/NullTestCase.xtend b/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/interpreter/NullTestCase.xtend index 0df55a0564..94de37884c 100644 --- a/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/interpreter/NullTestCase.xtend +++ b/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/interpreter/NullTestCase.xtend @@ -27,8 +27,8 @@ class NullTestCase extends AbstractWollokInterpreterTestCase { ''' «defineAssertWithMessage» program a { - extendedAssert.assertException({ null.sayHi() }, "Cannot send message sayHi() to null") - extendedAssert.assertException({ null.toString() }, "Cannot send message toString() to null") + extendedAssert.assertException({ null.sayHi() }, "Wrong message sayHi() sent to null") + extendedAssert.assertException({ null.toString() }, "Wrong message toString() sent to null") } '''.interpretPropagatingErrors } @@ -38,10 +38,10 @@ class NullTestCase extends AbstractWollokInterpreterTestCase { ''' «defineAssertWithMessage» program a { - extendedAssert.assertException({ null + 3 }, "Cannot send message + to null") - extendedAssert.assertException({ null - 3 }, "Cannot send message - to null") - extendedAssert.assertException({ null * 3 }, "Cannot send message * to null") - extendedAssert.assertException({ null / 3 }, "Cannot send message / to null") + extendedAssert.assertException({ null + 3 }, "Wrong message + sent to null") + extendedAssert.assertException({ null - 3 }, "Wrong message - sent to null") + extendedAssert.assertException({ null * 3 }, "Wrong message * sent to null") + extendedAssert.assertException({ null / 3 }, "Wrong message / sent to null") } '''.interpretPropagatingErrors } @@ -51,8 +51,8 @@ class NullTestCase extends AbstractWollokInterpreterTestCase { ''' «defineAssertWithMessage» program a { - extendedAssert.assertException({ null || null }, "Cannot send message || to null") - extendedAssert.assertException({ null && null }, "Cannot send message && to null") + extendedAssert.assertException({ null || null }, "Wrong message || sent to null") + extendedAssert.assertException({ null && null }, "Wrong message && sent to null") } '''.interpretPropagatingErrorsWithoutStaticChecks } diff --git a/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/xpect/CheckMessagesToWKO.wlk.xt b/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/xpect/CheckMessagesToWKO.wlk.xt index 47371e08a5..fd9cf7cbdb 100644 --- a/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/xpect/CheckMessagesToWKO.wlk.xt +++ b/org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/xpect/CheckMessagesToWKO.wlk.xt @@ -8,13 +8,13 @@ class Persona { // XPECT errors --> "Wrong message fooBar() sent to pepita" at "fooBar" pepita.fooBar() - // XPECT errors --> "Wrong message fooBar(param1, param2) sent to pepita" at "fooBar" + // XPECT errors --> "Wrong message fooBar(2, "hola") sent to pepita" at "fooBar" pepita.fooBar(2, "hola") // XPECT errors --> "Wrong argument count in message fooWithParam() sent to pepita, however similar definitions exist: fooWithParam(p)" at "fooWithParam" pepita.fooWithParam() - // XPECT errors --> "Wrong argument count in message fooWithParam(param1, param2, param3) sent to pepita, however similar definitions exist: fooWithParam(p)" at "fooWithParam" + // XPECT errors --> "Wrong argument count in message fooWithParam(new Date(), 2, 4) sent to pepita, however similar definitions exist: fooWithParam(p)" at "fooWithParam" pepita.fooWithParam(new Date(), 2, 4) // XPECT errors --> "Wrong case-sensitive message foO() sent to pepita. Use foo()" at "foO" @@ -23,7 +23,7 @@ class Persona { // XPECT errors --> "Wrong argument count in message severalDef() sent to pepita, however similar definitions exist: severalDef(a), severalDef(a, b)" at "severalDef" pepita.severalDef() - // XPECT errors --> "Wrong argument count in message severalDef(param1, param2, param3, param4) sent to pepita, however similar definitions exist: severalDef(a), severalDef(a, b)" at "severalDef" + // XPECT errors --> "Wrong argument count in message severalDef(1, 2, 3, 4) sent to pepita, however similar definitions exist: severalDef(a), severalDef(a, b)" at "severalDef" pepita.severalDef(1, 2, 3, 4) } } diff --git a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/Messages.java b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/Messages.java index 21cd928d99..1ebee9e7b2 100644 --- a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/Messages.java +++ b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/Messages.java @@ -15,6 +15,11 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.uqbar.project.wollok.messages"; //$NON-NLS-1$ public static String LINKING_COULD_NOT_RESOLVE_REFERENCE; + + public static String WollokInterpreter_cannot_use_null_in_if; + public static String WollokInterpreter_expression_in_if_must_evaluate_to_boolean; + + public static String WollokNativeLobby_cannot_use_self_in_program; public static String WollokDslValidator_CLASS_NAME_MUST_START_UPPERCASE; public static String WollokDslValidator_REFERENCIABLE_NAME_MUST_START_LOWERCASE; diff --git a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/WollokInterpreterEvaluator.xtend b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/WollokInterpreterEvaluator.xtend index 7873dbc874..4040f9506b 100644 --- a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/WollokInterpreterEvaluator.xtend +++ b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/WollokInterpreterEvaluator.xtend @@ -7,6 +7,8 @@ import java.util.List import java.util.Map import org.eclipse.emf.common.util.EList import org.eclipse.emf.ecore.EObject +import org.eclipse.osgi.util.NLS +import org.uqbar.project.wollok.Messages import org.uqbar.project.wollok.interpreter.api.XInterpreterEvaluator import org.uqbar.project.wollok.interpreter.context.UnresolvableReference import org.uqbar.project.wollok.interpreter.core.CallableSuper @@ -64,7 +66,6 @@ import static extension org.uqbar.project.wollok.interpreter.context.EvaluationC import static extension org.uqbar.project.wollok.interpreter.nativeobj.WollokJavaConversions.* import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.* import static extension org.uqbar.project.wollok.model.WollokModelExtensions.* -import static extension org.uqbar.project.xtext.utils.XTextExtensions.sourceCode /** * It's the real "interpreter". @@ -153,11 +154,11 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator // I18N ! if (cond === null) { - throw newWollokExceptionAsJava('''Cannot use null in 'if' expression''') + throw newWollokExceptionAsJava(NLS.bind(Messages.WollokInterpreter_cannot_use_null_in_if, NULL)) } if (!(cond.isWBoolean)) - throw new WollokInterpreterException('''Expression in 'if' must evaluate to a boolean. Instead got: «cond» («cond?.class.name»)''', - it) + throw new WollokInterpreterException(NLS.bind(Messages.WollokInterpreter_expression_in_if_must_evaluate_to_boolean, cond, cond?.class.name), it) + if (wollokToJava(cond, Boolean) == Boolean.TRUE) then.eval else @@ -394,7 +395,7 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator private def validateNullOperand(WollokObject leftOperand, String operation) { if (leftOperand === null && !#["==", "!=", "===", "!=="].contains(operation)) { - throw newWollokExceptionAsJava('''Cannot send message «operation» to null''') + throw newWollokExceptionAsJava(NLS.bind(Messages.WollokDslValidator_METHOD_DOESNT_EXIST, NULL, operation)) } } @@ -433,7 +434,7 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator def dispatch evaluate(WFeatureCall call) { val target = call.evaluateTarget if (target === null) - throw newWollokExceptionAsJava('''Cannot send message «call.feature»(«call.memberCallArguments.map[sourceCode].join(',')») to null''') + throw newWollokExceptionAsJava(NLS.bind(Messages.WollokDslValidator_METHOD_DOESNT_EXIST, NULL, call.fullMessage)) target.call(call.feature, call.memberCallArguments.evalEach) } diff --git a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokNativeLobby.xtend b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokNativeLobby.xtend index 3f1f1faaf9..7e030e5e0d 100644 --- a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokNativeLobby.xtend +++ b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokNativeLobby.xtend @@ -1,7 +1,7 @@ package org.uqbar.project.wollok.interpreter.core import java.util.Map -import org.eclipse.xtend.lib.annotations.Accessors +import org.uqbar.project.wollok.Messages import org.uqbar.project.wollok.interpreter.WollokInterpreter import org.uqbar.project.wollok.interpreter.WollokInterpreterConsole import org.uqbar.project.wollok.interpreter.context.EvaluationContext @@ -29,7 +29,7 @@ class WollokNativeLobby extends AbstractWollokDeclarativeNativeObject implements this.console = console } - override getThisObject() { throw new UnsupportedOperationException("Cannot use reference to self in a program's code !")} + override getThisObject() { throw new UnsupportedOperationException(Messages.WollokNativeLobby_cannot_use_self_in_program)} override allReferenceNames() { localProgramVariables.keySet.map[new WVariable(it, true)] diff --git a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokObject.xtend b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokObject.xtend index b88b13ad92..781f20b171 100644 --- a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokObject.xtend +++ b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/interpreter/core/WollokObject.xtend @@ -70,13 +70,19 @@ class WollokObject extends AbstractWollokCallable implements EvaluationContext