/* * reserved comment block * DO NOT REMOVE OR ALTER! */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sun.org.apache.bcel.internal.util; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import com.sun.org.apache.bcel.internal.Const; import com.sun.org.apache.bcel.internal.classfile.Attribute; import com.sun.org.apache.bcel.internal.classfile.Code; import com.sun.org.apache.bcel.internal.classfile.CodeException; import com.sun.org.apache.bcel.internal.classfile.ConstantPool; import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; import com.sun.org.apache.bcel.internal.classfile.ConstantValue; import com.sun.org.apache.bcel.internal.classfile.ExceptionTable; import com.sun.org.apache.bcel.internal.classfile.InnerClass; import com.sun.org.apache.bcel.internal.classfile.InnerClasses; import com.sun.org.apache.bcel.internal.classfile.LineNumber; import com.sun.org.apache.bcel.internal.classfile.LineNumberTable; import com.sun.org.apache.bcel.internal.classfile.LocalVariable; import com.sun.org.apache.bcel.internal.classfile.LocalVariableTable; import com.sun.org.apache.bcel.internal.classfile.SourceFile; import com.sun.org.apache.bcel.internal.classfile.Utility; /** * Convert found attributes into HTML file. * * */ final class AttributeHTML { private final String class_name; // name of current class private final PrintWriter file; // file to write to private int attr_count = 0; private final ConstantHTML constant_html; private final ConstantPool constant_pool; AttributeHTML(final String dir, final String class_name, final ConstantPool constant_pool, final ConstantHTML constant_html) throws IOException { this.class_name = class_name; this.constant_pool = constant_pool; this.constant_html = constant_html; file = new PrintWriter(new FileOutputStream(dir + class_name + "_attributes.html")); file.println(""); } private String codeLink( final int link, final int method_number ) { return "" + link + ""; } void close() { file.println("
"); file.close(); } void writeAttribute( final Attribute attribute, final String anchor ) { writeAttribute(attribute, anchor, 0); } void writeAttribute( final Attribute attribute, final String anchor, final int method_number ) { final byte tag = attribute.getTag(); int index; if (tag == Const.ATTR_UNKNOWN) { return; } attr_count++; // Increment number of attributes found so far if (attr_count % 2 == 0) { file.print(""); } else { file.print(""); } file.println("

" + attr_count + " " + Const.getAttributeName(tag) + "

"); /* Handle different attributes */ switch (tag) { case Const.ATTR_CODE: final Code c = (Code) attribute; // Some directly printable values file.print("\n"); // Get handled exceptions and list them final CodeException[] ce = c.getExceptionTable(); final int len = ce.length; if (len > 0) { file.print("

Exceptions handled

"); } break; case Const.ATTR_CONSTANT_VALUE: index = ((ConstantValue) attribute).getConstantValueIndex(); // Reference _cp.html file.print("\n"); break; case Const.ATTR_SOURCE_FILE: index = ((SourceFile) attribute).getSourceFileIndex(); // Reference _cp.html file.print("\n"); break; case Const.ATTR_EXCEPTIONS: // List thrown exceptions final int[] indices = ((ExceptionTable) attribute).getExceptionIndexTable(); file.print("\n"); break; case Const.ATTR_LINE_NUMBER_TABLE: final LineNumber[] line_numbers = ((LineNumberTable) attribute).getLineNumberTable(); // List line number pairs file.print("

"); for (int i = 0; i < line_numbers.length; i++) { file.print("(" + line_numbers[i].getStartPC() + ", " + line_numbers[i].getLineNumber() + ")"); if (i < line_numbers.length - 1) { file.print(", "); // breakable } } break; case Const.ATTR_LOCAL_VARIABLE_TABLE: final LocalVariable[] vars = ((LocalVariableTable) attribute).getLocalVariableTable(); // List name, range and type file.print("

\n"); break; case Const.ATTR_INNER_CLASSES: final InnerClass[] classes = ((InnerClasses) attribute).getInnerClasses(); // List inner classes file.print("\n"); break; default: // Such as Unknown attribute or Deprecated file.print("

" + attribute); } file.println(""); file.flush(); } }