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