1 /*
   2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.openjdk.buildtools.jdwpgen;
  27 
  28 import java.util.*;
  29 import java.io.*;
  30 
  31 class ConstantSetNode extends AbstractNamedNode {
  32 
  33     /**
  34      * The mapping between a constant and its value.
  35      */
  36     protected static final Map<String, String> constantMap = new HashMap<>();
  37 
  38     void prune() {
  39         List<Node> addons = new ArrayList<>();
  40 
  41         if (!addons.isEmpty()) {
  42             components.addAll(addons);
  43         }
  44         super.prune();
  45     }
  46 
  47     void constrainComponent(Context ctx, Node node) {
  48         if (node instanceof ConstantNode) {
  49             node.constrain(ctx);
  50             constantMap.put(name + "_" + ((ConstantNode) node).getName(), node.comment());
  51         } else {
  52             error("Expected 'Constant', got: " + node);
  53         }
  54     }
  55 
  56     void document(PrintWriter writer) {
  57         writer.println("<h2 id=\"" + context.whereC + "\">" + name + " Constants</h2>");
  58         writer.println(comment());
  59         writer.println("<table><tr>");
  60         writer.println("<th class=\"bold\" style=\"width: 30%\" scope=\"col\">Name");
  61         writer.println("<th class=\"centered bold\" style=\"width: 5%\" scope=\"col\">Value");
  62         writer.println("<th class=\"bold\" style=\"width: 65%\" scope=\"col\">Description");
  63         writer.println("</tr>");
  64         for (Node node : components) {
  65             node.document(writer);
  66         }
  67         writer.println("</table>");
  68     }
  69 
  70     void documentIndex(PrintWriter writer) {
  71         writer.print("<li><a href=\"#" + context.whereC + "\">");
  72         writer.println(name() + "</a> Constants");
  73 //        writer.println("<ul>");
  74 //        for (Iterator it = components.iterator(); it.hasNext();) {
  75 //            ((Node)it.next()).documentIndex(writer);
  76 //        }
  77 //        writer.println("</ul>");
  78     }
  79 
  80     void genJavaClassSpecifics(PrintWriter writer, int depth) {
  81     }
  82 
  83     void genJava(PrintWriter writer, int depth) {
  84         genJavaClass(writer, depth);
  85     }
  86 
  87     public static String getConstant(String key){
  88         String com = constantMap.get(key);
  89         if(com == null){
  90             return "";
  91         } else {
  92             return com;
  93         }
  94     }
  95 
  96 }