use of org.metaborg.core.action.NamedGoal in project spoofax by metaborg.
the class ActionFacetFromESV method menu.
private static Menu menu(IStrategoTerm menuTerm, TransformActionFlags flags, ImmutableList<String> nesting, Multimap<ITransformGoal, ITransformAction> actions) {
final String name = name(menuTerm.getSubterm(0));
final ImmutableList<String> newNesting = ImmutableList.<String>builder().addAll(nesting).add(name).build();
final TransformActionFlags extraFlags = flags(menuTerm.getSubterm(1));
final TransformActionFlags mergedFlags = TransformActionFlags.merge(flags, extraFlags);
final Iterable<IStrategoTerm> items = menuTerm.getSubterm(2);
final Menu menu = new Menu(name);
for (IStrategoTerm item : items) {
final String constructor = Tools.constructorName(item);
if (constructor == null) {
logger.error("Could not interpret menu item from term {}", item);
continue;
}
switch(constructor) {
case "Submenu":
final Menu submenu = menu(item, mergedFlags, newNesting, actions);
menu.add(submenu);
break;
case "Action":
final String actionName = name(item.getSubterm(0));
final String strategy = Tools.asJavaString(item.getSubterm(1).getSubterm(0));
final TransformActionFlags actionFlags = flags(item.getSubterm(2));
final TransformActionFlags mergedActionFlags = TransformActionFlags.merge(mergedFlags, actionFlags);
final ImmutableList<String> newActionNesting = ImmutableList.<String>builder().addAll(newNesting).add(actionName).build();
final NamedGoal goal = new NamedGoal(newActionNesting);
final TransformAction action = new TransformAction(actionName, goal, mergedActionFlags, strategy);
actions.put(goal, action);
actions.put(new EndNamedGoal(goal.names.get(goal.names.size() - 1)), action);
final MenuAction menuAction = new MenuAction(action);
menu.add(menuAction);
break;
case "Separator":
final Separator separator = new Separator();
menu.add(separator);
break;
default:
logger.warn("Unhandled menu item term {}", item);
break;
}
}
return menu;
}
Aggregations