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: abstract class AbstractNamedNode extends Node {
032:
033: NameNode nameNode;
034: String name;
035:
036: public String name() {
037: return name;
038: }
039:
040: void prune() {
041: Iterator it = components.iterator();
042:
043: if (it.hasNext()) {
044: Node nameNode = (Node) it.next();
045:
046: if (nameNode instanceof NameNode) {
047: this .nameNode = (NameNode) nameNode;
048: this .name = this .nameNode.text();
049: it.remove();
050: } else {
051: error("Bad name: " + name);
052: }
053: } else {
054: error("empty");
055: }
056: super .prune();
057: }
058:
059: void constrain(Context ctx) {
060: nameNode.constrain(ctx);
061: super .constrain(ctx.subcontext(name));
062: }
063:
064: void document(PrintWriter writer) {
065: writer.println("<h4><a name=" + name + ">" + name
066: + " Command Set</a></h4>");
067: for (Iterator it = components.iterator(); it.hasNext();) {
068: ((Node) it.next()).document(writer);
069: }
070: }
071:
072: String javaClassName() {
073: return name();
074: }
075:
076: void genJavaClassSpecifics(PrintWriter writer, int depth) {
077: }
078:
079: String javaClassImplements() {
080: return ""; // does not implement anything, by default
081: }
082:
083: void genJavaClass(PrintWriter writer, int depth) {
084: writer.println();
085: genJavaComment(writer, depth);
086: indent(writer, depth);
087: if (depth != 0) {
088: writer.print("static ");
089: }
090: writer.print("class " + javaClassName());
091: writer.println(javaClassImplements() + " {");
092: genJavaClassSpecifics(writer, depth + 1);
093: for (Iterator it = components.iterator(); it.hasNext();) {
094: ((Node) it.next()).genJava(writer, depth + 1);
095: }
096: indent(writer, depth);
097: writer.println("}");
098: }
099:
100: void genCInclude(PrintWriter writer) {
101: if (nameNode instanceof NameValueNode) {
102: writer.println("#define " + context.whereC + " "
103: + nameNode.value());
104: }
105: super.genCInclude(writer);
106: }
107: }
|