}
private void extractFields(ATerm t, Location loc) {
AFun fun;
ATermAppl appl;
ATermList list;
switch (t.getType()) {
case ATerm.APPL :
//{{{ Call 'extractFields' for every argument
appl = (ATermAppl) t;
fun = appl.getAFun();
for (int i = 0; i < fun.getArity(); i++) {
Location newloc = (Location) loc.clone();
newloc.addStep(new Step(Step.ARG, i));
extractFields(appl.getArgument(i), newloc);
}
//}}}
break;
case ATerm.LIST :
//{{{ Call 'extractFields' for every element
list = (ATermList) t;
for (int i = 0; !list.isEmpty(); i++) {
Location newloc = (Location) loc.clone();
newloc.addStep(new Step(Step.ELEM, i));
extractFields(list.getFirst(), newloc);
list = list.getNext();
}
//}}}
break;
case ATerm.PLACEHOLDER :
//{{{ Add a new field based on this placeholder
ATerm ph = ((ATermPlaceholder) t).getPlaceholder();
if (ph.getType() == ATerm.LIST) {
list = (ATermList) ph;
appl = (ATermAppl) list.elementAt(0);
String fieldId = appl.getAFun().getName();
appl = (ATermAppl) appl.getArgument(0);
String fieldType = appl.getAFun().getName();
loc.makeTail();
addField(fieldId, fieldType, loc);