support Java 5.0 Signature attribute and small refactorings

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@543 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-01-10 14:41:02 +00:00
parent 0cbef74b5d
commit 335bf7de1e
10 changed files with 16 additions and 101 deletions

View File

@ -30,6 +30,7 @@ import com.ibm.wala.shrikeCT.ConstantValueReader;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.shrikeCT.LineNumberTableReader;
import com.ibm.wala.shrikeCT.LocalVariableTableReader;
import com.ibm.wala.shrikeCT.SignatureReader;
import com.ibm.wala.shrikeCT.SourceFileReader;
/**
@ -37,12 +38,14 @@ import com.ibm.wala.shrikeCT.SourceFileReader;
* javap that shows more information.
*
* In Unix I run it like this: java -cp ~/dev/shrike/shrike
* com.ibm.wala.shrikeBT.shrikeCT.tools.ClassPrinter test.jar This will print the
* contents of every class in the JAR file.
* com.ibm.wala.shrikeBT.shrikeCT.tools.ClassPrinter test.jar This will print
* the contents of every class in the JAR file.
*/
public class ClassPrinter {
private PrintWriter w;
private boolean printLineNumberInfo = true;
private boolean printConstantPool = true;
/**
@ -257,6 +260,9 @@ public class ClassPrinter {
} else if (name.equals("SourceFile")) {
SourceFileReader sr = new SourceFileReader(attrs);
w.write(" file: " + cr.getCP().getCPUtf8(sr.getSourceFileCPIndex()) + "\n");
} else if (name.equals("Signature")) {
SignatureReader sr = new SignatureReader(attrs);
w.write(" signature: " + cr.getCP().getCPUtf8(sr.getSignatureCPIndex()) + "\n");
} else {
int len = attrs.getDataSize();
int pos = attrs.getDataOffset();

View File

@ -1,91 +0,0 @@
/*******************************************************************************
* Copyright (c) 2002,2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.wala.shrikeCT;
/**
* This is a base class for "attribute readers", the classes which provide
* access to the contents of attributes.
*/
public abstract class ClassReaderAttribute {
protected ClassReader cr;
protected int attr;
protected int length;
/**
* Construct a reader for a particular attribute.
*
* @param attr
* a valid attribute iterator pointing at the attribute to read
* @param expectedName
* the name the attribute must have
*/
protected ClassReaderAttribute(ClassReader.AttrIterator attr, String expectedName) throws InvalidClassFileException {
attr.verifyValid();
this.cr = attr.cr;
this.attr = attr.offset;
this.length = attr.size;
String n = attr.getName();
if (expectedName != n && !expectedName.equals(n)) {
throw new IllegalArgumentException("Attribute " + n + " is not a " + expectedName + " attribute");
}
}
/**
* @return the class reader the attribute belongs to
*/
public final ClassReader getClassReader() {
return cr;
}
/**
* @return the offset of the raw attribute data (including the attribute
* header)
*/
public final int getRawOffset() {
return attr;
}
/**
* @return the size of the raw attribute data (including the attribute header)
*/
public final int getRawSize() {
return length;
}
/**
* Ensure that the len bytes starting at offset fall within the attribute
* data.
*
* @throws InvalidClassFileException
* if the bytes fall outside the data
*/
protected final void checkSize(int offset, int len) throws InvalidClassFileException {
if (length < offset - attr + len) {
throw new InvalidClassFileException(offset, "Attribute data too short, expected " + len + " bytes, got "
+ (length + attr - offset));
}
}
/**
* Ensure that the len bytes starting at offset end at the end of the
* attribute data.
*
* @throws InvalidClassFileException
* if the bytes do not end at the end of the attribute
*/
protected final void checkSizeEquals(int offset, int len) throws InvalidClassFileException {
if (length != offset - attr + len) {
throw new InvalidClassFileException(offset, "Attribute data invalid length, expected " + len + " bytes, got "
+ (length + attr - offset));
}
}
}

View File

@ -13,7 +13,7 @@ package com.ibm.wala.shrikeCT;
/**
* This attribute reader reads Code attributes from methods.
*/
public final class CodeReader extends ClassReaderAttribute {
public final class CodeReader extends AttributeReader {
private int codeLen;
private int exnTableLen;

View File

@ -13,7 +13,7 @@ package com.ibm.wala.shrikeCT;
/**
* This class reads ConstantValue attributes.
*/
public final class ConstantValueReader extends ClassReaderAttribute {
public final class ConstantValueReader extends AttributeReader {
/**
* Build a reader for the attribute 'iter'.
*/

View File

@ -13,7 +13,7 @@ package com.ibm.wala.shrikeCT;
/**
* This class reads Exceptions attributes.
*/
public final class ExceptionsReader extends ClassReaderAttribute {
public final class ExceptionsReader extends AttributeReader {
/**
* Build a reader for the attribute 'iter'.
*/

View File

@ -13,7 +13,7 @@ package com.ibm.wala.shrikeCT;
/**
* This class reads InnerClasses attributes.
*/
public final class InnerClassesReader extends ClassReaderAttribute {
public final class InnerClassesReader extends AttributeReader {
/**
* Build a reader for the attribute 'iter'.
*/

View File

@ -18,7 +18,7 @@ package com.ibm.wala.shrikeCT;
* to aggregate line number data from all the LineNumberTable attributes for a
* given Code.
*/
public final class LineNumberTableReader extends ClassReaderAttribute {
public final class LineNumberTableReader extends AttributeReader {
/**
* Build a reader for a LineNumberTable attribute.
*/

View File

@ -17,7 +17,7 @@ package com.ibm.wala.shrikeCT;
* LocalVariableTable.makeVarMap for convenient access to aggregate local
* variable data from all the LocalVariableTable attributes for a given Code.
*/
public final class LocalVariableTableReader extends ClassReaderAttribute {
public final class LocalVariableTableReader extends AttributeReader {
public LocalVariableTableReader(ClassReader.AttrIterator iter) throws InvalidClassFileException {
super(iter, "LocalVariableTable");

View File

@ -10,7 +10,7 @@
*******************************************************************************/
package com.ibm.wala.shrikeCT;
public class SourceDebugExtensionReader extends ClassReaderAttribute {
public class SourceDebugExtensionReader extends AttributeReader {
public SourceDebugExtensionReader(ClassReader.AttrIterator iter) throws InvalidClassFileException {
super(iter, "SourceDebugExtension");

View File

@ -13,7 +13,7 @@ package com.ibm.wala.shrikeCT;
/**
* This class reads SourceFile attributes.
*/
public final class SourceFileReader extends ClassReaderAttribute {
public final class SourceFileReader extends AttributeReader {
/**
* Build a reader for the attribute 'iter'.
*/