[Jarspy-commits] CVS: JarSpy/src/com/ociweb/classinfo ClassReader.java,1.5,1.6
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2002-09-13 23:13:16
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo
In directory usw-pr-cvs1:/tmp/cvs-serv12534/src/com/ociweb/classinfo
Modified Files:
ClassReader.java
Log Message:
first cut of using new constantpool api
Index: ClassReader.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo/ClassReader.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ClassReader.java 20 Jul 2002 18:12:23 -0000 1.5
--- ClassReader.java 13 Sep 2002 23:13:13 -0000 1.6
***************
*** 19,22 ****
--- 19,24 ----
package com.ociweb.classinfo;
+ import com.ociweb.classinfo.constantpool.*;
+
import java.io.DataInputStream;
import java.io.File;
***************
*** 58,74 ****
private short minorVersion_;
! private static final String DEPRECATED_FLAG = "Deprecated";
! private static final byte CONSTANT_Utf8 = 1;
! private static final byte CONSTANT_Integer = 3;
! private static final byte CONSTANT_Float = 4;
! private static final byte CONSTANT_Long = 5;
! private static final byte CONSTANT_Double = 6;
! private static final byte CONSTANT_Class = 7;
! private static final byte CONSTANT_String = 8;
! private static final byte CONSTANT_Fieldref = 9;
! private static final byte CONSTANT_Methodref = 10;
! private static final byte CONSTANT_InterfaceMethodref = 11;
! private static final byte CONSTANT_NameAndType = 12;
! private static final int MAGIC_NUMBER = 0xCAFEBABE;
/**
--- 60,64 ----
private short minorVersion_;
! private static final int MAGIC_NUMBER = 0xCAFEBABE;
/**
***************
*** 144,165 ****
public static final short ACC_ABSTRACT = 0x0400;
! /**
! * @param filename the name of a class file that this
! * <code>ClassReader</code> will attempt to parse. This constructor does
! * not declare it, but an <code>InvalidClassFileException</code> will be
! * thrown if the first 4 bytes of the file do not contain 0xCAFEBABE --
! * the "magic number" of a java class file
! */
! public ClassReader(File file) {
!
! FileInputStream is = null;
!
! try {
! is = new FileInputStream(file);
! read(is);//, file.getName());
! } catch (Exception e) {
! e.printStackTrace();
! }
! }
public ClassReader(InputStream is) {
--- 134,157 ----
public static final short ACC_ABSTRACT = 0x0400;
! // --Recycle Bin START (9/13/02 5:57 PM):
! // /**
! // * @param file
! // * <code>ClassReader</code> will attempt to parse. This constructor does
! // * not declare it, but an <code>InvalidClassFileException</code> will be
! // * thrown if the first 4 bytes of the file do not contain 0xCAFEBABE --
! // * the "magic number" of a java class file
! // */
! // public ClassReader(File file) {
! //
! // FileInputStream is = null;
! //
! // try {
! // is = new FileInputStream(file);
! // read(is);//, file.getName());
! // } catch (Exception e) {
! // e.printStackTrace();
! // }
! // }
! // --Recycle Bin STOP (9/13/02 5:57 PM)
public ClassReader(InputStream is) {
***************
*** 177,257 ****
minorVersion_ = di.readShort();
majorVersion_ = di.readShort();
! short constantPoolCount = di.readShort();
! constantPool = new String[constantPoolCount + 1];
! for (int i = 1; i < constantPoolCount; i++) {
! int tag = di.readUnsignedByte();
! switch (tag) {
! case CONSTANT_Utf8:
! constantPool[i] = di.readUTF();
! break;
! case CONSTANT_Integer:
! Integer tInt = new Integer(di.readInt());
! constantPool[i] = tInt.toString();
! break;
! case CONSTANT_Float:
! Float tFloat = new Float(di.readFloat());
! constantPool[i] = tFloat.toString();
! break;
! case CONSTANT_Long:
! Long tLong = new Long(di.readLong());
! constantPool[i] = tLong.toString();
! constantPool[++i] = tLong.toString();
! break;
! case CONSTANT_Double:
! Double tDouble = new Double(di.readDouble());
! constantPool[i] = tDouble.toString();
! constantPool[++i] = tDouble.toString();
! break;
! case CONSTANT_Class:
! Short tShort = new Short(di.readShort());
! constantPool[i] = tShort.toString();
! classRefs_.addElement(constantPool[i]);
! break;
! case CONSTANT_String:
! Short tString =
! new Short(di.readShort());
! constantPool[i] = tString.toString();
! break;
! case CONSTANT_Fieldref:
! short st6 = di.readShort();
! short st7 = di.readShort();
! constantPool[i] = st6 + ", " + st7;
! // constantPool[i] = "4";
! break;
! case CONSTANT_Methodref:
! short st2 = di.readShort();
! short st3 = di.readShort();
! constantPool[i] = st2 + ", " + st3;
! break;
! case CONSTANT_InterfaceMethodref:
! short ss1 = di.readShort();
! short ss2 = di.readShort();
! constantPool[i] = ss1 + ", " + ss2;
! break;
! case CONSTANT_NameAndType:
! short st4 = di.readShort();
! short st5 = di.readShort();
! constantPool[i] = st4 + ", " + st5;
! break;
! default:
! System.out.println("whoops: i = " +
! i + " tag = " + tag);
}
-
- }
-
- for (int i = 0; i < classRefs_.size(); i++) {
- String temp = (String) classRefs_.elementAt(i);
- int ti = Integer.parseInt(temp);
- String s = constantPool[ti];
-
- classDependencies_.addClass(s);
}
accessFlags_ = di.readShort();
! className_ = constantPool[Integer.valueOf
! (constantPool[di.readShort()]).intValue()].replace('/', '.');
int lastDot = className_.lastIndexOf('.');
--- 169,192 ----
minorVersion_ = di.readShort();
majorVersion_ = di.readShort();
! constantPool = new DefaultConstantPool(di);
! // populate the dependencies...
! ConstantPoolEntry[] entries = constantPool.getEntries();
! for (int i = 0; i < entries.length; i++) {
! ConstantPoolEntry entry = entries[i];
! if(entry instanceof CP_ClassEntry) {
! int index = ((CP_ClassEntry)entry).getIndex();
! CP_Utf8Entry ue = (CP_Utf8Entry) constantPool.getEntryAt(index);
! classDependencies_.addClass(ue.getValue());
}
}
accessFlags_ = di.readShort();
! short classNameIndex = di.readShort();
! ConstantPoolEntry e = constantPool.getEntryAt(classNameIndex);
! CP_ClassEntry classStringEntry = (CP_ClassEntry) e;
! CP_Utf8Entry c = (CP_Utf8Entry) constantPool.getEntryAt(classStringEntry.getIndex());
! className_ = c.getValue().replace('/', '.');
int lastDot = className_.lastIndexOf('.');
***************
*** 260,270 ****
int i2 = di.readShort();
if (i2 > 0) {
! int i1 = Integer.valueOf(constantPool[i2]).intValue();
! superClassName_ = constantPool[i1].replace('/', '.');
}
short interfaces_count = di.readShort();
for (int i = 1; i <= interfaces_count; i++) {
! short s = di.readShort();
}
--- 195,206 ----
int i2 = di.readShort();
if (i2 > 0) {
! CP_ClassEntry superClassEntry = (CP_ClassEntry) constantPool.getEntries()[i2];
! CP_Utf8Entry c2 = (CP_Utf8Entry) constantPool.getEntryAt(superClassEntry.getIndex());
! superClassName_ = c2.getValue().replace('/', '.');
}
short interfaces_count = di.readShort();
for (int i = 1; i <= interfaces_count; i++) {
! /*short s = */di.readShort();
}
***************
*** 278,314 ****
short descriptor_index = di.readShort();
short attributes_count = di.readShort();
! fields_[i] = new CRField(constantPool[name_index],
! local_access_flags,
! constantPool[descriptor_index]);
!
for (int j = 0; j < attributes_count; j++) {
! short attribute_name_index = di.readShort();
!
int attribute_length = di.readInt();
for (int k = 0; k < attribute_length; k++) {
! byte info = di.readByte();
}
}
}
short methods_count = di.readShort();
-
methods_ = new CRMethod[methods_count];
for (int i = 0; i < methods_count; i++) {
! short methodAccessFlag = di.readShort();
short name_index2 = di.readShort();
short descriptor_index2 = di.readShort();
short attributes_count2 = di.readShort();
!
! methods_[i] = new CRMethod(constantPool[name_index2],
! methodAccessFlag,
! constantPool[descriptor_index2]);
for (int j = 0; j < attributes_count2; j++) {
! short attribute_name_index2 = di.readShort();
int attribute_length2 = di.readInt();
for (int k = 0; k < attribute_length2; k++) {
! byte info2 = di.readByte();
}
}
--- 214,250 ----
short descriptor_index = di.readShort();
short attributes_count = di.readShort();
! CP_Utf8Entry nameEntry = (CP_Utf8Entry) constantPool.getEntryAt(name_index);
! CP_Utf8Entry descriptorEntry = (CP_Utf8Entry) constantPool.getEntryAt(descriptor_index);
! fields_[i] = new CRField(nameEntry.getValue(),
! local_access_flags,
! descriptorEntry.getValue());
for (int j = 0; j < attributes_count; j++) {
! /*short attribute_name_index = */di.readShort();
int attribute_length = di.readInt();
for (int k = 0; k < attribute_length; k++) {
! di.readByte();
}
}
}
short methods_count = di.readShort();
methods_ = new CRMethod[methods_count];
for (int i = 0; i < methods_count; i++) {
! short methodAccessflag = di.readShort();
short name_index2 = di.readShort();
short descriptor_index2 = di.readShort();
short attributes_count2 = di.readShort();
! CP_Utf8Entry nameEntry = (CP_Utf8Entry) constantPool.getEntryAt(name_index2);
! CP_Utf8Entry descriptorEntry = (CP_Utf8Entry) constantPool.getEntryAt(descriptor_index2);
! methods_[i] = new CRMethod(nameEntry.getValue(),
! methodAccessflag,
! descriptorEntry.getValue());
for (int j = 0; j < attributes_count2; j++) {
! /*short attribute_name_index2 = */di.readShort();
int attribute_length2 = di.readInt();
for (int k = 0; k < attribute_length2; k++) {
! /*byte info2 = */di.readByte();
}
}
***************
*** 328,331 ****
--- 264,271 ----
}
+ public ConstantPool getConstantPool() {
+ return constantPool;
+ }
+
/**
* @return the name of this class
***************
*** 372,381 ****
}
! /**
! * @return the access flags for this class.
! */
! public short getAccessFlags() {
! return accessFlags_;
! }
/**
--- 312,323 ----
}
! // --Recycle Bin START (9/13/02 6:01 PM):
! // /**
! // * @return the access flags for this class.
! // */
! // public short getAccessFlags() {
! // return accessFlags_;
! // }
! // --Recycle Bin STOP (9/13/02 6:01 PM)
/**
***************
*** 411,415 ****
}
! private String[] constantPool;
public Vector getDependencies() {
--- 353,358 ----
}
! // private String[] constantPool;
! ConstantPool constantPool;
public Vector getDependencies() {
***************
*** 417,421 ****
}
! private Vector classRefs_ = new Vector();
private CRClassDependencies classDependencies_ =
--- 360,364 ----
}
! // --Recycle Bin (9/13/02 5:57 PM): private Vector classRefs_ = new Vector();
private CRClassDependencies classDependencies_ =
***************
*** 482,486 ****
int endOfType = descriptor.indexOf(';');
if (endOfType < 0) {
! endOfType = descriptor.length();
typeDescription +=
convertDescriptor(descriptor.substring(1)) + brackets;
--- 425,429 ----
int endOfType = descriptor.indexOf(';');
if (endOfType < 0) {
! // endOfType = descriptor.length();
typeDescription +=
convertDescriptor(descriptor.substring(1)) + brackets;
***************
*** 489,493 ****
typeDescription +=
convertDescriptor(descriptor.substring
! (arrayCounter, endOfType)) + brackets;
descriptor = descriptor.substring(endOfType + 1);
}
--- 432,436 ----
typeDescription +=
convertDescriptor(descriptor.substring
! (arrayCounter, endOfType)) + brackets;
descriptor = descriptor.substring(endOfType + 1);
}
|