use of org.spoofax.interpreter.terms.IStrategoTerm in project spoofax by metaborg.
the class AbsolutePathPrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) {
if (!(current instanceof IStrategoString)) {
return null;
}
String path = Tools.asJavaString(current);
IStrategoTerm basePathTerm = tvars[0];
if (!(basePathTerm instanceof IStrategoString)) {
return null;
}
String basePath = Tools.asJavaString(basePathTerm);
final FileObject base = resourceService.resolve(basePath);
final FileObject abs = resourceService.resolve(base, path);
return factory.makeString(abs.getName().getURI());
}
use of org.spoofax.interpreter.terms.IStrategoTerm in project spoofax by metaborg.
the class LanguageSourceDirectoriesPrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) {
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 Iterable<FileObject> sourceLocations = languagePathService.sourcePaths(project, languageName);
final List<IStrategoTerm> terms = Lists.newArrayList();
for (FileObject sourceLocation : sourceLocations) {
terms.add(factory.makeString(sourceLocation.getName().getURI()));
}
return factory.makeList(terms);
}
use of org.spoofax.interpreter.terms.IStrategoTerm 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.spoofax.interpreter.terms.IStrategoTerm in project spoofax by metaborg.
the class LanguageIncludeDirectoriesPrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException, IOException {
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 Iterable<FileObject> includeLocations = languagePathService.includePaths(project, languageName);
final List<IStrategoTerm> terms = Lists.newArrayList();
for (FileObject includeLocation : includeLocations) {
terms.add(factory.makeString(includeLocation.getName().getURI()));
}
return factory.makeList(terms);
}
use of org.spoofax.interpreter.terms.IStrategoTerm 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);
}
}
Aggregations