I've just made some mods to make JDepend show us (Maven - http://jakarta.apache.org/turbine/maven) the source file that a particular class comes from.
(This is in order to let us link from the jdepend report to our source code xref. Inner classes need to link to the actual file they are from).
I'd really like these changes to be amalgamated back into JDepend rather than us maintaining patches to your tree.
Essentially the changes boil down to the following:
new attribute on JavaClass - sourceFile
JavaClassFileParser now reads and processes attributes. Has special case handling for SourceFile attribute as per VM Spec 4.7.7
xmlui.JDepend now display classes as
<Class sourceFile="Bob.java">BobsInnerClass</Class>
If you have any questions etc let me know.
Thanks (and thanks for making & maintaining JDepend)
Ben
--- JavaClass.java.orig 2003-02-01 16:15:20.000000000 +1000
+++ JavaClass.java 2003-02-01 15:52:00.000000000 +1000
@@ -16,6 +16,7 @@
private String packageName;
private boolean isAbstract;
private HashMap imports;
+ private String sourceFile;
/**
* Constructs a <code>JavaClass</code> instance.
@@ -151,4 +152,20 @@
+ /**
+ * Returns the sourceFile.
+ * @return String
+ */
+ public String getSourceFile() {
+ return sourceFile;
+ }
+
+ /**
+ * Sets the sourceFile.
+ * @param sourceFile The sourceFile to set
+ */
+ public void setSourceFile(String sourceFile) {
+ this.sourceFile = sourceFile;
+ }
+
}
--- JavaSourceFileParser.java.orig 2003-02-01 16:24:17.000000000 +1000
+++ JavaSourceFileParser.java 2003-02-01 16:08:56.000000000 +1000
@@ -64,6 +64,7 @@
debug("\nParsing " + filename + "...");
JavaClass jClass = new JavaClass("Unknown");
+ jClass.setSourceFile(sourceFile.getName());
int lineNumber = 0;
BufferedReader reader = null;
--- JavaClassFileParser.java.orig 2003-02-01 16:20:52.000000000 +1000
+++ JavaClassFileParser.java 2003-02-01 16:23:05.000000000 +1000
@@ -40,7 +40,8 @@
private Constant[] constantPool;
private FieldOrMethodInfo[] fields;
private FieldOrMethodInfo[] methods;
-
+ private AttributeInfo[] attributes;
+
private DataInputStream in;
/**
@@ -139,6 +140,8 @@
parseFields();
parseMethods();
+
+ parseAttributes();
addClassConstantReferences();
@@ -253,7 +256,26 @@
}
}
}
-
+
+ private void parseAttributes() throws IOException {
+ int attributesCount = in.readUnsignedShort();
+ attributes = new AttributeInfo[attributesCount];
+ for (int i = 0; i < attributesCount; i++) {
+ attributes[i] = parseAttribute();
+
+ //Section 4.7.7 of VM Spec - Class File Format
+ if (attributes[i].getName() != null) {
+
+ if (attributes[i].getName().equals("SourceFile")) {
+ byte[] b = attributes[i].getValue();
+ int pe = b[0] * 256 + b[1];
+ String descriptor = toUTF8(pe);
+ jClass.setSourceFile(descriptor);
+ }
+ }
+ }
+ }
+
private Constant parseConstant() throws IOException {
Constant result;
@@ -310,13 +332,22 @@
return result;
}
- private void parseAttribute() throws IOException {
- int nameIndex = in.readUnsignedShort();
- int length = in.readInt();
- for (int b=0; b < length; b++) {
- byte eatByte = in.readByte();
- }
- }
+ private AttributeInfo parseAttribute() throws IOException {
+ AttributeInfo result = new AttributeInfo();
+
+ int nameIndex = in.readUnsignedShort();
+ if (nameIndex != -1) {
+ result.setName(toUTF8(nameIndex));
+ }
+
+ int attributeLength = in.readInt();
+ byte[] value = new byte[attributeLength];
+ for (int b = 0; b < attributeLength; b++) {
+ value[b] = in.readByte();
+ }
+ result.setValue(value);
+ return result;
+ }
private Constant getConstantPoolEntry(int entryIndex)
throws IOException {
@@ -552,6 +583,26 @@
return s.toString();
}
}
+
+ class AttributeInfo {
+ private String name;
+ private byte[] value;
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setValue(byte[] value) {
+ this.value = value;
+ }
+
+ public byte[] getValue() {
+ return this.value;
+ }
+ }
/**
* Returns a string representation of this object. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
