当前位置: 首页>>代码示例>>Java>>正文


Java Tools.asJavaString方法代码示例

本文整理汇总了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;

}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:17,代码来源:native_name_matches_varscheme_0_1.java

示例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);

}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:22,代码来源:CallDynamic.java

示例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);
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:24,代码来源:ParseFileStrategy.java

示例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);
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:21,代码来源:LanguageIncludeDirectoriesPrimitive.java

示例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());
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:18,代码来源:AbsolutePathPrimitive.java

示例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);
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:21,代码来源:LanguageSourceDirectoriesPrimitive.java

示例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);
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:19,代码来源:HoverService.java

示例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;
}
 
开发者ID:metaborg,项目名称:jsglr,代码行数:19,代码来源:OriginSetLocationOffsetPrimitive.java

示例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;
}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:9,代码来源:L_String.java

示例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;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:31,代码来源:JFF_find_primitive_type.java

示例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;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:37,代码来源:JFF_chmod_0_0.java

示例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;
}
 
开发者ID:metaborg,项目名称:sdf,代码行数:9,代码来源:unquote_0_0.java

示例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);
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:31,代码来源:LanguageSpecSrcGenDirectory.java

示例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;
	}
}
 
开发者ID:metaborg,项目名称:jsglr,代码行数:12,代码来源:STRSGLR_parse_string_pt.java

示例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);
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:30,代码来源:RelativeSourceOrIncludePath.java


注:本文中的org.spoofax.interpreter.core.Tools.asJavaString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。