use of org.metaborg.core.action.ITransformGoal in project spoofax by metaborg.
the class Builder method transform.
private Collection<T> transform(BuildInput input, ILanguageImpl langImpl, FileObject location, Multimap<IContext, A> allAnalysisUnits, Set<FileName> includeFiles, boolean pardoned, Set<FileName> removedResources, Collection<IMessage> extraMessages, RefBool success, IProgress progress, ICancel cancel) throws InterruptedException {
final int size = allAnalysisUnits.size();
progress.setWorkRemaining(size);
final Collection<T> allTransformUnits = Lists.newArrayListWithCapacity(size);
if (size == 0) {
return allTransformUnits;
}
progress.setDescription("Compiling " + size + " file(s) of " + langImpl.belongsTo().name());
logger.debug("Compiling {} analysis results", size);
for (Entry<IContext, Collection<A>> entry : allAnalysisUnits.asMap().entrySet()) {
cancel.throwIfCancelled();
final IContext context = entry.getKey();
final Iterable<A> analysisResults = entry.getValue();
try (IClosableLock lock = context.read()) {
for (A analysisResult : analysisResults) {
cancel.throwIfCancelled();
final FileObject source = analysisResult.source();
final FileName name = source.getName();
if (removedResources.contains(name) || includeFiles.contains(name)) {
// Don't compile removed resources, which the analysis results contain for legacy reasons.
// Don't transform included resources, they should just be parsed and analyzed.
progress.work(1);
continue;
}
if (!analysisResult.valid()) {
logger.warn("Input result for {} is invalid, cannot transform it", source != null ? source.getName().getPath() : "detached source");
progress.work(1);
continue;
}
for (ITransformGoal goal : input.transformGoals) {
cancel.throwIfCancelled();
if (!transformService.available(context, goal)) {
logger.trace("No {} transformation required for {}", goal, context.language());
progress.work(1);
continue;
}
try {
final Collection<TA> results = transformService.transform(analysisResult, context, goal);
for (TA result : results) {
final boolean noErrors = printMessages(result.messages(), goal + " transformation", input, pardoned);
success.and(noErrors);
@SuppressWarnings("unchecked") final T genericResult = (T) result;
allTransformUnits.add(genericResult);
}
progress.work(1);
} catch (TransformException e) {
final String message = String.format("Transformation failed unexpectedly for %s", name);
logger.error(message, e);
final boolean noErrors = printMessage(source, message, e, input, pardoned);
success.and(noErrors);
extraMessages.add(MessageFactory.newBuilderErrorAtTop(location, "Transformation failed unexpectedly", e));
}
}
}
// GTODO: also compile any affected sources
}
}
return allTransformUnits;
}
use of org.metaborg.core.action.ITransformGoal in project spoofax by metaborg.
the class ActionFacetFromESV method create.
@Nullable
public static ActionFacet create(IStrategoAppl esv) {
final Iterable<IStrategoAppl> menuTerms = ESVReader.collectTerms(esv, "ToolbarMenu");
final Collection<IMenu> menus = Lists.newLinkedList();
final Multimap<ITransformGoal, ITransformAction> actions = HashMultimap.create();
final ImmutableList<String> nesting = ImmutableList.of();
for (IStrategoAppl menuTerm : menuTerms) {
final IMenu submenu = menu(menuTerm, new TransformActionFlags(), nesting, actions);
menus.add(submenu);
}
addCompileGoal(esv, actions);
if (menus.isEmpty() && actions.isEmpty()) {
return null;
}
return new ActionFacet(actions, menus);
}
use of org.metaborg.core.action.ITransformGoal in project spoofax by metaborg.
the class ActionFacetFromESV method addCompileGoal.
private static void addCompileGoal(IStrategoAppl esv, Multimap<ITransformGoal, ITransformAction> actions) {
final List<IStrategoAppl> onSaveHandlers = ESVReader.collectTerms(esv, "OnSave");
if (onSaveHandlers.isEmpty()) {
return;
}
for (IStrategoAppl onSaveHandler : onSaveHandlers) {
final String strategyName = Tools.asJavaString(onSaveHandler.getSubterm(0).getSubterm(0));
final ITransformGoal goal = new CompileGoal();
final ITransformAction action = new TransformAction("Compile", goal, new TransformActionFlags(), strategyName);
actions.put(goal, action);
}
}
Aggregations