Skip to content

Commit

Permalink
[lang] Add 'abstract' modifier to the event type.
Browse files Browse the repository at this point in the history
close #1069

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Apr 13, 2021
1 parent 1374a29 commit d2c1402
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1278,11 +1278,10 @@ protected void initialize(SarlEvent source, JvmGenericType inferredJvmType) {
// Change the modifiers on the generated type.
setVisibility(inferredJvmType, source);
inferredJvmType.setStatic(false);
inferredJvmType.setAbstract(false);
final boolean isAbstract = source.isAbstract() || Utils.hasAbstractMember(source);
inferredJvmType.setAbstract(isAbstract);
inferredJvmType.setStrictFloatingPoint(false);
if (!inferredJvmType.isAbstract()) {
inferredJvmType.setFinal(source.isFinal());
}
inferredJvmType.setFinal(!isAbstract && source.isFinal());

// Generate the annotations.
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public class SARLValidator extends AbstractSARLValidator {

@SuppressWarnings("synthetic-access")
private final SARLModifierValidator eventModifierValidator = new SARLModifierValidator(
newArrayList("public", "package", "final")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
newArrayList("public", "package", "final", "abstract")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$

@SuppressWarnings("synthetic-access")
private final SARLModifierValidator fieldInEventModifierValidator = new SARLModifierValidator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,39 @@ public void eventmodifier_public() throws Exception {
""));
}

@Test
public void eventmodifier_abstract() throws Exception {
getCompileHelper().assertCompilesTo(
multilineString(
"abstract event E1"
),
multilineString(
"import io.sarl.lang.annotation.SarlElementType;",
"import io.sarl.lang.annotation.SarlSpecification;",
"import io.sarl.lang.annotation.SyntheticMember;",
"import io.sarl.lang.core.Address;",
"import io.sarl.lang.core.Event;",
"",
"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
"@SarlElementType(" + SarlPackage.SARL_EVENT + ")",
"@SuppressWarnings(\"all\")",
"public abstract class E1 extends Event {",
" @SyntheticMember",
" public E1() {",
" super();",
" }",
" ",
" @SyntheticMember",
" public E1(final Address arg0) {",
" super(arg0);",
" }",
" ",
" @SyntheticMember",
" private static final long serialVersionUID = 588368462L;",
"}",
""));
}

@Test
public void eventmodifier_package() throws Exception {
getCompileHelper().assertCompilesTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,22 @@ public void eventmodifier_package() throws Exception {
@Test
@Tag("sarlValidation")
public void eventmodifier_abstract() throws Exception {
SarlScript mas = file(getParseHelper(), multilineString(
SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
"package io.sarl.lang.tests.test",
"abstract event E1"
));
validate(getValidationHelper(), getInjector(), mas).assertError(
SarlPackage.eINSTANCE.getSarlEvent(),
org.eclipse.xtend.core.validation.IssueCodes.INVALID_MODIFIER);
assertEquals(1, mas.getXtendTypes().size());
//
assertEquals("io.sarl.lang.tests.test", mas.getPackage());
//
SarlEvent event = (SarlEvent) mas.getXtendTypes().get(0);
assertEquals("E1", event.getName());
assertNull(event.getExtends());
assertEquals(JvmVisibility.PUBLIC, event.getVisibility());
assertEquals(0, event.getMembers().size());
assertTrue(event.isAbstract());
assertFalse(event.isFinal());
assertFalse(event.isStatic());
}

@Test
Expand Down

0 comments on commit d2c1402

Please sign in to comment.