001: /*
002: * @(#)AltNode.java 1.14 06/10/25
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.tools.jdwpgen;
028:
029: import java.util.*;
030: import java.io.*;
031:
032: class AltNode extends AbstractGroupNode implements TypeNode {
033:
034: SelectNode select;
035:
036: void constrain(Context ctx) {
037: super .constrain(ctx);
038:
039: if (!(nameNode instanceof NameValueNode)) {
040: error("Alt name must have value: " + nameNode);
041: }
042: if (parent instanceof SelectNode) {
043: select = (SelectNode) parent;
044: } else {
045: error("Alt must be in Select");
046: }
047: }
048:
049: void document(PrintWriter writer) {
050: docRowStart(writer);
051: writer.println("<td colspan="
052: + (maxStructIndent - structIndent + 1) + ">");
053: writer.println("Case " + nameNode.name + " - if <i>"
054: + ((SelectNode) parent).typeNode.name + "</i> is "
055: + nameNode.value() + ":");
056: writer.println("<td>" + comment() + " ");
057: ++structIndent;
058: super .document(writer);
059: --structIndent;
060: }
061:
062: String javaClassImplements() {
063: return " extends " + select.commonBaseClass();
064: }
065:
066: void genJavaClassSpecifics(PrintWriter writer, int depth) {
067: indent(writer, depth);
068: writer.print("static final " + select.typeNode.javaType());
069: writer.println(" ALT_ID = " + nameNode.value() + ";");
070: if (context.isWritingCommand()) {
071: genJavaCreateMethod(writer, depth);
072: } else {
073: indent(writer, depth);
074: writer.println(select.typeNode.javaParam() + "() {");
075: indent(writer, depth + 1);
076: writer.println("return ALT_ID;");
077: indent(writer, depth);
078: writer.println("}");
079: }
080: super .genJavaClassSpecifics(writer, depth);
081: }
082:
083: void genJavaWriteMethod(PrintWriter writer, int depth) {
084: genJavaWriteMethod(writer, depth, "");
085: }
086:
087: void genJavaReadsSelectCase(PrintWriter writer, int depth,
088: String common) {
089: indent(writer, depth);
090: writer.println("case " + nameNode.value() + ":");
091: indent(writer, depth + 1);
092: writer.println(common + " = new " + name + "(vm, ps);");
093: indent(writer, depth + 1);
094: writer.println("break;");
095: }
096:
097: void genJavaCreateMethod(PrintWriter writer, int depth) {
098: indent(writer, depth);
099: writer.print("static " + select.name() + " create(");
100: writer.print(javaParams());
101: writer.println(") {");
102: indent(writer, depth + 1);
103: writer.print("return new " + select.name() + "(");
104: writer.print("ALT_ID, new " + javaClassName() + "(");
105: for (Iterator it = components.iterator(); it.hasNext();) {
106: TypeNode tn = (TypeNode) it.next();
107: writer.print(tn.name());
108: if (it.hasNext()) {
109: writer.print(", ");
110: }
111: }
112: writer.println("));");
113: indent(writer, depth);
114: writer.println("}");
115: }
116:
117: }
|