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);
  }
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 ) ; }
Find the index of the type of a model element in a list of element types

@param modelElement the model element which type is searched for
@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