本文整理汇总了Java中org.spoofax.interpreter.core.Tools.asJavaString方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.asJavaString方法的具体用法?Java Tools.asJavaString怎么用?Java Tools.asJavaString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.core.Tools
的用法示例。
在下文中一共展示了Tools.asJavaString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm usedWordTerm, IStrategoTerm schemeNameTerm) {
if (usedWordTerm instanceof IStrategoString) {
if (schemeNameTerm instanceof IStrategoString) {
final String schemeName = Tools.asJavaString(schemeNameTerm);
final String usedWord = Tools.asJavaString(usedWordTerm);
final String regex = schemeName + "(_.+|[0-9]+'*|'+[0-9]*)";
if (usedWord.matches(regex)) {
return usedWordTerm;
}
}
}
return null;
}
示例2: eval
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public IConstruct eval(final IContext env) throws InterpreterException {
if (DebugUtil.isDebugging()) {
debug("CallDynamic.eval() - ", env.current());
}
if (Tools.isTermAppl(sref) && Tools.isVar((IStrategoAppl) sref, env)) {
IStrategoTerm actualSRef = env.lookupVar(Tools.javaStringAt(
(IStrategoAppl) sref, 0));
if (Tools.isTermString(actualSRef)) {
String sname = Tools.asJavaString(actualSRef);
Strategy callt = new CallT(sname, svars, tvars);
callt.getHook().push(this.getHook().pop());
return callt.eval(env);
}
}
throw new InterpreterException(
"Invocation target is invalid (cannot be evaluated): " + sref);
}
示例3: 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);
}
}
示例4: 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);
}
示例5: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@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());
}
示例6: 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;
}
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);
}
示例7: hover
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private Hover hover(@Nullable TermWithRegion tuple) {
if(tuple == null) {
return null;
}
final IStrategoTerm output = tuple.term;
final ISourceRegion offsetRegion = tuple.region;
final String text;
if(output.getTermType() == IStrategoTerm.STRING) {
text = Tools.asJavaString(output);
} else {
text = output.toString();
}
final String massagedText = text.replace("\\\"", "\"").replace("\\n", "");
return new Hover(offsetRegion, massagedText);
}
示例8: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的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;
}
示例9: fromStrategoTerm
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static L_String fromStrategoTerm(IStrategoTerm alist) {
L_String list = new L_String(SourceSectionUtil.fromStrategoTerm(alist));
for (IStrategoTerm elem : alist) {
final SourceSection src = SourceSectionUtil.fromStrategoTerm(elem);
list = new L_String(src, Tools.asJavaString(elem), list);
}
return list;
}
示例10: 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;
}
示例11: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext context, Strategy[] svars, IStrategoTerm[] tvars) {
if(!Tools.isTermString(tvars[0]))
return false;
if(!Tools.isTermString(tvars[1]))
return false;
String fileName = Tools.asJavaString(tvars[0]);
String modeString = Tools.asJavaString(tvars[1]);
int mode = Integer.parseInt(modeString, 8);
System.out.println(mode);
if(fileName == null)
return true;
File f = new File(fileName);
boolean r = true;
boolean readable = (mode & (S_IRUSR | S_IROTH)) != 0;
boolean readableUserOnly = (mode & S_IROTH) == 0;
r &= f.setReadable(readable, readableUserOnly);
boolean writable = (mode & (S_IWUSR | S_IWOTH)) != 0;
boolean writableUserOnly = (mode & S_IWOTH) == 0;
r &= f.setWritable(writable, writableUserOnly);
boolean executable = (mode & (S_IXUSR | S_IXOTH)) != 0;
boolean executableUserOnly = (mode & S_IXOTH) == 0;
r &= f.setWritable(executable, executableUserOnly);
return r;
}
示例12: invoke
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override public IStrategoTerm invoke(Context context, IStrategoTerm current) {
final String str = Tools.asJavaString(current);
final ITermFactory factory = context.getFactory();
IStrategoTerm after = factory.makeString(unquote(str));
after = factory.annotateTerm(after, current.getAnnotations());
after = factory.copyAttachments(current, after);
return after;
}
示例13: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) throws MetaborgException {
final IProject project = context.project();
if(project == null) {
return null;
}
final CommonPaths paths = new CommonPaths(project.location());
if(languageSpecServiceProvider == null) {
// Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
// should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
logger.error("Language specification service is not available; static injection failed");
return null;
}
if(!Tools.isTermString(current)) {
throw new MetaborgException("Expect a string as argument term, got " + current);
}
String name = Tools.asJavaString(current);
final String srcGenDir;
try {
srcGenDir = ResourceUtils.relativeName(paths.srcGenDir().resolveFile(name).getName(),
project.location().getName(), true);
} catch(FileSystemException e) {
return null;
}
return factory.makeString(srcGenDir);
}
示例14: computeStartSymbol
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
protected static String computeStartSymbol(IStrategoTerm symbolTerm) {
if (Tools.isTermString(symbolTerm)) {
return Tools.asJavaString(symbolTerm);
} else if (symbolTerm.getSubtermCount() == 0
&& symbolTerm.getTermType() == IStrategoTerm.APPL
&& ((IStrategoAppl) symbolTerm).getConstructor().getName().equals("None")) {
return null;
} else {
return INVALID;
}
}
示例15: 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);
}