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