Skip to content

Commit

Permalink
also verify error position for anonymous class' members
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Jan 8, 2024
1 parent 96d25ab commit aff64b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,41 @@ class ValidationBug435020Test extends AbstractXtendTestCase {
}

@Test def void test_02() {
val c = parser.parse('''
val source = '''
class Foo {
def void foo() {
new Object {
static var x = 1
}
}
}
''')
c.assertError(XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD)
'''
val c = parser.parse(source)
c.assertError(XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD,
source.indexOf("static"), "static".length,
"A static field of an anonymous class must be final"
)
}

@Test def void test_03() {
val c = parser.parse('''
val source = '''
class Foo {
def void foo() {
new Object {
static val x = Math.max(1, 2)
}
}
}
''')
c.assertError(XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD)
'''
val c = parser.parse(source)
c.assertError(XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD,
source.indexOf("Math.max(1, 2)"), "Math.max(1, 2)".length,
"must be initialized with a constant expression"
)
}

@Test def void test_04() {
val c = parser.parse('''
val source = '''
class Foo {
def void foo() {
new Object {
Expand All @@ -77,8 +85,12 @@ class ValidationBug435020Test extends AbstractXtendTestCase {
}
}
}
''')
c.assertError(XtendPackage.Literals.XTEND_FUNCTION, IssueCodes.ANONYMOUS_CLASS_STATIC_METHOD)
'''
val c = parser.parse(source)
c.assertError(XtendPackage.Literals.XTEND_FUNCTION, IssueCodes.ANONYMOUS_CLASS_STATIC_METHOD,
source.indexOf("static"), "static".length,
"A method of an anonymous class cannot be static"
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public void test_02() {
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile c = this.parser.parse(_builder);
this.helper.assertError(c, XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD);
final String source = _builder.toString();
final XtendFile c = this.parser.parse(source);
this.helper.assertError(c, XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD,
source.indexOf("static"), "static".length(),
"A static field of an anonymous class must be final");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
Expand Down Expand Up @@ -124,8 +127,11 @@ public void test_03() {
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile c = this.parser.parse(_builder);
this.helper.assertError(c, XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD);
final String source = _builder.toString();
final XtendFile c = this.parser.parse(source);
this.helper.assertError(c, XtendPackage.Literals.XTEND_FIELD, IssueCodes.ANONYMOUS_CLASS_STATIC_FIELD,
source.indexOf("Math.max(1, 2)"), "Math.max(1, 2)".length(),
"must be initialized with a constant expression");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
Expand Down Expand Up @@ -157,8 +163,11 @@ public void test_04() {
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile c = this.parser.parse(_builder);
this.helper.assertError(c, XtendPackage.Literals.XTEND_FUNCTION, IssueCodes.ANONYMOUS_CLASS_STATIC_METHOD);
final String source = _builder.toString();
final XtendFile c = this.parser.parse(source);
this.helper.assertError(c, XtendPackage.Literals.XTEND_FUNCTION, IssueCodes.ANONYMOUS_CLASS_STATIC_METHOD,
source.indexOf("static"), "static".length(),
"A method of an anonymous class cannot be static");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
Expand Down

0 comments on commit aff64b8

Please sign in to comment.