01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2006 New York University
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.xform;
20:
21: import java.util.List;
22: import java.util.Iterator;
23:
24: import xtc.tree.Node;
25:
26: /**
27: * LinesFunction external method class.
28: *
29: * @version $Revision: 1.7 $
30: */
31: class LinesFunction implements Function {
32: /**
33: * Get the name of the function.
34: * @return The functions name
35: */
36: public String getName() {
37: return "lines";
38: }
39:
40: /**
41: * prints line information for each item in the sequence
42: * @param args The sequence of items
43: * @return The sequence of items passed in args
44: */
45: public Object apply(List<Object> args) {
46: Engine.Sequence<?> arg = (Engine.Sequence<?>) args.get(0);
47:
48: for (Iterator<?> argIter = arg.flatIterator(); argIter
49: .hasNext();) {
50: Item item = (Item) argIter.next();
51: if (null != item.object) {
52: System.out.println(((Node) item.object).getLocation());
53: System.out.flush();
54: }
55: }
56: return arg;
57: }
58: }
|