Skip to content

Commit

Permalink
additional test for Duplicate interface
Browse files Browse the repository at this point in the history
When the language automatically adds a supertype
  • Loading branch information
LorenzoBettini committed Feb 8, 2024
1 parent f717a7f commit d76bf84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ protected void inferClassWithSuperTypes(MyClassWithSuperTypes myClass, IJvmDecla
(JvmGenericType it) -> {
jvmTypesBuilder.setDocumentation(it, jvmTypesBuilder.getDocumentation(myClass));
var superTypes = myClass.getSuperTypes();
it.getSuperTypes().add(typeReferences.getTypeForName(Serializable.class, myClass));
for (int i = 0; i < superTypes.size(); i++) {
if (i == 0) {
jvmTypesBuilder.setSuperClass(it, superTypes.get(i));
} else {
jvmTypesBuilder.addSuperInterface(it, superTypes.get(i));
}
}
it.getSuperTypes().add(typeReferences.getTypeForName(Serializable.class, myClass));
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ public class JvmGenericTypeValidatorTest {
"Duplicate interface Serializable for the type Foo");
}

@Test public void testDuplicateImplementedInterfacesWithImplicitInterface() throws Exception {
// this class construct automatically has Serializable as a supertype
var source = "import java.io.Serializable\n"
+ "classWithSuperTypes Foo superTypes "
+ "Object, java.io.Serializable, Cloneable, Serializable {}";
var model = parse(source);
validationHelper.assertError(model, MY_CLASS_WITH_SUPER_TYPES, DUPLICATE_INTERFACE,
source.lastIndexOf("java.io.Serializable"), "java.io.Serializable".length(),
"Duplicate interface Serializable for the type Foo");
validationHelper.assertError(model, MY_CLASS_WITH_SUPER_TYPES, DUPLICATE_INTERFACE,
source.lastIndexOf("Serializable"), "Serializable".length(),
"Duplicate interface Serializable for the type Foo");
}

@Test public void testCheckSuperTypesWithClassWithSuperTypes() throws Exception {
// the first supertype must be a class, and then the other ones interfaces
var source = "classWithSuperTypes Foo superTypes Cloneable, Object {}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ protected void checkSuperTypes(EObject sourceType, JvmGenericType type) {
for (int i = 0; i < superTypes.size(); ++i) {
JvmTypeReference extendedType = superTypes.get(i);
var associated = getSuperTypeSourceElement(extendedType);
if (associated == null)
if (associated == null) {
// we still record this supertype for possible duplication checks
seen.add(extendedType.getIdentifier());
continue; // synthetic superclass (e.g., Object)
}
var eContainingFeature = associated.eContainingFeature();
int featureIndex = INSIGNIFICANT_INDEX;
multiFeatureIndex++;
Expand Down

0 comments on commit d76bf84

Please sign in to comment.