本文整理汇总了Java中org.spoofax.interpreter.core.Tools.isTermString方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.isTermString方法的具体用法?Java Tools.isTermString怎么用?Java Tools.isTermString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.core.Tools
的用法示例。
在下文中一共展示了Tools.isTermString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@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);
}
示例2: invoke
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override public IStrategoTerm invoke(Context context, IStrategoTerm current) {
if(!Tools.isTermString(current))
return null;
try {
final String path = Tools.asJavaString(current);
final FileObject resource = resourceService.resolve(path);
if(resource.getType() != FileType.FILE) {
return null;
}
final IdentifiedResource identifiedResource = languageIdentifierService.identifyToResource(resource);
if(identifiedResource == null) {
return null;
}
final String text = sourceTextService.text(resource);
final ISpoofaxInputUnit input =
unitService.inputUnit(resource, text, identifiedResource.language, identifiedResource.dialect);
final ISpoofaxParseUnit result = syntaxService.parse(input);
return result.ast();
} catch(ParseException | IOException e) {
throw new StrategoException("Parsing failed unexpectedly", e);
}
}
示例3: getTermConstructor
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private IStrategoTerm getTermConstructor(IContext env, IStrategoTerm t) throws InterpreterException {
if (Tools.isTermInt(t) || Tools.isTermReal(t)) {
return t;
} else if (Tools.isTermString(t)) {
return env.getFactory().makeString("\"" + ((IStrategoString)t).stringValue() + "\"");
} else if (Tools.isTermAppl(t)) {
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isCons(a, env) || Tools.isNil(a, env))
return env.getFactory().makeAppl(env.getStrategoSignature().getNil());
else
return env.getFactory().makeString(((IStrategoAppl)t).getConstructor().getName());
} else if (Tools.isTermList(t)) {
return env.getFactory().makeList();
} else if (Tools.isTermTuple(t)) {
return env.getFactory().makeString("");
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例4: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
String dir = Tools.javaString(tvars[0]);
String[] entries = or.getIOAgent().readdir(dir);
if(entries == null)
return false;
ITermFactory fac = env.getFactory();
IStrategoTerm[] ts = new IStrategoTerm[entries.length];
for(int i = 0; i< entries.length; i++)
ts[i] = fac.makeString(entries[i]);
env.setCurrent(fac.makeList(ts));
return true;
}
示例5: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的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;
}
示例6: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
try {
IStrategoTerm t = env.getFactory().parseFromString(Tools.javaString(tvars[0]));
env.setCurrent(t);
} catch (ParseError e) {
SSLLibrary.instance(env).getIOAgent().printError(NAME + ": " + e.getMessage());
return false;
}
return true;
}
示例7: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
String fn = Tools.javaString(tvars[0]);
File f = or.getIOAgent().openFile(fn);
if(f == null)
return false;
long result = f.lastModified() / 1000;
env.setCurrent(env.getFactory().makeInt((int) result));
return true;
}
示例8: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
try {
IOAgent io = op.getIOAgent();
io.setWorkingDir(Tools.asJavaString(tvars[0]));
env.setCurrent(env.getFactory().makeInt(0));
} catch (IOException e) {
env.setCurrent(env.getFactory().makeInt(-1));
}
return true;
}
示例9: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
JFFLibrary lib = JFFLibrary.instance(env);
final String typeName = Tools.asJavaString(tvars[0]);
if("int".equals(typeName)) {
env.setCurrent(lib.wrapObject(Integer.TYPE));
} else if("float".equals(typeName)) {
env.setCurrent(lib.wrapObject(Float.TYPE));
} else if("double".equals(typeName)) {
env.setCurrent(lib.wrapObject(Double.TYPE));
} else if("char".equals(typeName)) {
env.setCurrent(lib.wrapObject(Character.TYPE));
} else if("byte".equals(typeName)) {
env.setCurrent(lib.wrapObject(Byte.TYPE));
} else if("long".equals(typeName)) {
env.setCurrent(lib.wrapObject(Long.TYPE));
} else if("short".equals(typeName)) {
env.setCurrent(lib.wrapObject(Short.TYPE));
} else {
return false;
}
return true;
}
示例10: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static String call(IStrategoList list) {
IStrategoTerm[] kids = list.getAllSubterms();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < kids.length; i++) {
if(!Tools.isTermString(kids[i]))
return null;
sb.append(Tools.asJavaString(kids[i]));
}
return sb.toString();
}
示例11: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!Tools.isTermString(targs[0]))
return false;
if(!Tools.isTermString(targs[1]))
return false;
String s = Tools.javaString(targs[0]);
String t = Tools.javaString(targs[1]);
env.setCurrent(env.getFactory().makeString(s + t));
return true;
}
示例12: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) {
if(!Tools.isTermString(tvars[0])) {
return null;
}
if(!Tools.isTermString(current)) {
return null;
}
final String path = Tools.asJavaString(current);
final FileObject resource = resourceService.resolve(path);
FileObject base = context.location();
final IProject project = projectService.get(context.location());
if(project != null) {
// GTODO: require language identifier instead of language name
final String languageName = Tools.asJavaString(tvars[0]);
final Iterable<FileObject> sourceLocations = languagePathService.sourceAndIncludePaths(project, languageName);
for(FileObject sourceLocation : sourceLocations) {
if(sourceLocation.getName().isDescendent(resource.getName())) {
base = sourceLocation;
break;
}
}
}
final String relativePath = ResourceUtils.relativeName(resource.getName(), base.getName(), true);
return factory.makeString(relativePath);
}
示例13: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
int result = op.getIOAgent().rmdir(Tools.asJavaString(tvars[0])) ? 0 : -1;
env.setCurrent(env.getFactory().makeInt(result));
return true;
}
示例14: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermString(tvars[0]))
return false;
SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
return op.getIOAgent().isDirectory(asJavaString(tvars[0]));
}
示例15: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!Tools.isTermString(targs[0]))
return false;
String s = Tools.javaString(targs[0]);
env.setCurrent(env.getFactory().makeInt(s.length()));
return true;
}