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