Search in sources :

Example 1 with IAction

use of org.metaborg.core.action.IAction in project spoofax by metaborg.

the class Menu method action.

@Override
@Nullable
public IAction action(String name) throws MetaborgException {
    final List<IAction> actions = Lists.newLinkedList();
    for (IMenuItem item : items) {
        if (item instanceof IMenuAction && name.equals(item.name())) {
            final IMenuAction menuAction = (IMenuAction) item;
            final IAction action = menuAction.action();
            actions.add(action);
        }
    }
    final int size = actions.size();
    if (size == 0) {
        return null;
    } else if (size > 1) {
        final String message = String.format("Found multiple actions with name %s: %s", name, Joiner.on(", ").join(actions));
        throw new MetaborgException(message);
    }
    return actions.get(0);
}
Also used : IAction(org.metaborg.core.action.IAction) MetaborgException(org.metaborg.core.MetaborgException) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 MetaborgException (org.metaborg.core.MetaborgException)1 IAction (org.metaborg.core.action.IAction)1