本文整理汇总了Java中org.spoofax.interpreter.terms.IStrategoTuple.getSubtermCount方法的典型用法代码示例。如果您正苦于以下问题:Java IStrategoTuple.getSubtermCount方法的具体用法?Java IStrategoTuple.getSubtermCount怎么用?Java IStrategoTuple.getSubtermCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.terms.IStrategoTuple
的用法示例。
在下文中一共展示了IStrategoTuple.getSubtermCount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTermArguments
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
private IStrategoTerm getTermArguments(IContext env, IStrategoTerm t) throws InterpreterException {
switch(t.getTermType()) {
case IStrategoTerm.INT:
case IStrategoTerm.REAL:
return env.getFactory().makeList();
case IStrategoTerm.APPL:
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isNil(a, env) || Tools.isCons(a, env))
return t;
else
return env.getFactory().makeList(a.getAllSubterms());
case IStrategoTerm.LIST:
return t;
case IStrategoTerm.STRING:
return env.getFactory().makeList();
case IStrategoTerm.TUPLE:
IStrategoTuple tup = (IStrategoTuple) t;
IStrategoTerm[] args = new IStrategoTerm[tup.getSubtermCount()];
for(int i = 0; i < args.length; i++)
args[i] = tup.get(i);
return env.getFactory().makeList(args);
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例2: getTermArguments
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
private IStrategoTerm getTermArguments(IContext env, IStrategoTerm t) throws InterpreterException {
switch(t.getTermType()) {
case IStrategoTerm.INT:
case IStrategoTerm.REAL:
return env.getFactory().makeList();
case IStrategoTerm.APPL:
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isNil(a, env) || Tools.isCons(a, env))
return t;
else
return env.getFactory().makeList(a.getArguments());
case IStrategoTerm.LIST:
return t;
case IStrategoTerm.STRING:
return env.getFactory().makeList();
case IStrategoTerm.TUPLE:
IStrategoTuple tup = (IStrategoTuple) t;
IStrategoTerm[] args = new IStrategoTerm[tup.getSubtermCount()];
for(int i = 0; i < args.length; i++)
args[i] = tup.get(i);
return env.getFactory().makeList(args);
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例3: call
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
@Override
public boolean call(IContext context, Strategy[] svars, IStrategoTerm[] tvars) {
IStrategoTerm current = context.current();
if(!(current instanceof IStrategoTuple))
return false;
IStrategoTuple t = (IStrategoTuple) current;
if(t.getSubtermCount() < 2)
return false;
if(!(t.get(0) instanceof IStrategoString))
return false;
IStrategoString fileName = (IStrategoString) t.get(0);
if(!(t.get(1) instanceof IStrategoString))
return false;
IStrategoString mode = (IStrategoString) t.get(1);
try {
RandomAccessFile raf = new RandomAccessFile(new File(fileName.stringValue()), mode.stringValue());
context.setCurrent(new GenericWrappedTerm("FileChannel", raf.getChannel()));
return true;
} catch(IOException e) {
return JFFLibrary.invokeExceptionHandler(context, e);
}
}
示例4: call
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
@Override
public boolean call(IContext context, Strategy[] svars, IStrategoTerm[] tvars) {
IStrategoTerm current = context.current();
if (!(current instanceof IStrategoTuple))
return false;
IStrategoTuple t = (IStrategoTuple) current;
if (t.getSubtermCount() < 2)
return false;
if (t.getSubtermCount() < 2)
return false;
if (!(t.get(0) instanceof IStrategoInt))
return false;
IStrategoInt bufferSize = (IStrategoInt) t.get(0);
if (!(t.get(1) instanceof IStrategoInt))
return false;
IStrategoInt direct = (IStrategoInt) t.get(1);
ByteBuffer buf = null;
if (direct.intValue() == 1)
buf = ByteBuffer.allocateDirect(bufferSize.intValue());
else
buf = ByteBuffer.allocate(bufferSize.intValue());
context.setCurrent(new GenericWrappedTerm("ByteBuffer", buf));
return true;
}
示例5: fromTupleWrapped
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T fromTupleWrapped(IStrategoTerm current, int index, Class<T> clazz) {
if(!(current instanceof IStrategoTuple))
return null;
IStrategoTuple tuple = (IStrategoTuple) current;
if(index >= tuple.getSubtermCount())
return null;
if(!(tuple.get(index) instanceof GenericWrappedTerm))
return null;
GenericWrappedTerm wrapper = (GenericWrappedTerm) tuple.get(index);
if(wrapper.getWrappee().getClass().equals(clazz))
return null;
return (T) wrapper.getWrappee();
}
示例6: placeholderCompletions
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
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;
}
示例7: optionalCompletions
import org.spoofax.interpreter.terms.IStrategoTuple; //导入方法依赖的package包/类
public Collection<ICompletion> optionalCompletions(Iterable<IStrategoTerm> optionals, boolean blankLineCompletion,
String languageName, ILanguageComponent component, FileObject location) throws MetaborgException {
Collection<ICompletion> completions = Lists.newLinkedList();
final ITermFactory termFactory = termFactoryService.get(component, null, false);
for(IStrategoTerm optional : optionals) {
ImploderAttachment attachment = optional.getAttachment(ImploderAttachment.TYPE);
String sort = attachment.getSort().substring(0, attachment.getSort().length());
String placeholderName = sort + "-Plhdr";
IStrategoAppl optionalPlaceholder = termFactory.makeAppl(termFactory.makeConstructor(placeholderName, 0));
final IStrategoTerm strategoInput =
termFactory.makeTuple(termFactory.makeString(sort), optional, optionalPlaceholder);
// call Stratego part of the framework to compute change
final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location, false);
final IStrategoTerm proposalsOptional =
strategoCommon.invoke(runtime, strategoInput, "get-proposals-optional-" + languageName);
if(proposalsOptional == null) {
logger.error("Getting proposals for {} failed", strategoInput);
continue;
}
for(IStrategoTerm proposalTerm : proposalsOptional) {
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, blankLineCompletion, "", "");
if(completion == null) {
logger.error("Unexpected proposal term {}, skipping", proposalTerm);
continue;
}
completions.add(completion);
}
}
}
return completions;
}