From 9c8360dd315bdb38203be40fd7e84b76fcf283cb Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Wed, 20 Dec 2023 11:21:34 +0100 Subject: [PATCH] also verify error's position for parameter INVALID_USE_OF_TYPE --- .../xtend/core/tests/AbstractXtendTestCase.java | 13 +++++++++++-- .../core/tests/validation/XtendValidationTest.java | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/AbstractXtendTestCase.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/AbstractXtendTestCase.java index be4a2d97b03..f26fec70098 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/AbstractXtendTestCase.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/AbstractXtendTestCase.java @@ -56,10 +56,19 @@ public abstract class AbstractXtendTestCase extends Assert { @Rule @Inject public TemporaryFolder temporaryFolder; - + @Inject private Provider resourceSetProvider; + /** + * To build a function or constructor for tests + */ + protected static final String TEMPLATE_CLASS = "class Foo { %s }"; + /** + * Use it to subtract from the index position of a source element of a function or constructor + */ + protected static final int TEMPLATE_CLASS_SIZE = TEMPLATE_CLASS.length() - 2; // 2 is the length of placeholder %s + protected XtendClass clazz(String string) throws Exception { return (XtendClass) file(string).getXtendTypes().get(0); } @@ -160,7 +169,7 @@ protected XtendEnum enumeration(String string) throws Exception { } protected XtendFunction function(String string) throws Exception { - XtendClass clazz = clazz("class Foo { " + string + "}"); + XtendClass clazz = clazz(String.format(TEMPLATE_CLASS, string)); return (XtendFunction) clazz.getMembers().get(0); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java index 00a90558671..0ff592d079a 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java @@ -589,8 +589,11 @@ public void clearPreferences() { } @Test public void testParameterTypeMayNotBeVoid() throws Exception { - XtendFunction function = function("def void foo(void myParam) { }"); - helper.assertError(function, TypesPackage.Literals.JVM_TYPE_REFERENCE, INVALID_USE_OF_TYPE); + var source = "def void foo(void myParam) { }"; + XtendFunction function = function(source); + helper.assertError(function, TypesPackage.Literals.JVM_TYPE_REFERENCE, + INVALID_USE_OF_TYPE, + source.lastIndexOf("void") - TEMPLATE_CLASS_SIZE, "void".length()); } @Test public void testVarArgIsNotExtension() throws Exception {