Package: ObjectContext

ObjectContext

nameinstructionbranchcomplexitylinemethod
ObjectContext(IInterpreterAssistantFactory, ILexLocation, String, Context, Context, ObjectValue)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
ObjectContext(IInterpreterAssistantFactory, ILexLocation, String, Context, ObjectValue)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
check(ILexNameToken)
M: 4 C: 39
91%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 2 C: 12
86%
M: 0 C: 1
100%
deepCopy()
M: 49 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getSelf()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
printStackTrace(PrintWriter, boolean)
M: 45 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
toString()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.interpreter.runtime;
25:
26: import java.io.PrintWriter;
27:
28: import org.overture.ast.intf.lex.ILexLocation;
29: import org.overture.ast.intf.lex.ILexNameToken;
30: import org.overture.interpreter.assistant.IInterpreterAssistantFactory;
31: import org.overture.interpreter.values.ObjectValue;
32: import org.overture.interpreter.values.Value;
33:
34: /**
35: * A root context for object method invocations.
36: */
37:
38: @SuppressWarnings("serial")
39: public class ObjectContext extends RootContext
40: {
41:         public final ObjectValue self;
42:
43:         /**
44:          * Create an ObjectContext from the values passed.
45:          *
46:          * @param af
47:          * @param location
48:          * The location of the context.
49:          * @param title
50:          * The name of the location.
51:          * @param freeVariables
52:          * @param outer
53:          * The context chain (not searched).
54:          * @param self
55:          * The object context.
56:          */
57:
58:         public ObjectContext(IInterpreterAssistantFactory af,
59:                         ILexLocation location, String title, Context freeVariables,
60:                         Context outer, ObjectValue self)
61:         {
62:                 super(af, location, title, freeVariables, outer);
63:                 this.self = self;
64:         }
65:
66:         public ObjectContext(IInterpreterAssistantFactory af,
67:                         ILexLocation location, String title, Context outer, ObjectValue self)
68:         {
69:                 this(af, location, title, null, outer, self);
70:         }
71:
72:         @Override
73:         public Context deepCopy()
74:         {
75:                 Context below = null;
76:
77:•                if (outer != null)
78:                 {
79:                         below = outer.deepCopy();
80:                 }
81:
82:                 Context result = new ObjectContext(assistantFactory, location, title, freeVariables, below, self.deepCopy());
83:
84:•                for (ILexNameToken var : keySet())
85:                 {
86:                         Value v = get(var);
87:                         result.put(var, v.deepCopy());
88:                 }
89:
90:                 return result;
91:         }
92:
93:         /**
94:          * Check for the name in the current context and self, and if not present search the global context. Note that the
95:          * context chain is not followed.
96:          *
97:          * @see Context#check(ILexNameToken)
98:          */
99:
100:         @Override
101:         public Value check(ILexNameToken name)
102:         {
103:                 // A RootContext stops the name search from continuing down the
104:                 // context chain. It first checks any local context, then it
105:                 // checks the "self" context, then it goes down to the global level.
106:
107:                 Value v = get(name); // Local variables
108:
109:•                if (v != null)
110:                 {
111:                         return v;
112:                 }
113:
114:•                if (freeVariables != null)
115:                 {
116:                         v = freeVariables.get(name);
117:
118:•                        if (v != null)
119:                         {
120:                                 return v;
121:                         }
122:                 }
123:
124:                 v = self.get(name, name.getExplicit());
125:
126:•                if (v != null)
127:                 {
128:                         return v;
129:                 }
130:
131:                 Context g = getGlobal();
132:
133:•                if (g != this)
134:                 {
135:                         return g.check(name);
136:                 }
137:
138:                 return v;
139:         }
140:
141:         @Override
142:         public String toString()
143:         {
144:                 // return super.toString(); // Self there anyway ...+ self.toString();
145:                 return (DEBUG ? "#" + id + " " : "") + format("", this)
146:                                 + self.toString().replace(", ", "\n\t")
147:                                 + "\n-------------------\n" + outer;
148:         }
149:
150:         @Override
151:         public void printStackTrace(PrintWriter out, boolean variables)
152:         {
153:•                if (outer == null) // Don't expand initial context
154:                 {
155:                         out.println("In object context of " + title);
156:                 } else
157:                 {
158:•                        if (variables)
159:                         {
160:                                 out.print(this.format("\t", this));
161:                         }
162:
163:                         out.println("In object context of " + title + " " + location);
164:                         outer.printStackTrace(out, false);
165:                 }
166:         }
167:
168:         @Override
169:         public ObjectValue getSelf()
170:         {
171:                 return self;
172:         }
173: }