[Jarspy-commits] CVS: JarSpy/src/com/ociweb/classinfo AccessFlags.java,1.1,1.2 CRField.java,1.4,1.5
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2002-10-04 01:57:19
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo
In directory usw-pr-cvs1:/tmp/cvs-serv11893/com/ociweb/classinfo
Modified Files:
AccessFlags.java CRField.java CRMethod.java ClassReader.java
SignatureDescriptor.java
Log Message:
implement several Comparable methods to support sorting methods and fields
Index: AccessFlags.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo/AccessFlags.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AccessFlags.java 29 Sep 2002 02:21:25 -0000 1.1
--- AccessFlags.java 4 Oct 2002 01:57:16 -0000 1.2
***************
*** 19,29 ****
package com.ociweb.classinfo;
- import java.util.Map;
import java.util.HashMap;
/**
* @version $Id$
*/
! public class AccessFlags {
public static final short ACC_PUBLIC = 0x0001;
--- 19,29 ----
package com.ociweb.classinfo;
import java.util.HashMap;
+ import java.util.Map;
/**
* @version $Id$
*/
! public class AccessFlags implements Comparable {
public static final short ACC_PUBLIC = 0x0001;
***************
*** 74,78 ****
Short key = new Short(accessFlags);
AccessFlags af = (AccessFlags) flagsToObject.get(key);
! if(af == null) {
af = new AccessFlags(accessFlags);
flagsToObject.put(key, af);
--- 74,78 ----
Short key = new Short(accessFlags);
AccessFlags af = (AccessFlags) flagsToObject.get(key);
! if (af == null) {
af = new AccessFlags(accessFlags);
flagsToObject.put(key, af);
***************
*** 91,94 ****
--- 91,101 ----
public String toString() {
return getAccessFlagsString();
+ }
+
+ public int compareTo(Object o) {
+ AccessFlags otherAccessFlags = (AccessFlags) o;
+ int returnValue = accessFlagsString.compareTo(otherAccessFlags.accessFlagsString);
+
+ return returnValue;
}
}
Index: CRField.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo/CRField.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** CRField.java 29 Sep 2002 02:21:25 -0000 1.4
--- CRField.java 4 Oct 2002 01:57:16 -0000 1.5
***************
*** 24,31 ****
* @version $Id$
*/
! public class CRField {
private AccessFlags accessFlags;
! private String methodName;
private SignatureDescriptor descriptor;
--- 24,31 ----
* @version $Id$
*/
! public class CRField implements Comparable {
private AccessFlags accessFlags;
! private String fieldName;
private SignatureDescriptor descriptor;
***************
*** 33,37 ****
short accessFlags,
String descriptor) {
! this.methodName = methodName;
this.accessFlags = AccessFlags.getAccessFlags(accessFlags);
this.descriptor = new SignatureDescriptor(descriptor);
--- 33,37 ----
short accessFlags,
String descriptor) {
! this.fieldName = methodName;
this.accessFlags = AccessFlags.getAccessFlags(accessFlags);
this.descriptor = new SignatureDescriptor(descriptor);
***************
*** 43,48 ****
buffer.append(descriptor);
buffer.append(" ");
! buffer.append(methodName);
return buffer.toString();
}
}
--- 43,67 ----
buffer.append(descriptor);
buffer.append(" ");
! buffer.append(fieldName);
return buffer.toString();
+ }
+
+ public int compareTo(Object o) {
+ CRField otherField = (CRField) o;
+ int returnValue = accessFlags.compareTo(otherField.accessFlags);
+ if (returnValue == 0) {
+ returnValue = descriptor.compareTo(otherField.descriptor);
+
+ if (returnValue == 0) {
+ returnValue = fieldName.compareTo(otherField.fieldName);
+
+ if (returnValue == 0) {
+ // this should never happen for two CRFields in the same class
+ returnValue = toString().compareTo(otherField.toString());
+ }
+ }
+ }
+
+ return returnValue;
}
}
Index: CRMethod.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo/CRMethod.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CRMethod.java 29 Sep 2002 02:21:25 -0000 1.5
--- CRMethod.java 4 Oct 2002 01:57:16 -0000 1.6
***************
*** 24,35 ****
* @version $Id$
*/
! public class CRMethod {
private String descriptor;
CRMethod(String methodName,
short accessFlags,
String descriptor) {
! AccessFlags af = AccessFlags.getAccessFlags(accessFlags);
int indexOfLastParen = descriptor.lastIndexOf(')');
--- 24,41 ----
* @version $Id$
*/
! public class CRMethod implements Comparable {
private String descriptor;
+ private AccessFlags accessFlags;
+ private SignatureDescriptor returnTypeDescriptor;
+ private SignatureDescriptor argumentsDescriptor;
+ private String methodName;
+
CRMethod(String methodName,
short accessFlags,
String descriptor) {
! this.accessFlags = AccessFlags.getAccessFlags(accessFlags);
! this.methodName = methodName;
int indexOfLastParen = descriptor.lastIndexOf(')');
***************
*** 37,45 ****
String arguments = descriptor.substring(1, indexOfLastParen);
! SignatureDescriptor returnTypeDescriptor = new SignatureDescriptor(returnType);
! SignatureDescriptor argumentsDescriptor = new SignatureDescriptor(arguments);
StringBuffer buffer = new StringBuffer();
! buffer.append(af);
buffer.append(returnTypeDescriptor);
buffer.append(" ");
--- 43,51 ----
String arguments = descriptor.substring(1, indexOfLastParen);
! returnTypeDescriptor = new SignatureDescriptor(returnType);
! argumentsDescriptor = new SignatureDescriptor(arguments);
StringBuffer buffer = new StringBuffer();
! buffer.append(this.accessFlags);
buffer.append(returnTypeDescriptor);
buffer.append(" ");
***************
*** 54,57 ****
--- 60,85 ----
public String toString() {
return descriptor;
+ }
+
+ public int compareTo(Object o) {
+ CRMethod otherMethod = (CRMethod) o;
+ int returnValue = accessFlags.compareTo(otherMethod.accessFlags);
+ if (returnValue == 0) {
+ returnValue = returnTypeDescriptor.compareTo(otherMethod.returnTypeDescriptor);
+ if (returnValue == 0) {
+ returnValue = methodName.compareTo(otherMethod.methodName);
+
+ if (returnValue == 0) {
+ returnValue = argumentsDescriptor.compareTo(otherMethod.argumentsDescriptor);
+
+ if (returnValue == 0) {
+ // this should never happen for two CRMethods in the same class
+ returnValue = descriptor.compareTo(descriptor);
+ }
+ }
+ }
+ }
+
+ return returnValue;
}
}
Index: ClassReader.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo/ClassReader.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** ClassReader.java 3 Oct 2002 23:33:08 -0000 1.11
--- ClassReader.java 4 Oct 2002 01:57:16 -0000 1.12
***************
*** 26,31 ****
--- 26,34 ----
import java.io.DataInputStream;
import java.io.InputStream;
+ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+ import java.util.SortedSet;
+ import java.util.TreeSet;
/**
***************
*** 42,47 ****
public class ClassReader {
! private CRField[] fields_;
! private CRMethod[] methods_;
private String className_;
--- 45,50 ----
public class ClassReader {
! private SortedSet fields_ = new TreeSet();
! private SortedSet methods_ = new TreeSet();
private String className_;
***************
*** 129,134 ****
short fields_count = di.readShort();
- fields_ = new CRField[fields_count];
-
for (int i = 0; i < fields_count; i++) {
short local_access_flags = di.readShort();
--- 132,135 ----
***************
*** 138,144 ****
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());
--- 139,145 ----
CP_Utf8Entry nameEntry = (CP_Utf8Entry) constantPool.getEntryAt(name_index);
CP_Utf8Entry descriptorEntry = (CP_Utf8Entry) constantPool.getEntryAt(descriptor_index);
! fields_.add(new CRField(nameEntry.getValue(),
! local_access_flags,
! descriptorEntry.getValue()));
***************
*** 150,155 ****
do {
bytesRead += di.read(fieldAttribute,
! bytesRead,
! attribute_length - bytesRead);
} while (bytesRead < attribute_length);
--- 151,156 ----
do {
bytesRead += di.read(fieldAttribute,
! bytesRead,
! attribute_length - bytesRead);
} while (bytesRead < attribute_length);
***************
*** 157,161 ****
}
short methods_count = di.readShort();
- methods_ = new CRMethod[methods_count];
for (int i = 0; i < methods_count; i++) {
--- 158,161 ----
***************
*** 166,172 ****
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++) {
--- 166,172 ----
CP_Utf8Entry nameEntry = (CP_Utf8Entry) constantPool.getEntryAt(name_index2);
CP_Utf8Entry descriptorEntry = (CP_Utf8Entry) constantPool.getEntryAt(descriptor_index2);
! methods_.add(new CRMethod(nameEntry.getValue(),
! methodAccessflag,
! descriptorEntry.getValue()));
for (int j = 0; j < attributes_count2; j++) {
***************
*** 178,183 ****
do {
bytesRead += di.read(fieldAttribute,
! bytesRead,
! attribute_length - bytesRead);
} while (bytesRead < attribute_length);
--- 178,183 ----
do {
bytesRead += di.read(fieldAttribute,
! bytesRead,
! attribute_length - bytesRead);
} while (bytesRead < attribute_length);
***************
*** 217,233 ****
/**
! * @return an array of <code>CRMethod</code> objects representing all of
* the methods in this class
*/
! public CRMethod[] getMethods() {
! return methods_;
}
/**
! * @return an array of <code>CRField</code> objects representing all of
* the fields in this class
*/
! public CRField[] getFields() {
! return fields_;
}
--- 217,233 ----
/**
! * @return a SortedSet of <code>CRMethod</code> objects representing all of
* the methods in this class
*/
! public SortedSet getMethods() {
! return Collections.unmodifiableSortedSet(methods_);
}
/**
! * @return a SortedSet of <code>CRField</code> objects representing all of
* the fields in this class
*/
! public SortedSet getFields() {
! return Collections.unmodifiableSortedSet(fields_);
}
Index: SignatureDescriptor.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/classinfo/SignatureDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SignatureDescriptor.java 29 Sep 2002 02:21:25 -0000 1.1
--- SignatureDescriptor.java 4 Oct 2002 01:57:16 -0000 1.2
***************
*** 21,25 ****
* @version $Id$
*/
! public class SignatureDescriptor {
private final String descriptor;
--- 21,25 ----
* @version $Id$
*/
! public class SignatureDescriptor implements Comparable {
private final String descriptor;
***************
*** 72,76 ****
typeDescription +=
convertDescriptor(descriptor.substring
! (arrayCounter, endOfType)) + brackets;
descriptor = descriptor.substring(endOfType + 1);
}
--- 72,76 ----
typeDescription +=
convertDescriptor(descriptor.substring
! (arrayCounter, endOfType)) + brackets;
descriptor = descriptor.substring(endOfType + 1);
}
***************
*** 108,111 ****
--- 108,117 ----
}
return typeDescription;
+ }
+
+ public int compareTo(Object o) {
+ SignatureDescriptor otherDescriptor = (SignatureDescriptor) o;
+ int returnValue = descriptor.compareTo(otherDescriptor.descriptor);
+ return returnValue;
}
|