* @param childElementTypes the list to search the type
* @return the index of the model element type in the list or -1 if it is not found
*/
public static int getIndexOfElementType(ModelElementInstance modelElement, List<ModelElementType> childElementTypes) {
for (int index = 0; index < childElementTypes.size(); index++) {
ModelElementType childElementType = childElementTypes.get(index);
Class<? extends ModelElementInstance> instanceType = childElementType.getInstanceType();
if(instanceType.isAssignableFrom(modelElement.getClass())) {
return index;
}
}
Collection<String> childElementTypeNames = new ArrayList<String>();
for (ModelElementType childElementType : childElementTypes) {
childElementTypeNames.add(childElementType.getTypeName());
}
throw new ModelException("New child is not a valid child element type: " + modelElement.getElementType().getTypeName() + "; valid types are: " + childElementTypeNames);
}