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);
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations