Search in sources :

Example 1 with IIterable

use of org.eclipse.core.expressions.IIterable in project eclipse.platform.runtime by eclipse.

the class Expressions method getAsIIterable.

/**
 * Converts the given variable into an <code>IIterable</code>. If a corresponding adapter can't be found an
 * exception is thrown. If the corresponding adapter isn't loaded yet, <code>null</code> is returned.
 *
 * @param var the variable to turn into an <code>IIterable</code>
 * @param expression the expression referring to the variable
 *
 * @return the <code>IIterable</code> or <code>null<code> if a corresponding adapter isn't loaded yet
 *
 * @throws CoreException if the var can't be adapted to an <code>IIterable</code>
 */
public static IIterable<?> getAsIIterable(Object var, Expression expression) throws CoreException {
    if (var instanceof IIterable) {
        return (IIterable<?>) var;
    } else {
        IAdapterManager manager = Platform.getAdapterManager();
        IIterable<?> result = manager.getAdapter(var, IIterable.class);
        if (result != null)
            return result;
        if (manager.queryAdapter(var, IIterable.class.getName()) == IAdapterManager.NOT_LOADED)
            return null;
        throw new CoreException(new ExpressionStatus(ExpressionStatus.VARIABLE_IS_NOT_A_COLLECTION, Messages.format(ExpressionMessages.Expression_variable_not_iterable, expression.toString())));
    }
}
Also used : IIterable(org.eclipse.core.expressions.IIterable) CoreException(org.eclipse.core.runtime.CoreException) IAdapterManager(org.eclipse.core.runtime.IAdapterManager)

Aggregations

IIterable (org.eclipse.core.expressions.IIterable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdapterManager (org.eclipse.core.runtime.IAdapterManager)1