aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/javassist/bytecode')
-rw-r--r--src/main/javassist/bytecode/AnnotationDefaultAttribute.java12
-rw-r--r--src/main/javassist/bytecode/AnnotationsAttribute.java70
-rw-r--r--src/main/javassist/bytecode/AttributeInfo.java222
-rw-r--r--src/main/javassist/bytecode/BadBytecode.java3
-rw-r--r--src/main/javassist/bytecode/BootstrapMethodsAttribute.java3
-rw-r--r--src/main/javassist/bytecode/ByteStream.java5
-rw-r--r--src/main/javassist/bytecode/Bytecode.java6
-rw-r--r--src/main/javassist/bytecode/ClassFile.java171
-rw-r--r--src/main/javassist/bytecode/ClassFilePrinter.java24
-rw-r--r--src/main/javassist/bytecode/ClassFileWriter.java3
-rw-r--r--src/main/javassist/bytecode/CodeAttribute.java45
-rw-r--r--src/main/javassist/bytecode/CodeIterator.java113
-rw-r--r--src/main/javassist/bytecode/ConstPool.java914
-rw-r--r--src/main/javassist/bytecode/ConstantAttribute.java5
-rw-r--r--src/main/javassist/bytecode/DeprecatedAttribute.java3
-rw-r--r--src/main/javassist/bytecode/Descriptor.java129
-rw-r--r--src/main/javassist/bytecode/DuplicateMemberException.java3
-rw-r--r--src/main/javassist/bytecode/EnclosingMethodAttribute.java18
-rw-r--r--src/main/javassist/bytecode/ExceptionTable.java53
-rw-r--r--src/main/javassist/bytecode/ExceptionsAttribute.java7
-rw-r--r--src/main/javassist/bytecode/FieldInfo.java22
-rw-r--r--src/main/javassist/bytecode/InnerClassesAttribute.java14
-rw-r--r--src/main/javassist/bytecode/LineNumberAttribute.java3
-rw-r--r--src/main/javassist/bytecode/LocalVariableAttribute.java10
-rw-r--r--src/main/javassist/bytecode/LocalVariableTypeAttribute.java5
-rw-r--r--src/main/javassist/bytecode/MethodInfo.java25
-rw-r--r--src/main/javassist/bytecode/MethodParametersAttribute.java3
-rw-r--r--src/main/javassist/bytecode/ParameterAnnotationsAttribute.java46
-rw-r--r--src/main/javassist/bytecode/SignatureAttribute.java85
-rw-r--r--src/main/javassist/bytecode/SourceFileAttribute.java3
-rw-r--r--src/main/javassist/bytecode/StackMap.java29
-rw-r--r--src/main/javassist/bytecode/StackMapTable.java50
-rw-r--r--src/main/javassist/bytecode/SyntheticAttribute.java3
-rw-r--r--src/main/javassist/bytecode/TypeAnnotationsAttribute.java51
-rw-r--r--src/main/javassist/bytecode/analysis/Analyzer.java9
-rw-r--r--src/main/javassist/bytecode/analysis/ControlFlow.java16
-rw-r--r--src/main/javassist/bytecode/analysis/Frame.java1
-rw-r--r--src/main/javassist/bytecode/analysis/MultiArrayType.java16
-rw-r--r--src/main/javassist/bytecode/analysis/MultiType.java83
-rw-r--r--src/main/javassist/bytecode/analysis/Subroutine.java17
-rw-r--r--src/main/javassist/bytecode/analysis/SubroutineScanner.java12
-rw-r--r--src/main/javassist/bytecode/analysis/Type.java71
-rw-r--r--src/main/javassist/bytecode/annotation/Annotation.java82
-rw-r--r--src/main/javassist/bytecode/annotation/AnnotationImpl.java39
-rw-r--r--src/main/javassist/bytecode/annotation/AnnotationMemberValue.java15
-rw-r--r--src/main/javassist/bytecode/annotation/AnnotationsWriter.java3
-rw-r--r--src/main/javassist/bytecode/annotation/ArrayMemberValue.java14
-rw-r--r--src/main/javassist/bytecode/annotation/BooleanMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/ByteMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/CharMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/ClassMemberValue.java13
-rw-r--r--src/main/javassist/bytecode/annotation/DoubleMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/EnumMemberValue.java9
-rw-r--r--src/main/javassist/bytecode/annotation/FloatMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/IntegerMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/LongMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/MemberValue.java15
-rw-r--r--src/main/javassist/bytecode/annotation/NoSuchClassError.java2
-rw-r--r--src/main/javassist/bytecode/annotation/ShortMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/StringMemberValue.java12
-rw-r--r--src/main/javassist/bytecode/annotation/TypeAnnotationsWriter.java1
-rw-r--r--src/main/javassist/bytecode/stackmap/BasicBlock.java77
-rw-r--r--src/main/javassist/bytecode/stackmap/MapMaker.java17
-rw-r--r--src/main/javassist/bytecode/stackmap/Tracer.java21
-rw-r--r--src/main/javassist/bytecode/stackmap/TypeData.java243
-rw-r--r--src/main/javassist/bytecode/stackmap/TypedBlock.java9
66 files changed, 1784 insertions, 1267 deletions
diff --git a/src/main/javassist/bytecode/AnnotationDefaultAttribute.java b/src/main/javassist/bytecode/AnnotationDefaultAttribute.java
index 7379b412..43021ecf 100644
--- a/src/main/javassist/bytecode/AnnotationDefaultAttribute.java
+++ b/src/main/javassist/bytecode/AnnotationDefaultAttribute.java
@@ -16,15 +16,15 @@
package javassist.bytecode;
-import javassist.CtClass;
-import javassist.bytecode.annotation.AnnotationsWriter;
-import javassist.bytecode.annotation.MemberValue;
-
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Map;
+import javassist.CtClass;
+import javassist.bytecode.annotation.AnnotationsWriter;
+import javassist.bytecode.annotation.MemberValue;
+
/**
* A class representing <code>AnnotationDefault_attribute</code>.
*
@@ -104,7 +104,8 @@ public class AnnotationDefaultAttribute extends AttributeInfo {
/**
* Copies this attribute and returns a new copy.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
AnnotationsAttribute.Copier copier
= new AnnotationsAttribute.Copier(info, constPool, newCp, classnames);
try {
@@ -154,6 +155,7 @@ public class AnnotationDefaultAttribute extends AttributeInfo {
/**
* Returns a string representation of this object.
*/
+ @Override
public String toString() {
return getDefaultValue().toString();
}
diff --git a/src/main/javassist/bytecode/AnnotationsAttribute.java b/src/main/javassist/bytecode/AnnotationsAttribute.java
index be69fe8b..73fcd73a 100644
--- a/src/main/javassist/bytecode/AnnotationsAttribute.java
+++ b/src/main/javassist/bytecode/AnnotationsAttribute.java
@@ -16,12 +16,28 @@
package javassist.bytecode;
-import java.util.Map;
-import java.util.HashMap;
-import java.io.IOException;
-import java.io.DataInputStream;
import java.io.ByteArrayOutputStream;
-import javassist.bytecode.annotation.*;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javassist.bytecode.annotation.Annotation;
+import javassist.bytecode.annotation.AnnotationMemberValue;
+import javassist.bytecode.annotation.AnnotationsWriter;
+import javassist.bytecode.annotation.ArrayMemberValue;
+import javassist.bytecode.annotation.BooleanMemberValue;
+import javassist.bytecode.annotation.ByteMemberValue;
+import javassist.bytecode.annotation.CharMemberValue;
+import javassist.bytecode.annotation.ClassMemberValue;
+import javassist.bytecode.annotation.DoubleMemberValue;
+import javassist.bytecode.annotation.EnumMemberValue;
+import javassist.bytecode.annotation.FloatMemberValue;
+import javassist.bytecode.annotation.IntegerMemberValue;
+import javassist.bytecode.annotation.LongMemberValue;
+import javassist.bytecode.annotation.MemberValue;
+import javassist.bytecode.annotation.ShortMemberValue;
+import javassist.bytecode.annotation.StringMemberValue;
/**
* A class representing
@@ -160,7 +176,8 @@ public class AnnotationsAttribute extends AttributeInfo {
/**
* Copies this attribute and returns a new copy.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
Copier copier = new Copier(info, constPool, newCp, classnames);
try {
copier.annotationArray();
@@ -297,13 +314,15 @@ public class AnnotationsAttribute extends AttributeInfo {
* @param oldname a JVM class name.
* @param newname a JVM class name.
*/
+ @Override
void renameClass(String oldname, String newname) {
- HashMap map = new HashMap();
+ Map<String,String> map = new HashMap<String,String>();
map.put(oldname, newname);
renameClass(map);
}
- void renameClass(Map classnames) {
+ @Override
+ void renameClass(Map<String,String> classnames) {
Renamer renamer = new Renamer(info, getConstPool(), classnames);
try {
renamer.annotationArray();
@@ -312,11 +331,13 @@ public class AnnotationsAttribute extends AttributeInfo {
}
}
- void getRefClasses(Map classnames) { renameClass(classnames); }
+ @Override
+ void getRefClasses(Map<String,String> classnames) { renameClass(classnames); }
/**
* Returns a string representation of this object.
*/
+ @Override
public String toString() {
Annotation[] a = getAnnotations();
StringBuilder sbuf = new StringBuilder();
@@ -458,7 +479,7 @@ public class AnnotationsAttribute extends AttributeInfo {
static class Renamer extends Walker {
ConstPool cpool;
- Map classnames;
+ Map<String,String> classnames;
/**
* Constructs a renamer. It renames some class names
@@ -469,17 +490,19 @@ public class AnnotationsAttribute extends AttributeInfo {
* @param map pairs of replaced and substituted class names.
* It can be null.
*/
- Renamer(byte[] info, ConstPool cp, Map map) {
+ Renamer(byte[] info, ConstPool cp, Map<String,String> map) {
super(info);
cpool = cp;
classnames = map;
}
+ @Override
int annotation(int pos, int type, int numPairs) throws Exception {
renameType(pos - 4, type);
return super.annotation(pos, type, numPairs);
}
+ @Override
void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
throws Exception
{
@@ -487,6 +510,7 @@ public class AnnotationsAttribute extends AttributeInfo {
super.enumMemberValue(pos, typeNameIndex, constNameIndex);
}
+ @Override
void classMemberValue(int pos, int index) throws Exception {
renameType(pos + 1, index);
super.classMemberValue(pos, index);
@@ -506,7 +530,7 @@ public class AnnotationsAttribute extends AttributeInfo {
ByteArrayOutputStream output;
AnnotationsWriter writer;
ConstPool srcPool, destPool;
- Map classnames;
+ Map<String,String> classnames;
/**
* Constructs a copier. This copier renames some class names
@@ -519,11 +543,11 @@ public class AnnotationsAttribute extends AttributeInfo {
* @param map pairs of replaced and substituted class names.
* It can be null.
*/
- Copier(byte[] info, ConstPool src, ConstPool dest, Map map) {
+ Copier(byte[] info, ConstPool src, ConstPool dest, Map<String,String> map) {
this(info, src, dest, map, true);
}
- Copier(byte[] info, ConstPool src, ConstPool dest, Map map, boolean makeWriter) {
+ Copier(byte[] info, ConstPool src, ConstPool dest, Map<String,String> map, boolean makeWriter) {
super(info);
output = new ByteArrayOutputStream();
if (makeWriter)
@@ -539,31 +563,37 @@ public class AnnotationsAttribute extends AttributeInfo {
return output.toByteArray();
}
+ @Override
void parameters(int numParam, int pos) throws Exception {
writer.numParameters(numParam);
super.parameters(numParam, pos);
}
+ @Override
int annotationArray(int pos, int num) throws Exception {
writer.numAnnotations(num);
return super.annotationArray(pos, num);
}
+ @Override
int annotation(int pos, int type, int numPairs) throws Exception {
writer.annotation(copyType(type), numPairs);
return super.annotation(pos, type, numPairs);
}
+ @Override
int memberValuePair(int pos, int nameIndex) throws Exception {
writer.memberValuePair(copy(nameIndex));
return super.memberValuePair(pos, nameIndex);
}
+ @Override
void constValueMember(int tag, int index) throws Exception {
writer.constValueIndex(tag, copy(index));
super.constValueMember(tag, index);
}
+ @Override
void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
throws Exception
{
@@ -571,16 +601,19 @@ public class AnnotationsAttribute extends AttributeInfo {
super.enumMemberValue(pos, typeNameIndex, constNameIndex);
}
+ @Override
void classMemberValue(int pos, int index) throws Exception {
writer.classInfoIndex(copyType(index));
super.classMemberValue(pos, index);
}
+ @Override
int annotationMemberValue(int pos) throws Exception {
writer.annotationValue();
return super.annotationMemberValue(pos);
}
+ @Override
int arrayMemberValue(int pos, int num) throws Exception {
writer.arrayValue(num);
return super.arrayMemberValue(pos, num);
@@ -650,6 +683,7 @@ public class AnnotationsAttribute extends AttributeInfo {
return currentMember;
}
+ @Override
void parameters(int numParam, int pos) throws Exception {
Annotation[][] params = new Annotation[numParam][];
for (int i = 0; i < numParam; ++i) {
@@ -660,6 +694,7 @@ public class AnnotationsAttribute extends AttributeInfo {
allParams = params;
}
+ @Override
int annotationArray(int pos, int num) throws Exception {
Annotation[] array = new Annotation[num];
for (int i = 0; i < num; ++i) {
@@ -671,17 +706,20 @@ public class AnnotationsAttribute extends AttributeInfo {
return pos;
}
+ @Override
int annotation(int pos, int type, int numPairs) throws Exception {
currentAnno = new Annotation(type, pool);
return super.annotation(pos, type, numPairs);
}
+ @Override
int memberValuePair(int pos, int nameIndex) throws Exception {
pos = super.memberValuePair(pos, nameIndex);
currentAnno.addMemberValue(nameIndex, currentMember);
return pos;
}
+ @Override
void constValueMember(int tag, int index) throws Exception {
MemberValue m;
ConstPool cp = pool;
@@ -721,6 +759,7 @@ public class AnnotationsAttribute extends AttributeInfo {
super.constValueMember(tag, index);
}
+ @Override
void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
throws Exception
{
@@ -729,11 +768,13 @@ public class AnnotationsAttribute extends AttributeInfo {
super.enumMemberValue(pos, typeNameIndex, constNameIndex);
}
+ @Override
void classMemberValue(int pos, int index) throws Exception {
currentMember = new ClassMemberValue(index, pool);
super.classMemberValue(pos, index);
}
+ @Override
int annotationMemberValue(int pos) throws Exception {
Annotation anno = currentAnno;
pos = super.annotationMemberValue(pos);
@@ -742,6 +783,7 @@ public class AnnotationsAttribute extends AttributeInfo {
return pos;
}
+ @Override
int arrayMemberValue(int pos, int num) throws Exception {
ArrayMemberValue amv = new ArrayMemberValue(pool);
MemberValue[] elements = new MemberValue[num];
diff --git a/src/main/javassist/bytecode/AttributeInfo.java b/src/main/javassist/bytecode/AttributeInfo.java
index 5fd73281..4bfd0dbb 100644
--- a/src/main/javassist/bytecode/AttributeInfo.java
+++ b/src/main/javassist/bytecode/AttributeInfo.java
@@ -19,11 +19,10 @@ package javassist.bytecode;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.util.Map;
import java.util.ArrayList;
-import java.util.ListIterator;
+import java.util.Arrays;
import java.util.List;
-import java.util.Iterator;
+import java.util.Map;
// Note: if you define a new subclass of AttributeInfo, then
// update AttributeInfo.read(), .copy(), and (maybe) write().
@@ -79,65 +78,58 @@ public class AttributeInfo {
int name = in.readUnsignedShort();
String nameStr = cp.getUtf8Info(name);
char first = nameStr.charAt(0);
- if (first < 'M') {
- if (first < 'E') {
- if (nameStr.equals(AnnotationDefaultAttribute.tag))
- return new AnnotationDefaultAttribute(cp, name, in);
- else if (nameStr.equals(BootstrapMethodsAttribute.tag))
- return new BootstrapMethodsAttribute(cp, name, in);
- else if (nameStr.equals(CodeAttribute.tag))
- return new CodeAttribute(cp, name, in);
- else if (nameStr.equals(ConstantAttribute.tag))
- return new ConstantAttribute(cp, name, in);
- else if (nameStr.equals(DeprecatedAttribute.tag))
- return new DeprecatedAttribute(cp, name, in);
- }
- else {
- if (nameStr.equals(EnclosingMethodAttribute.tag))
- return new EnclosingMethodAttribute(cp, name, in);
- else if (nameStr.equals(ExceptionsAttribute.tag))
- return new ExceptionsAttribute(cp, name, in);
- else if (nameStr.equals(InnerClassesAttribute.tag))
- return new InnerClassesAttribute(cp, name, in);
- else if (nameStr.equals(LineNumberAttribute.tag))
- return new LineNumberAttribute(cp, name, in);
- else if (nameStr.equals(LocalVariableAttribute.tag))
- return new LocalVariableAttribute(cp, name, in);
- else if (nameStr.equals(LocalVariableTypeAttribute.tag))
- return new LocalVariableTypeAttribute(cp, name, in);
- }
- }
- else {
- if (first < 'S') {
- /* Note that the names of Annotations attributes begin with 'R'.
- */
- if (nameStr.equals(MethodParametersAttribute.tag))
- return new MethodParametersAttribute(cp, name, in);
- else if (nameStr.equals(AnnotationsAttribute.visibleTag)
- || nameStr.equals(AnnotationsAttribute.invisibleTag)) {
- // RuntimeVisibleAnnotations or RuntimeInvisibleAnnotations
- return new AnnotationsAttribute(cp, name, in);
- }
- else if (nameStr.equals(ParameterAnnotationsAttribute.visibleTag)
- || nameStr.equals(ParameterAnnotationsAttribute.invisibleTag))
- return new ParameterAnnotationsAttribute(cp, name, in);
- else if (nameStr.equals(TypeAnnotationsAttribute.visibleTag)
- || nameStr.equals(TypeAnnotationsAttribute.invisibleTag))
- return new TypeAnnotationsAttribute(cp, name, in);
- }
- else {
- if (nameStr.equals(SignatureAttribute.tag))
- return new SignatureAttribute(cp, name, in);
- else if (nameStr.equals(SourceFileAttribute.tag))
- return new SourceFileAttribute(cp, name, in);
- else if (nameStr.equals(SyntheticAttribute.tag))
- return new SyntheticAttribute(cp, name, in);
- else if (nameStr.equals(StackMap.tag))
- return new StackMap(cp, name, in);
- else if (nameStr.equals(StackMapTable.tag))
- return new StackMapTable(cp, name, in);
- }
- }
+ if (first < 'E')
+ if (nameStr.equals(AnnotationDefaultAttribute.tag))
+ return new AnnotationDefaultAttribute(cp, name, in);
+ else if (nameStr.equals(BootstrapMethodsAttribute.tag))
+ return new BootstrapMethodsAttribute(cp, name, in);
+ else if (nameStr.equals(CodeAttribute.tag))
+ return new CodeAttribute(cp, name, in);
+ else if (nameStr.equals(ConstantAttribute.tag))
+ return new ConstantAttribute(cp, name, in);
+ else if (nameStr.equals(DeprecatedAttribute.tag))
+ return new DeprecatedAttribute(cp, name, in);
+
+ if (first < 'M')
+ if (nameStr.equals(EnclosingMethodAttribute.tag))
+ return new EnclosingMethodAttribute(cp, name, in);
+ else if (nameStr.equals(ExceptionsAttribute.tag))
+ return new ExceptionsAttribute(cp, name, in);
+ else if (nameStr.equals(InnerClassesAttribute.tag))
+ return new InnerClassesAttribute(cp, name, in);
+ else if (nameStr.equals(LineNumberAttribute.tag))
+ return new LineNumberAttribute(cp, name, in);
+ else if (nameStr.equals(LocalVariableAttribute.tag))
+ return new LocalVariableAttribute(cp, name, in);
+ else if (nameStr.equals(LocalVariableTypeAttribute.tag))
+ return new LocalVariableTypeAttribute(cp, name, in);
+
+ if (first < 'S')
+ /* Note that the names of Annotations attributes begin with 'R'. */
+ if (nameStr.equals(MethodParametersAttribute.tag))
+ return new MethodParametersAttribute(cp, name, in);
+ else if (nameStr.equals(AnnotationsAttribute.visibleTag)
+ || nameStr.equals(AnnotationsAttribute.invisibleTag))
+ // RuntimeVisibleAnnotations or RuntimeInvisibleAnnotations
+ return new AnnotationsAttribute(cp, name, in);
+ else if (nameStr.equals(ParameterAnnotationsAttribute.visibleTag)
+ || nameStr.equals(ParameterAnnotationsAttribute.invisibleTag))
+ return new ParameterAnnotationsAttribute(cp, name, in);
+ else if (nameStr.equals(TypeAnnotationsAttribute.visibleTag)
+ || nameStr.equals(TypeAnnotationsAttribute.invisibleTag))
+ return new TypeAnnotationsAttribute(cp, name, in);
+
+ if (first >= 'S')
+ if (nameStr.equals(SignatureAttribute.tag))
+ return new SignatureAttribute(cp, name, in);
+ else if (nameStr.equals(SourceFileAttribute.tag))
+ return new SourceFileAttribute(cp, name, in);
+ else if (nameStr.equals(SyntheticAttribute.tag))
+ return new SyntheticAttribute(cp, name, in);
+ else if (nameStr.equals(StackMap.tag))
+ return new StackMap(cp, name, in);
+ else if (nameStr.equals(StackMapTable.tag))
+ return new StackMapTable(cp, name, in);
return new AttributeInfo(cp, name, in);
}
@@ -189,88 +181,68 @@ public class AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
- int s = info.length;
- byte[] srcInfo = info;
- byte[] newInfo = new byte[s];
- for (int i = 0; i < s; ++i)
- newInfo[i] = srcInfo[i];
-
- return new AttributeInfo(newCp, getName(), newInfo);
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames)
+ {
+ return new AttributeInfo(newCp, getName(), Arrays.copyOf(info, info.length));
}
- void write(DataOutputStream out) throws IOException {
+ void write(DataOutputStream out) throws IOException
+ {
out.writeShort(name);
out.writeInt(info.length);
if (info.length > 0)
out.write(info);
}
- static int getLength(ArrayList list) {
+ static int getLength(List<AttributeInfo> attributes) {
int size = 0;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo attr = (AttributeInfo)list.get(i);
+
+ for (AttributeInfo attr:attributes)
size += attr.length();
- }
return size;
}
- static AttributeInfo lookup(ArrayList list, String name) {
- if (list == null)
+ static AttributeInfo lookup(List<AttributeInfo> attributes, String name) {
+ if (attributes == null)
return null;
- ListIterator iterator = list.listIterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
+ for (AttributeInfo ai:attributes)
if (ai.getName().equals(name))
return ai;
- }
return null; // no such attribute
}
- static synchronized AttributeInfo remove(ArrayList list, String name) {
- if (list == null)
+ static synchronized AttributeInfo remove(List<AttributeInfo> attributes, String name) {
+ if (attributes == null)
return null;
- AttributeInfo removed = null;
- ListIterator iterator = list.listIterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
- if (ai.getName().equals(name)) {
- iterator.remove();
- removed = ai;
- }
- }
-
- return removed;
+ for (AttributeInfo ai:attributes)
+ if (ai.getName().equals(name))
+ if (attributes.remove(ai))
+ return ai;
+
+ return null;
}
- static void writeAll(ArrayList list, DataOutputStream out)
+ static void writeAll(List<AttributeInfo> attributes, DataOutputStream out)
throws IOException
{
- if (list == null)
+ if (attributes == null)
return;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo attr = (AttributeInfo)list.get(i);
+ for (AttributeInfo attr:attributes)
attr.write(out);
- }
}
- static ArrayList copyAll(ArrayList list, ConstPool cp) {
- if (list == null)
+ static List<AttributeInfo> copyAll(List<AttributeInfo> attributes, ConstPool cp) {
+ if (attributes == null)
return null;
- ArrayList newList = new ArrayList();
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo attr = (AttributeInfo)list.get(i);
+ List<AttributeInfo> newList = new ArrayList<AttributeInfo>();
+ for (AttributeInfo attr:attributes)
newList.add(attr.copy(cp, null));
- }
return newList;
}
@@ -282,31 +254,31 @@ public class AttributeInfo {
* override these methods.
*/
void renameClass(String oldname, String newname) {}
- void renameClass(Map classnames) {}
+ void renameClass(Map<String,String> classnames) {}
- static void renameClass(List attributes, String oldname, String newname) {
- Iterator iterator = attributes.iterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
+ static void renameClass(List<AttributeInfo> attributes, String oldname, String newname) {
+ if (attributes == null)
+ return;
+
+ for (AttributeInfo ai:attributes)
ai.renameClass(oldname, newname);
- }
}
- static void renameClass(List attributes, Map classnames) {
- Iterator iterator = attributes.iterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
+ static void renameClass(List<AttributeInfo> attributes, Map<String,String> classnames) {
+ if (attributes == null)
+ return;
+
+ for (AttributeInfo ai:attributes)
ai.renameClass(classnames);
- }
}
- void getRefClasses(Map classnames) {}
+ void getRefClasses(Map<String,String> classnames) {}
+
+ static void getRefClasses(List<AttributeInfo> attributes, Map<String,String> classnames) {
+ if (attributes == null)
+ return;
- static void getRefClasses(List attributes, Map classnames) {
- Iterator iterator = attributes.iterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
+ for (AttributeInfo ai:attributes)
ai.getRefClasses(classnames);
- }
}
}
diff --git a/src/main/javassist/bytecode/BadBytecode.java b/src/main/javassist/bytecode/BadBytecode.java
index 9959ae6c..7a049b45 100644
--- a/src/main/javassist/bytecode/BadBytecode.java
+++ b/src/main/javassist/bytecode/BadBytecode.java
@@ -20,6 +20,9 @@ package javassist.bytecode;
* Signals that a bad bytecode sequence has been found.
*/
public class BadBytecode extends Exception {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public BadBytecode(int opcode) {
super("bytecode " + opcode);
}
diff --git a/src/main/javassist/bytecode/BootstrapMethodsAttribute.java b/src/main/javassist/bytecode/BootstrapMethodsAttribute.java
index 98268b87..94a0481f 100644
--- a/src/main/javassist/bytecode/BootstrapMethodsAttribute.java
+++ b/src/main/javassist/bytecode/BootstrapMethodsAttribute.java
@@ -108,7 +108,8 @@ public class BootstrapMethodsAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
BootstrapMethod[] methods = getMethods();
ConstPool thisCp = getConstPool();
for (int i = 0; i < methods.length; i++) {
diff --git a/src/main/javassist/bytecode/ByteStream.java b/src/main/javassist/bytecode/ByteStream.java
index 29302f30..ee485911 100644
--- a/src/main/javassist/bytecode/ByteStream.java
+++ b/src/main/javassist/bytecode/ByteStream.java
@@ -16,8 +16,8 @@
package javassist.bytecode;
-import java.io.OutputStream;
import java.io.IOException;
+import java.io.OutputStream;
final class ByteStream extends OutputStream {
private byte[] buf;
@@ -38,16 +38,19 @@ final class ByteStream extends OutputStream {
count += len;
}
+ @Override
public void write(byte[] data) {
write(data, 0, data.length);
}
+ @Override
public void write(byte[] data, int off, int len) {
enlarge(len);
System.arraycopy(data, off, buf, count, len);
count += len;
}
+ @Override
public void write(int b) {
enlarge(1);
int oldCount = count;
diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java
index 34068f8d..37a6d127 100644
--- a/src/main/javassist/bytecode/Bytecode.java
+++ b/src/main/javassist/bytecode/Bytecode.java
@@ -28,6 +28,7 @@ class ByteVector implements Cloneable {
size = 0;
}
+ @Override
public Object clone() throws CloneNotSupportedException {
ByteVector bv = (ByteVector)super.clone();
bv.buffer = (byte[])buffer.clone();
@@ -164,6 +165,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
* The constant pool object is shared between this object
* and the cloned object.
*/
+ @Override
public Object clone() {
try {
Bytecode bc = (Bytecode)super.clone();
@@ -325,6 +327,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
*
* @throws ArrayIndexOutOfBoundsException if offset is invalid.
*/
+ @Override
public int read(int offset) {
return super.read(offset);
}
@@ -355,6 +358,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
*
* @throws ArrayIndexOutOfBoundsException if offset is invalid.
*/
+ @Override
public void write(int offset, int value) {
super.write(offset, value);
}
@@ -380,6 +384,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
/**
* Appends an 8bit value to the end of the bytecode sequence.
*/
+ @Override
public void add(int code) {
super.add(code);
}
@@ -396,6 +401,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
*
* @param length the gap length in byte.
*/
+ @Override
public void addGap(int length) {
super.addGap(length);
}
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java
index 1a404cff..880c18b8 100644
--- a/src/main/javassist/bytecode/ClassFile.java
+++ b/src/main/javassist/bytecode/ClassFile.java
@@ -62,9 +62,9 @@ public final class ClassFile {
int accessFlags;
int superClass;
int[] interfaces;
- ArrayList fields;
- ArrayList methods;
- ArrayList attributes;
+ List<FieldInfo> fields;
+ List<MethodInfo> methods;
+ List<AttributeInfo> attributes;
String thisclassname; // not JVM-internal name
String[] cachedInterfaces;
String cachedSuperclass;
@@ -186,11 +186,11 @@ public final class ClassFile {
initSuperclass(superclass);
interfaces = null;
- fields = new ArrayList();
- methods = new ArrayList();
+ fields = new ArrayList<FieldInfo>();
+ methods = new ArrayList<MethodInfo>();
thisclassname = classname;
- attributes = new ArrayList();
+ attributes = new ArrayList<AttributeInfo>();
attributes.add(new SourceFileAttribute(constPool,
getSourcefileName(thisclassname)));
}
@@ -207,11 +207,7 @@ public final class ClassFile {
}
private static String getSourcefileName(String qname) {
- int index = qname.lastIndexOf('.');
- if (index >= 0)
- qname = qname.substring(index + 1);
-
- return qname + ".java";
+ return qname.replaceAll("^.*\\.","") + ".java";
}
/**
@@ -221,19 +217,11 @@ public final class ClassFile {
*/
public void compact() {
ConstPool cp = compact0();
- ArrayList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ for (MethodInfo minfo:methods)
minfo.compact(cp);
- }
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ for (FieldInfo finfo:fields)
finfo.compact(cp);
- }
attributes = AttributeInfo.copyAll(attributes, cp);
constPool = cp;
@@ -246,12 +234,10 @@ public final class ClassFile {
if (sc != null)
superClass = cp.addClassInfo(getSuperclass());
- if (interfaces != null) {
- int n = interfaces.length;
- for (int i = 0; i < n; ++i)
+ if (interfaces != null)
+ for (int i = 0; i < interfaces.length; ++i)
interfaces[i]
= cp.addClassInfo(constPool.getClassInfo(interfaces[i]));
- }
return cp;
}
@@ -264,7 +250,7 @@ public final class ClassFile {
*/
public void prune() {
ConstPool cp = compact0();
- ArrayList newAttributes = new ArrayList();
+ List<AttributeInfo> newAttributes = new ArrayList<AttributeInfo>();
AttributeInfo invisibleAnnotations
= getAttribute(AnnotationsAttribute.invisibleTag);
if (invisibleAnnotations != null) {
@@ -279,26 +265,18 @@ public final class ClassFile {
newAttributes.add(visibleAnnotations);
}
- AttributeInfo signature
+ AttributeInfo signature
= getAttribute(SignatureAttribute.tag);
if (signature != null) {
signature = signature.copy(cp, null);
newAttributes.add(signature);
}
-
- ArrayList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+
+ for (MethodInfo minfo:methods)
minfo.prune(cp);
- }
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ for (FieldInfo finfo:fields)
finfo.prune(cp);
- }
attributes = newAttributes;
constPool = cp;
@@ -423,12 +401,8 @@ public final class ClassFile {
try {
this.superClass = constPool.addClassInfo(superclass);
- ArrayList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ for (MethodInfo minfo:methods)
minfo.setSuperclass(superclass);
- }
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
@@ -451,9 +425,6 @@ public final class ClassFile {
* the substituted class name
*/
public final void renameClass(String oldname, String newname) {
- ArrayList list;
- int n;
-
if (oldname.equals(newname))
return;
@@ -465,19 +436,13 @@ public final class ClassFile {
constPool.renameClass(oldname, newname);
AttributeInfo.renameClass(attributes, oldname, newname);
- list = methods;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ for (MethodInfo minfo :methods) {
String desc = minfo.getDescriptor();
minfo.setDescriptor(Descriptor.rename(desc, oldname, newname));
AttributeInfo.renameClass(minfo.getAttributes(), oldname, newname);
}
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ for (FieldInfo finfo:fields) {
String desc = finfo.getDescriptor();
finfo.setDescriptor(Descriptor.rename(desc, oldname, newname));
AttributeInfo.renameClass(finfo.getAttributes(), oldname, newname);
@@ -493,8 +458,8 @@ public final class ClassFile {
* representation like <code>java/lang/Object</code>.
* @see #renameClass(String,String)
*/
- public final void renameClass(Map classnames) {
- String jvmNewThisName = (String)classnames.get(Descriptor
+ public final void renameClass(Map<String,String> classnames) {
+ String jvmNewThisName = classnames.get(Descriptor
.toJvmName(thisclassname));
if (jvmNewThisName != null)
thisclassname = Descriptor.toJavaName(jvmNewThisName);
@@ -502,19 +467,13 @@ public final class ClassFile {
constPool.renameClass(classnames);
AttributeInfo.renameClass(attributes, classnames);
- ArrayList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ for (MethodInfo minfo:methods) {
String desc = minfo.getDescriptor();
minfo.setDescriptor(Descriptor.rename(desc, classnames));
AttributeInfo.renameClass(minfo.getAttributes(), classnames);
}
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ for (FieldInfo finfo:fields) {
String desc = finfo.getDescriptor();
finfo.setDescriptor(Descriptor.rename(desc, classnames));
AttributeInfo.renameClass(finfo.getAttributes(), classnames);
@@ -525,23 +484,17 @@ public final class ClassFile {
* Internal-use only.
* <code>CtClass.getRefClasses()</code> calls this method.
*/
- public final void getRefClasses(Map classnames) {
+ public final void getRefClasses(Map<String,String> classnames) {
constPool.renameClass(classnames);
AttributeInfo.getRefClasses(attributes, classnames);
- ArrayList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ for (MethodInfo minfo:methods) {
String desc = minfo.getDescriptor();
Descriptor.rename(desc, classnames);
AttributeInfo.getRefClasses(minfo.getAttributes(), classnames);
}
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ for (FieldInfo finfo:fields) {
String desc = finfo.getDescriptor();
Descriptor.rename(desc, classnames);
AttributeInfo.getRefClasses(finfo.getAttributes(), classnames);
@@ -560,9 +513,8 @@ public final class ClassFile {
if (interfaces == null)
rtn = new String[0];
else {
- int n = interfaces.length;
- String[] list = new String[n];
- for (int i = 0; i < n; ++i)
+ String[] list = new String[interfaces.length];
+ for (int i = 0; i < interfaces.length; ++i)
list[i] = constPool.getClassInfo(interfaces[i]);
rtn = list;
@@ -581,9 +533,8 @@ public final class ClassFile {
public void setInterfaces(String[] nameList) {
cachedInterfaces = null;
if (nameList != null) {
- int n = nameList.length;
- interfaces = new int[n];
- for (int i = 0; i < n; ++i)
+ interfaces = new int[nameList.length];
+ for (int i = 0; i < nameList.length; ++i)
interfaces[i] = constPool.addClassInfo(nameList[i]);
}
}
@@ -613,7 +564,7 @@ public final class ClassFile {
* @return a list of <code>FieldInfo</code>.
* @see FieldInfo
*/
- public List getFields() {
+ public List<FieldInfo> getFields() {
return fields;
}
@@ -641,12 +592,9 @@ public final class ClassFile {
private void testExistingField(String name, String descriptor)
throws DuplicateMemberException {
- ListIterator it = fields.listIterator(0);
- while (it.hasNext()) {
- FieldInfo minfo = (FieldInfo)it.next();
+ for (FieldInfo minfo:fields)
if (minfo.getName().equals(name))
throw new DuplicateMemberException("duplicate field: " + name);
- }
}
/**
@@ -655,7 +603,7 @@ public final class ClassFile {
* @return a list of <code>MethodInfo</code>.
* @see MethodInfo
*/
- public List getMethods() {
+ public List<MethodInfo> getMethods() {
return methods;
}
@@ -666,14 +614,9 @@ public final class ClassFile {
* @return null if no such method is found.
*/
public MethodInfo getMethod(String name) {
- ArrayList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ for (MethodInfo minfo:methods)
if (minfo.getName().equals(name))
return minfo;
- }
-
return null;
}
@@ -714,16 +657,16 @@ public final class ClassFile {
{
String name = newMinfo.getName();
String descriptor = newMinfo.getDescriptor();
- ListIterator it = methods.listIterator(0);
+ ListIterator<MethodInfo> it = methods.listIterator(0);
while (it.hasNext())
- if (isDuplicated(newMinfo, name, descriptor, (MethodInfo)it.next(), it))
+ if (isDuplicated(newMinfo, name, descriptor, it.next(), it))
throw new DuplicateMemberException("duplicate method: " + name
+ " in " + this.getName());
}
private static boolean isDuplicated(MethodInfo newMethod, String newName,
String newDesc, MethodInfo minfo,
- ListIterator it)
+ ListIterator<MethodInfo> it)
{
if (!minfo.getName().equals(newName))
return false;
@@ -735,14 +678,11 @@ public final class ClassFile {
if (desc.equals(newDesc)) {
if (notBridgeMethod(minfo))
return true;
- else {
// if the bridge method with the same signature
// already exists, replace it.
- it.remove();
- return false;
- }
+ it.remove();
+ return false;
}
- else
return false;
// return notBridgeMethod(minfo) && notBridgeMethod(newMethod);
}
@@ -763,7 +703,7 @@ public final class ClassFile {
* @return a list of <code>AttributeInfo</code> objects.
* @see AttributeInfo
*/
- public List getAttributes() {
+ public List<AttributeInfo> getAttributes() {
return attributes;
}
@@ -776,19 +716,14 @@ public final class ClassFile {
* {@link AnnotationsAttribute#visibleTag} or
* {@link AnnotationsAttribute#invisibleTag}.
* </p>
- *
+ *
* @param name attribute name
* @see #getAttributes()
*/
public AttributeInfo getAttribute(String name) {
- ArrayList list = attributes;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo ai = (AttributeInfo)list.get(i);
+ for (AttributeInfo ai:attributes)
if (ai.getName().equals(name))
return ai;
- }
-
return null;
}
@@ -824,8 +759,7 @@ public final class ClassFile {
= (SourceFileAttribute)getAttribute(SourceFileAttribute.tag);
if (sf == null)
return null;
- else
- return sf.getFileName();
+ return sf.getFileName();
}
private void read(DataInputStream in) throws IOException {
@@ -852,16 +786,16 @@ public final class ClassFile {
ConstPool cp = constPool;
n = in.readUnsignedShort();
- fields = new ArrayList();
+ fields = new ArrayList<FieldInfo>();
for (i = 0; i < n; ++i)
addField2(new FieldInfo(cp, in));
n = in.readUnsignedShort();
- methods = new ArrayList();
+ methods = new ArrayList<MethodInfo>();
for (i = 0; i < n; ++i)
addMethod2(new MethodInfo(cp, in));
- attributes = new ArrayList();
+ attributes = new ArrayList<AttributeInfo>();
n = in.readUnsignedShort();
for (i = 0; i < n; ++i)
addAttribute(AttributeInfo.read(cp, in));
@@ -892,21 +826,16 @@ public final class ClassFile {
for (i = 0; i < n; ++i)
out.writeShort(interfaces[i]);
- ArrayList list = fields;
- n = list.size();
+ n = fields.size();
out.writeShort(n);
for (i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ FieldInfo finfo = fields.get(i);
finfo.write(out);
}
- list = methods;
- n = list.size();
- out.writeShort(n);
- for (i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ out.writeShort(methods.size());
+ for (MethodInfo minfo:methods)
minfo.write(out);
- }
out.writeShort(attributes.size());
AttributeInfo.writeAll(attributes, out);
diff --git a/src/main/javassist/bytecode/ClassFilePrinter.java b/src/main/javassist/bytecode/ClassFilePrinter.java
index 388ab517..a9c7d9ba 100644
--- a/src/main/javassist/bytecode/ClassFilePrinter.java
+++ b/src/main/javassist/bytecode/ClassFilePrinter.java
@@ -17,9 +17,10 @@
package javassist.bytecode;
import java.io.PrintWriter;
-import javassist.Modifier;
import java.util.List;
+import javassist.Modifier;
+
/**
* A utility class for priting the contents of a class file.
* It prints a constant pool table, fields, and methods in a
@@ -37,9 +38,6 @@ public class ClassFilePrinter {
* Prints the contents of a class file.
*/
public static void print(ClassFile cf, PrintWriter out) {
- List list;
- int n;
-
/* 0x0020 (SYNCHRONIZED) means ACC_SUPER if the modifiers
* are of a class.
*/
@@ -62,10 +60,8 @@ public class ClassFilePrinter {
}
out.println();
- list = cf.getFields();
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
+ List<FieldInfo> fields = cf.getFields();
+ for (FieldInfo finfo:fields) {
int acc = finfo.getAccessFlags();
out.println(Modifier.toString(AccessFlag.toModifier(acc))
+ " " + finfo.getName() + "\t"
@@ -74,10 +70,8 @@ public class ClassFilePrinter {
}
out.println();
- list = cf.getMethods();
- n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ List<MethodInfo> methods = cf.getMethods();
+ for (MethodInfo minfo:methods) {
int acc = minfo.getAccessFlags();
out.println(Modifier.toString(AccessFlag.toModifier(acc))
+ " " + minfo.getName() + "\t"
@@ -90,13 +84,11 @@ public class ClassFilePrinter {
printAttributes(cf.getAttributes(), out, 'c');
}
- static void printAttributes(List list, PrintWriter out, char kind) {
+ static void printAttributes(List<AttributeInfo> list, PrintWriter out, char kind) {
if (list == null)
return;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo ai = (AttributeInfo)list.get(i);
+ for (AttributeInfo ai:list) {
if (ai instanceof CodeAttribute) {
CodeAttribute ca = (CodeAttribute)ai;
out.println("attribute: " + ai.getName() + ": "
diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFileWriter.java
index d1e76ce0..931ffcb4 100644
--- a/src/main/javassist/bytecode/ClassFileWriter.java
+++ b/src/main/javassist/bytecode/ClassFileWriter.java
@@ -16,10 +16,9 @@
package javassist.bytecode;
-import java.io.OutputStream;
import java.io.DataOutputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
/**
* A quick class-file writer. This is useful when a generated
diff --git a/src/main/javassist/bytecode/CodeAttribute.java b/src/main/javassist/bytecode/CodeAttribute.java
index 090ae74d..4c8ea2f2 100644
--- a/src/main/javassist/bytecode/CodeAttribute.java
+++ b/src/main/javassist/bytecode/CodeAttribute.java
@@ -19,9 +19,8 @@ package javassist.bytecode;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.util.List;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
/**
@@ -45,7 +44,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
private int maxStack;
private int maxLocals;
private ExceptionTable exceptions;
- private ArrayList attributes;
+ private List<AttributeInfo> attributes;
/**
* Constructs a <code>Code_attribute</code>.
@@ -64,7 +63,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
maxLocals = locals;
info = code;
exceptions = etable;
- attributes = new ArrayList();
+ attributes = new ArrayList<AttributeInfo>();
}
/**
@@ -76,7 +75,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* @param classnames pairs of replaced and substituted
* class names.
*/
- private CodeAttribute(ConstPool cp, CodeAttribute src, Map classnames)
+ private CodeAttribute(ConstPool cp, CodeAttribute src, Map<String,String> classnames)
throws BadBytecode
{
super(cp, tag);
@@ -84,11 +83,11 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
maxStack = src.getMaxStack();
maxLocals = src.getMaxLocals();
exceptions = src.getExceptionTable().copy(cp, classnames);
- attributes = new ArrayList();
- List src_attr = src.getAttributes();
+ attributes = new ArrayList<AttributeInfo>();
+ List<AttributeInfo> src_attr = src.getAttributes();
int num = src_attr.size();
for (int i = 0; i < num; ++i) {
- AttributeInfo ai = (AttributeInfo)src_attr.get(i);
+ AttributeInfo ai = src_attr.get(i);
attributes.add(ai.copy(cp, classnames));
}
@@ -99,6 +98,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
throws IOException
{
super(cp, name_id, (byte[])null);
+ @SuppressWarnings("unused")
int attr_len = in.readInt();
maxStack = in.readUnsignedShort();
@@ -110,7 +110,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
exceptions = new ExceptionTable(cp, in);
- attributes = new ArrayList();
+ attributes = new ArrayList<AttributeInfo>();
int num = in.readUnsignedShort();
for (int i = 0; i < num; ++i)
attributes.add(AttributeInfo.read(cp, in));
@@ -130,7 +130,8 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
*
* @return <code>CodeAttribute</code> object.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames)
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames)
throws RuntimeCopyException
{
try {
@@ -146,6 +147,9 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* in <code>CodeAttribute</code>.
*/
public static class RuntimeCopyException extends RuntimeException {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
/**
* Constructs an exception.
*/
@@ -159,11 +163,13 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* structure.
* The returned value is <code>attribute_length + 6</code>.
*/
+ @Override
public int length() {
return 18 + info.length + exceptions.size() * 8
+ AttributeInfo.getLength(attributes);
}
+ @Override
void write(DataOutputStream out) throws IOException {
out.writeShort(name); // attribute_name_index
out.writeInt(length() - 6); // attribute_length
@@ -181,7 +187,8 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
*
* @throws java.lang.UnsupportedOperationException always thrown.
*/
- public byte[] get() {
+ @Override
+ public byte[] get() {
throw new UnsupportedOperationException("CodeAttribute.get()");
}
@@ -190,19 +197,23 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
*
* @throws java.lang.UnsupportedOperationException always thrown.
*/
+ @Override
public void set(byte[] newinfo) {
throw new UnsupportedOperationException("CodeAttribute.set()");
}
+ @Override
void renameClass(String oldname, String newname) {
AttributeInfo.renameClass(attributes, oldname, newname);
}
- void renameClass(Map classnames) {
+ @Override
+ void renameClass(Map<String,String> classnames) {
AttributeInfo.renameClass(attributes, classnames);
}
- void getRefClasses(Map classnames) {
+ @Override
+ void getRefClasses(Map<String,String> classnames) {
AttributeInfo.getRefClasses(attributes, classnames);
}
@@ -294,7 +305,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
*
* @see AttributeInfo
*/
- public List getAttributes() { return attributes; }
+ public List<AttributeInfo> getAttributes() { return attributes; }
/**
* Returns the attribute with the specified name.
@@ -339,7 +350,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
/**
* Copies code.
*/
- private byte[] copyCode(ConstPool destCp, Map classnames,
+ private byte[] copyCode(ConstPool destCp, Map<String,String> classnames,
ExceptionTable etable, CodeAttribute destCa)
throws BadBytecode
{
@@ -353,7 +364,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
private static LdcEntry copyCode(byte[] code, int beginPos, int endPos,
ConstPool srcCp, byte[] newcode,
- ConstPool destCp, Map classnameMap)
+ ConstPool destCp, Map<String,String> classnameMap)
throws BadBytecode
{
int i2, index;
@@ -425,7 +436,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
private static void copyConstPoolInfo(int i, byte[] code, ConstPool srcCp,
byte[] newcode, ConstPool destCp,
- Map classnameMap) {
+ Map<String,String> classnameMap) {
int index = ((code[i] & 0xff) << 8) | (code[i + 1] & 0xff);
index = srcCp.copy(index, destCp, classnameMap);
newcode[i] = (byte)(index >> 8);
diff --git a/src/main/javassist/bytecode/CodeIterator.java b/src/main/javassist/bytecode/CodeIterator.java
index e1edcbb7..b9a23c2c 100644
--- a/src/main/javassist/bytecode/CodeIterator.java
+++ b/src/main/javassist/bytecode/CodeIterator.java
@@ -17,6 +17,7 @@
package javassist.bytecode;
import java.util.ArrayList;
+import java.util.List;
/**
* An iterator for editing a code attribute.
@@ -305,8 +306,8 @@ public class CodeIterator implements Opcode {
String cname = cp.getMethodrefClassName(mref);
if (cname.equals(thisClassName) == (skipThis > 0))
return index;
- else
- break;
+
+ break;
}
}
}
@@ -772,19 +773,15 @@ public class CodeIterator implements Opcode {
return index + 6;
else
return index + 4; // WIDE ...
- else {
- int index2 = (index & ~3) + 8;
- if (opcode == LOOKUPSWITCH) {
- int npairs = ByteArray.read32bit(code, index2);
- return index2 + npairs * 8 + 4;
- }
- else if (opcode == TABLESWITCH) {
- int low = ByteArray.read32bit(code, index2);
- int high = ByteArray.read32bit(code, index2 + 4);
- return index2 + (high - low + 1) * 4 + 8;
- }
- // else
- // throw new BadBytecode(opcode);
+ int index2 = (index & ~3) + 8;
+ if (opcode == LOOKUPSWITCH) {
+ int npairs = ByteArray.read32bit(code, index2);
+ return index2 + npairs * 8 + 4;
+ }
+ else if (opcode == TABLESWITCH) {
+ int low = ByteArray.read32bit(code, index2);
+ int high = ByteArray.read32bit(code, index2 + 4);
+ return index2 + (high - low + 1) * 4 + 8;
}
}
catch (IndexOutOfBoundsException e) {
@@ -796,7 +793,10 @@ public class CodeIterator implements Opcode {
// methods for implementing insertGap().
- static class AlignmentException extends Exception {}
+ static class AlignmentException extends Exception {
+
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;}
/**
* insertGapCore0() inserts a gap (some NOPs).
@@ -1075,7 +1075,7 @@ public class CodeIterator implements Opcode {
throws BadBytecode
{
Pointers pointers = new Pointers(0, 0, 0, etable, ca);
- ArrayList jumps = makeJumpList(code, code.length, pointers);
+ List<Branch> jumps = makeJumpList(code, code.length, pointers);
while (ldcs != null) {
addLdcW(ldcs, jumps);
ldcs = ldcs.next;
@@ -1085,12 +1085,12 @@ public class CodeIterator implements Opcode {
return r;
}
- private static void addLdcW(CodeAttribute.LdcEntry ldcs, ArrayList jumps) {
+ private static void addLdcW(CodeAttribute.LdcEntry ldcs, List<Branch> jumps) {
int where = ldcs.where;
LdcW ldcw = new LdcW(where, ldcs.index);
int s = jumps.size();
for (int i = 0; i < s; i++)
- if (where < ((Branch)jumps.get(i)).orgPos) {
+ if (where < jumps.get(i).orgPos) {
jumps.add(i, ldcw);
return;
}
@@ -1119,7 +1119,7 @@ public class CodeIterator implements Opcode {
return code;
Pointers pointers = new Pointers(currentPos, mark, where, etable, ca);
- ArrayList jumps = makeJumpList(code, code.length, pointers);
+ List<Branch> jumps = makeJumpList(code, code.length, pointers);
byte[] r = insertGap2w(code, where, gapLength, exclusive, jumps, pointers);
currentPos = pointers.cursor;
mark = pointers.mark;
@@ -1136,42 +1136,39 @@ public class CodeIterator implements Opcode {
}
private static byte[] insertGap2w(byte[] code, int where, int gapLength,
- boolean exclusive, ArrayList jumps, Pointers ptrs)
+ boolean exclusive, List<Branch> jumps, Pointers ptrs)
throws BadBytecode
{
- int n = jumps.size();
if (gapLength > 0) {
ptrs.shiftPc(where, gapLength, exclusive);
- for (int i = 0; i < n; i++)
- ((Branch)jumps.get(i)).shift(where, gapLength, exclusive);
+ for (Branch b:jumps)
+ b.shift(where, gapLength, exclusive);
}
boolean unstable = true;
do {
while (unstable) {
unstable = false;
- for (int i = 0; i < n; i++) {
- Branch b = (Branch)jumps.get(i);
+ for (Branch b:jumps) {
if (b.expanded()) {
unstable = true;
int p = b.pos;
int delta = b.deltaSize();
ptrs.shiftPc(p, delta, false);
- for (int j = 0; j < n; j++)
- ((Branch)jumps.get(j)).shift(p, delta, false);
+ for (Branch bb:jumps)
+ bb.shift(p, delta, false);
}
}
}
- for (int i = 0; i < n; i++) {
- Branch b = (Branch)jumps.get(i);
+ for (Branch b:jumps) {
int diff = b.gapChanged();
if (diff > 0) {
unstable = true;
int p = b.pos;
ptrs.shiftPc(p, diff, false);
- for (int j = 0; j < n; j++)
- ((Branch)jumps.get(j)).shift(p, diff, false);
+ for (Branch bb:jumps)
+ bb.shift(p, diff, false);
}
}
} while (unstable);
@@ -1179,10 +1176,10 @@ public class CodeIterator implements Opcode {
return makeExapndedCode(code, jumps, where, gapLength);
}
- private static ArrayList makeJumpList(byte[] code, int endPos, Pointers ptrs)
+ private static List<Branch> makeJumpList(byte[] code, int endPos, Pointers ptrs)
throws BadBytecode
{
- ArrayList jumps = new ArrayList();
+ List<Branch> jumps = new ArrayList<Branch>();
int nextPos;
for (int i = 0; i < endPos; i = nextPos) {
nextPos = nextOpcode(code, i);
@@ -1240,16 +1237,14 @@ public class CodeIterator implements Opcode {
return jumps;
}
- private static byte[] makeExapndedCode(byte[] code, ArrayList jumps,
+ private static byte[] makeExapndedCode(byte[] code, List<Branch> jumps,
int where, int gapLength)
throws BadBytecode
{
int n = jumps.size();
int size = code.length + gapLength;
- for (int i = 0; i < n; i++) {
- Branch b = (Branch)jumps.get(i);
+ for (Branch b:jumps)
size += b.deltaSize();
- }
byte[] newcode = new byte[size];
int src = 0, dest = 0, bindex = 0;
@@ -1257,12 +1252,12 @@ public class CodeIterator implements Opcode {
Branch b;
int bpos;
if (0 < n) {
- b = (Branch)jumps.get(0);
+ b = jumps.get(0);
bpos = b.orgPos;
}
else {
b = null;
- bpos = len; // src will be never equal to bpos
+ bpos = len; // src will be never equal to bpos
}
while (src < len) {
@@ -1279,7 +1274,7 @@ public class CodeIterator implements Opcode {
src += s;
dest += s + b.deltaSize();
if (++bindex < n) {
- b = (Branch)jumps.get(bindex);
+ b = jumps.get(bindex);
bpos = b.orgPos;
}
else {
@@ -1341,17 +1336,19 @@ public class CodeIterator implements Opcode {
state = true;
}
+ @Override
boolean expanded() {
if (state) {
state = false;
return true;
}
- else
- return false;
+ return false;
}
+ @Override
int deltaSize() { return 1; }
+ @Override
int write(int srcPos, byte[] code, int destPos, byte[] newcode) {
newcode[destPos] = LDC_W;
ByteArray.write16bit(index, newcode, destPos + 1);
@@ -1372,6 +1369,7 @@ public class CodeIterator implements Opcode {
state = BIT16;
}
+ @Override
void shift(int where, int gapLength, boolean exclusive) {
offset = shiftOffset(pos, offset, where, gapLength, exclusive);
super.shift(where, gapLength, exclusive);
@@ -1380,18 +1378,20 @@ public class CodeIterator implements Opcode {
state = EXPAND;
}
+ @Override
boolean expanded() {
if (state == EXPAND) {
state = BIT32;
return true;
}
- else
- return false;
+ return false;
}
+ @Override
abstract int deltaSize();
abstract void write32(int src, byte[] code, int dest, byte[] newcode);
+ @Override
int write(int src, byte[] code, int dest, byte[] newcode) {
if (state == BIT32)
write32(src, code, dest, newcode);
@@ -1410,10 +1410,12 @@ public class CodeIterator implements Opcode {
super(p, off);
}
+ @Override
int deltaSize() {
return state == BIT32 ? 2 : 0;
}
+ @Override
void write32(int src, byte[] code, int dest, byte[] newcode) {
newcode[dest] = (byte)(((code[src] & 0xff) == GOTO) ? GOTO_W : JSR_W);
ByteArray.write32bit(offset, newcode, dest + 1);
@@ -1426,10 +1428,12 @@ public class CodeIterator implements Opcode {
super(p, off);
}
+ @Override
int deltaSize() {
return state == BIT32 ? 5 : 0;
}
+ @Override
void write32(int src, byte[] code, int dest, byte[] newcode) {
newcode[dest] = (byte)opcode(code[src] & 0xff);
newcode[dest + 1] = 0;
@@ -1443,12 +1447,9 @@ public class CodeIterator implements Opcode {
return IFNONNULL;
else if (op == IFNONNULL)
return IFNULL;
- else {
- if (((op - IFEQ) & 1) == 0)
- return op + 1;
- else
- return op - 1;
- }
+ if (((op - IFEQ) & 1) == 0)
+ return op + 1;
+ return op - 1;
}
}
@@ -1460,11 +1461,13 @@ public class CodeIterator implements Opcode {
offset = off;
}
+ @Override
void shift(int where, int gapLength, boolean exclusive) {
offset = shiftOffset(pos, offset, where, gapLength, exclusive);
super.shift(where, gapLength, exclusive);
}
+ @Override
int write(int src, byte[] code, int dest, byte[] newcode) {
newcode[dest] = code[src];
ByteArray.write32bit(offset, newcode, dest + 1);
@@ -1485,6 +1488,7 @@ public class CodeIterator implements Opcode {
this.pointers = ptrs;
}
+ @Override
void shift(int where, int gapLength, boolean exclusive) {
int p = pos;
defaultByte = shiftOffset(p, defaultByte, where, gapLength, exclusive);
@@ -1495,6 +1499,7 @@ public class CodeIterator implements Opcode {
super.shift(where, gapLength, exclusive);
}
+ @Override
int gapChanged() {
int newGap = 3 - (pos & 3);
if (newGap > gap) {
@@ -1506,10 +1511,12 @@ public class CodeIterator implements Opcode {
return 0;
}
+ @Override
int deltaSize() {
return gap - (3 - (orgPos & 3));
}
+ @Override
int write(int src, byte[] code, int dest, byte[] newcode) throws BadBytecode {
int padding = 3 - (pos & 3);
int nops = gap - padding;
@@ -1562,6 +1569,7 @@ public class CodeIterator implements Opcode {
this.high = high;
}
+ @Override
int write2(int dest, byte[] newcode) {
ByteArray.write32bit(low, newcode, dest);
ByteArray.write32bit(high, newcode, dest + 4);
@@ -1575,6 +1583,7 @@ public class CodeIterator implements Opcode {
return 8 + 4 * n;
}
+ @Override
int tableSize() { return 8 + 4 * offsets.length; }
}
@@ -1586,6 +1595,7 @@ public class CodeIterator implements Opcode {
this.matches = matches;
}
+ @Override
int write2(int dest, byte[] newcode) {
int n = matches.length;
ByteArray.write32bit(n, newcode, dest);
@@ -1599,6 +1609,7 @@ public class CodeIterator implements Opcode {
return 4 + 8 * n;
}
+ @Override
int tableSize() { return 4 + 8 * matches.length; }
}
}
diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java
index 2ac31ba2..0447ece7 100644
--- a/src/main/javassist/bytecode/ConstPool.java
+++ b/src/main/javassist/bytecode/ConstPool.java
@@ -16,11 +16,11 @@
package javassist.bytecode;
+import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -31,11 +31,12 @@ import javassist.CtClass;
/**
* Constant pool table.
*/
-public final class ConstPool {
+public final class ConstPool
+{
LongVector items;
int numOfItems;
int thisClassInfo;
- HashMap itemsCache;
+ Map<ConstInfo,ConstInfo> itemsCache;
/**
* <code>CONSTANT_Class</code>
@@ -174,7 +175,8 @@ public final class ConstPool {
* @param thisclass the name of the class using this constant
* pool table
*/
- public ConstPool(String thisclass) {
+ public ConstPool(String thisclass)
+ {
items = new LongVector();
itemsCache = null;
numOfItems = 0;
@@ -187,7 +189,8 @@ public final class ConstPool {
*
* @param in byte stream.
*/
- public ConstPool(DataInputStream in) throws IOException {
+ public ConstPool(DataInputStream in) throws IOException
+ {
itemsCache = null;
thisClassInfo = 0;
/* read() initializes items and numOfItems, and do addItem(null).
@@ -195,21 +198,24 @@ public final class ConstPool {
read(in);
}
- void prune() {
+ void prune()
+ {
itemsCache = null;
}
/**
* Returns the number of entries in this table.
*/
- public int getSize() {
+ public int getSize()
+ {
return numOfItems;
}
/**
* Returns the name of the class using this constant pool table.
*/
- public String getClassName() {
+ public String getClassName()
+ {
return getClassInfo(thisClassInfo);
}
@@ -217,15 +223,18 @@ public final class ConstPool {
* Returns the index of <code>CONSTANT_Class_info</code> structure
* specifying the class using this constant pool table.
*/
- public int getThisClassInfo() {
+ public int getThisClassInfo()
+ {
return thisClassInfo;
}
- void setThisClassInfo(int i) {
+ void setThisClassInfo(int i)
+ {
thisClassInfo = i;
}
- ConstInfo getItem(int n) {
+ ConstInfo getItem(int n)
+ {
return items.elementAt(n);
}
@@ -236,7 +245,8 @@ public final class ConstPool {
* @return either <code>CONST_Class</code>, <code>CONST_Fieldref</code>,
* <code>CONST_Methodref</code>, or ...
*/
- public int getTag(int index) {
+ public int getTag(int index)
+ {
return getItem(index).getTag();
}
@@ -251,12 +261,12 @@ public final class ConstPool {
* are not slashes but dots).
* @see javassist.ClassPool#getCtClass(String)
*/
- public String getClassInfo(int index) {
+ public String getClassInfo(int index)
+ {
ClassInfo c = (ClassInfo)getItem(index);
if (c == null)
return null;
- else
- return Descriptor.toJavaName(getUtf8Info(c.name));
+ return Descriptor.toJavaName(getUtf8Info(c.name));
}
/**
@@ -268,17 +278,15 @@ public final class ConstPool {
* @see javassist.ClassPool#getCtClass(String)
* @since 3.15
*/
- public String getClassInfoByDescriptor(int index) {
+ public String getClassInfoByDescriptor(int index)
+ {
ClassInfo c = (ClassInfo)getItem(index);
if (c == null)
return null;
- else {
- String className = getUtf8Info(c.name);
- if (className.charAt(0) == '[')
- return className;
- else
- return Descriptor.of(className);
- }
+ String className = getUtf8Info(c.name);
+ if (className.charAt(0) == '[')
+ return className;
+ return Descriptor.of(className);
}
/**
@@ -286,7 +294,8 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* at the given index.
*/
- public int getNameAndTypeName(int index) {
+ public int getNameAndTypeName(int index)
+ {
NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
return ntinfo.memberName;
}
@@ -296,7 +305,8 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* at the given index.
*/
- public int getNameAndTypeDescriptor(int index) {
+ public int getNameAndTypeDescriptor(int index)
+ {
NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
return ntinfo.typeDescriptor;
}
@@ -310,7 +320,8 @@ public final class ConstPool {
*
* @since 3.6
*/
- public int getMemberClass(int index) {
+ public int getMemberClass(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.classIndex;
}
@@ -324,7 +335,8 @@ public final class ConstPool {
*
* @since 3.6
*/
- public int getMemberNameAndType(int index) {
+ public int getMemberNameAndType(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.nameAndTypeIndex;
}
@@ -334,7 +346,8 @@ public final class ConstPool {
* <code>CONSTANT_Fieldref_info</code> structure
* at the given index.
*/
- public int getFieldrefClass(int index) {
+ public int getFieldrefClass(int index)
+ {
FieldrefInfo finfo = (FieldrefInfo)getItem(index);
return finfo.classIndex;
}
@@ -346,12 +359,12 @@ public final class ConstPool {
*
* @return the name of the class at that <code>class_index</code>.
*/
- public String getFieldrefClassName(int index) {
+ public String getFieldrefClassName(int index)
+ {
FieldrefInfo f = (FieldrefInfo)getItem(index);
if (f == null)
return null;
- else
- return getClassInfo(f.classIndex);
+ return getClassInfo(f.classIndex);
}
/**
@@ -359,7 +372,8 @@ public final class ConstPool {
* <code>CONSTANT_Fieldref_info</code> structure
* at the given index.
*/
- public int getFieldrefNameAndType(int index) {
+ public int getFieldrefNameAndType(int index)
+ {
FieldrefInfo finfo = (FieldrefInfo)getItem(index);
return finfo.nameAndTypeIndex;
}
@@ -372,17 +386,15 @@ public final class ConstPool {
* @param index an index to a <code>CONSTANT_Fieldref_info</code>.
* @return the name of the field.
*/
- public String getFieldrefName(int index) {
+ public String getFieldrefName(int index)
+ {
FieldrefInfo f = (FieldrefInfo)getItem(index);
if (f == null)
return null;
- else {
- NameAndTypeInfo n = (NameAndTypeInfo)getItem(f.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.memberName);
- }
+ NameAndTypeInfo n = (NameAndTypeInfo)getItem(f.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.memberName);
}
/**
@@ -393,17 +405,15 @@ public final class ConstPool {
* @param index an index to a <code>CONSTANT_Fieldref_info</code>.
* @return the type descriptor of the field.
*/
- public String getFieldrefType(int index) {
+ public String getFieldrefType(int index)
+ {
FieldrefInfo f = (FieldrefInfo)getItem(index);
if (f == null)
return null;
- else {
- NameAndTypeInfo n = (NameAndTypeInfo)getItem(f.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.typeDescriptor);
- }
+ NameAndTypeInfo n = (NameAndTypeInfo)getItem(f.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.typeDescriptor);
}
/**
@@ -411,7 +421,8 @@ public final class ConstPool {
* <code>CONSTANT_Methodref_info</code> structure
* at the given index.
*/
- public int getMethodrefClass(int index) {
+ public int getMethodrefClass(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.classIndex;
}
@@ -423,12 +434,12 @@ public final class ConstPool {
*
* @return the name of the class at that <code>class_index</code>.
*/
- public String getMethodrefClassName(int index) {
+ public String getMethodrefClassName(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
- else
- return getClassInfo(minfo.classIndex);
+ return getClassInfo(minfo.classIndex);
}
/**
@@ -436,7 +447,8 @@ public final class ConstPool {
* <code>CONSTANT_Methodref_info</code> structure
* at the given index.
*/
- public int getMethodrefNameAndType(int index) {
+ public int getMethodrefNameAndType(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.nameAndTypeIndex;
}
@@ -449,18 +461,16 @@ public final class ConstPool {
* @param index an index to a <code>CONSTANT_Methodref_info</code>.
* @return the name of the method.
*/
- public String getMethodrefName(int index) {
+ public String getMethodrefName(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.memberName);
- }
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.memberName);
}
/**
@@ -471,18 +481,16 @@ public final class ConstPool {
* @param index an index to a <code>CONSTANT_Methodref_info</code>.
* @return the descriptor of the method.
*/
- public String getMethodrefType(int index) {
+ public String getMethodrefType(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.typeDescriptor);
- }
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.typeDescriptor);
}
/**
@@ -490,7 +498,8 @@ public final class ConstPool {
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index.
*/
- public int getInterfaceMethodrefClass(int index) {
+ public int getInterfaceMethodrefClass(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.classIndex;
}
@@ -502,7 +511,8 @@ public final class ConstPool {
*
* @return the name of the class at that <code>class_index</code>.
*/
- public String getInterfaceMethodrefClassName(int index) {
+ public String getInterfaceMethodrefClassName(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return getClassInfo(minfo.classIndex);
}
@@ -512,7 +522,8 @@ public final class ConstPool {
* <code>CONSTANT_InterfaceMethodref_info</code> structure
* at the given index.
*/
- public int getInterfaceMethodrefNameAndType(int index) {
+ public int getInterfaceMethodrefNameAndType(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
return minfo.nameAndTypeIndex;
}
@@ -526,18 +537,16 @@ public final class ConstPool {
* a <code>CONSTANT_InterfaceMethodref_info</code>.
* @return the name of the method.
*/
- public String getInterfaceMethodrefName(int index) {
+ public String getInterfaceMethodrefName(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.memberName);
- }
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.memberName);
}
/**
@@ -549,18 +558,16 @@ public final class ConstPool {
* a <code>CONSTANT_InterfaceMethodref_info</code>.
* @return the descriptor of the method.
*/
- public String getInterfaceMethodrefType(int index) {
+ public String getInterfaceMethodrefType(int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (minfo == null)
return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.typeDescriptor);
- }
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.typeDescriptor);
}
/**
* Reads <code>CONSTANT_Integer_info</code>, <code>_Float_info</code>,
@@ -571,7 +578,8 @@ public final class ConstPool {
* @return a <code>String</code> value or a wrapped primitive-type
* value.
*/
- public Object getLdcValue(int index) {
+ public Object getLdcValue(int index)
+ {
ConstInfo constInfo = this.getItem(index);
Object value = null;
if (constInfo instanceof StringInfo)
@@ -584,8 +592,6 @@ public final class ConstPool {
value = Long.valueOf(getLongInfo(index));
else if (constInfo instanceof DoubleInfo)
value = Double.valueOf(getDoubleInfo(index));
- else
- value = null;
return value;
}
@@ -596,7 +602,8 @@ public final class ConstPool {
*
* @return the value specified by this entry.
*/
- public int getIntegerInfo(int index) {
+ public int getIntegerInfo(int index)
+ {
IntegerInfo i = (IntegerInfo)getItem(index);
return i.value;
}
@@ -607,7 +614,8 @@ public final class ConstPool {
*
* @return the value specified by this entry.
*/
- public float getFloatInfo(int index) {
+ public float getFloatInfo(int index)
+ {
FloatInfo i = (FloatInfo)getItem(index);
return i.value;
}
@@ -618,7 +626,8 @@ public final class ConstPool {
*
* @return the value specified by this entry.
*/
- public long getLongInfo(int index) {
+ public long getLongInfo(int index)
+ {
LongInfo i = (LongInfo)getItem(index);
return i.value;
}
@@ -629,7 +638,8 @@ public final class ConstPool {
*
* @return the value specified by this entry.
*/
- public double getDoubleInfo(int index) {
+ public double getDoubleInfo(int index)
+ {
DoubleInfo i = (DoubleInfo)getItem(index);
return i.value;
}
@@ -640,7 +650,8 @@ public final class ConstPool {
*
* @return the string specified by <code>string_index</code>.
*/
- public String getStringInfo(int index) {
+ public String getStringInfo(int index)
+ {
StringInfo si = (StringInfo)getItem(index);
return getUtf8Info(si.string);
}
@@ -651,7 +662,8 @@ public final class ConstPool {
*
* @return the string specified by this entry.
*/
- public String getUtf8Info(int index) {
+ public String getUtf8Info(int index)
+ {
Utf8Info utf = (Utf8Info)getItem(index);
return utf.string;
}
@@ -672,7 +684,8 @@ public final class ConstPool {
* @see #REF_putStatic
* @since 3.17
*/
- public int getMethodHandleKind(int index) {
+ public int getMethodHandleKind(int index)
+ {
MethodHandleInfo mhinfo = (MethodHandleInfo)getItem(index);
return mhinfo.refKind;
}
@@ -684,7 +697,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int getMethodHandleIndex(int index) {
+ public int getMethodHandleIndex(int index)
+ {
MethodHandleInfo mhinfo = (MethodHandleInfo)getItem(index);
return mhinfo.refIndex;
}
@@ -696,7 +710,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int getMethodTypeInfo(int index) {
+ public int getMethodTypeInfo(int index)
+ {
MethodTypeInfo mtinfo = (MethodTypeInfo)getItem(index);
return mtinfo.descriptor;
}
@@ -708,7 +723,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int getInvokeDynamicBootstrap(int index) {
+ public int getInvokeDynamicBootstrap(int index)
+ {
InvokeDynamicInfo iv = (InvokeDynamicInfo)getItem(index);
return iv.bootstrap;
}
@@ -720,7 +736,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int getInvokeDynamicNameAndType(int index) {
+ public int getInvokeDynamicNameAndType(int index)
+ {
InvokeDynamicInfo iv = (InvokeDynamicInfo)getItem(index);
return iv.nameAndType;
}
@@ -734,17 +751,15 @@ public final class ConstPool {
* @return the descriptor of the method.
* @since 3.17
*/
- public String getInvokeDynamicType(int index) {
+ public String getInvokeDynamicType(int index)
+ {
InvokeDynamicInfo iv = (InvokeDynamicInfo)getItem(index);
if (iv == null)
return null;
- else {
- NameAndTypeInfo n = (NameAndTypeInfo)getItem(iv.nameAndType);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.typeDescriptor);
- }
+ NameAndTypeInfo n = (NameAndTypeInfo)getItem(iv.nameAndType);
+ if(n == null)
+ return null;
+ return getUtf8Info(n.typeDescriptor);
}
/**
@@ -754,7 +769,8 @@ public final class ConstPool {
* @return the module name at <code>name_index</code>.
* @since 3.22
*/
- public String getModuleInfo(int index) {
+ public String getModuleInfo(int index)
+ {
ModuleInfo mi = (ModuleInfo)getItem(index);
return getUtf8Info(mi.name);
}
@@ -763,11 +779,12 @@ public final class ConstPool {
* Reads the <code>name_index</code> field of the
* <code>CONSTANT_Package_info</code> structure at the given index.
*
- * @return the package name at <code>name_index</code>. It is a slash-separated name
- * such as com/oracle/net.
+ * @return the package name at <code>name_index</code>. It is a slash-
+ * separated name such as com/oracle/net.
* @since 3.22
*/
- public String getPackageInfo(int index) {
+ public String getPackageInfo(int index)
+ {
PackageInfo mi = (PackageInfo)getItem(index);
return getUtf8Info(mi.name);
}
@@ -782,7 +799,8 @@ public final class ConstPool {
* If it is not that constructor,
* <code>isConstructor()</code> returns 0.
*/
- public int isConstructor(String classname, int index) {
+ public int isConstructor(String classname, int index)
+ {
return isMember(classname, MethodInfo.nameInit, index);
}
@@ -802,7 +820,8 @@ public final class ConstPool {
* If it is not that member,
* <code>isMember()</code> returns 0.
*/
- public int isMember(String classname, String membername, int index) {
+ public int isMember(String classname, String membername, int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
if (getClassInfo(minfo.classIndex).equals(classname)) {
NameAndTypeInfo ntinfo
@@ -831,34 +850,34 @@ public final class ConstPool {
* Otherwise, null if that structure does not
* match the given member name and descriptor.
*/
- public String eqMember(String membername, String desc, int index) {
+ public String eqMember(String membername, String desc, int index)
+ {
MemberrefInfo minfo = (MemberrefInfo)getItem(index);
NameAndTypeInfo ntinfo
= (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
if (getUtf8Info(ntinfo.memberName).equals(membername)
&& getUtf8Info(ntinfo.typeDescriptor).equals(desc))
return getClassInfo(minfo.classIndex);
- else
- return null; // false
+ return null; // false
}
- private int addItem0(ConstInfo info) {
+ private int addItem0(ConstInfo info)
+ {
items.addElement(info);
return numOfItems++;
}
- private int addItem(ConstInfo info) {
+ private int addItem(ConstInfo info)
+ {
if (itemsCache == null)
itemsCache = makeItemsCache(items);
- ConstInfo found = (ConstInfo)itemsCache.get(info);
+ ConstInfo found = itemsCache.get(info);
if (found != null)
return found.index;
- else {
- items.addElement(info);
- itemsCache.put(info, info);
- return numOfItems++;
- }
+ items.addElement(info);
+ itemsCache.put(info, info);
+ return numOfItems++;
}
/**
@@ -872,7 +891,8 @@ public final class ConstPool {
* @param classnames the map or null.
* @return the index of the copied item into the destination ClassPool.
*/
- public int copy(int n, ConstPool dest, Map classnames) {
+ public int copy(int n, ConstPool dest, Map<String,String> classnames)
+ {
if (n == 0)
return 0;
@@ -892,7 +912,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addClassInfo(CtClass c) {
+ public int addClassInfo(CtClass c)
+ {
if (c == THIS)
return thisClassInfo;
else if (!c.isArray())
@@ -917,7 +938,8 @@ public final class ConstPool {
* (or the JVM-internal representation of that name).
* @return the index of the added entry.
*/
- public int addClassInfo(String qname) {
+ public int addClassInfo(String qname)
+ {
int utf8 = addUtf8Info(Descriptor.toJvmName(qname));
return addItem(new ClassInfo(utf8, numOfItems));
}
@@ -931,7 +953,8 @@ public final class ConstPool {
* @param type <code>descriptor_index</code>
* @return the index of the added entry.
*/
- public int addNameAndTypeInfo(String name, String type) {
+ public int addNameAndTypeInfo(String name, String type)
+ {
return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type));
}
@@ -942,7 +965,8 @@ public final class ConstPool {
* @param type <code>descriptor_index</code>
* @return the index of the added entry.
*/
- public int addNameAndTypeInfo(int name, int type) {
+ public int addNameAndTypeInfo(int name, int type)
+ {
return addItem(new NameAndTypeInfo(name, type, numOfItems));
}
@@ -959,7 +983,8 @@ public final class ConstPool {
* of <code>CONSTANT_NameAndType_info</code>.
* @return the index of the added entry.
*/
- public int addFieldrefInfo(int classInfo, String name, String type) {
+ public int addFieldrefInfo(int classInfo, String name, String type)
+ {
int nt = addNameAndTypeInfo(name, type);
return addFieldrefInfo(classInfo, nt);
}
@@ -971,8 +996,10 @@ public final class ConstPool {
* @param nameAndTypeInfo <code>name_and_type_index</code>.
* @return the index of the added entry.
*/
- public int addFieldrefInfo(int classInfo, int nameAndTypeInfo) {
- return addItem(new FieldrefInfo(classInfo, nameAndTypeInfo, numOfItems));
+ public int addFieldrefInfo(int classInfo, int nameAndTypeInfo)
+ {
+ return addItem(new FieldrefInfo(classInfo, nameAndTypeInfo,
+ numOfItems));
}
/**
@@ -988,7 +1015,8 @@ public final class ConstPool {
* of <code>CONSTANT_NameAndType_info</code>.
* @return the index of the added entry.
*/
- public int addMethodrefInfo(int classInfo, String name, String type) {
+ public int addMethodrefInfo(int classInfo, String name, String type)
+ {
int nt = addNameAndTypeInfo(name, type);
return addMethodrefInfo(classInfo, nt);
}
@@ -1000,8 +1028,10 @@ public final class ConstPool {
* @param nameAndTypeInfo <code>name_and_type_index</code>.
* @return the index of the added entry.
*/
- public int addMethodrefInfo(int classInfo, int nameAndTypeInfo) {
- return addItem(new MethodrefInfo(classInfo, nameAndTypeInfo, numOfItems));
+ public int addMethodrefInfo(int classInfo, int nameAndTypeInfo)
+ {
+ return addItem(new MethodrefInfo(classInfo,
+ nameAndTypeInfo, numOfItems));
}
/**
@@ -1018,8 +1048,10 @@ public final class ConstPool {
* of <code>CONSTANT_NameAndType_info</code>.
* @return the index of the added entry.
*/
- public int addInterfaceMethodrefInfo(int classInfo, String name,
- String type) {
+ public int addInterfaceMethodrefInfo(int classInfo,
+ String name,
+ String type)
+ {
int nt = addNameAndTypeInfo(name, type);
return addInterfaceMethodrefInfo(classInfo, nt);
}
@@ -1033,8 +1065,10 @@ public final class ConstPool {
* @return the index of the added entry.
*/
public int addInterfaceMethodrefInfo(int classInfo,
- int nameAndTypeInfo) {
- return addItem(new InterfaceMethodrefInfo(classInfo, nameAndTypeInfo,
+ int nameAndTypeInfo)
+ {
+ return addItem(new InterfaceMethodrefInfo(classInfo,
+ nameAndTypeInfo,
numOfItems));
}
@@ -1047,7 +1081,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addStringInfo(String str) {
+ public int addStringInfo(String str)
+ {
int utf = addUtf8Info(str);
return addItem(new StringInfo(utf, numOfItems));
}
@@ -1058,7 +1093,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addIntegerInfo(int i) {
+ public int addIntegerInfo(int i)
+ {
return addItem(new IntegerInfo(i, numOfItems));
}
@@ -1068,7 +1104,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addFloatInfo(float f) {
+ public int addFloatInfo(float f)
+ {
return addItem(new FloatInfo(f, numOfItems));
}
@@ -1078,7 +1115,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addLongInfo(long l) {
+ public int addLongInfo(long l)
+ {
int i = addItem(new LongInfo(l, numOfItems));
if (i == numOfItems - 1) // if not existing
addConstInfoPadding();
@@ -1092,7 +1130,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addDoubleInfo(double d) {
+ public int addDoubleInfo(double d)
+ {
int i = addItem(new DoubleInfo(d, numOfItems));
if (i == numOfItems - 1) // if not existing
addConstInfoPadding();
@@ -1106,7 +1145,8 @@ public final class ConstPool {
*
* @return the index of the added entry.
*/
- public int addUtf8Info(String utf8) {
+ public int addUtf8Info(String utf8)
+ {
return addItem(new Utf8Info(utf8, numOfItems));
}
@@ -1121,7 +1161,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int addMethodHandleInfo(int kind, int index) {
+ public int addMethodHandleInfo(int kind, int index)
+ {
return addItem(new MethodHandleInfo(kind, index, numOfItems));
}
@@ -1134,7 +1175,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int addMethodTypeInfo(int desc) {
+ public int addMethodTypeInfo(int desc)
+ {
return addItem(new MethodTypeInfo(desc, numOfItems));
}
@@ -1148,7 +1190,8 @@ public final class ConstPool {
*
* @since 3.17
*/
- public int addInvokeDynamicInfo(int bootstrap, int nameAndType) {
+ public int addInvokeDynamicInfo(int bootstrap, int nameAndType)
+ {
return addItem(new InvokeDynamicInfo(bootstrap, nameAndType, numOfItems));
}
@@ -1158,7 +1201,8 @@ public final class ConstPool {
* @return the index of the added entry.
* @since 3.22
*/
- public int addModuleInfo(int nameIndex) {
+ public int addModuleInfo(int nameIndex)
+ {
return addItem(new ModuleInfo(nameIndex, numOfItems));
}
@@ -1168,7 +1212,8 @@ public final class ConstPool {
* @return the index of the added entry.
* @since 3.22
*/
- public int addPackageInfo(int nameIndex) {
+ public int addPackageInfo(int nameIndex)
+ {
return addItem(new PackageInfo(nameIndex, numOfItems));
}
@@ -1177,8 +1222,9 @@ public final class ConstPool {
*
* @return a set of class names (<code>String</code> objects).
*/
- public Set getClassNames() {
- HashSet result = new HashSet();
+ public Set<String> getClassNames()
+ {
+ Set<String> result = new HashSet<String>();
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i) {
@@ -1195,7 +1241,8 @@ public final class ConstPool {
* @param oldName the replaced name (JVM-internal representation).
* @param newName the substituted name (JVM-internal representation).
*/
- public void renameClass(String oldName, String newName) {
+ public void renameClass(String oldName, String newName)
+ {
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i) {
@@ -1210,7 +1257,8 @@ public final class ConstPool {
* @param classnames specifies pairs of replaced and substituted
* name.
*/
- public void renameClass(Map classnames) {
+ public void renameClass(Map<String,String> classnames)
+ {
LongVector v = items;
int size = numOfItems;
for (int i = 1; i < size; ++i) {
@@ -1219,7 +1267,8 @@ public final class ConstPool {
}
}
- private void read(DataInputStream in) throws IOException {
+ private void read(DataInputStream in) throws IOException
+ {
int n = in.readUnsignedShort();
items = new LongVector(n);
@@ -1235,21 +1284,22 @@ public final class ConstPool {
}
}
- private static HashMap makeItemsCache(LongVector items) {
- HashMap cache = new HashMap();
+ private static Map<ConstInfo,ConstInfo> makeItemsCache(LongVector items)
+ {
+ Map<ConstInfo,ConstInfo> cache = new HashMap<ConstInfo,ConstInfo>();
int i = 1;
while (true) {
ConstInfo info = items.elementAt(i++);
if (info == null)
break;
- else
- cache.put(info, info);
+ cache.put(info, info);
}
return cache;
}
- private int readOne(DataInputStream in) throws IOException {
+ private int readOne(DataInputStream in) throws IOException
+ {
ConstInfo info;
int tag = in.readUnsignedByte();
switch (tag) {
@@ -1302,7 +1352,8 @@ public final class ConstPool {
info = new PackageInfo(in, numOfItems);
break;
default :
- throw new IOException("invalid constant type: " + tag + " at " + numOfItems);
+ throw new IOException("invalid constant type: "
+ + tag + " at " + numOfItems);
}
addItem0(info);
@@ -1312,7 +1363,8 @@ public final class ConstPool {
/**
* Writes the contents of the constant pool table.
*/
- public void write(DataOutputStream out) throws IOException {
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeShort(numOfItems);
LongVector v = items;
int size = numOfItems;
@@ -1323,14 +1375,16 @@ public final class ConstPool {
/**
* Prints the contents of the constant pool table.
*/
- public void print() {
+ public void print()
+ {
print(new PrintWriter(System.out, true));
}
/**
* Prints the contents of the constant pool table.
*/
- public void print(PrintWriter out) {
+ public void print(PrintWriter out)
+ {
int size = numOfItems;
for (int i = 1; i < size; ++i) {
out.print(i);
@@ -1340,7 +1394,8 @@ public final class ConstPool {
}
}
-abstract class ConstInfo {
+abstract class ConstInfo
+{
int index;
public ConstInfo(int i) { index = i; }
@@ -1348,14 +1403,18 @@ abstract class ConstInfo {
public abstract int getTag();
public String getClassName(ConstPool cp) { return null; }
- public void renameClass(ConstPool cp, String oldName, String newName, HashMap cache) {}
- public void renameClass(ConstPool cp, Map classnames, HashMap cache) {}
- public abstract int copy(ConstPool src, ConstPool dest, Map classnames);
- // ** classnames is a mapping between JVM names.
+ public void renameClass(ConstPool cp, String oldName, String newName,
+ Map<ConstInfo,ConstInfo> cache) {}
+ public void renameClass(ConstPool cp, Map<String,String> classnames,
+ Map<ConstInfo,ConstInfo> cache) {}
+ public abstract int copy(ConstPool src, ConstPool dest,
+ Map<String, String> classnames);
+ // ** classnames is a mapping between JVM names.
public abstract void write(DataOutputStream out) throws IOException;
public abstract void print(PrintWriter out);
+ @Override
public String toString() {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(bout);
@@ -1366,49 +1425,68 @@ abstract class ConstInfo {
/* padding following DoubleInfo or LongInfo.
*/
-class ConstInfoPadding extends ConstInfo {
+class ConstInfoPadding extends ConstInfo
+{
public ConstInfoPadding(int i) { super(i); }
+ @Override
public int getTag() { return 0; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
return dest.addConstInfoPadding();
}
+ @Override
public void write(DataOutputStream out) throws IOException {}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.println("padding");
}
}
-class ClassInfo extends ConstInfo {
+class ClassInfo extends ConstInfo
+{
static final int tag = 7;
int name;
- public ClassInfo(int className, int index) {
+ public ClassInfo(int className, int index)
+ {
super(index);
name = className;
}
- public ClassInfo(DataInputStream in, int index) throws IOException {
+ public ClassInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
name = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return name; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
return obj instanceof ClassInfo && ((ClassInfo)obj).name == name;
}
+ @Override
public int getTag() { return tag; }
- public String getClassName(ConstPool cp) {
+ @Override
+ public String getClassName(ConstPool cp)
+ {
return cp.getUtf8Info(name);
}
- public void renameClass(ConstPool cp, String oldName, String newName, HashMap cache) {
+ @Override
+ public void renameClass(ConstPool cp, String oldName, String newName,
+ Map<ConstInfo,ConstInfo> cache)
+ {
String nameStr = cp.getUtf8Info(name);
String newNameStr = null;
if (nameStr.equals(oldName))
@@ -1429,7 +1507,10 @@ class ClassInfo extends ConstInfo {
}
}
- public void renameClass(ConstPool cp, Map map, HashMap cache) {
+ @Override
+ public void renameClass(ConstPool cp, Map<String,String> map,
+ Map<ConstInfo,ConstInfo> cache)
+ {
String oldName = cp.getUtf8Info(name);
String newName = null;
if (oldName.charAt(0) == '[') {
@@ -1438,7 +1519,7 @@ class ClassInfo extends ConstInfo {
newName = s;
}
else {
- String s = (String)map.get(oldName);
+ String s = map.get(oldName);
if (s != null && !s.equals(oldName))
newName = s;
}
@@ -1454,10 +1535,12 @@ class ClassInfo extends ConstInfo {
}
}
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
String classname = src.getUtf8Info(name);
if (map != null) {
- String newname = (String)map.get(classname);
+ String newname = map.get(classname);
if (newname != null)
classname = newname;
}
@@ -1465,48 +1548,62 @@ class ClassInfo extends ConstInfo {
return dest.addClassInfo(classname);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeShort(name);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("Class #");
out.println(name);
}
}
-class NameAndTypeInfo extends ConstInfo {
+class NameAndTypeInfo extends ConstInfo
+{
static final int tag = 12;
int memberName;
int typeDescriptor;
- public NameAndTypeInfo(int name, int type, int index) {
+ public NameAndTypeInfo(int name, int type, int index)
+ {
super(index);
memberName = name;
typeDescriptor = type;
}
- public NameAndTypeInfo(DataInputStream in, int index) throws IOException {
+ public NameAndTypeInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
memberName = in.readUnsignedShort();
typeDescriptor = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return (memberName << 16) ^ typeDescriptor; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
if (obj instanceof NameAndTypeInfo) {
NameAndTypeInfo nti = (NameAndTypeInfo)obj;
- return nti.memberName == memberName && nti.typeDescriptor == typeDescriptor;
+ return nti.memberName == memberName
+ && nti.typeDescriptor == typeDescriptor;
}
- else
- return false;
+ return false;
}
+ @Override
public int getTag() { return tag; }
- public void renameClass(ConstPool cp, String oldName, String newName, HashMap cache) {
+ @Override
+ public void renameClass(ConstPool cp, String oldName, String newName,
+ Map<ConstInfo,ConstInfo> cache)
+ {
String type = cp.getUtf8Info(typeDescriptor);
String type2 = Descriptor.rename(type, oldName, newName);
if (type != type2)
@@ -1519,7 +1616,10 @@ class NameAndTypeInfo extends ConstInfo {
}
}
- public void renameClass(ConstPool cp, Map map, HashMap cache) {
+ @Override
+ public void renameClass(ConstPool cp, Map<String,String> map,
+ Map<ConstInfo,ConstInfo> cache)
+ {
String type = cp.getUtf8Info(typeDescriptor);
String type2 = Descriptor.rename(type, map);
if (type != type2)
@@ -1532,7 +1632,9 @@ class NameAndTypeInfo extends ConstInfo {
}
}
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
String mname = src.getUtf8Info(memberName);
String tdesc = src.getUtf8Info(typeDescriptor);
tdesc = Descriptor.rename(tdesc, map);
@@ -1540,12 +1642,14 @@ class NameAndTypeInfo extends ConstInfo {
dest.addUtf8Info(tdesc));
}
+ @Override
public void write(DataOutputStream out) throws IOException {
out.writeByte(tag);
out.writeShort(memberName);
out.writeShort(typeDescriptor);
}
+ @Override
public void print(PrintWriter out) {
out.print("NameAndType #");
out.print(memberName);
@@ -1554,35 +1658,43 @@ class NameAndTypeInfo extends ConstInfo {
}
}
-abstract class MemberrefInfo extends ConstInfo {
+abstract class MemberrefInfo extends ConstInfo
+{
int classIndex;
int nameAndTypeIndex;
- public MemberrefInfo(int cindex, int ntindex, int thisIndex) {
+ public MemberrefInfo(int cindex, int ntindex, int thisIndex)
+ {
super(thisIndex);
classIndex = cindex;
nameAndTypeIndex = ntindex;
}
- public MemberrefInfo(DataInputStream in, int thisIndex) throws IOException {
+ public MemberrefInfo(DataInputStream in, int thisIndex)
+ throws IOException
+ {
super(thisIndex);
classIndex = in.readUnsignedShort();
nameAndTypeIndex = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return (classIndex << 16) ^ nameAndTypeIndex; }
+ @Override
public boolean equals(Object obj) {
if (obj instanceof MemberrefInfo) {
MemberrefInfo mri = (MemberrefInfo)obj;
- return mri.classIndex == classIndex && mri.nameAndTypeIndex == nameAndTypeIndex
- && mri.getClass() == this.getClass();
+ return mri.classIndex == classIndex
+ && mri.nameAndTypeIndex == nameAndTypeIndex
+ && mri.getClass() == this.getClass();
}
- else
- return false;
+ return false;
}
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
int classIndex2 = src.getItem(classIndex).copy(src, dest, map);
int ntIndex2 = src.getItem(nameAndTypeIndex).copy(src, dest, map);
return copy2(dest, classIndex2, ntIndex2);
@@ -1590,13 +1702,17 @@ abstract class MemberrefInfo extends ConstInfo {
abstract protected int copy2(ConstPool dest, int cindex, int ntindex);
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(getTag());
out.writeShort(classIndex);
out.writeShort(nameAndTypeIndex);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print(getTagName() + " #");
out.print(classIndex);
out.print(", name&type #");
@@ -1606,287 +1722,391 @@ abstract class MemberrefInfo extends ConstInfo {
public abstract String getTagName();
}
-class FieldrefInfo extends MemberrefInfo {
+class FieldrefInfo extends MemberrefInfo
+{
static final int tag = 9;
- public FieldrefInfo(int cindex, int ntindex, int thisIndex) {
+ public FieldrefInfo(int cindex, int ntindex, int thisIndex)
+ {
super(cindex, ntindex, thisIndex);
}
- public FieldrefInfo(DataInputStream in, int thisIndex) throws IOException {
+ public FieldrefInfo(DataInputStream in, int thisIndex)
+ throws IOException
+ {
super(in, thisIndex);
}
+ @Override
public int getTag() { return tag; }
+ @Override
public String getTagName() { return "Field"; }
- protected int copy2(ConstPool dest, int cindex, int ntindex) {
+ @Override
+ protected int copy2(ConstPool dest, int cindex, int ntindex)
+ {
return dest.addFieldrefInfo(cindex, ntindex);
}
}
-class MethodrefInfo extends MemberrefInfo {
+class MethodrefInfo extends MemberrefInfo
+{
static final int tag = 10;
- public MethodrefInfo(int cindex, int ntindex, int thisIndex) {
+ public MethodrefInfo(int cindex, int ntindex, int thisIndex)
+ {
super(cindex, ntindex, thisIndex);
}
- public MethodrefInfo(DataInputStream in, int thisIndex) throws IOException {
+ public MethodrefInfo(DataInputStream in, int thisIndex)
+ throws IOException
+ {
super(in, thisIndex);
}
+ @Override
public int getTag() { return tag; }
+ @Override
public String getTagName() { return "Method"; }
- protected int copy2(ConstPool dest, int cindex, int ntindex) {
+ @Override
+ protected int copy2(ConstPool dest, int cindex, int ntindex)
+ {
return dest.addMethodrefInfo(cindex, ntindex);
}
}
-class InterfaceMethodrefInfo extends MemberrefInfo {
+class InterfaceMethodrefInfo extends MemberrefInfo
+{
static final int tag = 11;
- public InterfaceMethodrefInfo(int cindex, int ntindex, int thisIndex) {
+ public InterfaceMethodrefInfo(int cindex, int ntindex, int thisIndex)
+ {
super(cindex, ntindex, thisIndex);
}
- public InterfaceMethodrefInfo(DataInputStream in, int thisIndex) throws IOException {
+ public InterfaceMethodrefInfo(DataInputStream in, int thisIndex)
+ throws IOException
+ {
super(in, thisIndex);
}
+ @Override
public int getTag() { return tag; }
+ @Override
public String getTagName() { return "Interface"; }
- protected int copy2(ConstPool dest, int cindex, int ntindex) {
+ @Override
+ protected int copy2(ConstPool dest, int cindex, int ntindex)
+ {
return dest.addInterfaceMethodrefInfo(cindex, ntindex);
}
}
-class StringInfo extends ConstInfo {
+class StringInfo extends ConstInfo
+{
static final int tag = 8;
int string;
- public StringInfo(int str, int index) {
+ public StringInfo(int str, int index)
+ {
super(index);
string = str;
}
- public StringInfo(DataInputStream in, int index) throws IOException {
+ public StringInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
string = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return string; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
return obj instanceof StringInfo && ((StringInfo)obj).string == string;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
return dest.addStringInfo(src.getUtf8Info(string));
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeShort(string);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("String #");
out.println(string);
}
}
-class IntegerInfo extends ConstInfo {
+class IntegerInfo extends ConstInfo
+{
static final int tag = 3;
int value;
- public IntegerInfo(int v, int index) {
+ public IntegerInfo(int v, int index)
+ {
super(index);
value = v;
}
- public IntegerInfo(DataInputStream in, int index) throws IOException {
+ public IntegerInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
value = in.readInt();
}
+ @Override
public int hashCode() { return value; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
return obj instanceof IntegerInfo && ((IntegerInfo)obj).value == value;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
return dest.addIntegerInfo(value);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeInt(value);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("Integer ");
out.println(value);
}
}
-class FloatInfo extends ConstInfo {
+class FloatInfo extends ConstInfo
+{
static final int tag = 4;
float value;
- public FloatInfo(float f, int index) {
+ public FloatInfo(float f, int index)
+ {
super(index);
value = f;
}
- public FloatInfo(DataInputStream in, int index) throws IOException {
+ public FloatInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
value = in.readFloat();
}
+ @Override
public int hashCode() { return Float.floatToIntBits(value); }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
return obj instanceof FloatInfo && ((FloatInfo)obj).value == value;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
return dest.addFloatInfo(value);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeFloat(value);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("Float ");
out.println(value);
}
}
-class LongInfo extends ConstInfo {
+class LongInfo extends ConstInfo
+{
static final int tag = 5;
long value;
- public LongInfo(long l, int index) {
+ public LongInfo(long l, int index)
+ {
super(index);
value = l;
}
- public LongInfo(DataInputStream in, int index) throws IOException {
+ public LongInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
value = in.readLong();
}
+ @Override
public int hashCode() { return (int)(value ^ (value >>> 32)); }
+ @Override
public boolean equals(Object obj) {
return obj instanceof LongInfo && ((LongInfo)obj).value == value;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
return dest.addLongInfo(value);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeLong(value);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("Long ");
out.println(value);
}
}
-class DoubleInfo extends ConstInfo {
+class DoubleInfo extends ConstInfo
+{
static final int tag = 6;
double value;
- public DoubleInfo(double d, int index) {
+ public DoubleInfo(double d, int index)
+ {
super(index);
value = d;
}
- public DoubleInfo(DataInputStream in, int index) throws IOException {
+ public DoubleInfo(DataInputStream in, int index) throws IOException
+ {
super(index);
value = in.readDouble();
}
+ @Override
public int hashCode() {
long v = Double.doubleToLongBits(value);
return (int)(v ^ (v >>> 32));
}
- public boolean equals(Object obj) {
- return obj instanceof DoubleInfo && ((DoubleInfo)obj).value == value;
+ @Override
+ public boolean equals(Object obj)
+ {
+ return obj instanceof DoubleInfo
+ && ((DoubleInfo)obj).value == value;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
return dest.addDoubleInfo(value);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeDouble(value);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("Double ");
out.println(value);
}
}
-class Utf8Info extends ConstInfo {
+class Utf8Info extends ConstInfo
+{
static final int tag = 1;
String string;
- public Utf8Info(String utf8, int index) {
+ public Utf8Info(String utf8, int index)
+ {
super(index);
string = utf8;
}
- public Utf8Info(DataInputStream in, int index) throws IOException {
+ public Utf8Info(DataInputStream in, int index)
+ throws IOException
+ {
super(index);
string = in.readUTF();
}
+ @Override
public int hashCode() {
return string.hashCode();
}
+ @Override
public boolean equals(Object obj) {
- return obj instanceof Utf8Info && ((Utf8Info)obj).string.equals(string);
+ return obj instanceof Utf8Info
+ && ((Utf8Info)obj).string.equals(string);
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest,
+ Map<String,String> map)
+ {
return dest.addUtf8Info(string);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out)
+ throws IOException
+ {
out.writeByte(tag);
out.writeUTF(string);
}
+ @Override
public void print(PrintWriter out) {
out.print("UTF8 \"");
out.print(string);
@@ -1904,36 +2124,47 @@ class MethodHandleInfo extends ConstInfo {
refIndex = referenceIndex;
}
- public MethodHandleInfo(DataInputStream in, int index) throws IOException {
+ public MethodHandleInfo(DataInputStream in, int index)
+ throws IOException
+ {
super(index);
refKind = in.readUnsignedByte();
refIndex = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return (refKind << 16) ^ refIndex; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
if (obj instanceof MethodHandleInfo) {
MethodHandleInfo mh = (MethodHandleInfo)obj;
- return mh.refKind == refKind && mh.refIndex == refIndex;
+ return mh.refKind == refKind && mh.refIndex == refIndex;
}
- else
- return false;
+ return false;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest,
+ Map<String,String> map)
+ {
return dest.addMethodHandleInfo(refKind,
- src.getItem(refIndex).copy(src, dest, map));
+ src.getItem(refIndex).copy(src, dest, map));
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeByte(refKind);
out.writeShort(refIndex);
}
+ @Override
public void print(PrintWriter out) {
out.print("MethodHandle #");
out.print(refKind);
@@ -1942,32 +2173,42 @@ class MethodHandleInfo extends ConstInfo {
}
}
-class MethodTypeInfo extends ConstInfo {
+class MethodTypeInfo extends ConstInfo
+{
static final int tag = 16;
int descriptor;
- public MethodTypeInfo(int desc, int index) {
+ public MethodTypeInfo(int desc, int index)
+ {
super(index);
descriptor = desc;
}
- public MethodTypeInfo(DataInputStream in, int index) throws IOException {
+ public MethodTypeInfo(DataInputStream in, int index)
+ throws IOException
+ {
super(index);
descriptor = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return descriptor; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
if (obj instanceof MethodTypeInfo)
return ((MethodTypeInfo)obj).descriptor == descriptor;
- else
- return false;
+ return false;
}
+ @Override
public int getTag() { return tag; }
- public void renameClass(ConstPool cp, String oldName, String newName, HashMap cache) {
+ @Override
+ public void renameClass(ConstPool cp, String oldName, String newName,
+ Map<ConstInfo,ConstInfo> cache)
+ {
String desc = cp.getUtf8Info(descriptor);
String desc2 = Descriptor.rename(desc, oldName, newName);
if (desc != desc2)
@@ -1980,7 +2221,10 @@ class MethodTypeInfo extends ConstInfo {
}
}
- public void renameClass(ConstPool cp, Map map, HashMap cache) {
+ @Override
+ public void renameClass(ConstPool cp, Map<String,String> map,
+ Map<ConstInfo,ConstInfo> cache)
+ {
String desc = cp.getUtf8Info(descriptor);
String desc2 = Descriptor.rename(desc, map);
if (desc != desc2)
@@ -1993,63 +2237,83 @@ class MethodTypeInfo extends ConstInfo {
}
}
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest, Map<String,String> map)
+ {
String desc = src.getUtf8Info(descriptor);
desc = Descriptor.rename(desc, map);
return dest.addMethodTypeInfo(dest.addUtf8Info(desc));
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeShort(descriptor);
}
+ @Override
public void print(PrintWriter out) {
out.print("MethodType #");
out.println(descriptor);
}
}
-class InvokeDynamicInfo extends ConstInfo {
+class InvokeDynamicInfo extends ConstInfo
+{
static final int tag = 18;
int bootstrap, nameAndType;
- public InvokeDynamicInfo(int bootstrapMethod, int ntIndex, int index) {
+ public InvokeDynamicInfo(int bootstrapMethod,
+ int ntIndex, int index)
+ {
super(index);
bootstrap = bootstrapMethod;
nameAndType = ntIndex;
}
- public InvokeDynamicInfo(DataInputStream in, int index) throws IOException {
+ public InvokeDynamicInfo(DataInputStream in, int index)
+ throws IOException
+ {
super(index);
bootstrap = in.readUnsignedShort();
nameAndType = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return (bootstrap << 16) ^ nameAndType; }
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj)
+ {
if (obj instanceof InvokeDynamicInfo) {
InvokeDynamicInfo iv = (InvokeDynamicInfo)obj;
- return iv.bootstrap == bootstrap && iv.nameAndType == nameAndType;
+ return iv.bootstrap == bootstrap
+ && iv.nameAndType == nameAndType;
}
- else
- return false;
+ return false;
}
+ @Override
public int getTag() { return tag; }
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest,
+ Map<String,String> map)
+ {
return dest.addInvokeDynamicInfo(bootstrap,
- src.getItem(nameAndType).copy(src, dest, map));
+ src.getItem(nameAndType).copy(src, dest, map));
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeShort(bootstrap);
out.writeShort(nameAndType);
}
+ @Override
public void print(PrintWriter out) {
out.print("InvokeDynamic #");
out.print(bootstrap);
@@ -2058,87 +2322,119 @@ class InvokeDynamicInfo extends ConstInfo {
}
}
-class ModuleInfo extends ConstInfo {
+class ModuleInfo extends ConstInfo
+{
static final int tag = 19;
int name;
- public ModuleInfo(int moduleName, int index) {
+ public ModuleInfo(int moduleName, int index)
+ {
super(index);
name = moduleName;
}
- public ModuleInfo(DataInputStream in, int index) throws IOException {
+ public ModuleInfo(DataInputStream in, int index)
+ throws IOException
+ {
super(index);
name = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return name; }
- public boolean equals(Object obj) {
- return obj instanceof ModuleInfo && ((ModuleInfo)obj).name == name;
+ @Override
+ public boolean equals(Object obj)
+ {
+ return obj instanceof ModuleInfo
+ && ((ModuleInfo)obj).name == name;
}
+ @Override
public int getTag() { return tag; }
- public String getModuleName(ConstPool cp) {
+ public String getModuleName(ConstPool cp)
+ {
return cp.getUtf8Info(name);
}
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest,
+ Map<String,String> map)
+ {
String moduleName = src.getUtf8Info(name);
int newName = dest.addUtf8Info(moduleName);
return dest.addModuleInfo(newName);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeShort(name);
}
+ @Override
public void print(PrintWriter out) {
out.print("Module #");
out.println(name);
}
}
-class PackageInfo extends ConstInfo {
+class PackageInfo extends ConstInfo
+{
static final int tag = 20;
int name;
- public PackageInfo(int moduleName, int index) {
+ public PackageInfo(int moduleName, int index)
+ {
super(index);
name = moduleName;
}
- public PackageInfo(DataInputStream in, int index) throws IOException {
+ public PackageInfo(DataInputStream in, int index)
+ throws IOException
+ {
super(index);
name = in.readUnsignedShort();
}
+ @Override
public int hashCode() { return name; }
+ @Override
public boolean equals(Object obj) {
- return obj instanceof PackageInfo && ((PackageInfo)obj).name == name;
+ return obj instanceof PackageInfo
+ && ((PackageInfo)obj).name == name;
}
+ @Override
public int getTag() { return tag; }
- public String getPackageName(ConstPool cp) {
+ public String getPackageName(ConstPool cp)
+ {
return cp.getUtf8Info(name);
}
- public int copy(ConstPool src, ConstPool dest, Map map) {
+ @Override
+ public int copy(ConstPool src, ConstPool dest,
+ Map<String,String> map)
+ {
String packageName = src.getUtf8Info(name);
int newName = dest.addUtf8Info(packageName);
return dest.addModuleInfo(newName);
}
- public void write(DataOutputStream out) throws IOException {
+ @Override
+ public void write(DataOutputStream out) throws IOException
+ {
out.writeByte(tag);
out.writeShort(name);
}
- public void print(PrintWriter out) {
+ @Override
+ public void print(PrintWriter out)
+ {
out.print("Package #");
out.println(name);
}
diff --git a/src/main/javassist/bytecode/ConstantAttribute.java b/src/main/javassist/bytecode/ConstantAttribute.java
index 0fb4cd4d..40c395c7 100644
--- a/src/main/javassist/bytecode/ConstantAttribute.java
+++ b/src/main/javassist/bytecode/ConstantAttribute.java
@@ -17,8 +17,8 @@
package javassist.bytecode;
import java.io.DataInputStream;
-import java.util.Map;
import java.io.IOException;
+import java.util.Map;
/**
* <code>ConstantValue_attribute</code>.
@@ -65,7 +65,8 @@ public class ConstantAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
int index = getConstPool().copy(getConstantValue(), newCp,
classnames);
return new ConstantAttribute(newCp, index);
diff --git a/src/main/javassist/bytecode/DeprecatedAttribute.java b/src/main/javassist/bytecode/DeprecatedAttribute.java
index f55acebd..eaf39ef6 100644
--- a/src/main/javassist/bytecode/DeprecatedAttribute.java
+++ b/src/main/javassist/bytecode/DeprecatedAttribute.java
@@ -50,7 +50,8 @@ public class DeprecatedAttribute extends AttributeInfo {
* @param newCp the constant pool table used by the new copy.
* @param classnames should be null.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
return new DeprecatedAttribute(newCp);
}
}
diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java
index 48cd5b8a..fc49b876 100644
--- a/src/main/javassist/bytecode/Descriptor.java
+++ b/src/main/javassist/bytecode/Descriptor.java
@@ -16,11 +16,12 @@
package javassist.bytecode;
+import java.util.Map;
+
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtPrimitiveType;
import javassist.NotFoundException;
-import java.util.Map;
/**
* A support class for dealing with descriptors.
@@ -59,8 +60,7 @@ public class Descriptor {
public static String toJvmName(CtClass clazz) {
if (clazz.isArray())
return of(clazz);
- else
- return toJvmName(clazz.getName());
+ return toJvmName(clazz.getName());
}
/**
@@ -109,14 +109,12 @@ public class Descriptor {
if (arrayDim == 0)
return name;
- else {
- StringBuffer sbuf = new StringBuffer(name);
- do {
- sbuf.append("[]");
- } while (--arrayDim > 0);
+ StringBuffer sbuf = new StringBuffer(name);
+ do {
+ sbuf.append("[]");
+ } while (--arrayDim > 0);
- return sbuf.toString();
- }
+ return sbuf.toString();
}
/**
@@ -183,13 +181,11 @@ public class Descriptor {
if (head == 0)
return desc;
- else {
- int len = desc.length();
- if (head < len)
- newdesc.append(desc.substring(head, len));
+ int len = desc.length();
+ if (head < len)
+ newdesc.append(desc.substring(head, len));
- return newdesc.toString();
- }
+ return newdesc.toString();
}
/**
@@ -200,7 +196,7 @@ public class Descriptor {
* JVM class names.
* @see Descriptor#toJvmName(String)
*/
- public static String rename(String desc, Map map) {
+ public static String rename(String desc, Map<String,String> map) {
if (map == null)
return desc;
@@ -218,7 +214,7 @@ public class Descriptor {
i = k + 1;
String name = desc.substring(j + 1, k);
- String name2 = (String)map.get(name);
+ String name2 = map.get(name);
if (name2 != null) {
newdesc.append(desc.substring(head, j));
newdesc.append('L');
@@ -230,13 +226,11 @@ public class Descriptor {
if (head == 0)
return desc;
- else {
- int len = desc.length();
- if (head < len)
- newdesc.append(desc.substring(head, len));
+ int len = desc.length();
+ if (head < len)
+ newdesc.append(desc.substring(head, len));
- return newdesc.toString();
- }
+ return newdesc.toString();
}
/**
@@ -329,15 +323,13 @@ public class Descriptor {
int i = desc.indexOf(')');
if (i < 0)
return desc;
- else {
- StringBuffer newdesc = new StringBuffer();
- newdesc.append(desc.substring(0, i));
- newdesc.append('L');
- newdesc.append(classname.replace('.', '/'));
- newdesc.append(';');
- newdesc.append(desc.substring(i));
- return newdesc.toString();
- }
+ StringBuffer newdesc = new StringBuffer();
+ newdesc.append(desc.substring(0, i));
+ newdesc.append('L');
+ newdesc.append(classname.replace('.', '/'));
+ newdesc.append(';');
+ newdesc.append(desc.substring(i));
+ return newdesc.toString();
}
/**
@@ -353,9 +345,8 @@ public class Descriptor {
public static String insertParameter(String classname, String desc) {
if (desc.charAt(0) != '(')
return desc;
- else
- return "(L" + classname.replace('.', '/') + ';'
- + desc.substring(1);
+ return "(L" + classname.replace('.', '/') + ';'
+ + desc.substring(1);
}
/**
@@ -370,13 +361,11 @@ public class Descriptor {
int i = descriptor.indexOf(')');
if (i < 0)
return descriptor;
- else {
- StringBuffer newdesc = new StringBuffer();
- newdesc.append(descriptor.substring(0, i));
- toDescriptor(newdesc, type);
- newdesc.append(descriptor.substring(i));
- return newdesc.toString();
- }
+ StringBuffer newdesc = new StringBuffer();
+ newdesc.append(descriptor.substring(0, i));
+ toDescriptor(newdesc, type);
+ newdesc.append(descriptor.substring(i));
+ return newdesc.toString();
}
/**
@@ -391,8 +380,7 @@ public class Descriptor {
String descriptor) {
if (descriptor.charAt(0) != '(')
return descriptor;
- else
- return "(" + of(type) + descriptor.substring(1);
+ return "(" + of(type) + descriptor.substring(1);
}
/**
@@ -407,14 +395,12 @@ public class Descriptor {
int i = desc.indexOf(')');
if (i < 0)
return desc;
- else {
- StringBuffer newdesc = new StringBuffer();
- newdesc.append(desc.substring(0, i + 1));
- newdesc.append('L');
- newdesc.append(classname.replace('.', '/'));
- newdesc.append(';');
- return newdesc.toString();
- }
+ StringBuffer newdesc = new StringBuffer();
+ newdesc.append(desc.substring(0, i + 1));
+ newdesc.append('L');
+ newdesc.append(classname.replace('.', '/'));
+ newdesc.append(';');
+ return newdesc.toString();
}
/**
@@ -430,16 +416,14 @@ public class Descriptor {
{
if (desc.charAt(0) != '(')
return null;
- else {
- int num = numOfParameters(desc);
- CtClass[] args = new CtClass[num];
- int n = 0;
- int i = 1;
- do {
- i = toCtClass(cp, desc, i, args, n++);
- } while (i > 0);
- return args;
- }
+ int num = numOfParameters(desc);
+ CtClass[] args = new CtClass[num];
+ int n = 0;
+ int i = 1;
+ do {
+ i = toCtClass(cp, desc, i, args, n++);
+ } while (i > 0);
+ return args;
}
/**
@@ -484,11 +468,9 @@ public class Descriptor {
int i = desc.indexOf(')');
if (i < 0)
return null;
- else {
- CtClass[] type = new CtClass[1];
- toCtClass(cp, desc, i + 1, type, 0);
- return type[0];
- }
+ CtClass[] type = new CtClass[1];
+ toCtClass(cp, desc, i + 1, type, 0);
+ return type[0];
}
/**
@@ -542,11 +524,9 @@ public class Descriptor {
int res = toCtClass(cp, desc, 0, clazz, 0);
if (res >= 0)
return clazz[0];
- else {
- // maybe, you forgot to surround the class name with
- // L and ;. It violates the protocol, but I'm tolerant...
- return cp.get(desc.replace('/', '.'));
- }
+ // maybe, you forgot to surround the class name with
+ // L and ;. It violates the protocol, but I'm tolerant...
+ return cp.get(desc.replace('/', '.'));
}
private static int toCtClass(ClassPool cp, String desc, int i,
@@ -577,8 +557,7 @@ public class Descriptor {
args[n] = type;
return i2; // neither an array type or a class type
}
- else
- name = type.getName();
+ name = type.getName();
}
if (arrayDim > 0) {
diff --git a/src/main/javassist/bytecode/DuplicateMemberException.java b/src/main/javassist/bytecode/DuplicateMemberException.java
index 3d763271..5a2edf57 100644
--- a/src/main/javassist/bytecode/DuplicateMemberException.java
+++ b/src/main/javassist/bytecode/DuplicateMemberException.java
@@ -25,6 +25,9 @@ import javassist.CannotCompileException;
* @see ClassFile#addField(FieldInfo)
*/
public class DuplicateMemberException extends CannotCompileException {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public DuplicateMemberException(String msg) {
super(msg);
}
diff --git a/src/main/javassist/bytecode/EnclosingMethodAttribute.java b/src/main/javassist/bytecode/EnclosingMethodAttribute.java
index 4f422fd7..9eee2a0e 100644
--- a/src/main/javassist/bytecode/EnclosingMethodAttribute.java
+++ b/src/main/javassist/bytecode/EnclosingMethodAttribute.java
@@ -20,8 +20,6 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.util.Map;
-import javassist.CtConstructor;
-
/**
* <code>EnclosingMethod_attribute</code>.
*/
@@ -108,10 +106,8 @@ public class EnclosingMethodAttribute extends AttributeInfo {
int mi = methodIndex();
if (mi == 0)
return MethodInfo.nameClinit;
- else {
- int ni = cp.getNameAndTypeName(mi);
- return cp.getUtf8Info(ni);
- }
+ int ni = cp.getNameAndTypeName(mi);
+ return cp.getUtf8Info(ni);
}
/**
@@ -132,11 +128,11 @@ public class EnclosingMethodAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
- if (methodIndex() == 0)
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
+ if (methodIndex() == 0)
return new EnclosingMethodAttribute(newCp, className());
- else
- return new EnclosingMethodAttribute(newCp, className(),
- methodName(), methodDescriptor());
+ return new EnclosingMethodAttribute(newCp, className(),
+ methodName(), methodDescriptor());
}
}
diff --git a/src/main/javassist/bytecode/ExceptionTable.java b/src/main/javassist/bytecode/ExceptionTable.java
index fb6b8217..d4e5e255 100644
--- a/src/main/javassist/bytecode/ExceptionTable.java
+++ b/src/main/javassist/bytecode/ExceptionTable.java
@@ -20,6 +20,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
class ExceptionTableEntry {
@@ -41,7 +42,7 @@ class ExceptionTableEntry {
*/
public class ExceptionTable implements Cloneable {
private ConstPool constPool;
- private ArrayList entries;
+ private List<ExceptionTableEntry> entries;
/**
* Constructs an <code>exception_table[]</code>.
@@ -50,13 +51,13 @@ public class ExceptionTable implements Cloneable {
*/
public ExceptionTable(ConstPool cp) {
constPool = cp;
- entries = new ArrayList();
+ entries = new ArrayList<ExceptionTableEntry>();
}
ExceptionTable(ConstPool cp, DataInputStream in) throws IOException {
constPool = cp;
int length = in.readUnsignedShort();
- ArrayList list = new ArrayList(length);
+ List<ExceptionTableEntry> list = new ArrayList<ExceptionTableEntry>(length);
for (int i = 0; i < length; ++i) {
int start = in.readUnsignedShort();
int end = in.readUnsignedShort();
@@ -73,9 +74,10 @@ public class ExceptionTable implements Cloneable {
* The constant pool object is shared between this object
* and the cloned object.
*/
+ @Override
public Object clone() throws CloneNotSupportedException {
ExceptionTable r = (ExceptionTable)super.clone();
- r.entries = new ArrayList(entries);
+ r.entries = new ArrayList<ExceptionTableEntry>(entries);
return r;
}
@@ -93,8 +95,7 @@ public class ExceptionTable implements Cloneable {
* @param nth the <i>n</i>-th (&gt;= 0).
*/
public int startPc(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.startPc;
+ return entries.get(nth).startPc;
}
/**
@@ -104,8 +105,7 @@ public class ExceptionTable implements Cloneable {
* @param value new value.
*/
public void setStartPc(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.startPc = value;
+ entries.get(nth).startPc = value;
}
/**
@@ -114,8 +114,7 @@ public class ExceptionTable implements Cloneable {
* @param nth the <i>n</i>-th (&gt;= 0).
*/
public int endPc(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.endPc;
+ return entries.get(nth).endPc;
}
/**
@@ -125,8 +124,7 @@ public class ExceptionTable implements Cloneable {
* @param value new value.
*/
public void setEndPc(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.endPc = value;
+ entries.get(nth).endPc = value;
}
/**
@@ -135,8 +133,7 @@ public class ExceptionTable implements Cloneable {
* @param nth the <i>n</i>-th (&gt;= 0).
*/
public int handlerPc(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.handlerPc;
+ return entries.get(nth).handlerPc;
}
/**
@@ -146,8 +143,7 @@ public class ExceptionTable implements Cloneable {
* @param value new value.
*/
public void setHandlerPc(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.handlerPc = value;
+ entries.get(nth).handlerPc = value;
}
/**
@@ -158,8 +154,7 @@ public class ExceptionTable implements Cloneable {
* or zero if this exception handler is for all exceptions.
*/
public int catchType(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.catchType;
+ return entries.get(nth).catchType;
}
/**
@@ -169,8 +164,7 @@ public class ExceptionTable implements Cloneable {
* @param value new value.
*/
public void setCatchType(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.catchType = value;
+ entries.get(nth).catchType = value;
}
/**
@@ -183,8 +177,7 @@ public class ExceptionTable implements Cloneable {
public void add(int index, ExceptionTable table, int offset) {
int len = table.size();
while (--len >= 0) {
- ExceptionTableEntry e
- = (ExceptionTableEntry)table.entries.get(len);
+ ExceptionTableEntry e = table.entries.get(len);
add(index, e.startPc + offset, e.endPc + offset,
e.handlerPc + offset, e.catchType);
}
@@ -236,12 +229,10 @@ public class ExceptionTable implements Cloneable {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public ExceptionTable copy(ConstPool newCp, Map classnames) {
+ public ExceptionTable copy(ConstPool newCp, Map<String,String> classnames) {
ExceptionTable et = new ExceptionTable(newCp);
ConstPool srcCp = constPool;
- int len = size();
- for (int i = 0; i < len; ++i) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
+ for (ExceptionTableEntry e:entries) {
int type = srcCp.copy(e.catchType, newCp, classnames);
et.add(e.startPc, e.endPc, e.handlerPc, type);
}
@@ -250,9 +241,7 @@ public class ExceptionTable implements Cloneable {
}
void shiftPc(int where, int gapLength, boolean exclusive) {
- int len = size();
- for (int i = 0; i < len; ++i) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
+ for (ExceptionTableEntry e:entries) {
e.startPc = shiftPc(e.startPc, where, gapLength, exclusive);
e.endPc = shiftPc(e.endPc, where, gapLength, exclusive);
e.handlerPc = shiftPc(e.handlerPc, where, gapLength, exclusive);
@@ -268,10 +257,8 @@ public class ExceptionTable implements Cloneable {
}
void write(DataOutputStream out) throws IOException {
- int len = size();
- out.writeShort(len); // exception_table_length
- for (int i = 0; i < len; ++i) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
+ out.writeShort(size()); // exception_table_length
+ for (ExceptionTableEntry e:entries) {
out.writeShort(e.startPc);
out.writeShort(e.endPc);
out.writeShort(e.handlerPc);
diff --git a/src/main/javassist/bytecode/ExceptionsAttribute.java b/src/main/javassist/bytecode/ExceptionsAttribute.java
index 50031efd..670e51e6 100644
--- a/src/main/javassist/bytecode/ExceptionsAttribute.java
+++ b/src/main/javassist/bytecode/ExceptionsAttribute.java
@@ -42,7 +42,7 @@ public class ExceptionsAttribute extends AttributeInfo {
* @param src source attribute.
*/
private ExceptionsAttribute(ConstPool cp, ExceptionsAttribute src,
- Map classnames) {
+ Map<String,String> classnames) {
super(cp, tag);
copyFrom(src, classnames);
}
@@ -67,7 +67,8 @@ public class ExceptionsAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names. It can be <code>null</code>.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
return new ExceptionsAttribute(newCp, this, classnames);
}
@@ -79,7 +80,7 @@ public class ExceptionsAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- private void copyFrom(ExceptionsAttribute srcAttr, Map classnames) {
+ private void copyFrom(ExceptionsAttribute srcAttr, Map<String,String> classnames) {
ConstPool srcCp = srcAttr.constPool;
ConstPool destCp = this.constPool;
byte[] src = srcAttr.info;
diff --git a/src/main/javassist/bytecode/FieldInfo.java b/src/main/javassist/bytecode/FieldInfo.java
index 926b8137..7d26327a 100644
--- a/src/main/javassist/bytecode/FieldInfo.java
+++ b/src/main/javassist/bytecode/FieldInfo.java
@@ -19,8 +19,8 @@ package javassist.bytecode;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
/**
* <code>field_info</code> structure.
@@ -43,7 +43,7 @@ public final class FieldInfo {
String cachedName;
String cachedType;
int descriptor;
- ArrayList attribute; // may be null.
+ List<AttributeInfo> attribute; // may be null.
private FieldInfo(ConstPool cp) {
constPool = cp;
@@ -75,6 +75,7 @@ public final class FieldInfo {
/**
* Returns a string representation of the object.
*/
+ @Override
public String toString() {
return getName() + " " + getDescriptor();
}
@@ -95,7 +96,7 @@ public final class FieldInfo {
}
void prune(ConstPool cp) {
- ArrayList newAttributes = new ArrayList();
+ List<AttributeInfo> newAttributes = new ArrayList<AttributeInfo>();
AttributeInfo invisibleAnnotations
= getAttribute(AnnotationsAttribute.invisibleTag);
if (invisibleAnnotations != null) {
@@ -110,13 +111,13 @@ public final class FieldInfo {
newAttributes.add(visibleAnnotations);
}
- AttributeInfo signature
+ AttributeInfo signature
= getAttribute(SignatureAttribute.tag);
if (signature != null) {
signature = signature.copy(cp, null);
newAttributes.add(signature);
}
-
+
int index = getConstantValue();
if (index != 0) {
index = constPool.copy(index, cp, null);
@@ -206,8 +207,7 @@ public final class FieldInfo {
= (ConstantAttribute)getAttribute(ConstantAttribute.tag);
if (attr == null)
return 0;
- else
- return attr.getConstantValue();
+ return attr.getConstantValue();
}
/**
@@ -220,9 +220,9 @@ public final class FieldInfo {
* @return a list of <code>AttributeInfo</code> objects.
* @see AttributeInfo
*/
- public List getAttributes() {
+ public List<AttributeInfo> getAttributes() {
if (attribute == null)
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
return attribute;
}
@@ -262,7 +262,7 @@ public final class FieldInfo {
*/
public void addAttribute(AttributeInfo info) {
if (attribute == null)
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
AttributeInfo.remove(attribute, info.getName());
attribute.add(info);
@@ -273,7 +273,7 @@ public final class FieldInfo {
name = in.readUnsignedShort();
descriptor = in.readUnsignedShort();
int n = in.readUnsignedShort();
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
for (int i = 0; i < n; ++i)
attribute.add(AttributeInfo.read(constPool, in));
}
diff --git a/src/main/javassist/bytecode/InnerClassesAttribute.java b/src/main/javassist/bytecode/InnerClassesAttribute.java
index b5b845d7..1bce893b 100644
--- a/src/main/javassist/bytecode/InnerClassesAttribute.java
+++ b/src/main/javassist/bytecode/InnerClassesAttribute.java
@@ -17,8 +17,8 @@
package javassist.bytecode;
import java.io.DataInputStream;
-import java.util.Map;
import java.io.IOException;
+import java.util.Map;
/**
* <code>InnerClasses_attribute</code>.
@@ -73,8 +73,7 @@ public class InnerClassesAttribute extends AttributeInfo {
int i = innerClassIndex(nth);
if (i == 0)
return null;
- else
- return constPool.getClassInfo(i);
+ return constPool.getClassInfo(i);
}
/**
@@ -102,8 +101,7 @@ public class InnerClassesAttribute extends AttributeInfo {
int i = outerClassIndex(nth);
if (i == 0)
return null;
- else
- return constPool.getClassInfo(i);
+ return constPool.getClassInfo(i);
}
/**
@@ -131,8 +129,7 @@ public class InnerClassesAttribute extends AttributeInfo {
int i = innerNameIndex(nth);
if (i == 0)
return null;
- else
- return constPool.getUtf8Info(i);
+ return constPool.getUtf8Info(i);
}
/**
@@ -257,7 +254,8 @@ public class InnerClassesAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
byte[] src = get();
byte[] dest = new byte[src.length];
ConstPool cp = getConstPool();
diff --git a/src/main/javassist/bytecode/LineNumberAttribute.java b/src/main/javassist/bytecode/LineNumberAttribute.java
index 08edb0d1..cead96e0 100644
--- a/src/main/javassist/bytecode/LineNumberAttribute.java
+++ b/src/main/javassist/bytecode/LineNumberAttribute.java
@@ -156,7 +156,8 @@ public class LineNumberAttribute extends AttributeInfo {
* @param newCp the constant pool table used by the new copy.
* @param classnames should be null.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
byte[] src = info;
int num = src.length;
byte[] dest = new byte[num];
diff --git a/src/main/javassist/bytecode/LocalVariableAttribute.java b/src/main/javassist/bytecode/LocalVariableAttribute.java
index 6ee2791a..a0a62cc3 100644
--- a/src/main/javassist/bytecode/LocalVariableAttribute.java
+++ b/src/main/javassist/bytecode/LocalVariableAttribute.java
@@ -53,6 +53,7 @@ public class LocalVariableAttribute extends AttributeInfo {
* @since 3.1
* @deprecated
*/
+ @Deprecated
public LocalVariableAttribute(ConstPool cp, String name) {
super(cp, name, new byte[2]);
ByteArray.write16bit(0, info, 0);
@@ -93,6 +94,7 @@ public class LocalVariableAttribute extends AttributeInfo {
info = newInfo;
}
+ @Override
void renameClass(String oldname, String newname) {
ConstPool cp = getConstPool();
int n = tableLength();
@@ -111,7 +113,8 @@ public class LocalVariableAttribute extends AttributeInfo {
return Descriptor.rename(desc, oldname, newname);
}
- void renameClass(Map classnames) {
+ @Override
+ void renameClass(Map<String,String> classnames) {
ConstPool cp = getConstPool();
int n = tableLength();
for (int i = 0; i < n; ++i) {
@@ -125,7 +128,7 @@ public class LocalVariableAttribute extends AttributeInfo {
}
}
- String renameEntry(String desc, Map classnames) {
+ String renameEntry(String desc, Map<String,String> classnames) {
return Descriptor.rename(desc, classnames);
}
@@ -291,7 +294,8 @@ public class LocalVariableAttribute extends AttributeInfo {
* @param newCp the constant pool table used by the new copy.
* @param classnames should be null.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
byte[] src = get();
byte[] dest = new byte[src.length];
ConstPool cp = getConstPool();
diff --git a/src/main/javassist/bytecode/LocalVariableTypeAttribute.java b/src/main/javassist/bytecode/LocalVariableTypeAttribute.java
index 44dc8b34..12a5bf7d 100644
--- a/src/main/javassist/bytecode/LocalVariableTypeAttribute.java
+++ b/src/main/javassist/bytecode/LocalVariableTypeAttribute.java
@@ -49,14 +49,17 @@ public class LocalVariableTypeAttribute extends LocalVariableAttribute {
super(cp, tag, dest);
}
+ @Override
String renameEntry(String desc, String oldname, String newname) {
return SignatureAttribute.renameClass(desc, oldname, newname);
}
- String renameEntry(String desc, Map classnames) {
+ @Override
+ String renameEntry(String desc, Map<String,String> classnames) {
return SignatureAttribute.renameClass(desc, classnames);
}
+ @Override
LocalVariableAttribute makeThisAttr(ConstPool cp, byte[] dest) {
return new LocalVariableTypeAttribute(cp, dest);
}
diff --git a/src/main/javassist/bytecode/MethodInfo.java b/src/main/javassist/bytecode/MethodInfo.java
index b42b7fe1..313fde99 100644
--- a/src/main/javassist/bytecode/MethodInfo.java
+++ b/src/main/javassist/bytecode/MethodInfo.java
@@ -59,7 +59,7 @@ public class MethodInfo {
int name;
String cachedName;
int descriptor;
- ArrayList attribute; // may be null
+ List<AttributeInfo> attribute; // may be null
/**
* If this value is true, Javassist maintains a <code>StackMap</code> attribute
@@ -129,7 +129,8 @@ public class MethodInfo {
* @see Descriptor
*/
public MethodInfo(ConstPool cp, String methodname, MethodInfo src,
- Map classnameMap) throws BadBytecode {
+ Map<String,String> classnameMap) throws BadBytecode
+ {
this(cp);
read(src, methodname, classnameMap);
}
@@ -137,6 +138,7 @@ public class MethodInfo {
/**
* Returns a string representation of the object.
*/
+ @Override
public String toString() {
return getName() + " " + getDescriptor();
}
@@ -157,7 +159,7 @@ public class MethodInfo {
}
void prune(ConstPool cp) {
- ArrayList newAttributes = new ArrayList();
+ List<AttributeInfo> newAttributes = new ArrayList<AttributeInfo>();
AttributeInfo invisibleAnnotations
= getAttribute(AnnotationsAttribute.invisibleTag);
@@ -304,9 +306,9 @@ public class MethodInfo {
* @return a list of <code>AttributeInfo</code> objects.
* @see AttributeInfo
*/
- public List getAttributes() {
+ public List<AttributeInfo> getAttributes() {
if (attribute == null)
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
return attribute;
}
@@ -347,7 +349,7 @@ public class MethodInfo {
*/
public void addAttribute(AttributeInfo info) {
if (attribute == null)
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
AttributeInfo.remove(attribute, info.getName());
attribute.add(info);
@@ -391,7 +393,7 @@ public class MethodInfo {
public void setExceptionsAttribute(ExceptionsAttribute cattr) {
removeExceptionsAttribute();
if (attribute == null)
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
attribute.add(cattr);
}
@@ -413,7 +415,7 @@ public class MethodInfo {
public void setCodeAttribute(CodeAttribute cattr) {
removeCodeAttribute();
if (attribute == null)
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
attribute.add(cattr);
}
@@ -536,8 +538,7 @@ public class MethodInfo {
}
}
- private void read(MethodInfo src, String methodname, Map classnames)
- throws BadBytecode {
+ private void read(MethodInfo src, String methodname, Map<String,String> classnames) {
ConstPool destCp = constPool;
accessFlags = src.accessFlags;
name = destCp.addUtf8Info(methodname);
@@ -547,7 +548,7 @@ public class MethodInfo {
String desc2 = Descriptor.rename(desc, classnames);
descriptor = destCp.addUtf8Info(desc2);
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
ExceptionsAttribute eattr = src.getExceptionsAttribute();
if (eattr != null)
attribute.add(eattr.copy(destCp, classnames));
@@ -562,7 +563,7 @@ public class MethodInfo {
name = in.readUnsignedShort();
descriptor = in.readUnsignedShort();
int n = in.readUnsignedShort();
- attribute = new ArrayList();
+ attribute = new ArrayList<AttributeInfo>();
for (int i = 0; i < n; ++i)
attribute.add(AttributeInfo.read(constPool, in));
}
diff --git a/src/main/javassist/bytecode/MethodParametersAttribute.java b/src/main/javassist/bytecode/MethodParametersAttribute.java
index b67a0f54..12521095 100644
--- a/src/main/javassist/bytecode/MethodParametersAttribute.java
+++ b/src/main/javassist/bytecode/MethodParametersAttribute.java
@@ -72,7 +72,8 @@ public class MethodParametersAttribute extends AttributeInfo {
* @param newCp the constant pool table used by the new copy.
* @param classnames ignored.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
int s = size();
ConstPool cp = getConstPool();
String[] names = new String[s];
diff --git a/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java b/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java
index 7a69cc61..49e2646f 100644
--- a/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java
+++ b/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java
@@ -16,16 +16,17 @@
package javassist.bytecode;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import java.io.IOException;
-import java.io.DataInputStream;
-import java.io.ByteArrayOutputStream;
import javassist.bytecode.AnnotationsAttribute.Copier;
import javassist.bytecode.AnnotationsAttribute.Parser;
import javassist.bytecode.AnnotationsAttribute.Renamer;
-import javassist.bytecode.annotation.*;
+import javassist.bytecode.annotation.Annotation;
+import javassist.bytecode.annotation.AnnotationsWriter;
/**
* A class representing <code>RuntimeVisibleAnnotations_attribute</code> and
@@ -104,7 +105,8 @@ public class ParameterAnnotationsAttribute extends AttributeInfo {
/**
* Copies this attribute and returns a new copy.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
Copier copier = new Copier(info, constPool, newCp, classnames);
try {
copier.parameters();
@@ -150,10 +152,8 @@ public class ParameterAnnotationsAttribute extends AttributeInfo {
ByteArrayOutputStream output = new ByteArrayOutputStream();
AnnotationsWriter writer = new AnnotationsWriter(output, constPool);
try {
- int n = params.length;
- writer.numParameters(n);
- for (int i = 0; i < n; ++i) {
- Annotation[] anno = params[i];
+ writer.numParameters(params.length);
+ for (Annotation[] anno:params) {
writer.numAnnotations(anno.length);
for (int j = 0; j < anno.length; ++j)
anno[j].write(writer);
@@ -172,13 +172,15 @@ public class ParameterAnnotationsAttribute extends AttributeInfo {
* @param oldname a JVM class name.
* @param newname a JVM class name.
*/
+ @Override
void renameClass(String oldname, String newname) {
- HashMap map = new HashMap();
+ Map<String,String> map = new HashMap<String,String>();
map.put(oldname, newname);
renameClass(map);
}
- void renameClass(Map classnames) {
+ @Override
+ void renameClass(Map<String,String> classnames) {
Renamer renamer = new Renamer(info, getConstPool(), classnames);
try {
renamer.parameters();
@@ -187,29 +189,23 @@ public class ParameterAnnotationsAttribute extends AttributeInfo {
}
}
- void getRefClasses(Map classnames) { renameClass(classnames); }
+ @Override
+ void getRefClasses(Map<String,String> classnames) { renameClass(classnames); }
/**
* Returns a string representation of this object.
*/
+ @Override
public String toString() {
Annotation[][] aa = getAnnotations();
StringBuilder sbuf = new StringBuilder();
- int k = 0;
- while (k < aa.length) {
- Annotation[] a = aa[k++];
- int i = 0;
- while (i < a.length) {
- sbuf.append(a[i++].toString());
- if (i != a.length)
- sbuf.append(" ");
- }
+ for (Annotation[] a : aa) {
+ for (Annotation i : a)
+ sbuf.append(i.toString()).append(" ");
- if (k != aa.length)
- sbuf.append(", ");
+ sbuf.append(", ");
}
- return sbuf.toString();
-
+ return sbuf.toString().replaceAll(" (?=,)|, $","");
}
}
diff --git a/src/main/javassist/bytecode/SignatureAttribute.java b/src/main/javassist/bytecode/SignatureAttribute.java
index 92064ee4..1a8a62dc 100644
--- a/src/main/javassist/bytecode/SignatureAttribute.java
+++ b/src/main/javassist/bytecode/SignatureAttribute.java
@@ -18,8 +18,11 @@ package javassist.bytecode;
import java.io.DataInputStream;
import java.io.IOException;
-import java.util.Map;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import javassist.CtClass;
/**
@@ -83,27 +86,30 @@ public class SignatureAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
return new SignatureAttribute(newCp, getSignature());
}
+ @Override
void renameClass(String oldname, String newname) {
String sig = renameClass(getSignature(), oldname, newname);
setSignature(sig);
}
- void renameClass(Map classnames) {
+ @Override
+ void renameClass(Map<String,String> classnames) {
String sig = renameClass(getSignature(), classnames);
setSignature(sig);
}
static String renameClass(String desc, String oldname, String newname) {
- Map map = new java.util.HashMap();
+ Map<String,String> map = new HashMap<String,String>();
map.put(oldname, newname);
return renameClass(desc, map);
}
- static String renameClass(String desc, Map map) {
+ static String renameClass(String desc, Map<String,String> map) {
if (map == null)
return desc;
@@ -132,7 +138,7 @@ public class SignatureAttribute extends AttributeInfo {
catch (IndexOutOfBoundsException e) { break; }
i = k + 1;
String name = nameBuf.toString();
- String name2 = (String)map.get(name);
+ String name2 = map.get(name);
if (name2 != null) {
newdesc.append(desc.substring(head, j));
newdesc.append('L');
@@ -144,15 +150,14 @@ public class SignatureAttribute extends AttributeInfo {
if (head == 0)
return desc;
- else {
- int len = desc.length();
- if (head < len)
- newdesc.append(desc.substring(head, len));
+ int len = desc.length();
+ if (head < len)
+ newdesc.append(desc.substring(head, len));
- return newdesc.toString();
- }
+ return newdesc.toString();
}
+ @SuppressWarnings("unused")
private static boolean isNamePart(int c) {
return c != ';' && c != '<';
}
@@ -164,10 +169,8 @@ public class SignatureAttribute extends AttributeInfo {
int i = s.indexOf(ch, position);
if (i < 0)
throw error(s);
- else {
- position = i + 1;
- return i;
- }
+ position = i + 1;
+ return i;
}
}
@@ -225,6 +228,7 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
@@ -314,6 +318,7 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
@@ -424,6 +429,7 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer(getName());
if (superClass != null)
@@ -550,6 +556,7 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
if (wildcard == '*')
return "?";
@@ -634,10 +641,12 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
return Descriptor.toClassName(Character.toString(descriptor));
}
+ @Override
void encode(StringBuffer sb) {
sb.append(descriptor);
}
@@ -669,8 +678,7 @@ public class SignatureAttribute extends AttributeInfo {
TypeArgument[] targs, ClassType parent) {
if (parent == null)
return new ClassType(s, b, e, targs);
- else
- return new NestedClassType(s, b, e, targs, parent);
+ return new NestedClassType(s, b, e, targs, parent);
}
ClassType(String signature, int begin, int end, TypeArgument[] targs) {
@@ -730,6 +738,7 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
ClassType parent = getDeclaringClass();
@@ -762,6 +771,7 @@ public class SignatureAttribute extends AttributeInfo {
* For example, if the type is a nested class {@code foo.Bar.Baz},
* then {@code foo.Bar$Baz} is returned.
*/
+ @Override
public String jvmTypeName() {
StringBuffer sbuf = new StringBuffer();
ClassType parent = getDeclaringClass();
@@ -771,6 +781,7 @@ public class SignatureAttribute extends AttributeInfo {
return toString2(sbuf);
}
+ @Override
void encode(StringBuffer sb) {
sb.append('L');
encode2(sb);
@@ -818,6 +829,7 @@ public class SignatureAttribute extends AttributeInfo {
* Returns the class that declares this nested class.
* This nested class is a member of that declaring class.
*/
+ @Override
public ClassType getDeclaringClass() { return parent; }
}
@@ -854,6 +866,7 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer(componentType.toString());
for (int i = 0; i < dim; i++)
@@ -862,6 +875,7 @@ public class SignatureAttribute extends AttributeInfo {
return sbuf.toString();
}
+ @Override
void encode(StringBuffer sb) {
for (int i = 0; i < dim; i++)
sb.append('[');
@@ -899,10 +913,12 @@ public class SignatureAttribute extends AttributeInfo {
/**
* Returns the string representation.
*/
+ @Override
public String toString() {
return name;
}
+ @Override
void encode(StringBuffer sb) {
sb.append('T').append(name).append(';');
}
@@ -991,12 +1007,12 @@ public class SignatureAttribute extends AttributeInfo {
TypeParameter[] tp = parseTypeParams(sig, cur);
ClassType superClass = parseClassType(sig, cur);
int sigLen = sig.length();
- ArrayList ifArray = new ArrayList();
+ List<ClassType> ifArray = new ArrayList<ClassType>();
while (cur.position < sigLen && sig.charAt(cur.position) == 'L')
ifArray.add(parseClassType(sig, cur));
ClassType[] ifs
- = (ClassType[])ifArray.toArray(new ClassType[ifArray.size()]);
+ = ifArray.toArray(new ClassType[ifArray.size()]);
return new ClassSignature(tp, superClass, ifs);
}
@@ -1008,7 +1024,7 @@ public class SignatureAttribute extends AttributeInfo {
if (sig.charAt(cur.position++) != '(')
throw error(sig);
- ArrayList params = new ArrayList();
+ List<Type> params = new ArrayList<Type>();
while (sig.charAt(cur.position) != ')') {
Type t = parseType(sig, cur);
params.add(t);
@@ -1017,7 +1033,7 @@ public class SignatureAttribute extends AttributeInfo {
cur.position++;
Type ret = parseType(sig, cur);
int sigLen = sig.length();
- ArrayList exceptions = new ArrayList();
+ List<ObjectType> exceptions = new ArrayList<ObjectType>();
while (cur.position < sigLen && sig.charAt(cur.position) == '^') {
cur.position++;
ObjectType t = parseObjectType(sig, cur, false);
@@ -1027,22 +1043,22 @@ public class SignatureAttribute extends AttributeInfo {
exceptions.add(t);
}
- Type[] p = (Type[])params.toArray(new Type[params.size()]);
- ObjectType[] ex = (ObjectType[])exceptions.toArray(new ObjectType[exceptions.size()]);
+ Type[] p = params.toArray(new Type[params.size()]);
+ ObjectType[] ex = exceptions.toArray(new ObjectType[exceptions.size()]);
return new MethodSignature(tp, p, ret, ex);
}
private static TypeParameter[] parseTypeParams(String sig, Cursor cur)
throws BadBytecode
{
- ArrayList typeParam = new ArrayList();
+ List<TypeParameter> typeParam = new ArrayList<TypeParameter>();
if (sig.charAt(cur.position) == '<') {
cur.position++;
while (sig.charAt(cur.position) != '>') {
int nameBegin = cur.position;
int nameEnd = cur.indexOf(sig, ':');
ObjectType classBound = parseObjectType(sig, cur, true);
- ArrayList ifBound = new ArrayList();
+ List<ObjectType> ifBound = new ArrayList<ObjectType>();
while (sig.charAt(cur.position) == ':') {
cur.position++;
ObjectType t = parseObjectType(sig, cur, false);
@@ -1050,14 +1066,14 @@ public class SignatureAttribute extends AttributeInfo {
}
TypeParameter p = new TypeParameter(sig, nameBegin, nameEnd,
- classBound, (ObjectType[])ifBound.toArray(new ObjectType[ifBound.size()]));
+ classBound, ifBound.toArray(new ObjectType[ifBound.size()]));
typeParam.add(p);
}
cur.position++;
}
- return (TypeParameter[])typeParam.toArray(new TypeParameter[typeParam.size()]);
+ return typeParam.toArray(new TypeParameter[typeParam.size()]);
}
private static ObjectType parseObjectType(String sig, Cursor c, boolean dontThrow)
@@ -1076,8 +1092,7 @@ public class SignatureAttribute extends AttributeInfo {
default :
if (dontThrow)
return null;
- else
- throw error(sig);
+ throw error(sig);
}
}
@@ -1086,8 +1101,7 @@ public class SignatureAttribute extends AttributeInfo {
{
if (sig.charAt(c.position) == 'L')
return parseClassType2(sig, c, null);
- else
- throw error(sig);
+ throw error(sig);
}
private static ClassType parseClassType2(String sig, Cursor c, ClassType parent)
@@ -1112,12 +1126,11 @@ public class SignatureAttribute extends AttributeInfo {
c.position--;
return parseClassType2(sig, c, thisClass);
}
- else
- return thisClass;
+ return thisClass;
}
private static TypeArgument[] parseTypeArgs(String sig, Cursor c) throws BadBytecode {
- ArrayList args = new ArrayList();
+ List<TypeArgument> args = new ArrayList<TypeArgument>();
char t;
while ((t = sig.charAt(c.position++)) != '>') {
TypeArgument ta;
@@ -1135,7 +1148,7 @@ public class SignatureAttribute extends AttributeInfo {
args.add(ta);
}
- return (TypeArgument[])args.toArray(new TypeArgument[args.size()]);
+ return args.toArray(new TypeArgument[args.size()]);
}
private static ObjectType parseArray(String sig, Cursor c) throws BadBytecode {
diff --git a/src/main/javassist/bytecode/SourceFileAttribute.java b/src/main/javassist/bytecode/SourceFileAttribute.java
index 23ebbf3e..77d32e52 100644
--- a/src/main/javassist/bytecode/SourceFileAttribute.java
+++ b/src/main/javassist/bytecode/SourceFileAttribute.java
@@ -65,7 +65,8 @@ public class SourceFileAttribute extends AttributeInfo {
* @param classnames pairs of replaced and substituted
* class names.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
return new SourceFileAttribute(newCp, getFileName());
}
}
diff --git a/src/main/javassist/bytecode/StackMap.java b/src/main/javassist/bytecode/StackMap.java
index 1abdc40f..96a84491 100644
--- a/src/main/javassist/bytecode/StackMap.java
+++ b/src/main/javassist/bytecode/StackMap.java
@@ -22,9 +22,6 @@ import java.io.IOException;
import java.util.Map;
import javassist.CannotCompileException;
-import javassist.bytecode.StackMapTable.InsertLocal;
-import javassist.bytecode.StackMapTable.NewRemover;
-import javassist.bytecode.StackMapTable.Shifter;
/**
* Another <code>stack_map</code> attribute defined in CLDC 1.1 for J2ME.
@@ -116,7 +113,8 @@ public class StackMap extends AttributeInfo {
/**
* Makes a copy.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
Copier copier = new Copier(this, newCp, classnames);
copier.visit();
return copier.getStackMap();
@@ -224,42 +222,47 @@ public class StackMap extends AttributeInfo {
static class Copier extends Walker {
byte[] dest;
ConstPool srcCp, destCp;
- Map classnames;
+ Map<String,String> classnames;
- Copier(StackMap map, ConstPool newCp, Map classnames) {
+ Copier(StackMap map, ConstPool newCp, Map<String,String> classnames) {
super(map);
srcCp = map.getConstPool();
dest = new byte[info.length];
destCp = newCp;
this.classnames = classnames;
}
-
+ @Override
public void visit() {
int num = ByteArray.readU16bit(info, 0);
ByteArray.write16bit(num, dest, 0);
super.visit();
}
+ @Override
public int locals(int pos, int offset, int num) {
ByteArray.write16bit(offset, dest, pos - 4);
return super.locals(pos, offset, num);
}
+ @Override
public int typeInfoArray(int pos, int offset, int num, boolean isLocals) {
ByteArray.write16bit(num, dest, pos - 2);
return super.typeInfoArray(pos, offset, num, isLocals);
}
+ @Override
public void typeInfo(int pos, byte tag) {
dest[pos] = tag;
}
+ @Override
public void objectVariable(int pos, int clazz) {
dest[pos] = OBJECT;
int newClazz = srcCp.copy(clazz, destCp, classnames);
ByteArray.write16bit(newClazz, dest, pos + 1);
}
+ @Override
public void uninitialized(int pos, int offset) {
dest[pos] = UNINIT;
ByteArray.write16bit(offset, dest, pos + 1);
@@ -305,30 +308,36 @@ public class StackMap extends AttributeInfo {
return writer.toByteArray();
}
+ @Override
public void visit() {
int num = ByteArray.readU16bit(info, 0);
writer.write16bit(num);
super.visit();
}
+ @Override
public int locals(int pos, int offset, int num) {
writer.write16bit(offset);
return super.locals(pos, offset, num);
}
+ @Override
public int typeInfoArray(int pos, int offset, int num, boolean isLocals) {
writer.write16bit(num);
return super.typeInfoArray(pos, offset, num, isLocals);
}
+ @Override
public void typeInfo(int pos, byte tag) {
writer.writeVerifyTypeInfo(tag, 0);
}
+ @Override
public void objectVariable(int pos, int clazz) {
writer.writeVerifyTypeInfo(OBJECT, clazz);
}
+ @Override
public void uninitialized(int pos, int offset) {
writer.writeVerifyTypeInfo(UNINIT, offset);
}
@@ -345,6 +354,7 @@ public class StackMap extends AttributeInfo {
this.varData = varData;
}
+ @Override
public int typeInfoArray(int pos, int offset, int num, boolean isLocals) {
if (!isLocals || num < varIndex)
return super.typeInfoArray(pos, offset, num, isLocals);
@@ -390,6 +400,7 @@ public class StackMap extends AttributeInfo {
this.exclusive = exclusive;
}
+ @Override
public int locals(int pos, int offset, int num) {
if (exclusive ? where <= offset : where < offset)
ByteArray.write16bit(offset + gap, info, pos - 4);
@@ -397,6 +408,7 @@ public class StackMap extends AttributeInfo {
return super.locals(pos, offset, num);
}
+ @Override
public void uninitialized(int pos, int offset) {
if (where <= offset)
ByteArray.write16bit(offset + gap, info, pos + 1);
@@ -419,6 +431,7 @@ public class StackMap extends AttributeInfo {
this.gap = gap;
}
+ @Override
public int locals(int pos, int offset, int num) {
if (where == pos + offset)
ByteArray.write16bit(offset - gap, info, pos - 4);
@@ -451,6 +464,7 @@ public class StackMap extends AttributeInfo {
posOfNew = where;
}
+ @Override
public int stack(int pos, int offset, int num) {
return stackTypeInfoArray(pos, offset, num);
}
@@ -519,6 +533,7 @@ public class StackMap extends AttributeInfo {
visit();
}
+ @Override
public int locals(int pos, int offset, int num) {
writer.println(" * offset " + offset);
return super.locals(pos, offset, num);
diff --git a/src/main/javassist/bytecode/StackMapTable.java b/src/main/javassist/bytecode/StackMapTable.java
index a02d5e72..9b8e5fae 100644
--- a/src/main/javassist/bytecode/StackMapTable.java
+++ b/src/main/javassist/bytecode/StackMapTable.java
@@ -16,12 +16,13 @@
package javassist.bytecode;
+import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.Map;
+
import javassist.CannotCompileException;
/**
@@ -62,7 +63,8 @@ public class StackMapTable extends AttributeInfo {
* <code>RuntimeCopyException</code>.
*
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames)
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames)
throws RuntimeCopyException
{
try {
@@ -79,6 +81,9 @@ public class StackMapTable extends AttributeInfo {
* in <code>StackMapTable</code>.
*/
public static class RuntimeCopyException extends RuntimeException {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
/**
* Constructs an exception.
*/
@@ -87,6 +92,7 @@ public class StackMapTable extends AttributeInfo {
}
}
+ @Override
void write(DataOutputStream out) throws IOException {
super.write(out);
}
@@ -338,8 +344,8 @@ public class StackMapTable extends AttributeInfo {
* @param stackData <code>stack[i].cpool_index</code>
* or <code>stack[i].offset</code>
*/
- public void fullFrame(int pos, int offsetDelta, int[] localTags, int[] localData,
- int[] stackTags, int[] stackData)
+ public void fullFrame(int pos, int offsetDelta, int[] localTags,
+ int[] localData, int[] stackTags, int[] stackData)
throws BadBytecode {}
private int verifyTypeInfo(int pos, int n, int[] tags, int[] data) {
@@ -380,22 +386,27 @@ public class StackMapTable extends AttributeInfo {
return writer.toByteArray();
}
+ @Override
public void sameFrame(int pos, int offsetDelta) {
writer.sameFrame(offsetDelta);
}
+ @Override
public void sameLocals(int pos, int offsetDelta, int stackTag, int stackData) {
writer.sameLocals(offsetDelta, stackTag, copyData(stackTag, stackData));
}
+ @Override
public void chopFrame(int pos, int offsetDelta, int k) {
writer.chopFrame(offsetDelta, k);
}
+ @Override
public void appendFrame(int pos, int offsetDelta, int[] tags, int[] data) {
writer.appendFrame(offsetDelta, tags, copyData(tags, data));
}
+ @Override
public void fullFrame(int pos, int offsetDelta, int[] localTags, int[] localData,
int[] stackTags, int[] stackData) {
writer.fullFrame(offsetDelta, localTags, copyData(localTags, localData),
@@ -413,22 +424,23 @@ public class StackMapTable extends AttributeInfo {
static class Copier extends SimpleCopy {
private ConstPool srcPool, destPool;
- private Map classnames;
+ private Map<String,String> classnames;
- public Copier(ConstPool src, byte[] data, ConstPool dest, Map names) {
+ public Copier(ConstPool src, byte[] data, ConstPool dest, Map<String,String> names) {
super(data);
srcPool = src;
destPool = dest;
classnames = names;
}
+ @Override
protected int copyData(int tag, int data) {
if (tag == OBJECT)
- return srcPool.copy(data, destPool, classnames);
- else
- return data;
+ return srcPool.copy(data, destPool, classnames);
+ return data;
}
+ @Override
protected int[] copyData(int[] tags, int[] data) {
int[] newData = new int[data.length];
for (int i = 0; i < data.length; i++)
@@ -504,6 +516,7 @@ public class StackMapTable extends AttributeInfo {
this.varData = varData;
}
+ @Override
public void fullFrame(int pos, int offsetDelta, int[] localTags, int[] localData,
int[] stackTags, int[] stackData) {
int len = localTags.length;
@@ -728,22 +741,26 @@ public class StackMapTable extends AttributeInfo {
offset = -1;
}
+ @Override
public void sameFrame(int pos, int offsetDelta) {
offset += offsetDelta + 1;
writer.println(offset + " same frame: " + offsetDelta);
}
+ @Override
public void sameLocals(int pos, int offsetDelta, int stackTag, int stackData) {
offset += offsetDelta + 1;
writer.println(offset + " same locals: " + offsetDelta);
printTypeInfo(stackTag, stackData);
}
+ @Override
public void chopFrame(int pos, int offsetDelta, int k) {
offset += offsetDelta + 1;
writer.println(offset + " chop frame: " + offsetDelta + ", " + k + " last locals");
}
+ @Override
public void appendFrame(int pos, int offsetDelta, int[] tags, int[] data) {
offset += offsetDelta + 1;
writer.println(offset + " append frame: " + offsetDelta);
@@ -751,6 +768,7 @@ public class StackMapTable extends AttributeInfo {
printTypeInfo(tags[i], data[i]);
}
+ @Override
public void fullFrame(int pos, int offsetDelta, int[] localTags, int[] localData,
int[] stackTags, int[] stackData) {
offset += offsetDelta + 1;
@@ -817,7 +835,8 @@ public class StackMapTable extends AttributeInfo {
this.gap = gap;
}
- public void objectOrUninitialized(int tag, int data, int pos) {
+ @Override
+ public void objectOrUninitialized(int tag, int data, int pos) {
if (tag == UNINIT)
if (where <= data)
ByteArray.write16bit(data + gap, info, pos);
@@ -847,10 +866,12 @@ public class StackMapTable extends AttributeInfo {
stackMap.set(updatedInfo);
}
+ @Override
public void sameFrame(int pos, int offsetDelta) {
update(pos, offsetDelta, 0, 251);
}
+ @Override
public void sameLocals(int pos, int offsetDelta, int stackTag, int stackData) {
update(pos, offsetDelta, 64, 247);
}
@@ -889,14 +910,17 @@ public class StackMapTable extends AttributeInfo {
return newinfo;
}
+ @Override
public void chopFrame(int pos, int offsetDelta, int k) {
update(pos, offsetDelta);
}
+ @Override
public void appendFrame(int pos, int offsetDelta, int[] tags, int[] data) {
update(pos, offsetDelta);
}
+ @Override
public void fullFrame(int pos, int offsetDelta, int[] localTags, int[] localData,
int[] stackTags, int[] stackData) {
update(pos, offsetDelta);
@@ -931,6 +955,7 @@ public class StackMapTable extends AttributeInfo {
super(smt, where, gap, false);
}
+ @Override
void update(int pos, int offsetDelta, int base, int entry) {
int oldPos = position;
position = oldPos + offsetDelta + (oldPos == 0 ? 0 : 1);
@@ -971,6 +996,7 @@ public class StackMapTable extends AttributeInfo {
return newinfo;
}
+ @Override
void update(int pos, int offsetDelta) {
int oldPos = position;
position = oldPos + offsetDelta + (oldPos == 0 ? 0 : 1);
@@ -1013,6 +1039,7 @@ public class StackMapTable extends AttributeInfo {
posOfNew = pos;
}
+ @Override
public void sameLocals(int pos, int offsetDelta, int stackTag, int stackData) {
if (stackTag == UNINIT && stackData == posOfNew)
super.sameFrame(pos, offsetDelta);
@@ -1020,6 +1047,7 @@ public class StackMapTable extends AttributeInfo {
super.sameLocals(pos, offsetDelta, stackTag, stackData);
}
+ @Override
public void fullFrame(int pos, int offsetDelta, int[] localTags, int[] localData,
int[] stackTags, int[] stackData) {
int n = stackTags.length - 1;
diff --git a/src/main/javassist/bytecode/SyntheticAttribute.java b/src/main/javassist/bytecode/SyntheticAttribute.java
index a42e19b7..be6b35e1 100644
--- a/src/main/javassist/bytecode/SyntheticAttribute.java
+++ b/src/main/javassist/bytecode/SyntheticAttribute.java
@@ -50,7 +50,8 @@ public class SyntheticAttribute extends AttributeInfo {
* @param newCp the constant pool table used by the new copy.
* @param classnames should be null.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
return new SyntheticAttribute(newCp);
}
}
diff --git a/src/main/javassist/bytecode/TypeAnnotationsAttribute.java b/src/main/javassist/bytecode/TypeAnnotationsAttribute.java
index 454401a9..86fea728 100644
--- a/src/main/javassist/bytecode/TypeAnnotationsAttribute.java
+++ b/src/main/javassist/bytecode/TypeAnnotationsAttribute.java
@@ -4,6 +4,7 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+
import javassist.bytecode.annotation.TypeAnnotationsWriter;
/**
@@ -57,7 +58,8 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
/**
* Copies this attribute and returns a new copy.
*/
- public AttributeInfo copy(ConstPool newCp, Map classnames) {
+ @Override
+ public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
Copier copier = new Copier(info, constPool, newCp, classnames);
try {
copier.annotationArray();
@@ -72,13 +74,15 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
* @param oldname a JVM class name.
* @param newname a JVM class name.
*/
+ @Override
void renameClass(String oldname, String newname) {
- HashMap map = new HashMap();
+ Map<String,String> map = new HashMap<String,String>();
map.put(oldname, newname);
renameClass(map);
}
- void renameClass(Map classnames) {
+ @Override
+ void renameClass(Map<String,String> classnames) {
Renamer renamer = new Renamer(info, getConstPool(), classnames);
try {
renamer.annotationArray();
@@ -87,7 +91,8 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
}
}
- void getRefClasses(Map classnames) { renameClass(classnames); }
+ @Override
+ void getRefClasses(Map<String,String> classnames) { renameClass(classnames); }
/**
* To visit each elements of the type annotation attribute,
@@ -103,6 +108,7 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
subWalker = new SubWalker(attrInfo);
}
+ @Override
int annotationArray(int pos, int num) throws Exception {
for (int i = 0; i < num; i++) {
int targetType = info[pos] & 0xff;
@@ -130,7 +136,7 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
typeParameterTarget(pos, type, index);
return pos + 1; }
case 0x10: {
- int index = ByteArray.readU16bit(info, pos);
+ int index = ByteArray.readU16bit(info, pos);
supertypeTarget(pos, index);
return pos + 2; }
case 0x11:
@@ -149,22 +155,22 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
formalParameterTarget(pos, index);
return pos + 1; }
case 0x17: {
- int index = ByteArray.readU16bit(info, pos);
+ int index = ByteArray.readU16bit(info, pos);
throwsTarget(pos, index);
return pos + 2; }
case 0x40:
case 0x41: {
- int len = ByteArray.readU16bit(info, pos);
+ int len = ByteArray.readU16bit(info, pos);
return localvarTarget(pos + 2, type, len); }
case 0x42: {
- int index = ByteArray.readU16bit(info, pos);
+ int index = ByteArray.readU16bit(info, pos);
catchTarget(pos, index);
return pos + 2; }
case 0x43:
case 0x44:
case 0x45:
case 0x46: {
- int offset = ByteArray.readU16bit(info, pos);
+ int offset = ByteArray.readU16bit(info, pos);
offsetTarget(pos, type, offset);
return pos + 2; }
case 0x47:
@@ -239,11 +245,12 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
static class Renamer extends AnnotationsAttribute.Renamer {
SubWalker sub;
- Renamer(byte[] attrInfo, ConstPool cp, Map map) {
+ Renamer(byte[] attrInfo, ConstPool cp, Map<String,String> map) {
super(attrInfo, cp, map);
sub = new SubWalker(attrInfo);
}
+ @Override
int annotationArray(int pos, int num) throws Exception {
for (int i = 0; i < num; i++) {
int targetType = info[pos] & 0xff;
@@ -259,13 +266,14 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
static class Copier extends AnnotationsAttribute.Copier {
SubCopier sub;
- Copier(byte[] attrInfo, ConstPool src, ConstPool dest, Map map) {
+ Copier(byte[] attrInfo, ConstPool src, ConstPool dest, Map<String,String> map) {
super(attrInfo, src, dest, map, false);
TypeAnnotationsWriter w = new TypeAnnotationsWriter(output, dest);
writer = w;
sub = new SubCopier(attrInfo, src, dest, map, w);
}
+ @Override
int annotationArray(int pos, int num) throws Exception {
writer.numAnnotations(num);
for (int i = 0; i < num; i++) {
@@ -281,11 +289,11 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
static class SubCopier extends SubWalker {
ConstPool srcPool, destPool;
- Map classnames;
+ Map<String,String> classnames;
TypeAnnotationsWriter writer;
- SubCopier(byte[] attrInfo, ConstPool src, ConstPool dest, Map map,
- TypeAnnotationsWriter w)
+ SubCopier(byte[] attrInfo, ConstPool src, ConstPool dest,
+ Map<String,String> map, TypeAnnotationsWriter w)
{
super(attrInfo);
srcPool = src;
@@ -294,16 +302,19 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
writer = w;
}
+ @Override
void typeParameterTarget(int pos, int targetType, int typeParameterIndex)
throws Exception
{
- writer.typeParameterTarget(targetType, typeParameterIndex);
+ writer.typeParameterTarget(targetType, typeParameterIndex);
}
+ @Override
void supertypeTarget(int pos, int superTypeIndex) throws Exception {
writer.supertypeTarget(superTypeIndex);
}
+ @Override
void typeParameterBoundTarget(int pos, int targetType, int typeParameterIndex,
int boundIndex)
throws Exception
@@ -311,48 +322,58 @@ public class TypeAnnotationsAttribute extends AttributeInfo {
writer.typeParameterBoundTarget(targetType, typeParameterIndex, boundIndex);
}
+ @Override
void emptyTarget(int pos, int targetType) throws Exception {
writer.emptyTarget(targetType);
}
+ @Override
void formalParameterTarget(int pos, int formalParameterIndex) throws Exception {
writer.formalParameterTarget(formalParameterIndex);
}
+ @Override
void throwsTarget(int pos, int throwsTypeIndex) throws Exception {
writer.throwsTarget(throwsTypeIndex);
}
+ @Override
int localvarTarget(int pos, int targetType, int tableLength) throws Exception {
writer.localVarTarget(targetType, tableLength);
return super.localvarTarget(pos, targetType, tableLength);
}
+ @Override
void localvarTarget(int pos, int targetType, int startPc, int length, int index)
throws Exception
{
writer.localVarTargetTable(startPc, length, index);
}
+ @Override
void catchTarget(int pos, int exceptionTableIndex) throws Exception {
writer.catchTarget(exceptionTableIndex);
}
+ @Override
void offsetTarget(int pos, int targetType, int offset) throws Exception {
writer.offsetTarget(targetType, offset);
}
+ @Override
void typeArgumentTarget(int pos, int targetType, int offset, int typeArgumentIndex)
throws Exception
{
writer.typeArgumentTarget(targetType, offset, typeArgumentIndex);
}
+ @Override
int typePath(int pos, int pathLength) throws Exception {
writer.typePath(pathLength);
return super.typePath(pos, pathLength);
}
+ @Override
void typePath(int pos, int typePathKind, int typeArgumentIndex) throws Exception {
writer.typePathPath(typePathKind, typeArgumentIndex);
}
diff --git a/src/main/javassist/bytecode/analysis/Analyzer.java b/src/main/javassist/bytecode/analysis/Analyzer.java
index 656a1741..5d1250dd 100644
--- a/src/main/javassist/bytecode/analysis/Analyzer.java
+++ b/src/main/javassist/bytecode/analysis/Analyzer.java
@@ -15,8 +15,6 @@
*/
package javassist.bytecode.analysis;
-import java.util.Iterator;
-
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
@@ -363,9 +361,7 @@ public class Analyzer implements Opcode {
if (subroutine == null)
throw new BadBytecode("Ret on no subroutine! [pos = " + pos + "]");
- Iterator callerIter = subroutine.callers().iterator();
- while (callerIter.hasNext()) {
- int caller = ((Integer) callerIter.next()).intValue();
+ for (int caller:subroutine.callers()) {
int returnLoc = getNext(iter, caller, pos);
boolean changed = false;
@@ -377,8 +373,7 @@ public class Analyzer implements Opcode {
changed = old.mergeStack(frame);
}
- for (Iterator i = subroutine.accessed().iterator(); i.hasNext(); ) {
- int index = ((Integer)i.next()).intValue();
+ for (int index:subroutine.accessed()) {
Type oldType = old.getLocal(index);
Type newType = frame.getLocal(index);
if (oldType != newType) {
diff --git a/src/main/javassist/bytecode/analysis/ControlFlow.java b/src/main/javassist/bytecode/analysis/ControlFlow.java
index 0bf76a3d..e47c00d3 100644
--- a/src/main/javassist/bytecode/analysis/ControlFlow.java
+++ b/src/main/javassist/bytecode/analysis/ControlFlow.java
@@ -17,6 +17,8 @@
package javassist.bytecode.analysis;
import java.util.ArrayList;
+import java.util.List;
+
import javassist.CtClass;
import javassist.CtMethod;
import javassist.bytecode.BadBytecode;
@@ -64,9 +66,11 @@ public class ControlFlow {
methodInfo = minfo;
frames = null;
basicBlocks = (Block[])new BasicBlock.Maker() {
+ @Override
protected BasicBlock makeBlock(int pos) {
return new Block(pos, methodInfo);
}
+ @Override
protected BasicBlock[] makeArray(int size) {
return new Block[size];
}
@@ -156,7 +160,9 @@ public class ControlFlow {
}
Access access = new Access(nodes) {
+ @Override
BasicBlock[] exits(Node n) { return n.block.getExit(); }
+ @Override
BasicBlock[] entrances(Node n) { return n.block.entrances; }
};
nodes[0].makeDepth1stTree(null, visited, 0, distance, access);
@@ -202,7 +208,9 @@ public class ControlFlow {
}
Access access = new Access(nodes) {
+ @Override
BasicBlock[] exits(Node n) { return n.block.entrances; }
+ @Override
BasicBlock[] entrances(Node n) { return n.block.getExit(); }
};
@@ -252,6 +260,7 @@ public class ControlFlow {
method = minfo;
}
+ @Override
protected void toString2(StringBuffer sbuf) {
super.toString2(sbuf);
sbuf.append(", incoming{");
@@ -314,14 +323,14 @@ public class ControlFlow {
* in this block.
*/
public Catcher[] catchers() {
- ArrayList catchers = new ArrayList();
+ List<Catcher> catchers = new ArrayList<Catcher>();
BasicBlock.Catch c = toCatch;
while (c != null) {
catchers.add(new Catcher(c));
c = c.next;
}
- return (Catcher[])catchers.toArray(new Catcher[catchers.size()]);
+ return catchers.toArray(new Catcher[catchers.size()]);
}
}
@@ -349,6 +358,7 @@ public class ControlFlow {
/**
* Returns a <code>String</code> representation.
*/
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append("Node[pos=").append(block().position());
@@ -473,7 +483,7 @@ public class ControlFlow {
Node n = all[i];
Node p = n.parent;
if (p != null)
- p.children[nchildren[p.block.index]++] = n;
+ p.children[nchildren[p.block.index]++] = n;
}
}
}
diff --git a/src/main/javassist/bytecode/analysis/Frame.java b/src/main/javassist/bytecode/analysis/Frame.java
index 1a2b46a9..28c62e35 100644
--- a/src/main/javassist/bytecode/analysis/Frame.java
+++ b/src/main/javassist/bytecode/analysis/Frame.java
@@ -229,6 +229,7 @@ public class Frame {
return changed;
}
+ @Override
public String toString() {
StringBuffer buffer = new StringBuffer();
diff --git a/src/main/javassist/bytecode/analysis/MultiArrayType.java b/src/main/javassist/bytecode/analysis/MultiArrayType.java
index 1d1b90b0..e430b850 100644
--- a/src/main/javassist/bytecode/analysis/MultiArrayType.java
+++ b/src/main/javassist/bytecode/analysis/MultiArrayType.java
@@ -34,6 +34,7 @@ public class MultiArrayType extends Type {
this.dims = dims;
}
+ @Override
public CtClass getCtClass() {
CtClass clazz = component.getCtClass();
if (clazz == null)
@@ -52,30 +53,37 @@ public class MultiArrayType extends Type {
}
}
+ @Override
boolean popChanged() {
return component.popChanged();
}
+ @Override
public int getDimensions() {
return dims;
}
+ @Override
public Type getComponent() {
return dims == 1 ? (Type)component : new MultiArrayType(component, dims - 1);
}
+ @Override
public int getSize() {
return 1;
}
+ @Override
public boolean isArray() {
return true;
}
+ @Override
public boolean isAssignableFrom(Type type) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public boolean isReference() {
return true;
}
@@ -115,6 +123,13 @@ public class MultiArrayType extends Type {
return component.isAssignableTo(typeRoot);
}
+
+ @Override
+ public int hashCode() {
+ return component.hashCode() + dims;
+ }
+
+ @Override
public boolean equals(Object o) {
if (! (o instanceof MultiArrayType))
return false;
@@ -123,6 +138,7 @@ public class MultiArrayType extends Type {
return component.equals(multi.component) && dims == multi.dims;
}
+ @Override
public String toString() {
// follows the same detailed formating scheme as component
return arrayName(component.toString(), dims);
diff --git a/src/main/javassist/bytecode/analysis/MultiType.java b/src/main/javassist/bytecode/analysis/MultiType.java
index 7baa661a..a8f6fc67 100644
--- a/src/main/javassist/bytecode/analysis/MultiType.java
+++ b/src/main/javassist/bytecode/analysis/MultiType.java
@@ -16,7 +16,6 @@
package javassist.bytecode.analysis;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import javassist.CtClass;
@@ -47,17 +46,17 @@ import javassist.CtClass;
* changes, and somehow communicating assignment changes to the Analyzer
*/
public class MultiType extends Type {
- private Map interfaces;
+ private Map<String,CtClass> interfaces;
private Type resolved;
private Type potentialClass;
private MultiType mergeSource;
private boolean changed = false;
- public MultiType(Map interfaces) {
+ public MultiType(Map<String,CtClass> interfaces) {
this(interfaces, null);
}
- public MultiType(Map interfaces, Type potentialClass) {
+ public MultiType(Map<String,CtClass> interfaces, Type potentialClass) {
super(null);
this.interfaces = interfaces;
this.potentialClass = potentialClass;
@@ -67,6 +66,7 @@ public class MultiType extends Type {
* Gets the class that corresponds with this type. If this information
* is not yet known, java.lang.Object will be returned.
*/
+ @Override
public CtClass getCtClass() {
if (resolved != null)
return resolved.getCtClass();
@@ -77,6 +77,7 @@ public class MultiType extends Type {
/**
* Always returns null since this type is never used for an array.
*/
+ @Override
public Type getComponent() {
return null;
}
@@ -84,6 +85,7 @@ public class MultiType extends Type {
/**
* Always returns 1, since this type is a reference.
*/
+ @Override
public int getSize() {
return 1;
}
@@ -91,6 +93,7 @@ public class MultiType extends Type {
/**
* Always reutnrs false since this type is never used for an array
*/
+ @Override
public boolean isArray() {
return false;
}
@@ -98,12 +101,14 @@ public class MultiType extends Type {
/**
* Returns true if the internal state has changed.
*/
+ @Override
boolean popChanged() {
boolean changed = this.changed;
this.changed = false;
return changed;
}
+ @Override
public boolean isAssignableFrom(Type type) {
throw new UnsupportedOperationException("Not implemented");
}
@@ -118,11 +123,11 @@ public class MultiType extends Type {
if (potentialClass != null && !type.isAssignableFrom(potentialClass))
potentialClass = null;
- Map map = mergeMultiAndSingle(this, type);
+ Map<String,CtClass> map = mergeMultiAndSingle(this, type);
if (map.size() == 1 && potentialClass == null) {
// Update previous merge paths to the same resolved type
- resolved = Type.get((CtClass)map.values().iterator().next());
+ resolved = Type.get(map.values().iterator().next());
propogateResolved();
return true;
@@ -168,16 +173,15 @@ public class MultiType extends Type {
*
* @return true
*/
+ @Override
public boolean isReference() {
return true;
}
- private Map getAllMultiInterfaces(MultiType type) {
- Map map = new HashMap();
+ private Map<String,CtClass> getAllMultiInterfaces(MultiType type) {
+ Map<String,CtClass> map = new HashMap<String,CtClass>();
- Iterator iter = type.interfaces.values().iterator();
- while (iter.hasNext()) {
- CtClass intf = (CtClass)iter.next();
+ for (CtClass intf:type.interfaces.values()) {
map.put(intf.getName(), intf);
getAllInterfaces(intf, map);
}
@@ -186,16 +190,16 @@ public class MultiType extends Type {
}
- private Map mergeMultiInterfaces(MultiType type1, MultiType type2) {
- Map map1 = getAllMultiInterfaces(type1);
- Map map2 = getAllMultiInterfaces(type2);
+ private Map<String,CtClass> mergeMultiInterfaces(MultiType type1, MultiType type2) {
+ Map<String,CtClass> map1 = getAllMultiInterfaces(type1);
+ Map<String,CtClass> map2 = getAllMultiInterfaces(type2);
return findCommonInterfaces(map1, map2);
}
- private Map mergeMultiAndSingle(MultiType multi, Type single) {
- Map map1 = getAllMultiInterfaces(multi);
- Map map2 = getAllInterfaces(single.getCtClass(), null);
+ private Map<String,CtClass> mergeMultiAndSingle(MultiType multi, Type single) {
+ Map<String,CtClass> map1 = getAllMultiInterfaces(multi);
+ Map<String,CtClass> map2 = getAllInterfaces(single.getCtClass(), null);
return findCommonInterfaces(map1, map2);
}
@@ -211,6 +215,7 @@ public class MultiType extends Type {
return false;
}
+ @Override
public Type merge(Type type) {
if (this == type)
return this;
@@ -235,7 +240,7 @@ public class MultiType extends Type {
}
}
- Map merged;
+ Map<String,CtClass> merged;
if (type instanceof MultiType) {
MultiType multi = (MultiType)type;
@@ -254,14 +259,13 @@ public class MultiType extends Type {
// Keep all previous merge paths up to date
if (merged.size() > 1 || (merged.size() == 1 && potentialClass != null)) {
// Check for changes
- if (merged.size() != interfaces.size()) {
+ if (merged.size() != interfaces.size())
changed = true;
- } else if (changed == false){
- Iterator iter = merged.keySet().iterator();
- while (iter.hasNext())
- if (! interfaces.containsKey(iter.next()))
+ else if (changed == false)
+ for (String key:merged.keySet())
+ if (!interfaces.containsKey(key))
changed = true;
- }
+
interfaces = merged;
propogateState();
@@ -269,19 +273,27 @@ public class MultiType extends Type {
return this;
}
- if (merged.size() == 1) {
- resolved = Type.get((CtClass) merged.values().iterator().next());
- } else if (potentialClass != null){
+ if (merged.size() == 1)
+ resolved = Type.get(merged.values().iterator().next());
+ else if (potentialClass != null)
resolved = potentialClass;
- } else {
+ else
resolved = OBJECT;
- }
propogateResolved();
return resolved;
}
+ @Override
+ public int hashCode() {
+ if (resolved != null)
+ return resolved.hashCode();
+
+ return interfaces.keySet().hashCode();
+ }
+
+ @Override
public boolean equals(Object o) {
if (! (o instanceof MultiType))
return false;
@@ -295,19 +307,18 @@ public class MultiType extends Type {
return interfaces.keySet().equals(multi.interfaces.keySet());
}
+ @Override
public String toString() {
if (resolved != null)
return resolved.toString();
StringBuffer buffer = new StringBuffer("{");
- Iterator iter = interfaces.keySet().iterator();
- while (iter.hasNext()) {
- buffer.append(iter.next());
- buffer.append(", ");
- }
- buffer.setLength(buffer.length() - 2);
+ for (String key:interfaces.keySet())
+ buffer.append(key).append(", ");
if (potentialClass != null)
- buffer.append(", *").append(potentialClass.toString());
+ buffer.append("*").append(potentialClass.toString());
+ else
+ buffer.setLength(buffer.length() - 2);
buffer.append("}");
return buffer.toString();
}
diff --git a/src/main/javassist/bytecode/analysis/Subroutine.java b/src/main/javassist/bytecode/analysis/Subroutine.java
index 381ed6ab..dff3084a 100644
--- a/src/main/javassist/bytecode/analysis/Subroutine.java
+++ b/src/main/javassist/bytecode/analysis/Subroutine.java
@@ -28,17 +28,17 @@ import java.util.Set;
*/
public class Subroutine {
//private Set callers = new HashSet();
- private List callers = new ArrayList();
- private Set access = new HashSet();
+ private List<Integer> callers = new ArrayList<Integer>();
+ private Set<Integer> access = new HashSet<Integer>();
private int start;
public Subroutine(int start, int caller) {
this.start = start;
- callers.add(Integer.valueOf(caller));
+ callers.add(caller);
}
public void addCaller(int caller) {
- callers.add(Integer.valueOf(caller));
+ callers.add(caller);
}
public int start() {
@@ -46,21 +46,22 @@ public class Subroutine {
}
public void access(int index) {
- access.add(Integer.valueOf(index));
+ access.add(index);
}
public boolean isAccessed(int index) {
- return access.contains(Integer.valueOf(index));
+ return access.contains(index);
}
- public Collection accessed() {
+ public Collection<Integer> accessed() {
return access;
}
- public Collection callers() {
+ public Collection<Integer> callers() {
return callers;
}
+ @Override
public String toString() {
return "start = " + start + " callers = " + callers.toString();
}
diff --git a/src/main/javassist/bytecode/analysis/SubroutineScanner.java b/src/main/javassist/bytecode/analysis/SubroutineScanner.java
index c0af816a..f9816267 100644
--- a/src/main/javassist/bytecode/analysis/SubroutineScanner.java
+++ b/src/main/javassist/bytecode/analysis/SubroutineScanner.java
@@ -35,8 +35,8 @@ import javassist.bytecode.Opcode;
public class SubroutineScanner implements Opcode {
private Subroutine[] subroutines;
- Map subTable = new HashMap();
- Set done = new HashSet();
+ Map<Integer,Subroutine> subTable = new HashMap<Integer,Subroutine>();
+ Set<Integer> done = new HashSet<Integer>();
public Subroutine[] scan(MethodInfo method) throws BadBytecode {
@@ -62,10 +62,10 @@ public class SubroutineScanner implements Opcode {
private void scan(int pos, CodeIterator iter, Subroutine sub) throws BadBytecode {
// Skip already processed blocks
- if (done.contains(Integer.valueOf(pos)))
+ if (done.contains(pos))
return;
- done.add(Integer.valueOf(pos));
+ done.add(pos);
int old = iter.lookAhead();
iter.move(pos);
@@ -103,10 +103,10 @@ public class SubroutineScanner implements Opcode {
if (Util.isJumpInstruction(opcode)) {
int target = Util.getJumpTarget(pos, iter);
if (opcode == JSR || opcode == JSR_W) {
- Subroutine s = (Subroutine) subTable.get(Integer.valueOf(target));
+ Subroutine s = subTable.get(target);
if (s == null) {
s = new Subroutine(target, pos);
- subTable.put(Integer.valueOf(target), s);
+ subTable.put(target, s);
scan(target, iter, s);
} else {
s.addCaller(pos);
diff --git a/src/main/javassist/bytecode/analysis/Type.java b/src/main/javassist/bytecode/analysis/Type.java
index ce02c172..db02df35 100644
--- a/src/main/javassist/bytecode/analysis/Type.java
+++ b/src/main/javassist/bytecode/analysis/Type.java
@@ -15,10 +15,8 @@
*/
package javassist.bytecode.analysis;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.IdentityHashMap;
-import java.util.Iterator;
import java.util.Map;
import javassist.ClassPool;
@@ -44,7 +42,7 @@ public class Type {
private final CtClass clazz;
private final boolean special;
- private static final Map prims = new IdentityHashMap();
+ private static final Map<CtClass,Type> prims = new IdentityHashMap<CtClass,Type>();
/** Represents the double primitive type */
public static final Type DOUBLE = new Type(CtClass.doubleType);
/** Represents the boolean primitive type */
@@ -451,7 +449,7 @@ public class Type {
// If its Object, then try and find a common interface(s)
if (superClass.getSuperclass() == null) {
- Map interfaces = findCommonInterfaces(type);
+ Map<String,CtClass> interfaces = findCommonInterfaces(type);
if (interfaces.size() == 1)
return new Type((CtClass) interfaces.values().iterator().next());
if (interfaces.size() > 1)
@@ -462,7 +460,7 @@ public class Type {
}
// Check for a common interface that is not on the found supertype
- Map commonDeclared = findExclusiveDeclaredInterfaces(type, superClass);
+ Map<String,CtClass> commonDeclared = findExclusiveDeclaredInterfaces(type, superClass);
if (commonDeclared.size() > 0) {
return new MultiType(commonDeclared, new Type(superClass));
}
@@ -470,21 +468,19 @@ public class Type {
return new Type(superClass);
}
- private Map findCommonInterfaces(Type type) {
- Map typeMap = getAllInterfaces(type.clazz, null);
- Map thisMap = getAllInterfaces(this.clazz, null);
+ private Map<String,CtClass> findCommonInterfaces(Type type) {
+ Map<String,CtClass> typeMap = getAllInterfaces(type.clazz, null);
+ Map<String,CtClass> thisMap = getAllInterfaces(this.clazz, null);
return findCommonInterfaces(typeMap, thisMap);
}
- private Map findExclusiveDeclaredInterfaces(Type type, CtClass exclude) {
- Map typeMap = getDeclaredInterfaces(type.clazz, null);
- Map thisMap = getDeclaredInterfaces(this.clazz, null);
- Map excludeMap = getAllInterfaces(exclude, null);
+ private Map<String,CtClass> findExclusiveDeclaredInterfaces(Type type, CtClass exclude) {
+ Map<String,CtClass> typeMap = getDeclaredInterfaces(type.clazz, null);
+ Map<String,CtClass> thisMap = getDeclaredInterfaces(this.clazz, null);
+ Map<String,CtClass> excludeMap = getAllInterfaces(exclude, null);
- Iterator i = excludeMap.keySet().iterator();
- while (i.hasNext()) {
- Object intf = i.next();
+ for (String intf:excludeMap.keySet()) {
typeMap.remove(intf);
thisMap.remove(intf);
}
@@ -493,19 +489,21 @@ public class Type {
}
- Map findCommonInterfaces(Map typeMap, Map alterMap) {
- Iterator i = alterMap.keySet().iterator();
- while (i.hasNext()) {
- if (! typeMap.containsKey(i.next()))
- i.remove();
- }
+ Map<String,CtClass> findCommonInterfaces(Map<String,CtClass> typeMap, Map<String,CtClass> alterMap) {
+ if (alterMap == null)
+ alterMap = new HashMap<String,CtClass>();
+
+ if (typeMap == null||typeMap.isEmpty())
+ alterMap.clear();
+
+ for (String name:alterMap.keySet())
+ if (!typeMap.containsKey(name))
+ alterMap.remove(name);
// Reduce to subinterfaces
// This does not need to be recursive since we make a copy,
// and that copy contains all super types for the whole hierarchy
- i = new ArrayList(alterMap.values()).iterator();
- while (i.hasNext()) {
- CtClass intf = (CtClass) i.next();
+ for (CtClass intf:alterMap.values()) {
CtClass[] interfaces;
try {
interfaces = intf.getInterfaces();
@@ -513,24 +511,23 @@ public class Type {
throw new RuntimeException(e);
}
- for (int c = 0; c < interfaces.length; c++)
- alterMap.remove(interfaces[c].getName());
+ for (CtClass c:interfaces)
+ alterMap.remove(c.getName());
}
return alterMap;
}
- Map getAllInterfaces(CtClass clazz, Map map) {
+ Map<String,CtClass> getAllInterfaces(CtClass clazz, Map<String,CtClass> map) {
if (map == null)
- map = new HashMap();
+ map = new HashMap<String,CtClass>();
if (clazz.isInterface())
map.put(clazz.getName(), clazz);
do {
try {
CtClass[] interfaces = clazz.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- CtClass intf = interfaces[i];
+ for (CtClass intf:interfaces) {
map.put(intf.getName(), intf);
getAllInterfaces(intf, map);
}
@@ -544,9 +541,9 @@ public class Type {
return map;
}
- Map getDeclaredInterfaces(CtClass clazz, Map map) {
+ Map<String,CtClass> getDeclaredInterfaces(CtClass clazz, Map<String,CtClass> map) {
if (map == null)
- map = new HashMap();
+ map = new HashMap<String,CtClass>();
if (clazz.isInterface())
map.put(clazz.getName(), clazz);
@@ -558,8 +555,7 @@ public class Type {
throw new RuntimeException(e);
}
- for (int i = 0; i < interfaces.length; i++) {
- CtClass intf = interfaces[i];
+ for (CtClass intf:interfaces) {
map.put(intf.getName(), intf);
getDeclaredInterfaces(intf, map);
}
@@ -567,6 +563,12 @@ public class Type {
return map;
}
+ @Override
+ public int hashCode() {
+ return getClass().hashCode() + clazz.hashCode();
+ }
+
+ @Override
public boolean equals(Object o) {
if (! (o instanceof Type))
return false;
@@ -578,6 +580,7 @@ public class Type {
return one == two || (one != null && two != null && one.getName().equals(two.getName()));
}
+ @Override
public String toString() {
if (this == BOGUS)
return "BOGUS";
diff --git a/src/main/javassist/bytecode/annotation/Annotation.java b/src/main/javassist/bytecode/annotation/Annotation.java
index 10ceb8ee..1cec468b 100644
--- a/src/main/javassist/bytecode/annotation/Annotation.java
+++ b/src/main/javassist/bytecode/annotation/Annotation.java
@@ -16,17 +16,17 @@
package javassist.bytecode.annotation;
-import javassist.bytecode.ConstPool;
-import javassist.bytecode.Descriptor;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
-
-import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Set;
-import java.util.Iterator;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
/**
* The <code>annotation</code> structure.
@@ -53,7 +53,7 @@ public class Annotation {
ConstPool pool;
int typeIndex;
- LinkedHashMap members; // this sould be LinkedHashMap
+ Map<String,Pair> members; // this sould be LinkedHashMap
// but it is not supported by JDK 1.3.
/**
@@ -106,17 +106,13 @@ public class Annotation {
throw new RuntimeException(
"Only interfaces are allowed for Annotation creation.");
- CtMethod methods[] = clazz.getDeclaredMethods();
- if (methods.length > 0) {
- members = new LinkedHashMap();
- }
+ CtMethod[] methods = clazz.getDeclaredMethods();
+ if (methods.length > 0)
+ members = new LinkedHashMap<String,Pair>();
- for (int i = 0; i < methods.length; i++) {
- CtClass returnType = methods[i].getReturnType();
- addMemberValue(methods[i].getName(),
- createMemberValue(cp, returnType));
-
- }
+ for (CtMethod m:methods)
+ addMemberValue(m.getName(),
+ createMemberValue(cp, m.getReturnType()));
}
/**
@@ -196,7 +192,7 @@ public class Annotation {
p.name = pool.addUtf8Info(name);
p.value = value;
if (members == null)
- members = new LinkedHashMap();
+ members = new LinkedHashMap<String,Pair>();
members.put(name, p);
}
@@ -204,7 +200,7 @@ public class Annotation {
private void addMemberValue(Pair pair) {
String name = pool.getUtf8Info(pair.name);
if (members == null)
- members = new LinkedHashMap();
+ members = new LinkedHashMap<String,Pair>();
members.put(name, pair);
}
@@ -212,18 +208,18 @@ public class Annotation {
/**
* Returns a string representation of the annotation.
*/
+ @Override
public String toString() {
StringBuffer buf = new StringBuffer("@");
buf.append(getTypeName());
if (members != null) {
buf.append("(");
- Iterator mit = members.keySet().iterator();
- while (mit.hasNext()) {
- String name = (String)mit.next();
- buf.append(name).append("=").append(getMemberValue(name));
- if (mit.hasNext())
- buf.append(", ");
+ for (String name:members.keySet()) {
+ buf.append(name).append("=")
+ .append(getMemberValue(name))
+ .append(", ");
}
+ buf.setLength(buf.length()-2);
buf.append(")");
}
@@ -244,11 +240,10 @@ public class Annotation {
*
* @return null if no members are defined.
*/
- public Set getMemberNames() {
+ public Set<String> getMemberNames() {
if (members == null)
return null;
- else
- return members.keySet();
+ return members.keySet();
}
/**
@@ -267,15 +262,9 @@ public class Annotation {
* @see javassist.bytecode.AnnotationDefaultAttribute
*/
public MemberValue getMemberValue(String name) {
- if (members == null)
+ if (members == null||members.get(name) == null)
return null;
- else {
- Pair p = (Pair)members.get(name);
- if (p == null)
- return null;
- else
- return p.value;
- }
+ return members.get(name).value;
}
/**
@@ -292,9 +281,9 @@ public class Annotation {
public Object toAnnotationType(ClassLoader cl, ClassPool cp)
throws ClassNotFoundException, NoSuchClassError
{
- Class clazz = MemberValue.loadClass(cl, getTypeName());
+ Class<?> clazz = MemberValue.loadClass(cl, getTypeName());
try {
- return AnnotationImpl.make(cl, clazz, cp, this);
+ return AnnotationImpl.make(cl, clazz, cp, this);
}
catch (IllegalArgumentException e) {
/* AnnotationImpl.make() may throw this exception
@@ -323,30 +312,35 @@ public class Annotation {
}
writer.annotation(typeName, members.size());
- Iterator it = members.values().iterator();
- while (it.hasNext()) {
- Pair pair = (Pair)it.next();
+ for (Pair pair:members.values()) {
writer.memberValuePair(pair.name);
pair.value.write(writer);
}
}
+ @Override
+ public int hashCode() {
+ return getTypeName().hashCode() +
+ (members == null ? 0 : members.hashCode());
+ }
+
/**
* Returns true if the given object represents the same annotation
* as this object. The equality test checks the member values.
*/
+ @Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || obj instanceof Annotation == false)
return false;
-
+
Annotation other = (Annotation) obj;
if (getTypeName().equals(other.getTypeName()) == false)
return false;
- LinkedHashMap otherMembers = other.members;
+ Map<String,Pair> otherMembers = other.members;
if (members == otherMembers)
return true;
else if (members == null)
diff --git a/src/main/javassist/bytecode/annotation/AnnotationImpl.java b/src/main/javassist/bytecode/annotation/AnnotationImpl.java
index 672d2f3c..e1706098 100644
--- a/src/main/javassist/bytecode/annotation/AnnotationImpl.java
+++ b/src/main/javassist/bytecode/annotation/AnnotationImpl.java
@@ -38,24 +38,24 @@ import javassist.bytecode.MethodInfo;
public class AnnotationImpl implements InvocationHandler {
private static final String JDK_ANNOTATION_CLASS_NAME = "java.lang.annotation.Annotation";
private static Method JDK_ANNOTATION_TYPE_METHOD = null;
-
+
private Annotation annotation;
private ClassPool pool;
private ClassLoader classLoader;
- private transient Class annotationType;
+ private transient Class<?> annotationType;
private transient int cachedHashCode = Integer.MIN_VALUE;
static {
// Try to resolve the JDK annotation type method
try {
- Class clazz = Class.forName(JDK_ANNOTATION_CLASS_NAME);
+ Class<?> clazz = Class.forName(JDK_ANNOTATION_CLASS_NAME);
JDK_ANNOTATION_TYPE_METHOD = clazz.getMethod("annotationType", (Class[])null);
}
catch (Exception ignored) {
// Probably not JDK5+
}
}
-
+
/**
* Constructs an annotation object.
*
@@ -66,14 +66,14 @@ public class AnnotationImpl implements InvocationHandler {
* @param anon the annotation.
* @return the annotation
*/
- public static Object make(ClassLoader cl, Class clazz, ClassPool cp,
+ public static Object make(ClassLoader cl, Class<?> clazz, ClassPool cp,
Annotation anon)
throws IllegalArgumentException
{
AnnotationImpl handler = new AnnotationImpl(anon, cp, cl);
return Proxy.newProxyInstance(cl, new Class[] { clazz }, handler);
}
-
+
private AnnotationImpl(Annotation a, ClassPool cp, ClassLoader loader) {
annotation = a;
pool = cp;
@@ -95,7 +95,7 @@ public class AnnotationImpl implements InvocationHandler {
* @return the annotation class
* @throws NoClassDefFoundError when the class could not loaded
*/
- private Class getAnnotationType() {
+ private Class<?> getAnnotationType() {
if (annotationType == null) {
String typeName = annotation.getTypeName();
try {
@@ -109,7 +109,7 @@ public class AnnotationImpl implements InvocationHandler {
}
return annotationType;
}
-
+
/**
* Obtains the internal data structure representing the annotation.
*
@@ -126,6 +126,7 @@ public class AnnotationImpl implements InvocationHandler {
* <code>AnnotationImpl</code>. The <code>annotationType()</code> method
* is also available on the proxy instance.
*/
+ @Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
@@ -147,10 +148,9 @@ public class AnnotationImpl implements InvocationHandler {
MemberValue mv = annotation.getMemberValue(name);
if (mv == null)
return getDefault(name, method);
- else
- return mv.getValue(classLoader, pool, method);
+ return mv.getValue(classLoader, pool, method);
}
-
+
private Object getDefault(String name, Method method)
throws ClassNotFoundException, RuntimeException
{
@@ -183,6 +183,7 @@ public class AnnotationImpl implements InvocationHandler {
/**
* Returns a hash code value for this object.
*/
+ @Override
public int hashCode() {
if (cachedHashCode == Integer.MIN_VALUE) {
int hashCode = 0;
@@ -217,15 +218,15 @@ public class AnnotationImpl implements InvocationHandler {
valueHashCode = arrayHashCode(value);
else
valueHashCode = value.hashCode();
- }
+ }
hashCode += 127 * name.hashCode() ^ valueHashCode;
}
-
+
cachedHashCode = hashCode;
}
return cachedHashCode;
}
-
+
/**
* Check that another annotation equals ourselves.
*
@@ -246,10 +247,10 @@ public class AnnotationImpl implements InvocationHandler {
}
}
- Class otherAnnotationType = (Class) JDK_ANNOTATION_TYPE_METHOD.invoke(obj, (Object[])null);
+ Class<?> otherAnnotationType = (Class<?>) JDK_ANNOTATION_TYPE_METHOD.invoke(obj);
if (getAnnotationType().equals(otherAnnotationType) == false)
return false;
-
+
Method[] methods = annotationType.getDeclaredMethods();
for (int i = 0; i < methods.length; ++ i) {
String name = methods[i].getName();
@@ -263,7 +264,7 @@ public class AnnotationImpl implements InvocationHandler {
value = mv.getValue(classLoader, pool, methods[i]);
if (value == null)
value = getDefault(name, methods[i]);
- otherValue = methods[i].invoke(obj, (Object[])null);
+ otherValue = methods[i].invoke(obj);
}
catch (RuntimeException e) {
throw e;
@@ -277,7 +278,7 @@ public class AnnotationImpl implements InvocationHandler {
if (value != null && value.equals(otherValue) == false)
return false;
}
-
+
return true;
}
@@ -294,7 +295,7 @@ public class AnnotationImpl implements InvocationHandler {
return 0;
int result = 1;
-
+
Object[] array = (Object[]) object;
for (int i = 0; i < array.length; ++i) {
int elementHashCode = 0;
diff --git a/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java b/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java
index b1237114..7691e44f 100644
--- a/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java
@@ -15,11 +15,12 @@
*/
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Nested annotation.
*
@@ -45,17 +46,18 @@ public class AnnotationMemberValue extends MemberValue {
value = a;
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m)
throws ClassNotFoundException
{
return AnnotationImpl.make(cl, getType(cl), cp, value);
}
- Class getType(ClassLoader cl) throws ClassNotFoundException {
+ @Override
+ Class<?> getType(ClassLoader cl) throws ClassNotFoundException {
if (value == null)
throw new ClassNotFoundException("no type specified");
- else
- return loadClass(cl, value.getTypeName());
+ return loadClass(cl, value.getTypeName());
}
/**
@@ -75,6 +77,7 @@ public class AnnotationMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return value.toString();
}
@@ -82,6 +85,7 @@ public class AnnotationMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.annotationValue();
value.write(writer);
@@ -90,6 +94,7 @@ public class AnnotationMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitAnnotationMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/AnnotationsWriter.java b/src/main/javassist/bytecode/annotation/AnnotationsWriter.java
index e2203d4e..8095fbe1 100644
--- a/src/main/javassist/bytecode/annotation/AnnotationsWriter.java
+++ b/src/main/javassist/bytecode/annotation/AnnotationsWriter.java
@@ -16,7 +16,8 @@
package javassist.bytecode.annotation;
-import java.io.*;
+import java.io.IOException;
+import java.io.OutputStream;
import javassist.bytecode.ByteArray;
import javassist.bytecode.ConstPool;
diff --git a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java
index 389bdf90..d1eeb271 100644
--- a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java
@@ -15,12 +15,13 @@
*/
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Array member.
*
@@ -51,6 +52,7 @@ public class ArrayMemberValue extends MemberValue {
values = null;
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method method)
throws ClassNotFoundException
{
@@ -59,7 +61,7 @@ public class ArrayMemberValue extends MemberValue {
"no array elements found: " + method.getName());
int size = values.length;
- Class clazz;
+ Class<?> clazz;
if (type == null) {
clazz = method.getReturnType().getComponentType();
if (clazz == null || size > 0)
@@ -76,7 +78,8 @@ public class ArrayMemberValue extends MemberValue {
return a;
}
- Class getType(ClassLoader cl) throws ClassNotFoundException {
+ @Override
+ Class<?> getType(ClassLoader cl) throws ClassNotFoundException {
if (type == null)
throw new ClassNotFoundException("no array type specified");
@@ -112,6 +115,7 @@ public class ArrayMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
StringBuffer buf = new StringBuffer("{");
if (values != null) {
@@ -129,6 +133,7 @@ public class ArrayMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
int num = values == null ? 0 : values.length;
writer.arrayValue(num);
@@ -139,6 +144,7 @@ public class ArrayMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitArrayMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java
index b005ad5a..c9ec3c32 100644
--- a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java
@@ -15,11 +15,12 @@
*/
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Boolean constant value.
*
@@ -58,11 +59,13 @@ public class BooleanMemberValue extends MemberValue {
setValue(false);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Boolean.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return boolean.class;
}
@@ -83,6 +86,7 @@ public class BooleanMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return getValue() ? "true" : "false";
}
@@ -90,6 +94,7 @@ public class BooleanMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -97,6 +102,7 @@ public class BooleanMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitBooleanMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/ByteMemberValue.java b/src/main/javassist/bytecode/annotation/ByteMemberValue.java
index d0fb5c61..be3f6e2e 100644
--- a/src/main/javassist/bytecode/annotation/ByteMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/ByteMemberValue.java
@@ -15,11 +15,12 @@
*/
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Byte constant value.
*
@@ -58,11 +59,13 @@ public class ByteMemberValue extends MemberValue {
setValue((byte)0);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Byte.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return byte.class;
}
@@ -83,6 +86,7 @@ public class ByteMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Byte.toString(getValue());
}
@@ -90,6 +94,7 @@ public class ByteMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -97,6 +102,7 @@ public class ByteMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitByteMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/CharMemberValue.java b/src/main/javassist/bytecode/annotation/CharMemberValue.java
index ce5d4199..bf8d7b44 100644
--- a/src/main/javassist/bytecode/annotation/CharMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/CharMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Char constant value.
*
@@ -59,11 +60,13 @@ public class CharMemberValue extends MemberValue {
setValue('\0');
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Character.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return char.class;
}
@@ -84,6 +87,7 @@ public class CharMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Character.toString(getValue());
}
@@ -91,6 +95,7 @@ public class CharMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -98,6 +103,7 @@ public class CharMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitCharMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/ClassMemberValue.java b/src/main/javassist/bytecode/annotation/ClassMemberValue.java
index 7169d723..e9fd7ec4 100644
--- a/src/main/javassist/bytecode/annotation/ClassMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/ClassMemberValue.java
@@ -16,15 +16,15 @@
package javassist.bytecode.annotation;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
import javassist.ClassPool;
import javassist.bytecode.BadBytecode;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
import javassist.bytecode.SignatureAttribute;
-import java.io.IOException;
-import java.lang.reflect.Method;
-
/**
* Class value.
*
@@ -64,6 +64,7 @@ public class ClassMemberValue extends MemberValue {
setValue("java.lang.Class");
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m)
throws ClassNotFoundException {
final String classname = getValue();
@@ -89,7 +90,8 @@ public class ClassMemberValue extends MemberValue {
return loadClass(cl, classname);
}
- Class getType(ClassLoader cl) throws ClassNotFoundException {
+ @Override
+ Class<?> getType(ClassLoader cl) throws ClassNotFoundException {
return loadClass(cl, "java.lang.Class");
}
@@ -120,6 +122,7 @@ public class ClassMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return getValue().replace('$', '.') + ".class";
}
@@ -127,6 +130,7 @@ public class ClassMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.classInfoIndex(cp.getUtf8Info(valueIndex));
}
@@ -134,6 +138,7 @@ public class ClassMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitClassMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java
index 0f18a72d..3d9fdb28 100644
--- a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Double floating-point number constant value.
*
@@ -60,11 +61,13 @@ public class DoubleMemberValue extends MemberValue {
setValue(0.0);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Double.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return double.class;
}
@@ -85,6 +88,7 @@ public class DoubleMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Double.toString(getValue());
}
@@ -92,6 +96,7 @@ public class DoubleMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -99,6 +104,7 @@ public class DoubleMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitDoubleMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/EnumMemberValue.java b/src/main/javassist/bytecode/annotation/EnumMemberValue.java
index a051b3a4..a0a4e036 100644
--- a/src/main/javassist/bytecode/annotation/EnumMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/EnumMemberValue.java
@@ -56,6 +56,7 @@ public class EnumMemberValue extends MemberValue {
typeIndex = valueIndex = 0;
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m)
throws ClassNotFoundException
{
@@ -70,7 +71,8 @@ public class EnumMemberValue extends MemberValue {
}
}
- Class getType(ClassLoader cl) throws ClassNotFoundException {
+ @Override
+ Class<?> getType(ClassLoader cl) throws ClassNotFoundException {
return loadClass(cl, getType());
}
@@ -86,7 +88,7 @@ public class EnumMemberValue extends MemberValue {
/**
* Changes the enum type name.
*
- * @param typename a fully-qualified type name.
+ * @param typename a fully-qualified type name.
*/
public void setType(String typename) {
typeIndex = cp.addUtf8Info(Descriptor.of(typename));
@@ -106,6 +108,7 @@ public class EnumMemberValue extends MemberValue {
valueIndex = cp.addUtf8Info(name);
}
+ @Override
public String toString() {
return getType() + "." + getValue();
}
@@ -113,6 +116,7 @@ public class EnumMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.enumConstValue(cp.getUtf8Info(typeIndex), getValue());
}
@@ -120,6 +124,7 @@ public class EnumMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitEnumMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/FloatMemberValue.java b/src/main/javassist/bytecode/annotation/FloatMemberValue.java
index 3bf07ef0..ef993792 100644
--- a/src/main/javassist/bytecode/annotation/FloatMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/FloatMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Floating-point number constant value.
*
@@ -60,11 +61,13 @@ public class FloatMemberValue extends MemberValue {
setValue(0.0F);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Float.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return float.class;
}
@@ -85,6 +88,7 @@ public class FloatMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Float.toString(getValue());
}
@@ -92,6 +96,7 @@ public class FloatMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -99,6 +104,7 @@ public class FloatMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitFloatMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java
index 83e4e70f..538b620c 100644
--- a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Integer constant value.
*
@@ -65,11 +66,13 @@ public class IntegerMemberValue extends MemberValue {
setValue(0);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Integer.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return int.class;
}
@@ -90,6 +93,7 @@ public class IntegerMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Integer.toString(getValue());
}
@@ -97,6 +101,7 @@ public class IntegerMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -104,6 +109,7 @@ public class IntegerMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitIntegerMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/LongMemberValue.java b/src/main/javassist/bytecode/annotation/LongMemberValue.java
index 7f0c6fec..3dd29a37 100644
--- a/src/main/javassist/bytecode/annotation/LongMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/LongMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Long integer constant value.
*
@@ -59,11 +60,13 @@ public class LongMemberValue extends MemberValue {
setValue(0L);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Long.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return long.class;
}
@@ -84,6 +87,7 @@ public class LongMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Long.toString(getValue());
}
@@ -91,6 +95,7 @@ public class LongMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -98,6 +103,7 @@ public class LongMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitLongMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/MemberValue.java b/src/main/javassist/bytecode/annotation/MemberValue.java
index ab60c959..da99885c 100644
--- a/src/main/javassist/bytecode/annotation/MemberValue.java
+++ b/src/main/javassist/bytecode/annotation/MemberValue.java
@@ -16,14 +16,13 @@
package javassist.bytecode.annotation;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
import javassist.ClassPool;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
-import java.io.IOException;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-
/**
* The value of a member declared in an annotation.
*
@@ -47,9 +46,9 @@ public abstract class MemberValue {
abstract Object getValue(ClassLoader cl, ClassPool cp, Method m)
throws ClassNotFoundException;
- abstract Class getType(ClassLoader cl) throws ClassNotFoundException;
+ abstract Class<?> getType(ClassLoader cl) throws ClassNotFoundException;
- static Class loadClass(ClassLoader cl, String classname)
+ static Class<?> loadClass(ClassLoader cl, String classname)
throws ClassNotFoundException, NoSuchClassError
{
try {
@@ -59,10 +58,10 @@ public abstract class MemberValue {
throw new NoSuchClassError(classname, e);
}
}
-
+
private static String convertFromArray(String classname)
{
- int index = classname.indexOf("[]");
+ int index = classname.indexOf("[]");
if (index != -1) {
String rawType = classname.substring(0, index);
StringBuffer sb = new StringBuffer(Descriptor.of(rawType));
diff --git a/src/main/javassist/bytecode/annotation/NoSuchClassError.java b/src/main/javassist/bytecode/annotation/NoSuchClassError.java
index 64187f8c..a2b23b34 100644
--- a/src/main/javassist/bytecode/annotation/NoSuchClassError.java
+++ b/src/main/javassist/bytecode/annotation/NoSuchClassError.java
@@ -21,6 +21,8 @@ package javassist.bytecode.annotation;
* It keeps the name of the class that caused this error.
*/
public class NoSuchClassError extends Error {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private String className;
/**
diff --git a/src/main/javassist/bytecode/annotation/ShortMemberValue.java b/src/main/javassist/bytecode/annotation/ShortMemberValue.java
index 82a6f59e..277c2820 100644
--- a/src/main/javassist/bytecode/annotation/ShortMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/ShortMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* Short integer constant value.
*
@@ -59,11 +60,13 @@ public class ShortMemberValue extends MemberValue {
setValue((short)0);
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return Short.valueOf(getValue());
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return short.class;
}
@@ -84,6 +87,7 @@ public class ShortMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return Short.toString(getValue());
}
@@ -91,6 +95,7 @@ public class ShortMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -98,6 +103,7 @@ public class ShortMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitShortMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/StringMemberValue.java b/src/main/javassist/bytecode/annotation/StringMemberValue.java
index 7e83f923..48fe1f6e 100644
--- a/src/main/javassist/bytecode/annotation/StringMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/StringMemberValue.java
@@ -16,11 +16,12 @@
package javassist.bytecode.annotation;
-import javassist.ClassPool;
-import javassist.bytecode.ConstPool;
import java.io.IOException;
import java.lang.reflect.Method;
+import javassist.ClassPool;
+import javassist.bytecode.ConstPool;
+
/**
* String constant value.
*
@@ -59,11 +60,13 @@ public class StringMemberValue extends MemberValue {
setValue("");
}
+ @Override
Object getValue(ClassLoader cl, ClassPool cp, Method m) {
return getValue();
}
- Class getType(ClassLoader cl) {
+ @Override
+ Class<?> getType(ClassLoader cl) {
return String.class;
}
@@ -84,6 +87,7 @@ public class StringMemberValue extends MemberValue {
/**
* Obtains the string representation of this object.
*/
+ @Override
public String toString() {
return "\"" + getValue() + "\"";
}
@@ -91,6 +95,7 @@ public class StringMemberValue extends MemberValue {
/**
* Writes the value.
*/
+ @Override
public void write(AnnotationsWriter writer) throws IOException {
writer.constValueIndex(getValue());
}
@@ -98,6 +103,7 @@ public class StringMemberValue extends MemberValue {
/**
* Accepts a visitor.
*/
+ @Override
public void accept(MemberValueVisitor visitor) {
visitor.visitStringMemberValue(this);
}
diff --git a/src/main/javassist/bytecode/annotation/TypeAnnotationsWriter.java b/src/main/javassist/bytecode/annotation/TypeAnnotationsWriter.java
index d9a61692..6f765b41 100644
--- a/src/main/javassist/bytecode/annotation/TypeAnnotationsWriter.java
+++ b/src/main/javassist/bytecode/annotation/TypeAnnotationsWriter.java
@@ -28,6 +28,7 @@ public class TypeAnnotationsWriter extends AnnotationsWriter {
* {@code Runtime(In)VisibleTypeAnnotations_attribute}.
* It must be followed by {@code num} instances of {@code type_annotation}.
*/
+ @Override
public void numAnnotations(int num) throws IOException {
super.numAnnotations(num);
}
diff --git a/src/main/javassist/bytecode/stackmap/BasicBlock.java b/src/main/javassist/bytecode/stackmap/BasicBlock.java
index 7a643609..231ffc3a 100644
--- a/src/main/javassist/bytecode/stackmap/BasicBlock.java
+++ b/src/main/javassist/bytecode/stackmap/BasicBlock.java
@@ -16,9 +16,18 @@
package javassist.bytecode.stackmap;
-import javassist.bytecode.*;
-import java.util.HashMap;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javassist.bytecode.BadBytecode;
+import javassist.bytecode.CodeAttribute;
+import javassist.bytecode.CodeIterator;
+import javassist.bytecode.ExceptionTable;
+import javassist.bytecode.MethodInfo;
+import javassist.bytecode.Opcode;
/**
* A basic block is a sequence of bytecode that does not contain jump/branch
@@ -28,6 +37,9 @@ import java.util.ArrayList;
*/
public class BasicBlock {
static class JsrBytecode extends BadBytecode {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
JsrBytecode() { super("JSR"); }
}
@@ -46,11 +58,9 @@ public class BasicBlock {
public static BasicBlock find(BasicBlock[] blocks, int pos)
throws BadBytecode
{
- for (int i = 0; i < blocks.length; i++) {
- int iPos = blocks[i].position;
- if (iPos <= pos && pos < iPos + blocks[i].length)
- return blocks[i];
- }
+ for (BasicBlock b:blocks)
+ if (b.position <= pos && pos < b.position + b.length)
+ return b;
throw new BadBytecode("no basic block at " + pos);
}
@@ -66,6 +76,7 @@ public class BasicBlock {
}
}
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
String cname = this.getClass().getName();
@@ -81,10 +92,9 @@ public class BasicBlock {
sbuf.append("pos=").append(position).append(", len=")
.append(length).append(", in=").append(incoming)
.append(", exit{");
- if (exit != null) {
- for (int i = 0; i < exit.length; i++)
- sbuf.append(exit[i].position).append(",");
- }
+ if (exit != null)
+ for (BasicBlock b:exit)
+ sbuf.append(b.position).append(",");
sbuf.append("}, {");
Catch th = toCatch;
@@ -101,7 +111,7 @@ public class BasicBlock {
* A Mark indicates the position of a branch instruction
* or a branch target.
*/
- static class Mark implements Comparable {
+ static class Mark implements Comparable<Mark> {
int position;
BasicBlock block;
BasicBlock[] jump;
@@ -118,13 +128,11 @@ public class BasicBlock {
catcher = null;
}
- public int compareTo(Object obj) {
- if (obj instanceof Mark) {
- int pos = ((Mark)obj).position;
- return position - pos;
- }
-
- return -1;
+ @Override
+ public int compareTo(Mark obj) {
+ if (null == obj)
+ return -1;
+ return position - obj.position;
}
void setJump(BasicBlock[] bb, int s, boolean always) {
@@ -172,7 +180,7 @@ public class BasicBlock {
ExceptionTable et)
throws BadBytecode
{
- HashMap marks = makeMarks(ci, begin, end, et);
+ Map<Integer,Mark> marks = makeMarks(ci, begin, end, et);
BasicBlock[] bb = makeBlocks(marks);
addCatchers(bb, et);
return bb;
@@ -180,24 +188,24 @@ public class BasicBlock {
/* Branch target
*/
- private Mark makeMark(HashMap table, int pos) {
+ private Mark makeMark(Map<Integer,Mark> table, int pos) {
return makeMark0(table, pos, true, true);
}
/* Branch instruction.
* size > 0
*/
- private Mark makeMark(HashMap table, int pos, BasicBlock[] jump,
+ private Mark makeMark(Map<Integer,Mark> table, int pos, BasicBlock[] jump,
int size, boolean always) {
Mark m = makeMark0(table, pos, false, false);
m.setJump(jump, size, always);
return m;
}
- private Mark makeMark0(HashMap table, int pos,
+ private Mark makeMark0(Map<Integer,Mark> table, int pos,
boolean isBlockBegin, boolean isTarget) {
- Integer p = Integer.valueOf(pos);
- Mark m = (Mark)table.get(p);
+ Integer p = pos;
+ Mark m = table.get(p);
if (m == null) {
m = new Mark(pos);
table.put(p, m);
@@ -214,13 +222,13 @@ public class BasicBlock {
return m;
}
- private HashMap makeMarks(CodeIterator ci, int begin, int end,
+ private Map<Integer,Mark> makeMarks(CodeIterator ci, int begin, int end,
ExceptionTable et)
throws BadBytecode
{
ci.begin();
ci.move(begin);
- HashMap marks = new HashMap();
+ Map<Integer,Mark> marks = new HashMap<Integer,Mark>();
while (ci.hasNext()) {
int index = ci.next();
if (index >= end)
@@ -296,7 +304,7 @@ public class BasicBlock {
return marks;
}
- private void makeGoto(HashMap marks, int pos, int target, int size) {
+ private void makeGoto(Map<Integer,Mark> marks, int pos, int target, int size) {
Mark to = makeMark(marks, target);
BasicBlock[] jumps = makeArray(to.block);
makeMark(marks, pos, jumps, size, true);
@@ -306,7 +314,7 @@ public class BasicBlock {
* We could ignore JSR since Java 7 or later does not allow it.
* See The JVM Spec. Sec. 4.10.2.5.
*/
- protected void makeJsr(HashMap marks, int pos, int target, int size) throws BadBytecode {
+ protected void makeJsr(Map<Integer,Mark> marks, int pos, int target, int size) throws BadBytecode {
/*
Mark to = makeMark(marks, target);
Mark next = makeMark(marks, pos + size);
@@ -316,11 +324,10 @@ public class BasicBlock {
throw new JsrBytecode();
}
- private BasicBlock[] makeBlocks(HashMap markTable) {
- Mark[] marks = (Mark[])markTable.values()
- .toArray(new Mark[markTable.size()]);
- java.util.Arrays.sort(marks);
- ArrayList blocks = new ArrayList();
+ private BasicBlock[] makeBlocks(Map<Integer,Mark> markTable) {
+ Mark[] marks = markTable.values().toArray(new Mark[markTable.size()]);
+ Arrays.sort(marks);
+ List<BasicBlock> blocks = new ArrayList<BasicBlock>();
int i = 0;
BasicBlock prev;
if (marks.length > 0 && marks[0].position == 0 && marks[0].block != null)
@@ -370,7 +377,7 @@ public class BasicBlock {
}
}
- return (BasicBlock[])blocks.toArray(makeArray(blocks.size()));
+ return blocks.toArray(makeArray(blocks.size()));
}
private static BasicBlock getBBlock(Mark m) {
diff --git a/src/main/javassist/bytecode/stackmap/MapMaker.java b/src/main/javassist/bytecode/stackmap/MapMaker.java
index 5c4d7a53..538fba67 100644
--- a/src/main/javassist/bytecode/stackmap/MapMaker.java
+++ b/src/main/javassist/bytecode/stackmap/MapMaker.java
@@ -17,10 +17,18 @@
package javassist.bytecode.stackmap;
import java.util.ArrayList;
+import java.util.List;
+
import javassist.ClassPool;
-import javassist.CtClass;
import javassist.NotFoundException;
-import javassist.bytecode.*;
+import javassist.bytecode.BadBytecode;
+import javassist.bytecode.ByteArray;
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.CodeAttribute;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.MethodInfo;
+import javassist.bytecode.StackMap;
+import javassist.bytecode.StackMapTable;
/**
* Stack map maker.
@@ -379,7 +387,7 @@ public class MapMaker extends Tracer {
* their types are also fixed when they are found.
*/
private void fixTypes(byte[] code, TypedBlock[] blocks) throws NotFoundException, BadBytecode {
- ArrayList preOrder = new ArrayList();
+ List<TypeData> preOrder = new ArrayList<TypeData>();
int len = blocks.length;
int index = 0;
for (int i = 0; i < len; i++) {
@@ -522,8 +530,7 @@ public class MapMaker extends Tracer {
return diffSize(newTd, len, newTdLen);
else
return -diffSize(oldTd, len, oldTdLen);
- else
- return -100;
+ return -100;
}
private static boolean stackMapEq(TypeData[] oldTd, TypeData[] newTd, int len) {
diff --git a/src/main/javassist/bytecode/stackmap/Tracer.java b/src/main/javassist/bytecode/stackmap/Tracer.java
index 182935e6..6f99e5f7 100644
--- a/src/main/javassist/bytecode/stackmap/Tracer.java
+++ b/src/main/javassist/bytecode/stackmap/Tracer.java
@@ -16,12 +16,12 @@
package javassist.bytecode.stackmap;
+import javassist.ClassPool;
+import javassist.bytecode.BadBytecode;
import javassist.bytecode.ByteArray;
-import javassist.bytecode.Opcode;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
-import javassist.bytecode.BadBytecode;
-import javassist.ClassPool;
+import javassist.bytecode.Opcode;
/*
* A class for performing abstract interpretation.
@@ -69,16 +69,13 @@ public abstract class Tracer implements TypeTag {
protected int doOpcode(int pos, byte[] code) throws BadBytecode {
try {
int op = code[pos] & 0xff;
+ if (op < 54)
+ return doOpcode0_53(pos, code, op);
if (op < 96)
- if (op < 54)
- return doOpcode0_53(pos, code, op);
- else
- return doOpcode54_95(pos, code, op);
- else
- if (op < 148)
- return doOpcode96_147(pos, code, op);
- else
- return doOpcode148_201(pos, code, op);
+ return doOpcode54_95(pos, code, op);
+ if (op < 148)
+ return doOpcode96_147(pos, code, op);
+ return doOpcode148_201(pos, code, op);
}
catch (ArrayIndexOutOfBoundsException e) {
throw new BadBytecode("inconsistent stack height " + e.getMessage(), e);
diff --git a/src/main/javassist/bytecode/stackmap/TypeData.java b/src/main/javassist/bytecode/stackmap/TypeData.java
index 206fd52a..9bc837d3 100644
--- a/src/main/javassist/bytecode/stackmap/TypeData.java
+++ b/src/main/javassist/bytecode/stackmap/TypeData.java
@@ -16,16 +16,19 @@
package javassist.bytecode.stackmap;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
+import javassist.bytecode.BadBytecode;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
import javassist.bytecode.StackMapTable;
-import javassist.bytecode.BadBytecode;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.ArrayList;
public abstract class TypeData {
/* Memo:
@@ -49,6 +52,7 @@ public abstract class TypeData {
*
* @param className dot-separated name unless the type is an array type.
*/
+ @SuppressWarnings("unused")
private static void setType(TypeData td, String className, ClassPool cp) throws BadBytecode {
td.setType(className, cp);
}
@@ -89,7 +93,7 @@ public abstract class TypeData {
* @param order a node stack in the order in which nodes are visited.
* @param index the index used by the algorithm.
*/
- public int dfs(ArrayList order, int index, ClassPool cp)
+ public int dfs(List<TypeData> order, int index, ClassPool cp)
throws NotFoundException
{
return index;
@@ -107,11 +111,12 @@ public abstract class TypeData {
// see UninitTypeVar and UninitData
public void constructorCalled(int offset) {}
+ @Override
public String toString() {
- return super.toString() + "(" + toString2(new HashSet()) + ")";
+ return super.toString() + "(" + toString2(new HashSet<TypeData>()) + ")";
}
- abstract String toString2(HashSet set);
+ abstract String toString2(Set<TypeData> set);
/**
* Primitive types.
@@ -127,31 +132,38 @@ public abstract class TypeData {
decodedName = decoded;
}
+ @Override
public int getTypeTag() { return typeTag; }
+ @Override
public int getTypeData(ConstPool cp) { return 0; }
+ @Override
public TypeData join() {
if (this == TypeTag.TOP)
return this;
- else
- return super.join();
+ return super.join();
}
+ @Override
public BasicType isBasicType() { return this; }
+ @Override
public boolean is2WordType() {
return typeTag == StackMapTable.LONG
|| typeTag == StackMapTable.DOUBLE;
}
+ @Override
public boolean eq(TypeData d) { return this == d; }
+ @Override
public String getName() {
return name;
}
public char getDecodedName() { return decodedName; }
+ @Override
public void setType(String s, ClassPool cp) throws BadBytecode {
throw new BadBytecode("conflict: " + name + " and " + s);
}
@@ -159,6 +171,7 @@ public abstract class TypeData {
/**
* @param dim array dimension. It may be negative.
*/
+ @Override
public TypeData getArrayType(int dim) throws NotFoundException {
if (this == TypeTag.TOP)
return this;
@@ -176,103 +189,109 @@ public abstract class TypeData {
}
}
- String toString2(HashSet set) { return name; }
+ @Override
+ String toString2(Set<TypeData> set) { return name; }
}
// a type variable
public static abstract class AbsTypeVar extends TypeData {
public AbsTypeVar() {}
public abstract void merge(TypeData t);
+ @Override
public int getTypeTag() { return StackMapTable.OBJECT; }
+ @Override
public int getTypeData(ConstPool cp) {
return cp.addClassInfo(getName());
}
+ @Override
public boolean eq(TypeData d) { return getName().equals(d.getName()); }
}
/* a type variable representing a class type or a basic type.
*/
public static class TypeVar extends AbsTypeVar {
- protected ArrayList lowers; // lower bounds of this type. ArrayList<TypeData>
- protected ArrayList usedBy; // reverse relations of lowers
- protected ArrayList uppers; // upper bounds of this type.
+ protected List<TypeData> lowers;// lower bounds of this type. ArrayList<TypeData>
+ protected List<TypeData> usedBy;// reverse relations of lowers
+ protected List<String> uppers; // upper bounds of this type.
protected String fixedType;
private boolean is2WordType; // cache
public TypeVar(TypeData t) {
uppers = null;
- lowers = new ArrayList(2);
- usedBy = new ArrayList(2);
+ lowers = new ArrayList<TypeData>(2);
+ usedBy = new ArrayList<TypeData>(2);
merge(t);
fixedType = null;
is2WordType = t.is2WordType();
}
+ @Override
public String getName() {
if (fixedType == null)
- return ((TypeData)lowers.get(0)).getName();
- else
- return fixedType;
+ return lowers.get(0).getName();
+ return fixedType;
}
+ @Override
public BasicType isBasicType() {
if (fixedType == null)
- return ((TypeData)lowers.get(0)).isBasicType();
- else
- return null;
+ return lowers.get(0).isBasicType();
+ return null;
}
+ @Override
public boolean is2WordType() {
if (fixedType == null) {
return is2WordType;
// return ((TypeData)lowers.get(0)).is2WordType();
}
- else
- return false;
+ return false;
}
+ @Override
public boolean isNullType() {
if (fixedType == null)
- return ((TypeData)lowers.get(0)).isNullType();
- else
- return false;
+ return lowers.get(0).isNullType();
+ return false;
}
+ @Override
public boolean isUninit() {
if (fixedType == null)
- return ((TypeData)lowers.get(0)).isUninit();
- else
- return false;
+ return lowers.get(0).isUninit();
+ return false;
}
+ @Override
public void merge(TypeData t) {
lowers.add(t);
if (t instanceof TypeVar)
((TypeVar)t).usedBy.add(this);
}
+ @Override
public int getTypeTag() {
/* If fixedType is null after calling dfs(), then this
type is NULL, Uninit, or a basic type. So call
getTypeTag() on the first element of lowers. */
if (fixedType == null)
- return ((TypeData)lowers.get(0)).getTypeTag();
- else
- return super.getTypeTag();
+ return lowers.get(0).getTypeTag();
+ return super.getTypeTag();
}
+ @Override
public int getTypeData(ConstPool cp) {
if (fixedType == null)
- return ((TypeData)lowers.get(0)).getTypeData(cp);
- else
- return super.getTypeData(cp);
+ return lowers.get(0).getTypeData(cp);
+ return super.getTypeData(cp);
}
+ @Override
public void setType(String typeName, ClassPool cp) throws BadBytecode {
if (uppers == null)
- uppers = new ArrayList();
+ uppers = new ArrayList<String>();
uppers.add(typeName);
}
@@ -282,6 +301,7 @@ public abstract class TypeData {
private boolean inList = false;
private int dimension = 0;
+ @Override
protected TypeVar toTypeVar(int dim) {
dimension = dim;
return this;
@@ -290,23 +310,22 @@ public abstract class TypeData {
/* When fixTypes() is called, getName() will return the correct
* (i.e. fixed) type name.
*/
+ @Override
public TypeData getArrayType(int dim) throws NotFoundException {
if (dim == 0)
return this;
- else {
- BasicType bt = isBasicType();
- if (bt == null)
- if (isNullType())
- return new NullType();
- else
- return new ClassName(getName()).getArrayType(dim);
+ BasicType bt = isBasicType();
+ if (bt == null)
+ if (isNullType())
+ return new NullType();
else
- return bt.getArrayType(dim);
- }
+ return new ClassName(getName()).getArrayType(dim);
+ return bt.getArrayType(dim);
}
// depth-first serach
- public int dfs(ArrayList preOrder, int index, ClassPool cp) throws NotFoundException {
+ @Override
+ public int dfs(List<TypeData> preOrder, int index, ClassPool cp) throws NotFoundException {
if (visited > 0)
return index; // MapMaker.make() may call an already visited node.
@@ -315,7 +334,7 @@ public abstract class TypeData {
inList = true;
int n = lowers.size();
for (int i = 0; i < n; i++) {
- TypeVar child = ((TypeData)lowers.get(i)).toTypeVar(dimension);
+ TypeVar child = lowers.get(i).toTypeVar(dimension);
if (child != null)
if (child.visited == 0) {
index = child.dfs(preOrder, index, cp);
@@ -328,7 +347,7 @@ public abstract class TypeData {
}
if (visited == smallest) {
- ArrayList scc = new ArrayList(); // strongly connected component
+ List<TypeData> scc = new ArrayList<TypeData>(); // strongly connected component
TypeVar cv;
do {
cv = (TypeVar)preOrder.remove(preOrder.size() - 1);
@@ -341,17 +360,17 @@ public abstract class TypeData {
return index;
}
- private void fixTypes(ArrayList scc, ClassPool cp) throws NotFoundException {
- HashSet lowersSet = new HashSet();
+ private void fixTypes(List<TypeData> scc, ClassPool cp) throws NotFoundException {
+ Set<String> lowersSet = new HashSet<String>();
boolean isBasicType = false;
TypeData kind = null;
int size = scc.size();
for (int i = 0; i < size; i++) {
TypeVar tvar = (TypeVar)scc.get(i);
- ArrayList tds = tvar.lowers;
+ List<TypeData> tds = tvar.lowers;
int size2 = tds.size();
for (int j = 0; j < size2; j++) {
- TypeData td = (TypeData)tds.get(j);
+ TypeData td = tds.get(j);
TypeData d = td.getArrayType(tvar.dimension);
BasicType bt = d.isBasicType();
if (kind == null) {
@@ -393,7 +412,7 @@ public abstract class TypeData {
}
}
- private void fixTypes1(ArrayList scc, TypeData kind) throws NotFoundException {
+ private void fixTypes1(List<TypeData> scc, TypeData kind) throws NotFoundException {
int size = scc.size();
for (int i = 0; i < size; i++) {
TypeVar cv = (TypeVar)scc.get(i);
@@ -408,24 +427,24 @@ public abstract class TypeData {
}
}
- private String fixTypes2(ArrayList scc, HashSet lowersSet, ClassPool cp) throws NotFoundException {
- Iterator it = lowersSet.iterator();
+ private String fixTypes2(List<TypeData> scc, Set<String> lowersSet, ClassPool cp) throws NotFoundException {
+ Iterator<String> it = lowersSet.iterator();
if (lowersSet.size() == 0)
return null; // only NullType
else if (lowersSet.size() == 1)
- return (String)it.next();
+ return it.next();
else {
- CtClass cc = cp.get((String)it.next());
+ CtClass cc = cp.get(it.next());
while (it.hasNext())
- cc = commonSuperClassEx(cc, cp.get((String)it.next()));
+ cc = commonSuperClassEx(cc, cp.get(it.next()));
if (cc.getSuperclass() == null || isObjectArray(cc))
- cc = fixByUppers(scc, cp, new HashSet(), cc);
+ cc = fixByUppers(scc, cp, new HashSet<TypeData>(), cc);
if (cc.isArray())
return Descriptor.toJvmName(cc);
- else
- return cc.getName();
+
+ return cc.getName();
}
}
@@ -433,7 +452,7 @@ public abstract class TypeData {
return cc.isArray() && cc.getComponentType().getSuperclass() == null;
}
- private CtClass fixByUppers(ArrayList users, ClassPool cp, HashSet visited, CtClass type)
+ private CtClass fixByUppers(List<TypeData> users, ClassPool cp, Set<TypeData> visited, CtClass type)
throws NotFoundException
{
if (users == null)
@@ -448,7 +467,7 @@ public abstract class TypeData {
if (t.uppers != null) {
int s = t.uppers.size();
for (int k = 0; k < s; k++) {
- CtClass cc = cp.get((String)t.uppers.get(k));
+ CtClass cc = cp.get(t.uppers.get(k));
if (cc.subtypeOf(type))
type = cc;
}
@@ -460,13 +479,13 @@ public abstract class TypeData {
return type;
}
- String toString2(HashSet hash) {
+ @Override
+ String toString2(Set<TypeData> hash) {
hash.add(this);
if (lowers.size() > 0) {
- TypeData e = (TypeData)lowers.get(0);
- if (e != null && !hash.contains(e)) {
+ TypeData e = lowers.get(0);
+ if (e != null && !hash.contains(e))
return e.toString2(hash);
- }
}
return "?";
@@ -494,7 +513,7 @@ public abstract class TypeData {
}
else if (one.isPrimitive() || two.isPrimitive())
return null; // TOP
- else if (one.isArray() || two.isArray()) // but !(one.isArray() && two.isArray())
+ else if (one.isArray() || two.isArray()) // but !(one.isArray() && two.isArray())
return one.getClassPool().get("java.lang.Object");
else
return commonSuperClass(one, two);
@@ -605,6 +624,7 @@ public abstract class TypeData {
throw new BadBytecode("bad AASTORE: " + element);
}
+ @Override
public void merge(TypeData t) {
try {
if (!t.isNullType())
@@ -616,13 +636,16 @@ public abstract class TypeData {
}
}
+ @Override
public String getName() {
return typeName(element.getName());
}
public AbsTypeVar elementType() { return element; }
+ @Override
public BasicType isBasicType() { return null; }
+ @Override
public boolean is2WordType() { return false; }
/* elementType must be a class name. Basic type names
@@ -631,25 +654,29 @@ public abstract class TypeData {
public static String typeName(String elementType) {
if (elementType.charAt(0) == '[')
return "[" + elementType;
- else
- return "[L" + elementType.replace('.', '/') + ";";
+ return "[L" + elementType.replace('.', '/') + ";";
}
+ @Override
public void setType(String s, ClassPool cp) throws BadBytecode {
element.setType(ArrayElement.typeName(s), cp);
}
+ @Override
protected TypeVar toTypeVar(int dim) { return element.toTypeVar(dim + 1); }
+ @Override
public TypeData getArrayType(int dim) throws NotFoundException {
return element.getArrayType(dim + 1);
}
- public int dfs(ArrayList order, int index, ClassPool cp) throws NotFoundException {
+ @Override
+ public int dfs(List<TypeData> order, int index, ClassPool cp) throws NotFoundException {
return element.dfs(order, index, cp);
}
- String toString2(HashSet set) {
+ @Override
+ String toString2(Set<TypeData> set) {
return "[" + element.toString2(set);
}
}
@@ -659,7 +686,7 @@ public abstract class TypeData {
*/
public static class ArrayElement extends AbsTypeVar {
private AbsTypeVar array;
-
+
private ArrayElement(AbsTypeVar a) { // a is never null
array = a;
}
@@ -676,6 +703,7 @@ public abstract class TypeData {
throw new BadBytecode("bad AASTORE: " + array);
}
+ @Override
public void merge(TypeData t) {
try {
if (!t.isNullType())
@@ -687,6 +715,7 @@ public abstract class TypeData {
}
}
+ @Override
public String getName() {
return typeName(array.getName());
}
@@ -697,8 +726,10 @@ public abstract class TypeData {
* not allowed.
*/
+ @Override
public BasicType isBasicType() { return null; }
+ @Override
public boolean is2WordType() { return false; }
private static String typeName(String arrayType) {
@@ -713,21 +744,26 @@ public abstract class TypeData {
return "java.lang.Object"; // the array type may be NullType
}
+ @Override
public void setType(String s, ClassPool cp) throws BadBytecode {
array.setType(ArrayType.typeName(s), cp);
}
+ @Override
protected TypeVar toTypeVar(int dim) { return array.toTypeVar(dim - 1); }
+ @Override
public TypeData getArrayType(int dim) throws NotFoundException {
return array.getArrayType(dim - 1);
}
- public int dfs(ArrayList order, int index, ClassPool cp) throws NotFoundException {
+ @Override
+ public int dfs(List<TypeData> order, int index, ClassPool cp) throws NotFoundException {
return array.dfs(order, index, cp);
}
- String toString2(HashSet set) {
+ @Override
+ String toString2(Set<TypeData> set) {
return "*" + array.toString2(set);
}
}
@@ -736,26 +772,38 @@ public abstract class TypeData {
protected TypeData type; // UninitData or TOP
public UninitTypeVar(UninitData t) { type = t; }
+ @Override
public int getTypeTag() { return type.getTypeTag(); }
+ @Override
public int getTypeData(ConstPool cp) { return type.getTypeData(cp); }
+ @Override
public BasicType isBasicType() { return type.isBasicType(); }
+ @Override
public boolean is2WordType() { return type.is2WordType(); }
+ @Override
public boolean isUninit() { return type.isUninit(); }
+ @Override
public boolean eq(TypeData d) { return type.eq(d); }
+ @Override
public String getName() { return type.getName(); }
+ @Override
protected TypeVar toTypeVar(int dim) { return null; }
+ @Override
public TypeData join() { return type.join(); }
+ @Override
public void setType(String s, ClassPool cp) throws BadBytecode {
type.setType(s, cp);
}
+ @Override
public void merge(TypeData t) {
if (!t.eq(type))
type = TypeTag.TOP;
}
+ @Override
public void constructorCalled(int offset) {
type.constructorCalled(offset);
}
@@ -763,15 +811,16 @@ public abstract class TypeData {
public int offset() {
if (type instanceof UninitData)
return ((UninitData)type).offset;
- else // if type == TypeTag.TOP
- throw new RuntimeException("not available");
+ throw new RuntimeException("not available");
}
+ @Override
public TypeData getArrayType(int dim) throws NotFoundException {
return type.getArrayType(dim);
}
- String toString2(HashSet set) { return ""; }
+ @Override
+ String toString2(Set<TypeData> set) { return ""; }
}
/**
@@ -784,24 +833,32 @@ public abstract class TypeData {
name = n;
}
+ @Override
public String getName() {
return name;
}
+ @Override
public BasicType isBasicType() { return null; }
+ @Override
public boolean is2WordType() { return false; }
+ @Override
public int getTypeTag() { return StackMapTable.OBJECT; }
+ @Override
public int getTypeData(ConstPool cp) {
return cp.addClassInfo(getName());
}
+ @Override
public boolean eq(TypeData d) { return name.equals(d.getName()); }
+ @Override
public void setType(String typeName, ClassPool cp) throws BadBytecode {}
+ @Override
public TypeData getArrayType(int dim) throws NotFoundException {
if (dim == 0)
return this;
@@ -825,7 +882,7 @@ public abstract class TypeData {
if (type == '[')
return new ClassName(name.substring(-dim));
else if (type == 'L')
- return new ClassName(name.substring(-dim + 1, name.length() - 1).replace('/', '.'));
+ return new ClassName(name.substring(-dim + 1, name.length() - 1).replace('/', '.'));
else if (type == TypeTag.DOUBLE.decodedName)
return TypeTag.DOUBLE;
else if (type == TypeTag.FLOAT.decodedName)
@@ -837,7 +894,8 @@ public abstract class TypeData {
}
}
- String toString2(HashSet set) {
+ @Override
+ String toString2(Set<TypeData> set) {
return name;
}
}
@@ -852,13 +910,17 @@ public abstract class TypeData {
super("null-type"); // type name
}
+ @Override
public int getTypeTag() {
return StackMapTable.NULL;
}
+ @Override
public boolean isNullType() { return true; }
+ @Override
public int getTypeData(ConstPool cp) { return 0; }
+ @Override
public TypeData getArrayType(int dim) { return this; }
}
@@ -877,40 +939,45 @@ public abstract class TypeData {
public UninitData copy() { return new UninitData(offset, getName()); }
+ @Override
public int getTypeTag() {
return StackMapTable.UNINIT;
}
+ @Override
public int getTypeData(ConstPool cp) {
return offset;
}
+ @Override
public TypeData join() {
if (initialized)
return new TypeVar(new ClassName(getName()));
- else
- return new UninitTypeVar(copy());
+ return new UninitTypeVar(copy());
}
+ @Override
public boolean isUninit() { return true; }
+ @Override
public boolean eq(TypeData d) {
if (d instanceof UninitData) {
UninitData ud = (UninitData)d;
return offset == ud.offset && getName().equals(ud.getName());
}
- else
- return false;
+ return false;
}
public int offset() { return offset; }
+ @Override
public void constructorCalled(int offset) {
if (offset == this.offset)
initialized = true;
}
- String toString2(HashSet set) { return getName() + "," + offset; }
+ @Override
+ String toString2(Set<TypeData> set) { return getName() + "," + offset; }
}
public static class UninitThis extends UninitData {
@@ -918,16 +985,20 @@ public abstract class TypeData {
super(-1, className);
}
+ @Override
public UninitData copy() { return new UninitThis(getName()); }
+ @Override
public int getTypeTag() {
return StackMapTable.THIS;
}
+ @Override
public int getTypeData(ConstPool cp) {
return 0;
}
- String toString2(HashSet set) { return "uninit:this"; }
+ @Override
+ String toString2(Set<TypeData> set) { return "uninit:this"; }
}
}
diff --git a/src/main/javassist/bytecode/stackmap/TypedBlock.java b/src/main/javassist/bytecode/stackmap/TypedBlock.java
index 719ad67f..14fa7f22 100644
--- a/src/main/javassist/bytecode/stackmap/TypedBlock.java
+++ b/src/main/javassist/bytecode/stackmap/TypedBlock.java
@@ -16,7 +16,11 @@
package javassist.bytecode.stackmap;
-import javassist.bytecode.*;
+import javassist.bytecode.AccessFlag;
+import javassist.bytecode.BadBytecode;
+import javassist.bytecode.CodeAttribute;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.MethodInfo;
public class TypedBlock extends BasicBlock {
public int stackTop, numLocals;
@@ -54,6 +58,7 @@ public class TypedBlock extends BasicBlock {
localsTypes = null;
}
+ @Override
protected void toString2(StringBuffer sbuf) {
super.toString2(sbuf);
sbuf.append(",\n stack={");
@@ -110,10 +115,12 @@ public class TypedBlock extends BasicBlock {
}
public static class Maker extends BasicBlock.Maker {
+ @Override
protected BasicBlock makeBlock(int pos) {
return new TypedBlock(pos);
}
+ @Override
protected BasicBlock[] makeArray(int size) {
return new TypedBlock[size];
}