Package: StateContext

StateContext

nameinstructionbranchcomplexitylinemethod
StateContext(IInterpreterAssistantFactory, ILexLocation, String)
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%
StateContext(IInterpreterAssistantFactory, ILexLocation, String, Context, Context)
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%
StateContext(IInterpreterAssistantFactory, ILexLocation, String, Context, Context, Context)
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%
check(ILexNameToken)
M: 0 C: 46
100%
M: 1 C: 13
93%
M: 1 C: 7
88%
M: 0 C: 16
100%
M: 0 C: 1
100%
printStackTrace(PrintWriter, boolean)
M: 51 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
toString()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 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.Value;
32:
33: /**
34: * A root context for non-object method invocations.
35: */
36:
37: @SuppressWarnings("serial")
38: public class StateContext extends RootContext
39: {
40:         /** The state context, if any. */
41:         public final Context stateCtxt;
42:
43:         /**
44:          * Create a RootContext 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 sctxt
55:          * Any state context.
56:          */
57:
58:         public StateContext(IInterpreterAssistantFactory af, ILexLocation location,
59:                         String title, Context freeVariables, Context outer, Context sctxt)
60:         {
61:                 super(af, location, title, freeVariables, outer);
62:                 this.stateCtxt = sctxt;
63:         }
64:
65:         public StateContext(IInterpreterAssistantFactory af, ILexLocation location,
66:                         String title, Context outer, Context sctxt)
67:         {
68:                 this(af, location, title, null, outer, sctxt);
69:         }
70:
71:         /**
72:          * Create a RootContext with no outer context or state.
73:          *
74:          * @param af
75:          * @param location
76:          * The location of the context.
77:          * @param title
78:          * The name of the location.
79:          */
80:
81:         public StateContext(IInterpreterAssistantFactory af, ILexLocation location,
82:                         String title)
83:         {
84:                 super(af, location, title, null, null);
85:                 this.stateCtxt = null;
86:         }
87:
88:         /**
89:          * Check for the name in the current context and state, and if not present search the global context. Note that the
90:          * context chain is not followed.
91:          *
92:          * @see Context#check(ILexNameToken)
93:          */
94:
95:         @Override
96:         public Value check(ILexNameToken name)
97:         {
98:                 Value v = get(name);
99:
100:•                if (v != null)
101:                 {
102:                         return v;
103:                 }
104:
105:•                if (freeVariables != null)
106:                 {
107:                         v = freeVariables.get(name);
108:
109:•                        if (v != null)
110:                         {
111:                                 return v;
112:                         }
113:                 }
114:
115:                 // A RootContext stops the name search from continuing down the
116:                 // context chain. It first checks any state context, then goes
117:                 // down to the global level.
118:
119:•                if (v == null)
120:                 {
121:•                        if (stateCtxt != null)
122:                         {
123:                                 v = stateCtxt.check(name);
124:
125:•                                if (v != null)
126:                                 {
127:                                         return v;
128:                                 }
129:                         }
130:
131:                         Context g = getGlobal();
132:
133:•                        if (g != this)
134:                         {
135:                                 return g.check(name);
136:                         }
137:                 }
138:
139:                 return v;
140:         }
141:
142:         @Override
143:         public String toString()
144:         {
145:•                if (stateCtxt != null)
146:                 {
147:                         return super.toString() + "\tState visible\n";
148:                 } else
149:                 {
150:                         return super.toString();
151:                 }
152:         }
153:
154:         @Override
155:         public void printStackTrace(PrintWriter out, boolean variables)
156:         {
157:•                if (outer == null) // Don't expand initial context
158:                 {
159:                         out.println("In root context of " + title);
160:                 } else
161:                 {
162:•                        if (variables)
163:                         {
164:                                 out.print(this.format("\t", this));
165:
166:•                                if (stateCtxt != null)
167:                                 {
168:                                         out.println("\tState visible");
169:                                 }
170:                         }
171:
172:                         out.println("In root context of " + title + " " + location);
173:                         outer.printStackTrace(out, false);
174:                 }
175:         }
176: }