jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/MethodHTML.java
author joehw
Mon, 17 Apr 2017 16:24:10 -0700
changeset 44797 8b3b3b911b8a
parent 25868 686eef1e7a79
child 46174 5611d2529b49
permissions -rw-r--r--
8162572: Update License Header for all JAXP sources Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
/*
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    14
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    18
 * See the License for the specific language governing permissions and
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    19
 * limitations under the License.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    20
 */
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.bcel.internal.util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.classfile.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.io.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * Convert methods and fields into HTML file.
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
final class MethodHTML implements com.sun.org.apache.bcel.internal.Constants {
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
  private String        class_name;     // name of current class
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
  private PrintWriter   file;           // file to write to
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
  private ConstantHTML  constant_html;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
  private AttributeHTML attribute_html;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
  MethodHTML(String dir, String class_name,
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
             Method[] methods, Field[] fields,
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
             ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
    this.class_name     = class_name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    this.attribute_html = attribute_html;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    this.constant_html  = constant_html;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html"));
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    file.println("<TR><TH ALIGN=LEFT>Access&nbsp;flags</TH><TH ALIGN=LEFT>Type</TH>" +
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
                 "<TH ALIGN=LEFT>Field&nbsp;name</TH></TR>");
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
    for(int i=0; i < fields.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
      writeField(fields[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    file.println("</TABLE>");
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access&nbsp;flags</TH>" +
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
                 "<TH ALIGN=LEFT>Return&nbsp;type</TH><TH ALIGN=LEFT>Method&nbsp;name</TH>" +
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
                 "<TH ALIGN=LEFT>Arguments</TH></TR>");
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    for(int i=0; i < methods.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
      writeMethod(methods[i], i);
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    file.println("</TABLE></BODY></HTML>");
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    file.close();
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   * Print field of class.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   * @param field field to print
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   * @exception java.io.IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  private void writeField(Field field) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    String       type   = Utility.signatureToString(field.getSignature());
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    String       name   = field.getName();
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    String       access = Utility.accessToString(field.getAccessFlags());
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    Attribute[]  attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    access = Utility.replace(access, " ", "&nbsp;");
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" +
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
               Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" +
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
               name + "</A></TD>");
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    attributes = field.getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    // Write them to the Attributes.html file with anchor "<name>[<i>]"
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    for(int i=0; i < attributes.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
      attribute_html.writeAttribute(attributes[i], name + "@" + i);
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    for(int i=0; i < attributes.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
      if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        String str = ((ConstantValue)attributes[i]).toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        // Reference attribute in _attributes.html
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" +
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
                   name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n");
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    file.println("</TR>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  private final void writeMethod(Method method, int method_number) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    // Get raw signature
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    String       signature      = method.getSignature();
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    // Get array of strings containing the argument types
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    String[]     args           = Utility.methodSignatureArgumentTypes(signature, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    // Get return type string
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    String       type           = Utility.methodSignatureReturnType(signature, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    // Get method name
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    String       name           = method.getName(), html_name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    // Get method's access flags
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    String       access         = Utility.accessToString(method.getAccessFlags());
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    // Get the method's attributes, the Code Attribute in particular
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    Attribute[]  attributes     = method.getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    /* HTML doesn't like names like <clinit> and spaces are places to break
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     * lines. Both we don't want...
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    access      = Utility.replace(access, " ", "&nbsp;");
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    html_name   = Class2HTML.toHTML(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number + ">" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
               access + "</A></FONT></TD>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
               "<A HREF=" + class_name + "_code.html#method" + method_number +
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
               " TARGET=Code>" + html_name + "</A></TD>\n<TD>(");
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    for(int i=0; i < args.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
      file.print(Class2HTML.referenceType(args[i]));
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
      if(i < args.length - 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        file.print(", ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    file.print(")</TD></TR>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    // Check for thrown exceptions
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    for(int i=0; i < attributes.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
      attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i,
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                                    method_number);
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
      byte tag = attributes[i].getTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
      if(tag == ATTR_EXCEPTIONS) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        for(int j=0; j < exceptions.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
          file.print(constant_html.referenceConstant(exceptions[j]));
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
          if(j < exceptions.length - 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
            file.print(", ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        file.println("</TD></TR>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
      } else if(tag == ATTR_CODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
        Attribute[] c_a = ((Code)attributes[i]).getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
        for(int j=0; j < c_a.length; j++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
          attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j,
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                                        method_number);
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
}