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