Search in sources :

Example 21 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class AnalysisResultProcessor method error.

@Override
public void error(Iterable<P> results, AnalysisException exception) {
    for (P parseResult : results) {
        final FileObject resource = parseResult.source();
        if (parseResult.detached()) {
            throw new MetaborgRuntimeException("Cannot process analysis errors for detached (no source) units");
        }
        final BehaviorSubject<AnalysisChange<A>> updates = getUpdates(resource.getName());
        updates.onNext(AnalysisChange.<A>error(resource, exception));
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) FileObject(org.apache.commons.vfs2.FileObject)

Example 22 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class AnalysisResultProcessor method update.

@Override
public void update(A result, Set<FileName> removedResources) {
    if (result.detached()) {
        throw new MetaborgRuntimeException("Cannot process updates for detached (no source) units");
    }
    final FileObject resource = result.source();
    final FileName name = resource.getName();
    if (removedResources.contains(name)) {
        remove(resource);
    } else {
        logger.trace("Pushing analysis result for {}", name);
        final BehaviorSubject<AnalysisChange<A>> updates = getUpdates(name);
        updates.onNext(AnalysisChange.update(resource, result));
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) FileName(org.apache.commons.vfs2.FileName) FileObject(org.apache.commons.vfs2.FileObject)

Example 23 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class TaskEngineAnalyzer method updateResult.

private ISpoofaxAnalyzeUnitUpdate updateResult(IStrategoTerm result, IContext context) {
    final String sourceString = Tools.asJavaString(result.getSubterm(0));
    final FileObject source;
    try {
        source = resourceService.resolve(sourceString);
    } catch (MetaborgRuntimeException e) {
        logger.error("Cannot find original source for {}, skipping update result", e, sourceString);
        return null;
    }
    final Collection<IMessage> errors = analysisCommon.messages(source, MessageSeverity.ERROR, result.getSubterm(1));
    final Collection<IMessage> warnings = analysisCommon.messages(source, MessageSeverity.WARNING, result.getSubterm(2));
    final Collection<IMessage> notes = analysisCommon.messages(source, MessageSeverity.NOTE, result.getSubterm(3));
    final Collection<IMessage> messages = Lists.newArrayListWithCapacity(errors.size() + warnings.size() + notes.size());
    messages.addAll(errors);
    messages.addAll(warnings);
    messages.addAll(notes);
    return unitService.analyzeUnitUpdate(source, new AnalyzeUpdateData(messages), context);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) AnalyzeUpdateData(org.metaborg.spoofax.core.unit.AnalyzeUpdateData) IMessage(org.metaborg.core.messages.IMessage) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) FileObject(org.apache.commons.vfs2.FileObject)

Example 24 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class ResourceService method localFile.

@Override
public File localFile(FileObject resource, FileObject dir) {
    if (resource instanceof LocalFile) {
        return FileUtils.toFile(resource);
    }
    final File localDir = localPath(dir);
    if (localDir == null) {
        throw new MetaborgRuntimeException("Replication directory " + dir + " is not on the local filesystem, cannot get local file for " + resource);
    }
    try {
        dir.createFolder();
        final FileObject copyLoc;
        if (resource.getType() == FileType.FOLDER) {
            copyLoc = dir;
        } else {
            copyLoc = dir.resolveFile(resource.getName().getBaseName());
        }
        copyLoc.copyFrom(resource, new AllFileSelector());
        return localDir;
    } catch (FileSystemException e) {
        throw new MetaborgRuntimeException("Could not get local file for " + resource, e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) LocalFile(org.apache.commons.vfs2.provider.local.LocalFile) FileSystemException(org.apache.commons.vfs2.FileSystemException) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) LocalFile(org.apache.commons.vfs2.provider.local.LocalFile)

Example 25 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class ResolverService method resolve.

@Override
public Resolution resolve(int offset, ISpoofaxParseUnit result) throws MetaborgException {
    if (!result.valid()) {
        return null;
    }
    final FileObject source = result.source();
    final IProject project = projectService.get(source);
    final ILanguageImpl langImpl = result.input().langImpl();
    @Nullable IContext context;
    if (project == null) {
        context = null;
    } else {
        try {
            context = contextService.get(source, project, langImpl);
        } catch (ContextException | MetaborgRuntimeException e) {
            // Failed to get a context, ignore and use the source file to get a stratego runtime later.
            context = null;
        }
    }
    final FacetContribution<ResolverFacet> facetContrib = facet(langImpl);
    final ResolverFacet facet = facetContrib.facet;
    final ILanguageComponent contributor = facetContrib.contributor;
    final String strategy = facet.strategyName;
    try {
        final ITermFactory termFactory = termFactoryService.get(contributor, project, true);
        final HybridInterpreter interpreter;
        if (context == null) {
            interpreter = strategoRuntimeService.runtime(contributor, source, true);
        } else {
            interpreter = strategoRuntimeService.runtime(contributor, context, true);
        }
        final Iterable<IStrategoTerm> inRegion = tracingService.fragments(result, new SourceRegion(offset));
        final TermWithRegion tuple = common.outputs(termFactory, interpreter, source, source, result.ast(), inRegion, strategy);
        return resolve(tuple);
    } catch (MetaborgException e) {
        throw new MetaborgException("Reference resolution failed", e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) IContext(org.metaborg.core.context.IContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) MetaborgException(org.metaborg.core.MetaborgException) HybridInterpreter(org.strategoxt.HybridInterpreter) ISourceRegion(org.metaborg.core.source.ISourceRegion) SourceRegion(org.metaborg.core.source.SourceRegion) IProject(org.metaborg.core.project.IProject) ContextException(org.metaborg.core.context.ContextException) TermWithRegion(org.metaborg.spoofax.core.tracing.TracingCommon.TermWithRegion) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) ITermFactory(org.spoofax.interpreter.terms.ITermFactory) Nullable(javax.annotation.Nullable)

Aggregations

MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)26 FileObject (org.apache.commons.vfs2.FileObject)16 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)9 MetaborgException (org.metaborg.core.MetaborgException)7 Nullable (javax.annotation.Nullable)6 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 IContext (org.metaborg.core.context.IContext)4 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)4 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)4 File (java.io.File)3 IOException (java.io.IOException)3 ContextException (org.metaborg.core.context.ContextException)3 ILanguage (org.metaborg.core.language.ILanguage)3 IdentifiedDialect (org.metaborg.core.language.dialect.IdentifiedDialect)3 IMessage (org.metaborg.core.messages.IMessage)3 IProject (org.metaborg.core.project.IProject)3 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)3 FileName (org.apache.commons.vfs2.FileName)2 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)2