KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > types > CofferConstructorInstance_c


1 package polyglot.ext.coffer.types;
2
3 import polyglot.ext.jl.types.*;
4 import polyglot.types.*;
5 import polyglot.util.*;
6 import java.util.*;
7
8 /** An implementation of the <code>CofferConstructorInstance</code> interface.
9  */

10 public class CofferConstructorInstance_c extends ConstructorInstance_c
11                      implements CofferConstructorInstance
12 {
13     protected KeySet entryKeys;
14     protected KeySet returnKeys;
15     protected List throwConstraints;
16
17     public CofferConstructorInstance_c(CofferTypeSystem ts, Position pos,
18         ClassType container, Flags flags,
19         List argTypes,
20             KeySet entryKeys, KeySet returnKeys, List throwConstraints)
21     {
22     super(ts, pos, container, flags, argTypes, Collections.EMPTY_LIST);
23         this.entryKeys = entryKeys;
24         this.returnKeys = returnKeys;
25         this.throwConstraints = TypedList.copyAndCheck(throwConstraints, ThrowConstraint.class, true);
26
27         if (entryKeys == null)
28             throw new InternalCompilerError("null entry keys for " + this);
29     }
30
31     public KeySet entryKeys() {
32     return entryKeys;
33     }
34
35     public KeySet returnKeys() {
36     return returnKeys;
37     }
38
39     public List throwConstraints() {
40         return throwConstraints;
41     }
42
43     public List throwTypes() {
44         return new CachingTransformingList(throwConstraints, new GetType());
45     }
46
47     public class GetType implements Transformation {
48         public Object JavaDoc transform(Object JavaDoc o) {
49             return ((ThrowConstraint) o).throwType();
50         }
51     }
52
53     public ConstructorInstance throwTypes(List throwTypes) {
54         Iterator i = throwTypes.iterator();
55         Iterator j = throwConstraints.iterator();
56
57         boolean changed = false;
58
59         List l = new LinkedList();
60
61         while (i.hasNext() && j.hasNext()) {
62             Type t = (Type) i.next();
63             ThrowConstraint c = (ThrowConstraint) j.next();
64             if (t != c.throwType()) {
65                 c = c.throwType(t);
66                 changed = true;
67             }
68
69             l.add(c);
70         }
71
72         if (i.hasNext() || j.hasNext()) {
73             throw new InternalCompilerError("unimplemented");
74         }
75
76         if (! changed) {
77             return this;
78         }
79
80         return (ConstructorInstance) throwConstraints(l);
81     }
82
83     public CofferProcedureInstance entryKeys(KeySet entryKeys) {
84     CofferConstructorInstance_c n = (CofferConstructorInstance_c) copy();
85         n.entryKeys = entryKeys;
86     return n;
87     }
88
89     public CofferProcedureInstance returnKeys(KeySet returnKeys) {
90     CofferConstructorInstance_c n = (CofferConstructorInstance_c) copy();
91         n.returnKeys = returnKeys;
92     return n;
93     }
94
95     public CofferProcedureInstance throwConstraints(List throwConstraints) {
96     CofferConstructorInstance_c n = (CofferConstructorInstance_c) copy();
97         n.throwConstraints = TypedList.copyAndCheck(throwConstraints, ThrowConstraint.class, true);
98     return n;
99     }
100
101     public String JavaDoc toString() {
102         return super.toString() + " " + entryKeys + "->" + returnKeys +
103                                   " throws " + throwConstraints;
104     }
105 }
106
Popular Tags