001: /*
002: * Copyright 1998-2002 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: abstract class AbstractTypeListNode extends AbstractNamedNode {
032:
033: void constrainComponent(Context ctx, Node node) {
034: if (node instanceof TypeNode) {
035: node.constrain(ctx);
036: } else {
037: error("Expected type descriptor item, got: " + node);
038: }
039: }
040:
041: void document(PrintWriter writer) {
042: writer.println("<dt>" + name() + " Data");
043: if (components.size() == 0) {
044: writer.println("<dd>(None)");
045: } else {
046: writer
047: .println("<dd><table border=1 cellpadding=3 cellspacing=0 width=\"90%\" summary=\"\"><tr>");
048: for (int i = maxStructIndent; i > 0; --i) {
049: writer.print("<th width=\"4%\">");
050: }
051: writer.println("<th width=\"15%\"><th width=\"65%\">");
052: writer.println("");
053: for (Iterator it = components.iterator(); it.hasNext();) {
054: ((Node) it.next()).document(writer);
055: }
056: writer.println("</table>");
057: }
058: }
059:
060: void genJavaClassBodyComponents(PrintWriter writer, int depth) {
061: for (Iterator it = components.iterator(); it.hasNext();) {
062: TypeNode tn = (TypeNode) it.next();
063:
064: tn.genJavaDeclaration(writer, depth);
065: }
066: }
067:
068: void genJavaReads(PrintWriter writer, int depth) {
069: for (Iterator it = components.iterator(); it.hasNext();) {
070: TypeNode tn = (TypeNode) it.next();
071: tn.genJavaRead(writer, depth, tn.name());
072: }
073: }
074:
075: void genJavaReadingClassBody(PrintWriter writer, int depth,
076: String className) {
077: genJavaClassBodyComponents(writer, depth);
078: writer.println();
079: indent(writer, depth);
080: if (!context.inEvent()) {
081: writer.print("private ");
082: }
083: writer.println(className
084: + "(VirtualMachineImpl vm, PacketStream ps) {");
085: genJavaReads(writer, depth + 1);
086: indent(writer, depth);
087: writer.println("}");
088: }
089:
090: String javaParams() {
091: StringBuffer sb = new StringBuffer();
092: for (Iterator it = components.iterator(); it.hasNext();) {
093: TypeNode tn = (TypeNode) it.next();
094: sb.append(tn.javaParam());
095: if (it.hasNext()) {
096: sb.append(", ");
097: }
098: }
099: return sb.toString();
100: }
101:
102: void genJavaWrites(PrintWriter writer, int depth) {
103: for (Iterator it = components.iterator(); it.hasNext();) {
104: TypeNode tn = (TypeNode) it.next();
105: tn.genJavaWrite(writer, depth, tn.name());
106: }
107: }
108:
109: void genJavaWritingClassBody(PrintWriter writer, int depth,
110: String className) {
111: genJavaClassBodyComponents(writer, depth);
112: writer.println();
113: indent(writer, depth);
114: writer.println(className + "(" + javaParams() + ") {");
115: for (Iterator it = components.iterator(); it.hasNext();) {
116: TypeNode tn = (TypeNode) it.next();
117: indent(writer, depth + 1);
118: writer.println("this." + tn.name() + " = " + tn.name()
119: + ";");
120: }
121: indent(writer, depth);
122: writer.println("}");
123: }
124: }
|