use of org.metaborg.core.MetaborgException 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.MetaborgException in project spoofax by metaborg.
the class StrategoRuntimeService method loadCtrees.
private static void loadCtrees(HybridInterpreter runtime, Iterable<FileObject> ctrees) throws MetaborgException {
try {
for (FileObject file : ctrees) {
logger.trace("Loading ctree {}", file.getName());
runtime.load(new BufferedInputStream(file.getContent().getInputStream()));
}
} catch (IOException | InterpreterException e) {
throw new MetaborgException("Failed to load ctree", e);
}
}
use of org.metaborg.core.MetaborgException in project spoofax by metaborg.
the class LanguageSourceFilesPrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
if (!Tools.isTermString(tvars[0])) {
return null;
}
final IProject project = projectService.get(context.location());
if (project == null) {
return factory.makeList();
}
// GTODO: require language identifier instead of language name
final String languageName = Tools.asJavaString(tvars[0]);
final ILanguage language = languageService.getLanguage(languageName);
if (language == null) {
final String message = String.format("Getting include files for %s failed, language could not be found", languageName);
throw new MetaborgException(message);
}
final ILanguageImpl impl = language.activeImpl();
if (impl == null) {
final String message = String.format("Getting include files for %s failed, no active language implementation could be found", languageName);
throw new MetaborgException(message);
}
final Iterable<IdentifiedResource> sourceFiles = languagePathService.sourceFiles(project, impl);
final List<IStrategoTerm> terms = Lists.newArrayList();
for (IdentifiedResource sourceFile : sourceFiles) {
terms.add(factory.makeString(sourceFile.resource.getName().getURI()));
}
return factory.makeList(terms);
}
use of org.metaborg.core.MetaborgException in project spoofax by metaborg.
the class OutlineService method outline.
@Override
public IOutline outline(ISpoofaxAnalyzeUnit result) throws MetaborgException {
if (!result.valid() || !result.hasAst()) {
return null;
}
final FileObject source = result.source();
final IContext context = result.context();
final ILanguageImpl language = context.language();
final FacetContribution<OutlineFacet> facetContrib = facet(language);
final OutlineFacet facet = facetContrib.facet;
final ILanguageComponent contributor = facetContrib.contributor;
final String strategy = facet.strategyName;
try {
final HybridInterpreter interpreter = strategoRuntimeService.runtime(contributor, context, true);
final IStrategoTerm input = common.builderInputTerm(result.ast(), source, context.location());
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);
}
}
use of org.metaborg.core.MetaborgException 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