Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/jdwpgen/AltNode.java
32287 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.jdwpgen;2627import java.util.*;28import java.io.*;2930class AltNode extends AbstractGroupNode implements TypeNode {3132SelectNode select = null;3334void constrain(Context ctx) {35super.constrain(ctx);3637if (!(nameNode instanceof NameValueNode)) {38error("Alt name must have value: " + nameNode);39}40if (parent instanceof SelectNode) {41select = (SelectNode)parent;42} else {43error("Alt must be in Select");44}45}4647void document(PrintWriter writer) {48docRowStart(writer);49writer.println("<td colspan=" +50(maxStructIndent - structIndent + 1) + ">");51writer.println("Case " + nameNode.name + " - if <i>" +52((SelectNode)parent).typeNode.name +53"</i> is " + nameNode.value() + ":");54writer.println("<td>" + comment() + " ");55++structIndent;56super.document(writer);57--structIndent;58}5960String javaClassImplements() {61return " extends " + select.commonBaseClass();62}6364void genJavaClassSpecifics(PrintWriter writer, int depth) {65indent(writer, depth);66writer.print("static final " + select.typeNode.javaType());67writer.println(" ALT_ID = " + nameNode.value() + ";");68if (context.isWritingCommand()) {69genJavaCreateMethod(writer, depth);70} else {71indent(writer, depth);72writer.println(select.typeNode.javaParam() + "() {");73indent(writer, depth+1);74writer.println("return ALT_ID;");75indent(writer, depth);76writer.println("}");77}78super.genJavaClassSpecifics(writer, depth);79}8081void genJavaWriteMethod(PrintWriter writer, int depth) {82genJavaWriteMethod(writer, depth, "");83}8485void genJavaReadsSelectCase(PrintWriter writer, int depth, String common) {86indent(writer, depth);87writer.println("case " + nameNode.value() + ":");88indent(writer, depth+1);89writer.println(common + " = new " + name + "(vm, ps);");90indent(writer, depth+1);91writer.println("break;");92}9394void genJavaCreateMethod(PrintWriter writer, int depth) {95indent(writer, depth);96writer.print("static " + select.name() + " create(");97writer.print(javaParams());98writer.println(") {");99indent(writer, depth+1);100writer.print("return new " + select.name() + "(");101writer.print("ALT_ID, new " + javaClassName() + "(");102for (Iterator<Node> it = components.iterator(); it.hasNext();) {103TypeNode tn = (TypeNode)it.next();104writer.print(tn.name());105if (it.hasNext()) {106writer.print(", ");107}108}109writer.println("));");110indent(writer, depth);111writer.println("}");112}113114}115116117