You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2014/09/12 22:50:18 UTC
svn commit: r1624642 - in
/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile: ClassParser.java
JavaClass.java Utility.java
Author: kkolinko
Date: Fri Sep 12 20:50:17 2014
New Revision: 1624642
URL: http://svn.apache.org/r1624642
Log:
Move int -> String mapping for class and interface names from JavaClass to ClassParser.
This avoids an intermediary int[] array.
Move commons classname lookup and compact code into a helper method.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java
tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java
tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java?rev=1624642&r1=1624641&r2=1624642&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java Fri Sep 12 20:50:17 2014
@@ -44,13 +44,14 @@ public final class ClassParser {
private final DataInputStream file;
private final String file_name;
- private int class_name_index, superclass_name_index;
+ private String class_name, superclass_name;
private int access_flags; // Access rights of parsed class
- private int[] interfaces; // Names of implemented interfaces
+ private String[] interface_names; // Names of implemented interfaces
private ConstantPool constant_pool; // collection of constants
private Annotations runtimeVisibleAnnotations; // "RuntimeVisibleAnnotations" attribute defined in the class
private static final int BUFSIZE = 8192;
+ private static final String[] INTERFACES_EMPTY_ARRAY = new String[0];
/**
* Parse class from the given stream.
@@ -101,8 +102,8 @@ public final class ClassParser {
readAttributes();
// Return the information we have gathered in a new object
- return new JavaClass(class_name_index, superclass_name_index,
- access_flags, constant_pool, interfaces,
+ return new JavaClass(class_name, superclass_name,
+ access_flags, constant_pool, interface_names,
runtimeVisibleAnnotations);
}
@@ -159,8 +160,17 @@ public final class ClassParser {
&& ((access_flags & Constants.ACC_FINAL) != 0)) {
throw new ClassFormatException("Class " + file_name + " can't be both final and abstract");
}
- class_name_index = file.readUnsignedShort();
- superclass_name_index = file.readUnsignedShort();
+
+ int class_name_index = file.readUnsignedShort();
+ class_name = Utility.getClassName(constant_pool, class_name_index);
+
+ int superclass_name_index = file.readUnsignedShort();
+ if (superclass_name_index > 0) {
+ // May be zero -> class is java.lang.Object
+ superclass_name = Utility.getClassName(constant_pool, superclass_name_index);
+ } else {
+ superclass_name = "java.lang.Object";
+ }
}
@@ -210,10 +220,13 @@ public final class ClassParser {
int interfaces_count;
interfaces_count = file.readUnsignedShort();
if (interfaces_count > 0) {
- interfaces = new int[interfaces_count];
+ interface_names = new String[interfaces_count];
for (int i = 0; i < interfaces_count; i++) {
- interfaces[i] = file.readUnsignedShort();
+ int index = file.readUnsignedShort();
+ interface_names[i] = Utility.getClassName(constant_pool, index);
}
+ } else {
+ interface_names = INTERFACES_EMPTY_ARRAY;
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java?rev=1624642&r1=1624641&r2=1624642&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java Fri Sep 12 20:50:17 2014
@@ -17,8 +17,6 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import org.apache.tomcat.util.bcel.Constants;
-
/**
* Represents a Java class, i.e., the data structures, constant pool,
* fields, methods and commands contained in a Java .class file.
@@ -36,50 +34,24 @@ public class JavaClass extends AccessFla
private String[] interface_names;
private Annotations runtimeVisibleAnnotations; // "RuntimeVisibleAnnotations" attribute defined in the class
- private static final String[] INTERFACES_EMPTY_ARRAY = new String[0];
-
/**
* Constructor gets all contents as arguments.
*
- * @param class_name_index Index into constant pool referencing a
- * ConstantClass that represents this class.
- * @param superclass_name_index Index into constant pool referencing a
- * ConstantClass that represents this class's superclass.
+ * @param class_name Name of this class.
+ * @param superclass_name Name of this class's superclass.
* @param access_flags Access rights defined by bit flags
* @param constant_pool Array of constants
* @param interfaces Implemented interfaces
* @param runtimeVisibleAnnotations "RuntimeVisibleAnnotations" attribute defined on the Class, or null
*/
- JavaClass(int class_name_index, int superclass_name_index,
- int access_flags, ConstantPool constant_pool, int[] interfaces,
+ JavaClass(String class_name, String superclass_name,
+ int access_flags, ConstantPool constant_pool, String[] interface_names,
Annotations runtimeVisibleAnnotations) {
this.access_flags = access_flags;
this.runtimeVisibleAnnotations = runtimeVisibleAnnotations;
-
- /* According to the specification the following entries must be of type
- * `ConstantClass' but we check that anyway via the
- * `ConstPool.getConstant' method.
- */
- class_name = constant_pool.getConstantString(class_name_index, Constants.CONSTANT_Class);
- class_name = Utility.compactClassName(class_name);
- if (superclass_name_index > 0) {
- // May be zero -> class is java.lang.Object
- superclass_name = constant_pool.getConstantString(superclass_name_index,
- Constants.CONSTANT_Class);
- superclass_name = Utility.compactClassName(superclass_name);
- } else {
- superclass_name = "java.lang.Object";
- }
-
- if (interfaces == null) {
- interface_names = INTERFACES_EMPTY_ARRAY;
- } else {
- interface_names = new String[interfaces.length];
- for (int i = 0; i < interfaces.length; i++) {
- String str = constant_pool.getConstantString(interfaces[i], Constants.CONSTANT_Class);
- interface_names[i] = Utility.compactClassName(str);
- }
- }
+ this.class_name = class_name;
+ this.superclass_name = superclass_name;
+ this.interface_names = interface_names;
}
/**
Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java?rev=1624642&r1=1624641&r2=1624642&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java Fri Sep 12 20:50:17 2014
@@ -21,6 +21,8 @@ import java.io.DataInput;
import java.io.EOFException;
import java.io.IOException;
+import org.apache.tomcat.util.bcel.Constants;
+
/**
* Utility functions that do not really belong to any class in particular.
*
@@ -45,6 +47,11 @@ final class Utility {
return str.replace('/', '.'); // Is `/' on all systems, even DOS
}
+ static String getClassName(ConstantPool constant_pool, int index) {
+ String name = constant_pool.getConstantString(index, Constants.CONSTANT_Class);
+ return compactClassName(name);
+ }
+
static void skipFully(DataInput file, int length) throws IOException {
int total = file.skipBytes(length);
if (total != length) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org