本文整理汇总了Java中org.spoofax.interpreter.stratego.Strategy类的典型用法代码示例。如果您正苦于以下问题:Java Strategy类的具体用法?Java Strategy怎么用?Java Strategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Strategy类属于org.spoofax.interpreter.stratego包,在下文中一共展示了Strategy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:25,代码来源:SSL_indexedSet_put.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:24,代码来源:SPX_interpreter_introspect_strategies.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:23,代码来源:SSL_list_loop.java
示例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;
}
开发者ID:metaborg,项目名称:jsglr,代码行数:26,代码来源:OriginTermFuzzyPrimitive.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:20,代码来源:JFF_find_class.java
示例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);
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:25,代码来源:StrategoCoreLoader.java
示例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;
}
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:19,代码来源:SSL_fflush.java
示例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;
}
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:30,代码来源:SSL_mkdtemp.java
示例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;
}
开发者ID:metaborg,项目名称:jsglr,代码行数:19,代码来源:OriginSetLocationOffsetPrimitive.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:18,代码来源:SSL_filesize.java
示例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);
}
开发者ID:metaborg,项目名称:spoofax,代码行数:21,代码来源:LanguageSourceDirectoriesPrimitive.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:25,代码来源:SSL_write_term_to_stream_saf.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:23,代码来源:SSL_mkdir.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:20,代码来源:SSL_explode_string.java
示例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;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:18,代码来源:SSL_TicksToSeconds.java
示例16: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
// We just convert it to a normal term and hope it won't
// go original later.
IStrategoTerm input = tvars[0];
IStrategoTerm result;
if (OriginAttachment.get(input) == null) {
result = input;
} else {
result = TermConverter.convert(env.getFactory(), input);
assert OriginAttachment.get(result) == null;
}
env.setCurrent(result);
return true;
}
开发者ID:metaborg,项目名称:jsglr,代码行数:17,代码来源:OriginStripPrimitive.java
示例17: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] tvars) throws InterpreterException {
double a, b;
if(Tools.isTermReal(tvars[0])) {
a = ((IStrategoReal) tvars[0]).realValue();
} else if (Tools.isTermInt(tvars[0])) {
a = ((IStrategoInt) tvars[0]).intValue();
} else {
return false;
}
if(Tools.isTermReal(tvars[1])) {
b = ((IStrategoReal) tvars[1]).realValue();
} else if (Tools.isTermInt(tvars[1])) {
b = ((IStrategoInt) tvars[1]).intValue();
} else {
return false;
}
env.setCurrent(env.getFactory().makeReal(a * b));
return true;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:24,代码来源:SSL_mulr.java
示例18: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!(Tools.isTermInt(targs[0])))
return false;
if(!(Tools.isTermInt(targs[1])))
return false;
int initialSize = ((IStrategoInt)targs[0]).intValue();
int maxLoad = ((IStrategoInt)targs[1]).intValue();
IStrategoTerm result = new StrategoSet(initialSize, maxLoad);
env.setCurrent(result);
return true;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:17,代码来源:SSL_indexedSet_create.java
示例19: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!Tools.isTermInt(targs[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
Writer out = or.getIOAgent().getWriter(Tools.asJavaInt(targs[0]));
if(out == null)
return false;
try {
new TermReader(env.getFactory()).unparseToFile(targs[1], out);
out.flush();
} catch(IOException e) {
throw new InterpreterException(e);
}
env.setCurrent(targs[0]);
return true;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:23,代码来源:SSL_write_term_to_stream_taf.java
示例20: call
import org.spoofax.interpreter.stratego.Strategy; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] targs)
throws InterpreterException {
// FIXME should we even bother with BAF? Now it's just text
if(!Tools.isTermInt(targs[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
Writer out = or.getIOAgent().getWriter(Tools.asJavaInt(targs[0]));
if(out == null)
return false;
try {
new TermReader(env.getFactory()).unparseToFile(targs[1], out);
out.flush();
} catch(IOException e) {
throw new InterpreterException(e);
}
env.setCurrent(targs[0]);
return true;
}
开发者ID:metaborg,项目名称:mb-exec,代码行数:25,代码来源:SSL_write_term_to_stream_baf.java
注:本文中的org.spoofax.interpreter.stratego.Strategy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论