use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.
the class JSGLRCompletionService method placeholderCompletions.
public Collection<ICompletion> placeholderCompletions(IStrategoAppl placeholder, String languageName, ILanguageComponent component, FileObject location) throws MetaborgException {
Collection<ICompletion> completions = Lists.newLinkedList();
// call Stratego part of the framework to compute change
final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location, false);
final ITermFactory termFactory = termFactoryService.get(component, null, false);
IStrategoTerm placeholderParent = ParentAttachment.getParent(placeholder);
if (placeholderParent == null) {
placeholderParent = placeholder;
}
IStrategoInt placeholderIdx = termFactory.makeInt(-1);
for (int i = 0; i < placeholderParent.getSubtermCount(); i++) {
if (placeholderParent.getSubterm(i) == placeholder) {
placeholderIdx = termFactory.makeInt(i);
}
}
final String sort = ImploderAttachment.getSort(placeholder);
final IStrategoTerm strategoInput = termFactory.makeTuple(termFactory.makeString(sort), placeholder, placeholderParent, placeholderIdx);
final IStrategoTerm proposalsPlaceholder = strategoCommon.invoke(runtime, strategoInput, "get-proposals-placeholder-" + languageName);
if (proposalsPlaceholder == null) {
logger.error("Getting proposals for {} failed", placeholder);
return completions;
}
for (IStrategoTerm proposalTerm : proposalsPlaceholder) {
if (!(proposalTerm instanceof IStrategoTuple)) {
logger.error("Unexpected proposal term {}, skipping", proposalTerm);
continue;
}
final IStrategoTuple tuple = (IStrategoTuple) proposalTerm;
if (tuple.getSubtermCount() != 4 || !(tuple.getSubterm(0) instanceof IStrategoString) || !(tuple.getSubterm(1) instanceof IStrategoString) || !(tuple.getSubterm(2) instanceof IStrategoString) || !(tuple.getSubterm(3) instanceof IStrategoAppl)) {
logger.error("Unexpected proposal term {}, skipping", proposalTerm);
continue;
}
final String name = Tools.asJavaString(tuple.getSubterm(0));
final String text = Tools.asJavaString(tuple.getSubterm(1));
final String additionalInfo = Tools.asJavaString(tuple.getSubterm(2));
final StrategoAppl change = (StrategoAppl) tuple.getSubterm(3);
if (change.getConstructor().getName().contains("REPLACE_TERM")) {
final ICompletion completion = createCompletionReplaceTerm(name, text, additionalInfo, change, false, "", "");
if (completion == null) {
logger.error("Unexpected proposal term {}, skipping", proposalTerm);
continue;
}
completions.add(completion);
}
}
return completions;
}
use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.
the class StrategoCommon method resourceTerm.
@Override
public IStrategoString resourceTerm(FileObject resource, FileObject location) {
final ITermFactory termFactory = termFactoryService.getGeneric();
String resourceURI = ResourceUtils.relativeName(resource.getName(), location.getName(), false);
final IStrategoString resourceTerm = termFactory.makeString(resourceURI);
return resourceTerm;
}
use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.
the class StrategoCommon method builderInputTerm.
@Override
public IStrategoTerm builderInputTerm(IStrategoTerm ast, FileObject resource, FileObject location) {
final ITermFactory termFactory = termFactoryService.getGeneric();
// TODO: support selected node
final IStrategoTerm node = ast;
// TODO: support position
final IStrategoTerm position = termFactory.makeList();
final String locationURI = location.getName().getURI();
final IStrategoString locationTerm = termFactory.makeString(locationURI);
String resourceURI = ResourceUtils.relativeName(resource.getName(), location.getName(), false);
final IStrategoString resourceTerm = termFactory.makeString(resourceURI);
return termFactory.makeTuple(node, position, ast, resourceTerm, locationTerm);
}
use of org.spoofax.interpreter.terms.IStrategoString 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.IStrategoString in project spoofax by metaborg.
the class LocalReplicatePrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) {
if (!(current instanceof IStrategoString)) {
return null;
}
final IStrategoString currentStr = (IStrategoString) current;
final String path = currentStr.stringValue();
final FileObject resource = resourceService.resolve(path);
final File localFile = resourceService.localFile(resource);
return factory.makeString(localFile.getPath());
}
Aggregations