if ((depthSpecified || depthEmpty) && flag.leaves) {
final IntegerCalc depthCalc =
depthSpecified
? compiler.compileInteger(call.getArg(1))
: null;
return new AbstractMemberListCalc(
call, new Calc[] {memberCalc, depthCalc})
{
public List<Member> evaluateMemberList(Evaluator evaluator) {
final Member member = memberCalc.evaluateMember(evaluator);
List<Member> result = new ArrayList<Member>();
int depth = -1;
if (depthCalc != null) {
depth = depthCalc.evaluateInteger(evaluator);
if (depth < 0) {
depth = -1; // no limit
}
}
final SchemaReader schemaReader =
evaluator.getSchemaReader();
descendantsLeavesByDepth(
member, result, schemaReader, depth);
hierarchizeMemberList(result, false);
return result;
}
};
} else if (depthSpecified) {
final IntegerCalc depthCalc =
compiler.compileInteger(call.getArg(1));
final Flag flag1 = flag;
return new AbstractMemberListCalc(
call, new Calc[] {memberCalc, depthCalc})
{
public List<Member> evaluateMemberList(Evaluator evaluator) {
final Member member = memberCalc.evaluateMember(evaluator);
List<Member> result = new ArrayList<Member>();
final int depth = depthCalc.evaluateInteger(evaluator);
final SchemaReader schemaReader =
evaluator.getSchemaReader();
descendantsByDepth(
member, result, schemaReader,
depth, flag1.before, flag1.self, flag1.after,
evaluator);
hierarchizeMemberList(result, false);
return result;
}
};
} else {
final LevelCalc levelCalc =
call.getArgCount() > 1
? compiler.compileLevel(call.getArg(1))
: null;
final Flag flag2 = flag;
return new AbstractMemberListCalc(
call, new Calc[] {memberCalc, levelCalc})
{
public List<Member> evaluateMemberList(Evaluator evaluator) {
final Evaluator context =
evaluator.isNonEmpty() ? evaluator : null;