• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Tools类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spoofax.interpreter.core.Tools的典型用法代码示例。如果您正苦于以下问题:Java Tools类的具体用法?Java Tools怎么用?Java Tools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Tools类属于org.spoofax.interpreter.core包,在下文中一共展示了Tools类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: invoke

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm current) {
	if (!(current instanceof IStrategoString)) {
		return null;
	}

	final IContext mbContext = (IContext) context.contextObject();
	final Injector injector = mbContext.injector();
	final IResourceService resources = injector.getInstance(IResourceService.class);
	final FileObject fileObj = resources.resolve(Tools.asJavaString(current));
	try {
		fileObj.setExecutable(true, false);
	} catch (FileSystemException e1) {
		return null;
	}

	return current;
}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:19,代码来源:fmakeexecutable_0_0.java


示例3: create

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
public static LiteralMatchPattern create(IStrategoAppl t, FrameDescriptor fd) {
	SourceSection source = SourceUtils.dynsemSourceSectionFromATerm(t);
	if (Tools.hasConstructor(t, "True", 0)) {
		return TrueLiteralTermMatchPatternNodeGen.create(source);
	}
	if (Tools.hasConstructor(t, "False", 0)) {
		return FalseLiteralTermMatchPatternNodeGen.create(source);
	}
	if (Tools.hasConstructor(t, "Int", 1)) {

		return IntLiteralTermMatchPatternNodeGen.create(Integer.parseInt(Tools.stringAt(t, 0).stringValue()),
				source);
	}
	if (Tools.hasConstructor(t, "String", 1)) {

		return StringLiteralTermMatchPatternNodeGen.create(Tools.stringAt(t, 0).stringValue(), source);
	}

	throw new NotImplementedException("Unsupported literal: " + t);
}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:21,代码来源:LiteralMatchPattern.java


示例4: create

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
public static Premise create(IStrategoAppl t, FrameDescriptor fd) {
	CompilerAsserts.neverPartOfCompilation();
	if (Tools.hasConstructor(t, "CaseMatch", 2)) {
		return CaseMatchPremise.create(t, fd);
	}
	IStrategoAppl premT = Tools.applAt(t, 0);
	if (Tools.hasConstructor(premT, "Relation", 3)) {
		return RelationPremise.create(premT, fd);
	}
	if (Tools.hasConstructor(premT, "RecRelation", 3)) {
		return RecursiveRelationPremise.create(premT, fd);
	}
	if (Tools.hasConstructor(premT, "Match", 2)) {
		return MatchPremise.create(premT, fd);
	}
	if (Tools.hasConstructor(premT, "TermEq", 2)) {
		return TermEqPremise.create(premT, fd);
	}
	if (Tools.hasConstructor(premT, "Fails", 1)) {
		return FailsPremise.create(premT, fd);
	}

	throw new NotImplementedException("Unsupported premise: " + t);
}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:25,代码来源:Premise.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
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


