• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package build.tools.jdwpgen;
27 
28 import java.util.*;
29 
30 class Context {
31 
32     static final int outer = 0;
33     static final int readingReply = 1;
34     static final int writingCommand = 2;
35 
36     final String whereJava;
37     final String whereC;
38 
39     int state = outer;
40     private boolean inEvent = false;
41 
Context()42     Context() {
43         whereJava = "";
44         whereC = "";
45     }
46 
Context(String whereJava, String whereC)47     private Context(String whereJava, String whereC) {
48         this.whereJava = whereJava;
49         this.whereC = whereC;
50     }
51 
subcontext(String level)52     Context subcontext(String level) {
53         Context ctx;
54         if (whereC.length() == 0) {
55             ctx = new Context(level, level);
56         } else {
57             ctx = new Context(whereJava + "." + level, whereC + "_" + level);
58         }
59         ctx.state = state;
60         ctx.inEvent = inEvent;
61         return ctx;
62     }
63 
cloneContext()64     private Context cloneContext() {
65         Context ctx = new Context(whereJava, whereC);
66         ctx.state = state;
67         ctx.inEvent = inEvent;
68         return ctx;
69     }
70 
replyReadingSubcontext()71     Context replyReadingSubcontext() {
72         Context ctx = cloneContext();
73         ctx.state = readingReply;
74         return ctx;
75     }
76 
commandWritingSubcontext()77     Context commandWritingSubcontext() {
78         Context ctx = cloneContext();
79         ctx.state = writingCommand;
80         return ctx;
81     }
82 
inEventSubcontext()83     Context inEventSubcontext() {
84         Context ctx = cloneContext();
85         ctx.inEvent = true;
86         return ctx;
87     }
88 
inEvent()89     boolean inEvent() {
90         return inEvent;
91     }
92 
isWritingCommand()93     boolean isWritingCommand() {
94         return state == writingCommand;
95     }
96 
isReadingReply()97     boolean isReadingReply() {
98         return state == readingReply;
99     }
100 }
101