本文整理汇总了Java中org.spoofax.interpreter.terms.IStrategoTerm.getTermType方法的典型用法代码示例。如果您正苦于以下问题:Java IStrategoTerm.getTermType方法的具体用法?Java IStrategoTerm.getTermType怎么用?Java IStrategoTerm.getTermType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.terms.IStrategoTerm
的用法示例。
在下文中一共展示了IStrategoTerm.getTermType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatch
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private static boolean dispatch(IStrategoTermVisitor visitor, IStrategoTerm term) {
switch(term.getTermType()) {
case IStrategoTerm.APPL:
return visitor.visit((IStrategoAppl) term);
case IStrategoTerm.LIST:
return visitor.visit((IStrategoList) term);
case IStrategoTerm.TUPLE:
return visitor.visit((IStrategoTuple) term);
case IStrategoTerm.INT:
visitor.visit((IStrategoInt) term);
return false;
case IStrategoTerm.REAL:
visitor.visit((IStrategoReal) term);
return false;
case IStrategoTerm.STRING:
visitor.visit((IStrategoString) term);
return false;
case IStrategoTerm.REF:
visitor.visit((IStrategoRef) term);
return false;
case IStrategoTerm.PLACEHOLDER:
return visitor.visit((IStrategoPlaceholder) term);
default:
return visitor.visit(term);
}
}
示例2: match
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
public static <T> T match(IStrategoTerm term, ICases<T> cases) {
switch(term.getTermType()) {
case IStrategoTerm.APPL:
return cases.caseAppl((IStrategoAppl) term);
case IStrategoTerm.LIST:
return cases.caseList((IStrategoList) term);
case IStrategoTerm.TUPLE:
return cases.caseTuple((IStrategoTuple) term);
case IStrategoTerm.INT:
return cases.caseInt((IStrategoInt) term);
case IStrategoTerm.REAL:
return cases.caseReal((IStrategoReal) term);
case IStrategoTerm.STRING:
return cases.caseString((IStrategoString) term);
default:
throw new IllegalArgumentException("Unsupported Stratego term type " + term.getTermType());
}
}
示例3: rebuildIfNecessary
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private IStrategoTerm rebuildIfNecessary(IStrategoTerm term) {
if(term.getTermType() == IStrategoTerm.APPL) {
IStrategoAppl appl = (IStrategoAppl) term;
if(context.getConstructorSignatures().containsKey(appl.getConstructor().getName())
&& TypesmartSortAttachment.getSorts(appl) == null)
return makeAppl(appl.getConstructor(), appl.getAllSubterms(), appl.getAnnotations());
else
return appl;
} else {
IStrategoTerm[] kids = new IStrategoTerm[term.getSubtermCount()];
boolean changed = false;
int i = 0;
for(IStrategoTerm kid : term) {
IStrategoTerm newkid = rebuildIfNecessary(kid);
kids[i] = newkid;
changed = changed || kid != newkid;
}
if(changed) {
switch(term.getTermType()) {
case IStrategoTerm.LIST:
return makeList(kids, term.getAnnotations());
case IStrategoTerm.TUPLE:
return makeTuple(kids, term.getAnnotations());
default:
throw new IllegalStateException();
}
} else {
return term;
}
}
}
示例4: esvTerm
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private IStrategoAppl esvTerm(FileObject location, FileObject esvFile)
throws ParseError, IOException, MetaborgException {
final TermReader reader =
new TermReader(termFactoryService.getGeneric().getFactoryWithStorageType(IStrategoTerm.MUTABLE));
final IStrategoTerm term = reader.parseFromStream(esvFile.getContent().getInputStream());
if(term.getTermType() != IStrategoTerm.APPL) {
final String message = logger.format(
"Cannot discover language at {}, ESV file at {} does not contain a valid ESV term", location, esvFile);
throw new MetaborgException(message);
}
return (IStrategoAppl) term;
}
示例5: haveSameSignature
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private boolean haveSameSignature(IStrategoTerm term, IStrategoTerm origin) {
if(term instanceof StrategoAppl && origin instanceof StrategoAppl){
if(!((StrategoAppl)term).getConstructor().equals(((StrategoAppl)origin).getConstructor()))
return false;
}
return
term.getTermType() == origin.getTermType() &&
term.getSubtermCount() == origin.getSubtermCount();
}
示例6: isLayout
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
public boolean isLayout() {
if (isLayout != null)
return isLayout;
IStrategoTerm t = prod.getSubterm(1);
while (true) {
if (t.getTermType() != IStrategoTerm.APPL) {
isLayout = false;
break;
}
IStrategoAppl app = (IStrategoAppl) t;
if (Term.hasConstructor(app, "layout")) {
isLayout = true;
break;
}
if (app.getSubtermCount() == 1 &&
(Term.hasConstructor(app, "cf") ||
Term.hasConstructor(app, "lex") ||
Term.hasConstructor(app, "opt") ||
Term.hasConstructor(app, "iter")))
t = app.getSubterm(0);
else {
isLayout = false;
break;
}
}
return isLayout;
}
示例7: collectTerms
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private static void collectTerms(IStrategoTerm term, String constructor, ArrayList<IStrategoAppl> results) {
if(term.getTermType() == IStrategoTerm.APPL && cons(term).equals(constructor))
results.add((IStrategoAppl) term);
// TODO: optimize: use TermVisitor, avoid indexed access to long lists
for(int i = 0; i < term.getSubtermCount(); i++) {
collectTerms(termAt(term, i), constructor, results);
}
}
示例8: match
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
public Results match(IContext env, IStrategoTerm t, IStrategoAppl p)
throws InterpreterException {
if (t == null) {
throw new InterpreterException("Null term while matching: term library or one of the primitives is defective");
}
switch (t.getTermType()) {
case IStrategoTerm.APPL:
return matchAppl(env, (IStrategoAppl) t, p);
case IStrategoTerm.INT:
return matchInt(env, (IStrategoInt) t, p);
case IStrategoTerm.REAL:
return matchReal(env, (IStrategoReal) t, p);
case IStrategoTerm.STRING:
return matchString(env, (IStrategoString) t, p);
case IStrategoTerm.LIST:
return matchList(env, (IStrategoList) t, p);
case IStrategoTerm.TUPLE:
return matchTuple(env, (IStrategoTuple) t, p);
case IStrategoTerm.REF:
return matchRef(env, (IStrategoRef)t, p);
case IStrategoTerm.BLOB:
return matchBlob(env, t, p);
default:
throw new InterpreterException("Unsupported term type : "
+ t.getClass().toString() + " [" + t.getTermType() + "]");
}
}
示例9: match
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
public Results match(IContext env, IStrategoTerm t, IStrategoAppl p)
throws InterpreterException {
if (t == null) {
throw new InterpreterException("Null term while matching: term library is defective");
}
switch (t.getTermType()) {
case IStrategoTerm.APPL:
return matchAppl(env, (IStrategoAppl) t, p);
case IStrategoTerm.INT:
return matchInt(env, (IStrategoInt) t, p);
case IStrategoTerm.REAL:
return matchReal(env, (IStrategoReal) t, p);
case IStrategoTerm.STRING:
return matchString(env, (IStrategoString) t, p);
case IStrategoTerm.LIST:
return matchList(env, (IStrategoList) t, p);
case IStrategoTerm.TUPLE:
return matchTuple(env, (IStrategoTuple) t, p);
case IStrategoTerm.REF:
return matchRef(env, (IStrategoRef)t, p);
case IStrategoTerm.BLOB:
return matchBlob(env, t, p);
default:
throw new InterpreterException("Unsupported term type : "
+ t.getClass().toString() + " [" + t.getTermType() + "]");
}
}
示例10: doSlowMatch
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
@Override
protected boolean doSlowMatch(IStrategoTerm second, int commonStorageType) {
if (second == this)
return true;
if (second == null || second.getTermType() != CTOR)
return false;
IStrategoConstructor other = (IStrategoConstructor) second;
return name.equals(other.getName()) && arity == other.getArity();
}
示例11: prettyPrintStratego
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private static String prettyPrintStratego(IStrategoTerm term) {
final org.strategoxt.lang.Context context = new org.strategoxt.lang.Context();
org.strategoxt.strc.Main.init(context);
IStrategoTerm termPP = pp_stratego_string_0_0.instance.invoke(context, term);
if(termPP == null || termPP.getTermType() != IStrategoTerm.STRING)
return "";
return ((StrategoString) termPP).stringValue();
}
示例12: haveSameSignature
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
/**
* True iff one of these conditions hold:
* 1. both are Appl with same constructor name and same number of subterms
* 2. both are lists
* 3. both are tuples
* @param t1
* @param t2
* @return
*/
public static boolean haveSameSignature(IStrategoTerm t1, IStrategoTerm t2){
if(t1 == null || t2 == null)
return false;
if(t1.getTermType() == StrategoTerm.APPL && t2.getTermType() == StrategoTerm.APPL){
boolean sameConstructorName = haveSameConstructorName(t1, t2);
return sameConstructorName && t1.getSubtermCount() == t2.getSubtermCount();
}
if (Tools.isTermList(t1) && Tools.isTermList(t2))
return true;
if (Tools.isTermTuple(t1) && Tools.isTermTuple(t2))
return true;
else
return false;
}
示例13: doSlowMatch
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
@Override
protected boolean doSlowMatch(IStrategoTerm second, int commonStorageType) {
if(second.getTermType() != IStrategoTerm.STRING)
return false;
String value = stringValue();
String secondValue = ((IStrategoString) second).stringValue();
if (value == secondValue) {
// Do nothing
} else if (value.equals(secondValue)) {
// Don't apply resharing here (StrategoXT/801) but maintain
// the string instance that may be in the string pool
// if (commonStorageType == SHARABLE)
// this.value = secondValue;
} else {
return false;
}
IStrategoList annotations = getAnnotations();
IStrategoList secondAnnotations = second.getAnnotations();
if (annotations == secondAnnotations) {
// assert annotations.isEmpty() ? this == second : true : "Maximal sharing contract broken";
return true;
} else if (annotations.match(secondAnnotations)) {
if (commonStorageType == SHARABLE) internalSetAnnotations(secondAnnotations);
return true;
} else {
return false;
}
}
示例14: isTreeAmb
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
private boolean isTreeAmb(IStrategoTerm t) {
return t.getTermType() == APPL
&& ((IStrategoAppl) t).getConstructor() == amb;
}
示例15: isTermString
import org.spoofax.interpreter.terms.IStrategoTerm; //导入方法依赖的package包/类
public static boolean isTermString(IStrategoTerm t) {
return t.getTermType() == STRING;
}