本文整理汇总了Java中org.spoofax.interpreter.stratego.Strategy类的典型用法代码示例。如果您正苦于以下问题:Java Strategy类的具体用法?Java Strategy怎么用?Java Strategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Strategy类属于org.spoofax.interpreter.stratego包,在下文中一共展示了Strategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs)
throws InterpreterException {
if(!(targs[0] instanceof StrategoSet))
return false;
StrategoSet is = (StrategoSet) targs[0];
if(is == null)
return false;
IStrategoTerm t = targs[1];
Strategy s = sargs[0];
if(is.containsKey(t)) {
env.setCurrent(env.getFactory().makeInt(is.getIndex(t)));
return s.evaluate(env);
}
env.setCurrent(env.getFactory().makeInt(is.put(t)));
return true;
}
示例2: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
final ITermFactory f = env.getFactory();
final LinkedList<IStrategoAppl> as = new LinkedList<IStrategoAppl>();
// see also Context.getStrategyNames()
VarScope v = env.getVarScope();
while(v.getParent() != null)
v = v.getParent();
// FIXME: ugh
if (env instanceof Context) {
final StrategoSignature sign = ((Context) env).getStrategoSignature();
for(SDefT sdef : v.getSVars()) {
as.addFirst(sdef.toExternalDef(f, sign));
}
}
env.setCurrent(f.makeList(as));
return true;
}
示例3: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermList(tvars[0]))
return false;
CallT s = (CallT) svars[0];
Strategy[] sv = new Strategy[0];
IStrategoTerm[] tv = new IStrategoTerm[0];
IStrategoTerm saved = env.current();
for (IStrategoList list = (IStrategoList) tvars[0]; !list.isEmpty(); list = list.tail()) {
env.setCurrent(list.head());
if(!s.evaluateWithArgs(env, sv, tv))
return false;
}
env.setCurrent(saved);
return true;
}
示例4: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) {
if(tvars.length != 1 || svars.length !=0)
return false;
IStrategoTerm term = tvars[0];
IStrategoTerm originTerm = OriginAttachment.getOrigin(term);
if(originTerm != null){
env.setCurrent(originTerm);
return true; //fuzzy origin term not needed
}
if(!(term instanceof StrategoAppl)){
return false; //only fuzzy origin term for appl terms
}
for (int i = 0; i < term.getSubtermCount(); i++) {
IStrategoTerm originSubTerm = OriginAttachment.getOrigin(term.getSubterm(i));
if(originSubTerm != null){
IStrategoTerm parent = ParentAttachment.getParent(originSubTerm);
if(isOriginRelatedFuzzy(term, parent)){
env.setCurrent(parent); //Term with the same signature and at least one origin related child
return true;
}
}
}
return false;
}
示例5: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if (!Tools.isTermString(tvars[0]))
return false;
try {
Class<?> c = Class.forName(Tools.asJavaString(tvars[0]));
JFFLibrary lib = JFFLibrary.instance(env);
env.setCurrent(lib.wrapObject(c));
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
示例6: parseCallT
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
private Strategy parseCallT(IStrategoAppl t) throws InterpreterException {
if (DebugUtil.isDebugging()) {
DebugUtil.debug("parseCallT()");
}
String name = Tools.javaStringAt(Tools.applAt(t, 0), 0);
if (DebugUtil.isDebugging()) {
DebugUtil.debug(" name : ", name);
}
IStrategoList svars = Tools.listAt(t, 1);
Strategy[] realsvars = parseStrategyList(svars);
IStrategoTerm[] realtvars = parseTermList(Tools.listAt(t, 2));
if (DebugUtil.isDebugging()) {
DebugUtil.debug(" -svars : ", realsvars);
}
if (DebugUtil.isDebugging()) {
DebugUtil.debug(" -tvars : ", realtvars);
}
return new CallT(name, realsvars, realtvars);
}
示例7: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermInt(tvars[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
Writer writer = or.getIOAgent().getWriter(Tools.asJavaInt(tvars[0]));
if (writer == null) return false;
try {
writer.flush();
return true;
} catch (IOException e) {
return false;
}
}
示例8: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
/**
* Create a new temp file.
*
* Stratego types: String -> String * Int.
*/
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if (tvars[0].getTermType() != IStrategoTerm.STRING)
return false;
// HACK: We ignore the template directory, and just use it as a filename prefix
String prefix = new File(javaString(tvars[0])).getName();
if (prefix.endsWith("XXXXXX"))
prefix = prefix.substring(0, prefix.length() - 6);
SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
IOAgent agent = op.getIOAgent();
ITermFactory factory = env.getFactory();
try {
String name = agent.createTempDir(prefix);
env.setCurrent(factory.makeString(name));
return true;
} catch (IOException e) {
return false;
}
}
示例9: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public final boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) {
final IStrategoTerm location = tvars[0];
if(!Tools.isTermTuple(location) && location.getSubtermCount() != 4)
return false;
final String filename = Tools.asJavaString(location.getSubterm(0));
final int line = Tools.asJavaInt(location.getSubterm(1));
final int column = Tools.asJavaInt(location.getSubterm(2));
final int startOffset = Tools.asJavaInt(location.getSubterm(3));
final int endOffset = Tools.asJavaInt(location.getSubterm(4));
final ImploderAttachment attachment =
ImploderAttachment.createCompactPositionAttachment(filename, line, column, startOffset, endOffset);
env.current().putAttachment(attachment);
return true;
}
示例10: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) {
if (tvars[0].getTermType() != IStrategoTerm.STRING)
return false;
IStrategoString filename = (IStrategoString) tvars[0];
SSLLibrary library = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
File file = library.getIOAgent().openFile(filename.stringValue());
if (!file.isFile()) {
return false;
}
env.setCurrent(env.getFactory().makeReal(file.length()));
return true;
}
示例11: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@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);
}
示例12: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] targs)
throws InterpreterException {
if(!Tools.isTermInt(targs[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
OutputStream out = or.getIOAgent().internalGetOutputStream(Tools.asJavaInt(targs[0]));
BufferedOutputStream bout = new BufferedOutputStream(out);
if(out == null)
return false;
try {
SAFWriter.writeTermToSAFStream(targs[1], bout);
bout.close();
} catch(IOException e) {
throw new InterpreterException(e);
}
env.setCurrent(targs[0]);
return true;
}
示例13: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if (!Tools.isTermString(tvars[0])) return false;
// if (!Tools.isTermList(tvars[1])) return false;
SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
int result = op.getIOAgent().mkdir(Tools.asJavaString(tvars[0])) ? 0 : -1;
/* access parameter is ignored in C version
AbstractPrimitive access = op.get("SSL_access");
if (result == 0) { // Set access rights
result = access.call(env, svars, tvars) ? 0 : -1;
}
*/
env.setCurrent(env.getFactory().makeInt(result));
return true;
}
示例14: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
IStrategoTerm t = tvars[0];
if (!Tools.isTermString(t))
return false;
String s = ((IStrategoString) t).stringValue();
ITermFactory factory = env.getFactory();
IStrategoList result = factory.makeList();
for (int i = s.length() - 1; i >= 0; i--) {
result = factory.makeListCons(factory.makeInt(s.charAt(i)), result);
}
env.setCurrent(result);
return true;
}
示例15: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
IStrategoTerm time = tvars[0];
int timeValue;
if (time.getTermType() == IStrategoTerm.REAL)
timeValue = (int) ((IStrategoReal) time).realValue();
else if (time.getTermType() == IStrategoTerm.INT)
timeValue = ((IStrategoInt) time).intValue();
else
return false;
env.setCurrent(env.getFactory().makeReal(timeValue / (double) SSL_times.TICKS_PER_SECOND));
return true;
}