public static TypeMirror getCollectionParam( @NotNull TypeMirror type ) {
if ( !( type instanceof DeclaredType ) ) {
throw new IllegalStateException( "Invalid type: " + type );
}
TypeDeclaration declaredType = ( ( DeclaredType ) type ).getDeclaration();
if ( declaredType == null ) {
throw new IllegalStateException( "No declaration found for <" + type + ">" );
}
if ( isCollection( declaredType.getQualifiedName() ) ) {
return getFirstTypeParam( ( DeclaredType ) type );
}
for ( InterfaceType interfaceType : declaredType.getSuperinterfaces() ) {
if ( isCollection( interfaceType.getDeclaration().getQualifiedName() ) ) {
return getFirstTypeParam( ( DeclaredType ) type );
}
}