Skip to content

Commit

Permalink
Fixed allInstances(Set) documentation and added a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Feb 23, 2024
1 parent 6322c35 commit bc5661b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1682,14 +1682,14 @@ public List<EObject> allInstances(EClass type) {

// @formatter:off
@Documentation(
value = "Returns all instances of any EClass from the OrderedSet",
value = "Returns all instances of each EClass from the OrderedSet",
params = {
@Param(name = "types", value = "The OrderedSet of EClass"),
},
result = "all instances of any EClass from the OrderedSet",
result = "all instances of each EClass from the OrderedSet",
examples = {
@Example(
expression = "anEClass.allInstances({ecore::EPackage | ecore::EClass})",
expression = "{ecore::EPackage | ecore::EClass}->allInstances()",
result = "Sequence{ePackage, eClass, ...}"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,33 @@ public void allInstancesTest() {
assertEquals(0, validationResult.getMessages(((Call)ast).getArguments().get(0)).size());
}

@Test
public void allInstancesSetTest() {
final IValidationResult validationResult = engine.validate(
"{ecore::EPackage | ecore::EClass}->allInstances()", variableTypes);
final Expression ast = validationResult.getAstResult().getAst();
final Set<IType> possibleTypes = validationResult.getPossibleTypes(ast);

assertEquals(2, possibleTypes.size());
final Iterator<IType> it = possibleTypes.iterator();
IType possibleType = it.next();
assertTrue(possibleType instanceof SequenceType);
assertTrue(((SequenceType)possibleType).getCollectionType() instanceof EClassifierType);
assertEquals(EcorePackage.eINSTANCE.getEPackage(), ((EClassifierType)((SequenceType)possibleType)
.getCollectionType()).getType());

possibleType = it.next();
assertTrue(possibleType instanceof SequenceType);
assertTrue(((SequenceType)possibleType).getCollectionType() instanceof EClassifierType);
assertEquals(EcorePackage.eINSTANCE.getEClass(), ((EClassifierType)((SequenceType)possibleType)
.getCollectionType()).getType());

assertEquals(0, validationResult.getMessages().size());

assertEquals(0, validationResult.getMessages(ast).size());
assertEquals(0, validationResult.getMessages(((Call)ast).getArguments().get(0)).size());
}

/**
* Asserts the given {@link IValidationMessage} against expected values.
*
Expand Down

0 comments on commit bc5661b

Please sign in to comment.