Search in sources :

Example 11 with MetaborgRuntimeException

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

the class TaskEngineAnalyzer method result.

@Nullable
private ISpoofaxAnalyzeUnit result(IStrategoTerm result, Map<String, ISpoofaxParseUnit> inputsPerSource, IContext context, long duration) {
    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 result", e, sourceString);
        return null;
    }
    final ISpoofaxParseUnit input = inputsPerSource.get(sourceString);
    if (input == null) {
        logger.error("Cannot find input parse result for {}, skipping result", sourceString);
        return null;
    }
    final IStrategoTerm ast = result.getSubterm(2);
    final Collection<IMessage> errors = analysisCommon.messages(source, MessageSeverity.ERROR, result.getSubterm(3));
    final Collection<IMessage> warnings = analysisCommon.messages(source, MessageSeverity.WARNING, result.getSubterm(4));
    final Collection<IMessage> notes = analysisCommon.messages(source, MessageSeverity.NOTE, result.getSubterm(5));
    final Collection<IMessage> ambiguities = analysisCommon.ambiguityMessages(source, ast);
    final Collection<IMessage> messages = Lists.newArrayListWithCapacity(errors.size() + warnings.size() + notes.size() + ambiguities.size());
    messages.addAll(errors);
    messages.addAll(warnings);
    messages.addAll(notes);
    messages.addAll(ambiguities);
    return unitService.analyzeUnit(input, new AnalyzeContrib(true, errors.isEmpty(), true, ast, messages, duration), context);
}
Also used : ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IMessage(org.metaborg.core.messages.IMessage) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) FileObject(org.apache.commons.vfs2.FileObject) AnalyzeContrib(org.metaborg.spoofax.core.unit.AnalyzeContrib) Nullable(javax.annotation.Nullable)

Example 12 with MetaborgRuntimeException

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

the class DialectService method add.

@Override
public ILanguageImpl add(String name, FileObject location, ILanguageImpl base, IFacet syntaxFacet) {
    if (nameToDialect.containsKey(name)) {
        final String message = String.format("Dialect with name %s already exists", name);
        logger.error(message);
        throw new MetaborgRuntimeException(message);
    }
    logger.debug("Adding dialect {} from {} with {} as base", name, location, base);
    final ILanguageImpl dialect = createDialect(name, location, base, syntaxFacet, true, true);
    nameToDialect.put(name, dialect);
    dialectToBase.put(dialect, base);
    baseLanguageToDialects.put(base, dialect);
    return dialect;
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) ILanguageImpl(org.metaborg.core.language.ILanguageImpl)

Example 13 with MetaborgRuntimeException

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

the class DialectService method update.

@Override
public ILanguageImpl update(String name, IFacet syntaxFacet) {
    final ILanguageImpl dialect = nameToDialect.get(name);
    if (dialect == null) {
        final String message = String.format("Dialect with name %s does not exist", name);
        logger.error(message);
        throw new MetaborgRuntimeException(message);
    }
    logger.debug("Updating syntax facet for dialect {}", name);
    final FileObject location = Iterables.get(dialect.components(), 0).location();
    final ILanguageImpl newDialect = createDialect(name, location, dialect, syntaxFacet, false, false);
    nameToDialect.put(name, newDialect);
    return newDialect;
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) FileObject(org.apache.commons.vfs2.FileObject)

Example 14 with MetaborgRuntimeException

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

the class StrategoRuntimeService method loadJars.

private void loadJars(HybridInterpreter runtime, Iterable<FileObject> jars) throws MetaborgException {
    try {
        final URL[] classpath = new URL[Iterables.size(jars)];
        int i = 0;
        for (FileObject jar : jars) {
            final File localJar = resourceService.localFile(jar);
            classpath[i] = localJar.toURI().toURL();
            ++i;
        }
        logger.trace("Loading jar files {}", (Object) classpath);
        final ClassLoader classLoader = new StrategoRuntimeClassLoader(additionalClassLoaders);
        runtime.loadJars(classLoader, classpath);
    } catch (IncompatibleJarException | IOException | MetaborgRuntimeException e) {
        throw new MetaborgException("Failed to load JAR", e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) IncompatibleJarException(org.strategoxt.IncompatibleJarException) MetaborgException(org.metaborg.core.MetaborgException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 15 with MetaborgRuntimeException

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

the class OutlineService method outline.

@Override
public IOutline outline(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<OutlineFacet> facetContrib = facet(langImpl);
    final OutlineFacet facet = facetContrib.facet;
    final ILanguageComponent contributor = facetContrib.contributor;
    final String strategy = facet.strategyName;
    try {
        final HybridInterpreter interpreter;
        if (context == null) {
            interpreter = strategoRuntimeService.runtime(contributor, source, true);
        } else {
            interpreter = strategoRuntimeService.runtime(contributor, context, true);
        }
        final IStrategoTerm input = common.builderInputTerm(result.ast(), source, source);
        final IStrategoTerm outlineTerm = common.invoke(interpreter, input, strategy);
        if (outlineTerm == null) {
            return null;
        }
        final IOutline outline = toOutline(outlineTerm, facet.expandTo, contributor.location());
        return outline;
    } catch (MetaborgException e) {
        throw new MetaborgException("Creating outline failed", e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) IContext(org.metaborg.core.context.IContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IOutline(org.metaborg.core.outline.IOutline) MetaborgException(org.metaborg.core.MetaborgException) HybridInterpreter(org.strategoxt.HybridInterpreter) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IProject(org.metaborg.core.project.IProject) ContextException(org.metaborg.core.context.ContextException) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) 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