示例7: buildOp

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
private IStrategoTerm buildOp(IContext env, IStrategoAppl t, ITermFactory factory)
        throws InterpreterException {
    // FIXME memoize constructors
    
    String ctr = Tools.javaStringAt(t, 0);
    IStrategoList children = (IStrategoList) t.getSubterm(1);
    
    if(ctr.length() == 0) {
        return buildTuple(env, t);
    } else if(children.getSubtermCount() == 0 && ctr.equals("Nil")) {
        return buildNil(env);
    } else if(children.getSubtermCount() == 2 && ctr.equals("Cons")) {
        return buildCons(env, t, factory);
    } else {
        return buildOp(ctr, env, t, factory);
    }
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:18,代码来源:Build.java


示例8: 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


示例9: termContents

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Nullable
public static String termContents(IStrategoTerm t) {
    if(t == null)
        return null;

    String result;

    if(t.getTermType() == STRING) {
        result = asJavaString(t);
    } else if(t.getSubtermCount() == 1 && "Values".equals(tryGetName(t))) {
        return concatTermStrings(Tools.listAt(t, 0));
    } else if(t.getTermType() == APPL && t.getSubtermCount() == 1 && termAt(t, 0).getTermType() == STRING) {
        result = asJavaString(termAt(t, 0));
    } else if(t.getTermType() == APPL && t.getSubtermCount() == 1) {
        return termContents(termAt(t, 0));
    } else {
        return null;
    }

    if(result.startsWith("\"") && result.endsWith("\"") && result.length() > 1)
        result = result.substring(1, result.length() - 1).replace("\\\\", "\"");

    return result;
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:25,代码来源:ESVReader.java


示例10: matchAnyExplode

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
private Results matchAnyExplode(IContext env, IStrategoTerm t,
        IStrategoAppl p) throws InterpreterException {

    if(DebugUtil.isDebugging()) {
        DebugUtil.debug("  pattern is Explode");
    }
    IStrategoAppl opPattern = Tools.applAt(p, 0);
    IStrategoAppl argsPattern = Tools.applAt(p, 1);

    IStrategoTerm op = getTermConstructor(env, t);
    IStrategoTerm args = getTermArguments(env, t);

    Results opResult = match(env, op, opPattern);
    Results argsResult = match(env, args, argsPattern);

    if (opResult == null || argsResult == null)
        return null;

    opResult.addAll(argsResult);

    return opResult;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:23,代码来源:Match.java


示例11: 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 + "'");
    }
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:21,代码来源:Match.java


示例12: type

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
public static @Nullable String type(IStrategoAppl esv) {
    final IStrategoAppl strategy = ESVReader.findTerm(esv, "SemanticObserver");
    if(strategy == null) {
        return null;
    }
    final IStrategoTerm annotations = strategy.getSubterm(1);
    boolean multifile  = false;
    boolean constraint = false;
    for(IStrategoTerm annotation : annotations) {
        multifile  |= Tools.hasConstructor((IStrategoAppl) annotation, "MultiFile", 0);
        constraint |= Tools.hasConstructor((IStrategoAppl) annotation, "Constraint", 0);
    }
    if(constraint) {
        return multifile ? ConstraintMultiFileAnalyzer.name : ConstraintSingleFileAnalyzer.name;
    } else if(multifile) {
        return TaskEngineAnalyzer.name;
    }
    return StrategoAnalyzer.name;
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:20,代码来源:AnalysisFacetFromESV.java


示例13: call

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, 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_addr.java


示例14: call

import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
        throws InterpreterException {
    
    IStrategoTerm input = tvars[0];
    
    if(!Tools.isTermAppl(input) && !isTermTuple(input))
        return false;
    
    Strategy c = svars[0];
    int arity = input.getSubtermCount();
    IStrategoTerm[] result = new IStrategoTerm[arity];
    IStrategoTerm[] applArgs = input.getAllSubterms();
    for(int i = 0; i < arity; i++) {
        env.setCurrent(applArgs[i]);
        if(!c.evaluate(env))
            return false;
        result[i] = env.current();
    }
    env.setCurrent(env.getFactory().makeList(result));
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:23,代码来源:SSL_get_appl_arguments_map.java


示例15: call

import org.spoofax.interpreter.core.Tools; //导入依赖的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


示例16: 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


示例17: 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


示例18: 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.isTermString(tvars[1]))
        return false;
    
    String fn = Tools.javaString(tvars[0]);
    String mode = Tools.javaString(tvars[1]);
    
    IStrategoInt result = call(env, fn, mode);
    if (result == null) return false;
    
    env.setCurrent(result);
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:19,代码来源:SSL_fopen.java


示例19: call

import org.spoofax.interpreter.core.Tools; //导入依赖的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_text.java


示例20: call

import org.spoofax.interpreter.core.Tools; //导入依赖的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;

    SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
    
    IOAgent agent = or.getIOAgent();
    
    try {
        agent.writeChar(asJavaInt(targs[1]), asJavaInt(targs[0]));
    } catch(IOException e) {
        throw new InterpreterException(e);
    }
    
    env.setCurrent(targs[1]);
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:22,代码来源:SSL_fputc.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MKEvent类代码示例发布时间:2022-05-22
下一篇:
Java GzipEncodingProvider类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap