use of org.metaborg.core.language.ILanguageImpl 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;
}
use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class BuildInputBuilder method build.
/**
* Builds a build input object from the current state.
*
* @throws MetaborgException
* When {@link IDependencyService#compileDeps} throws.
*/
public BuildInput build(IDependencyService dependencyService, ILanguagePathService languagePathService) throws MetaborgException {
if (state == null) {
state = new BuildState();
}
if (addDependencyLanguages) {
final Iterable<ILanguageComponent> compileComponents = dependencyService.compileDeps(this.project);
final Iterable<ILanguageImpl> compileImpls = LanguageUtils.toImpls(compileComponents);
addLanguages(compileImpls);
}
if (addDefaultIncludePaths) {
for (ILanguageImpl language : languages) {
addIncludePaths(language, languagePathService.includePaths(this.project, language.belongsTo().name()));
}
}
if (addSourcesFromDefaultSourceLocations) {
for (ILanguageImpl language : languages) {
final Iterable<IdentifiedResource> sources = languagePathService.sourceFiles(this.project, language);
addIdentifiedSources(sources);
}
}
for (ILanguageImpl language : languages) {
if (pardonedLanguageStrings.contains(language.belongsTo().name())) {
addPardonedLanguage(language);
}
}
return new BuildInput(state, this.project, sourceChanges, includePaths, new BuildOrder(languages), selector, analyze, analyzeSelector, transform, transformSelector, transformGoals, messagePrinter, throwOnErrors, pardonedLanguages);
}
use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class AnalysisService method analyzeAll.
@Override
public IAnalyzeResults<A, AU> analyzeAll(Iterable<P> inputs, IContext context, IProgress progress, ICancel cancel) throws AnalysisException, InterruptedException {
final ILanguageImpl langImpl = context.language();
final AnalyzerFacet<P, A, AU> facet = facet(langImpl);
if (facet == null) {
final String message = logger.format("Cannot get an analyzer for {}", langImpl);
throw new AnalysisException(context, message);
}
final IAnalyzer<P, A, AU> analyzer = facet.analyzer;
return analyzer.analyzeAll(inputs, context, progress, cancel);
}
use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class LanguageChangeProcessor method removedImpl.
/**
* Implementation was removed
*
* @param impl
* Removed implementation
*/
protected void removedImpl(ILanguageImpl impl) {
for (ILanguageCache languageCache : languageCaches) {
languageCache.invalidateCache(impl);
}
parseResultProcessor.invalidate(impl);
analysisResultProcessor.invalidate(impl);
final Iterable<IEditor> editors = editorRegistry.openEditors();
for (IEditor editor : editors) {
final ILanguageImpl language = editor.language();
if (language != null && language.equals(impl)) {
editor.reconfigure();
editor.disable();
}
}
}
use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class SyntaxService method parse.
@Override
public P parse(I input, IProgress progress, ICancel cancel) throws ParseException, InterruptedException {
final ILanguageImpl langImpl = input.langImpl();
final IParser<I, P> parser = parser(langImpl);
if (parser == null) {
final String message = logger.format("Cannot get a parser for {}", langImpl);
throw new ParseException(input, message);
}
return parser.parse(input, progress, cancel);
}
Aggregations