KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > LocationProc


1 // Copyright (c) 2005 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.mapping;
5
6 /** A Procedure that evaluates to the value of a Location.
7  * Calling it with one argument sets the value, for compatibility
8  * with the "parameter objects" of SRFI-39.
9  */

10 public class LocationProc extends Procedure0or1 implements HasSetter
11 {
12   Location loc;
13
14   public LocationProc (Location loc)
15   {
16     this.loc = loc;
17   }
18
19   public static LocationProc makeNamed (Symbol name, Location loc)
20   {
21     LocationProc lproc = new LocationProc(loc);
22     lproc.setSymbol(name);
23     return lproc;
24   }
25
26   public LocationProc (Location loc, Procedure converter)
27   {
28     this.loc = loc;
29     if (converter != null)
30       pushConverter(converter);
31   }
32
33   public void pushConverter (Procedure converter)
34   {
35     loc = ConstrainedLocation.make(loc, converter);
36   }
37
38   public Object JavaDoc apply0 () throws Throwable JavaDoc
39   {
40     return loc.get();
41   }
42
43   public Object JavaDoc apply1 (Object JavaDoc value) throws Throwable JavaDoc
44   {
45     set0(value);
46     return Values.empty;
47   }
48
49   public void set0 (Object JavaDoc value) throws Throwable JavaDoc
50   {
51     loc.set(value);
52   }
53
54   public Procedure getSetter()
55   {
56     return new Setter0(this);
57   }
58
59   public final Location getLocation ()
60   {
61     return loc;
62   }
63
64   public String JavaDoc toString ()
65   {
66     Object JavaDoc n = getSymbol();
67     if (n != null)
68       return super.toString();
69     return "#<location-proc "+loc+">";
70   }
71 }
72
Popular Tags