Search in sources :

Example 1 with RefBool

use of org.metaborg.util.RefBool in project spoofax by metaborg.

the class Builder method updateLanguageResources.

private Collection<FileObject> updateLanguageResources(BuildInput input, ILanguageImpl language, LanguageBuildDiff diff, IBuildOutputInternal<P, A, AU, T> output, boolean pardoned, IProgress progress, ICancel cancel) throws InterruptedException {
    cancel.throwIfCancelled();
    final boolean analyze = input.analyze && analysisService.available(language);
    final boolean transform = input.transform;
    progress.setWorkRemaining(10 + (analyze ? 45 : 0) + (transform ? 45 : 0));
    final Iterable<IdentifiedResourceChange> sourceChanges = diff.sourceChanges;
    final Iterable<IdentifiedResourceChange> includeChanges = diff.includeChanges;
    final Set<FileName> includes = Sets.newHashSet();
    for (IdentifiedResourceChange includeChange : includeChanges) {
        includes.add(includeChange.change.resource.getName());
    }
    final FileObject location = input.project.location();
    final Collection<FileObject> changedSources = Sets.newHashSet();
    final Set<FileName> removedResources = Sets.newHashSet();
    final Collection<IMessage> extraMessages = Lists.newLinkedList();
    final RefBool success = new RefBool(true);
    logger.info("Building {} sources, {} includes of {}", Iterables.size(sourceChanges), Iterables.size(includeChanges), language);
    // Parse
    cancel.throwIfCancelled();
    final Collection<P> sourceParseUnits = parse(input, language, sourceChanges, pardoned, changedSources, removedResources, extraMessages, success, progress.subProgress(5), cancel);
    // GTODO: when a new context is created, all include files need to be parsed and analyzed in that context, this
    // approach does not do that!
    final Collection<P> includeParseUnits = parse(input, language, includeChanges, pardoned, changedSources, removedResources, extraMessages, success, progress.subProgress(5), cancel);
    final Iterable<P> allParseResults = Iterables.concat(sourceParseUnits, includeParseUnits);
    // Analyze
    cancel.throwIfCancelled();
    final Multimap<IContext, A> allAnalyzeUnits;
    final Collection<AU> allAnalyzeUpdates = Lists.newArrayList();
    if (analyze) {
        // Segregate by context
        final Multimap<IContext, P> parseUnitsPerContext = ArrayListMultimap.create();
        for (P parseResult : sourceParseUnits) {
            cancel.throwIfCancelled();
            final FileObject resource = parseResult.source();
            final ILanguageImpl langImpl = parseResult.input().langImpl();
            try {
                if (contextService.available(langImpl)) {
                    final IContext context = contextService.get(resource, input.project, langImpl);
                    parseUnitsPerContext.put(context, parseResult);
                }
            } catch (ContextException e) {
                final String message = String.format("Failed to retrieve context for parse result of %s", resource);
                printMessage(resource, message, e, input, pardoned);
                extraMessages.add(MessageFactory.newAnalysisErrorAtTop(resource, "Failed to retrieve context", e));
            }
        }
        // Run analysis
        cancel.throwIfCancelled();
        allAnalyzeUnits = analyze(input, language, location, parseUnitsPerContext, includeParseUnits, pardoned, allAnalyzeUpdates, removedResources, extraMessages, success, progress.subProgress(45), cancel);
    } else {
        allAnalyzeUnits = ArrayListMultimap.create();
    }
    // Transform
    cancel.throwIfCancelled();
    final Collection<T> allTransformUnits;
    if (transform) {
        allTransformUnits = transform(input, language, location, allAnalyzeUnits, includes, pardoned, removedResources, extraMessages, success, progress.subProgress(45), cancel);
    } else {
        allTransformUnits = Lists.newLinkedList();
    }
    printMessages(extraMessages, "Something", input, pardoned);
    output.add(success.get(), removedResources, includes, changedSources, allParseResults, allAnalyzeUnits.values(), allAnalyzeUpdates, allTransformUnits, extraMessages);
    final Collection<FileObject> newResources = Lists.newArrayList();
    for (T transformUnit : allTransformUnits) {
        for (ITransformOutput transformOutput : transformUnit.outputs()) {
            final FileObject outputFile = transformOutput.output();
            if (outputFile != null) {
                newResources.add(outputFile);
            }
        }
    }
    return newResources;
}
Also used : ITransformOutput(org.metaborg.core.transform.ITransformOutput) IContext(org.metaborg.core.context.IContext) FileName(org.apache.commons.vfs2.FileName) IdentifiedResourceChange(org.metaborg.core.resource.IdentifiedResourceChange) ContextException(org.metaborg.core.context.ContextException) FileObject(org.apache.commons.vfs2.FileObject) IMessage(org.metaborg.core.messages.IMessage) RefBool(org.metaborg.util.RefBool) ILanguageImpl(org.metaborg.core.language.ILanguageImpl)

Aggregations

FileName (org.apache.commons.vfs2.FileName)1 FileObject (org.apache.commons.vfs2.FileObject)1 ContextException (org.metaborg.core.context.ContextException)1 IContext (org.metaborg.core.context.IContext)1 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)1 IMessage (org.metaborg.core.messages.IMessage)1 IdentifiedResourceChange (org.metaborg.core.resource.IdentifiedResourceChange)1 ITransformOutput (org.metaborg.core.transform.ITransformOutput)1 RefBool (org.metaborg.util.RefBool)1