aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-23 17:08:37 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-23 17:08:37 +0000
commitcdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6 (patch)
tree0471a4d9b985b11969ecd6f521f660e3d468f1d1 /src/main/javassist/bytecode
parentfb431982111b03608b888953f7ed8ba7e98f421c (diff)
downloadjavassist-cdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6.tar.gz
javassist-cdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6.zip
Changed the copyright notices and removed tab characters.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@9 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode')
-rw-r--r--src/main/javassist/bytecode/AccessFlag.java49
-rw-r--r--src/main/javassist/bytecode/AttributeInfo.java237
-rw-r--r--src/main/javassist/bytecode/BadBytecode.java35
-rw-r--r--src/main/javassist/bytecode/ByteArray.java67
-rw-r--r--src/main/javassist/bytecode/Bytecode.java1113
-rw-r--r--src/main/javassist/bytecode/ClassFile.java547
-rw-r--r--src/main/javassist/bytecode/ClassFileWriter.java149
-rw-r--r--src/main/javassist/bytecode/CodeAttribute.java389
-rw-r--r--src/main/javassist/bytecode/CodeIterator.java678
-rw-r--r--src/main/javassist/bytecode/ConstPool.java1003
-rw-r--r--src/main/javassist/bytecode/ConstantAttribute.java65
-rw-r--r--src/main/javassist/bytecode/Descriptor.java703
-rw-r--r--src/main/javassist/bytecode/ExceptionTable.java235
-rw-r--r--src/main/javassist/bytecode/ExceptionsAttribute.java173
-rw-r--r--src/main/javassist/bytecode/FieldInfo.java119
-rw-r--r--src/main/javassist/bytecode/InnerClassesAttribute.java115
-rw-r--r--src/main/javassist/bytecode/LineNumberAttribute.java99
-rw-r--r--src/main/javassist/bytecode/LongVector.java105
-rw-r--r--src/main/javassist/bytecode/MethodInfo.java275
-rw-r--r--src/main/javassist/bytecode/Mnemonic.java435
-rw-r--r--src/main/javassist/bytecode/Opcode.java435
-rw-r--r--src/main/javassist/bytecode/SourceFileAttribute.java61
-rw-r--r--src/main/javassist/bytecode/SyntheticAttribute.java47
-rw-r--r--src/main/javassist/bytecode/package.html18
24 files changed, 3463 insertions, 3689 deletions
diff --git a/src/main/javassist/bytecode/AccessFlag.java b/src/main/javassist/bytecode/AccessFlag.java
index c964ca7c..289445a2 100644
--- a/src/main/javassist/bytecode/AccessFlag.java
+++ b/src/main/javassist/bytecode/AccessFlag.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
/**
@@ -52,7 +41,7 @@ public class AccessFlag {
* cleared.
*/
public static int setPublic(int accflags) {
- return (accflags & ~(PRIVATE | PROTECTED)) | PUBLIC;
+ return (accflags & ~(PRIVATE | PROTECTED)) | PUBLIC;
}
/**
@@ -60,7 +49,7 @@ public class AccessFlag {
* cleared.
*/
public static int setProtected(int accflags) {
- return (accflags & ~(PRIVATE | PUBLIC)) | PROTECTED;
+ return (accflags & ~(PRIVATE | PUBLIC)) | PROTECTED;
}
/**
@@ -68,40 +57,40 @@ public class AccessFlag {
* cleared.
*/
public static int setPrivate(int accflags) {
- return (accflags & ~(PROTECTED | PUBLIC)) | PRIVATE;
+ return (accflags & ~(PROTECTED | PUBLIC)) | PRIVATE;
}
/**
* Clears the public, protected, and private bits.
*/
public static int setPackage(int accflags) {
- return (accflags & ~(PROTECTED | PUBLIC | PRIVATE));
+ return (accflags & ~(PROTECTED | PUBLIC | PRIVATE));
}
/**
* Clears a specified bit in <code>accflags</code>.
*/
public static int clear(int accflags, int clearBit) {
- return accflags & ~clearBit;
+ return accflags & ~clearBit;
}
/**
* Converts a javassist.Modifier into
* a javassist.bytecode.AccessFlag.
*
- * @param modifier javassist.Modifier
+ * @param modifier javassist.Modifier
*/
public static int of(int modifier) {
- return modifier;
+ return modifier;
}
/**
* Converts a javassist.bytecode.AccessFlag
* into a javassist.Modifier.
*
- * @param accflags javassist.bytecode.Accessflag
+ * @param accflags javassist.bytecode.Accessflag
*/
public static int toModifier(int accflags) {
- return accflags;
+ return accflags;
}
}
diff --git a/src/main/javassist/bytecode/AttributeInfo.java b/src/main/javassist/bytecode/AttributeInfo.java
index 29d7904b..ea7f0d40 100644
--- a/src/main/javassist/bytecode/AttributeInfo.java
+++ b/src/main/javassist/bytecode/AttributeInfo.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -33,7 +22,7 @@ import java.util.LinkedList;
import java.util.ListIterator;
// Note: if you define a new subclass of AttributeInfo, then
-// update AttributeInfo.read().
+// update AttributeInfo.read().
/**
* <code>attribute_info</code> structure.
@@ -44,66 +33,66 @@ public class AttributeInfo {
byte[] info;
protected AttributeInfo(ConstPool cp, int attrname, byte[] attrinfo) {
- constPool = cp;
- name = attrname;
- info = attrinfo;
+ constPool = cp;
+ name = attrname;
+ info = attrinfo;
}
protected AttributeInfo(ConstPool cp, String attrname) {
- this(cp, attrname, (byte[])null);
+ this(cp, attrname, (byte[])null);
}
/**
* Constructs an <code>attribute_info</code> structure.
*
- * @param cp constant pool table
- * @param attrname attribute name
- * @param attrinfo <code>info</code> field
- * of <code>attribute_info</code> structure.
+ * @param cp constant pool table
+ * @param attrname attribute name
+ * @param attrinfo <code>info</code> field
+ * of <code>attribute_info</code> structure.
*/
public AttributeInfo(ConstPool cp, String attrname, byte[] attrinfo) {
- this(cp, cp.addUtf8Info(attrname), attrinfo);
+ this(cp, cp.addUtf8Info(attrname), attrinfo);
}
protected AttributeInfo(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- constPool = cp;
- name = n;
- int len = in.readInt();
- info = new byte[len];
- if (len > 0)
- in.readFully(info);
+ constPool = cp;
+ name = n;
+ int len = in.readInt();
+ info = new byte[len];
+ if (len > 0)
+ in.readFully(info);
}
static AttributeInfo read(ConstPool cp, DataInputStream in)
- throws IOException
+ throws IOException
{
- int name = in.readUnsignedShort();
- String nameStr = cp.getUtf8Info(name);
- if (nameStr.equals(CodeAttribute.tag))
- return new CodeAttribute(cp, name, in);
- else if (nameStr.equals(ExceptionsAttribute.tag))
- return new ExceptionsAttribute(cp, name, in);
- else if (nameStr.equals(ConstantAttribute.tag))
- return new ConstantAttribute(cp, name, in);
- else if (nameStr.equals(SourceFileAttribute.tag))
- return new SourceFileAttribute(cp, name, in);
- else if (nameStr.equals(LineNumberAttribute.tag))
- return new LineNumberAttribute(cp, name, in);
- else if (nameStr.equals(SyntheticAttribute.tag))
- return new SyntheticAttribute(cp, name, in);
- else if (nameStr.equals(InnerClassesAttribute.tag))
- return new InnerClassesAttribute(cp, name, in);
- else
- return new AttributeInfo(cp, name, in);
+ int name = in.readUnsignedShort();
+ String nameStr = cp.getUtf8Info(name);
+ if (nameStr.equals(CodeAttribute.tag))
+ return new CodeAttribute(cp, name, in);
+ else if (nameStr.equals(ExceptionsAttribute.tag))
+ return new ExceptionsAttribute(cp, name, in);
+ else if (nameStr.equals(ConstantAttribute.tag))
+ return new ConstantAttribute(cp, name, in);
+ else if (nameStr.equals(SourceFileAttribute.tag))
+ return new SourceFileAttribute(cp, name, in);
+ else if (nameStr.equals(LineNumberAttribute.tag))
+ return new LineNumberAttribute(cp, name, in);
+ else if (nameStr.equals(SyntheticAttribute.tag))
+ return new SyntheticAttribute(cp, name, in);
+ else if (nameStr.equals(InnerClassesAttribute.tag))
+ return new InnerClassesAttribute(cp, name, in);
+ else
+ return new AttributeInfo(cp, name, in);
}
/**
* Returns an attribute name.
*/
public String getName() {
- return constPool.getUtf8Info(name);
+ return constPool.getUtf8Info(name);
}
/**
@@ -117,7 +106,7 @@ public class AttributeInfo {
* The returned value is <code>attribute_length + 6</code>.
*/
public int length() {
- return info.length + 6;
+ return info.length + 6;
}
/**
@@ -142,99 +131,99 @@ public class AttributeInfo {
* Makes a copy. Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- int s = info.length;
- byte[] newInfo = new byte[s];
- for (int i = 0; i < s; ++i)
- newInfo[i] = info[i];
+ int s = info.length;
+ byte[] newInfo = new byte[s];
+ for (int i = 0; i < s; ++i)
+ newInfo[i] = info[i];
- return new AttributeInfo(newCp, getName(), newInfo);
+ return new AttributeInfo(newCp, getName(), newInfo);
}
void write(DataOutputStream out) throws IOException {
- out.writeShort(name);
- out.writeInt(info.length);
- if (info.length > 0)
- out.write(info);
+ out.writeShort(name);
+ out.writeInt(info.length);
+ if (info.length > 0)
+ out.write(info);
}
static int getLength(LinkedList list) {
- int size = 0;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo attr = (AttributeInfo)list.get(i);
- size += attr.length();
- }
-
- return size;
+ int size = 0;
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ AttributeInfo attr = (AttributeInfo)list.get(i);
+ size += attr.length();
+ }
+
+ return size;
}
static AttributeInfo lookup(LinkedList list, String name) {
- if (list == null)
- return null;
+ if (list == null)
+ return null;
- ListIterator iterator = list.listIterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
- if (ai.getName().equals(name))
- return ai;
- }
+ ListIterator iterator = list.listIterator();
+ while (iterator.hasNext()) {
+ AttributeInfo ai = (AttributeInfo)iterator.next();
+ if (ai.getName().equals(name))
+ return ai;
+ }
- return null; // no such attribute
+ return null; // no such attribute
}
static AttributeInfo lookup(LinkedList list, Class type) {
- if (list == null)
- return null;
+ if (list == null)
+ return null;
- ListIterator iterator = list.listIterator();
- while (iterator.hasNext()) {
- Object obj = iterator.next();
- if (type.isInstance(obj))
- return (AttributeInfo)obj;
- }
+ ListIterator iterator = list.listIterator();
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (type.isInstance(obj))
+ return (AttributeInfo)obj;
+ }
- return null; // no such attribute
+ return null; // no such attribute
}
static synchronized void remove(LinkedList list, String name) {
- if (list == null)
- return;
-
- ListIterator iterator = list.listIterator();
- while (iterator.hasNext()) {
- AttributeInfo ai = (AttributeInfo)iterator.next();
- if (ai.getName().equals(name))
- iterator.remove();
- }
+ if (list == null)
+ return;
+
+ ListIterator iterator = list.listIterator();
+ while (iterator.hasNext()) {
+ AttributeInfo ai = (AttributeInfo)iterator.next();
+ if (ai.getName().equals(name))
+ iterator.remove();
+ }
}
static synchronized void remove(LinkedList list, Class type) {
- if (list == null)
- return;
-
- ListIterator iterator = list.listIterator();
- while (iterator.hasNext()) {
- Object obj = iterator.next();
- if (type.isInstance(obj))
- iterator.remove();
- }
+ if (list == null)
+ return;
+
+ ListIterator iterator = list.listIterator();
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (type.isInstance(obj))
+ iterator.remove();
+ }
}
static void writeAll(LinkedList list, DataOutputStream out)
- throws IOException
+ throws IOException
{
- if (list == null)
- return;
-
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo attr = (AttributeInfo)list.get(i);
- attr.write(out);
- }
+ if (list == null)
+ return;
+
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ AttributeInfo attr = (AttributeInfo)list.get(i);
+ attr.write(out);
+ }
}
}
diff --git a/src/main/javassist/bytecode/BadBytecode.java b/src/main/javassist/bytecode/BadBytecode.java
index 51d287d7..88cf6e95 100644
--- a/src/main/javassist/bytecode/BadBytecode.java
+++ b/src/main/javassist/bytecode/BadBytecode.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
/**
@@ -30,10 +19,10 @@ package javassist.bytecode;
*/
public class BadBytecode extends Exception {
public BadBytecode(int opcode) {
- super("bytecode " + opcode);
+ super("bytecode " + opcode);
}
public BadBytecode(String msg) {
- super(msg);
+ super(msg);
}
}
diff --git a/src/main/javassist/bytecode/ByteArray.java b/src/main/javassist/bytecode/ByteArray.java
index e10231e8..5d1c7500 100644
--- a/src/main/javassist/bytecode/ByteArray.java
+++ b/src/main/javassist/bytecode/ByteArray.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
/**
@@ -33,54 +22,54 @@ public class ByteArray {
* Reads an unsigned 16bit integer at the index.
*/
public static int readU16bit(byte[] code, int index) {
- return ((code[index] & 0xff) << 8) | (code[index + 1] & 0xff);
+ return ((code[index] & 0xff) << 8) | (code[index + 1] & 0xff);
}
/**
* Reads a signed 16bit integer at the index.
*/
public static int readS16bit(byte[] code, int index) {
- return (code[index] << 8) | (code[index + 1] & 0xff);
+ return (code[index] << 8) | (code[index + 1] & 0xff);
}
/**
* Writes a 16bit integer at the index.
*/
public static void write16bit(int value, byte[] code, int index) {
- code[index] = (byte)(value >>> 8);
- code[index + 1] = (byte)value;
+ code[index] = (byte)(value >>> 8);
+ code[index + 1] = (byte)value;
}
/**
* Reads a 32bit integer at the index.
*/
public static int read32bit(byte[] code, int index) {
- return (code[index] << 24) | ((code[index + 1] & 0xff) << 16)
- | ((code[index + 2] & 0xff) << 8) | (code[index + 3] & 0xff);
+ return (code[index] << 24) | ((code[index + 1] & 0xff) << 16)
+ | ((code[index + 2] & 0xff) << 8) | (code[index + 3] & 0xff);
}
/**
* Writes a 32bit integer at the index.
*/
public static void write32bit(int value, byte[] code, int index) {
- code[index] = (byte)(value >>> 24);
- code[index + 1] = (byte)(value >>> 16);
- code[index + 2] = (byte)(value >>> 8);
- code[index + 3] = (byte)value;
+ code[index] = (byte)(value >>> 24);
+ code[index + 1] = (byte)(value >>> 16);
+ code[index + 2] = (byte)(value >>> 8);
+ code[index + 3] = (byte)value;
}
/**
* Copies a 32bit integer.
*
- * @param src the source byte array.
- * @param isrc the index into the source byte array.
- * @param dest the destination byte array.
- * @param idest the index into the destination byte array.
+ * @param src the source byte array.
+ * @param isrc the index into the source byte array.
+ * @param dest the destination byte array.
+ * @param idest the index into the destination byte array.
*/
static void copy32bit(byte[] src, int isrc, byte[] dest, int idest) {
- dest[idest] = src[isrc];
- dest[idest + 1] = src[isrc + 1];
- dest[idest + 2] = src[isrc + 2];
- dest[idest + 3] = src[isrc + 3];
+ dest[idest] = src[isrc];
+ dest[idest + 1] = src[isrc + 1];
+ dest[idest + 2] = src[isrc + 2];
+ dest[idest + 3] = src[isrc + 3];
}
}
diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java
index f903e4be..2a72547b 100644
--- a/src/main/javassist/bytecode/Bytecode.java
+++ b/src/main/javassist/bytecode/Bytecode.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataOutputStream;
@@ -78,25 +67,25 @@ public class Bytecode implements Opcode {
* of <code>max_stack</code> and <code>max_locals</code>.
* They can be changed later.
*
- * @param cp constant pool table.
- * @param stacksize <code>max_stack</code>.
- * @param localvars <code>max_locals</code>.
+ * @param cp constant pool table.
+ * @param stacksize <code>max_stack</code>.
+ * @param localvars <code>max_locals</code>.
*/
public Bytecode(ConstPool cp, int stacksize, int localvars) {
- this();
- constPool = cp;
- maxStack = stacksize;
- maxLocals = localvars;
- tryblocks = new ExceptionTable(cp);
- stackDepth = 0;
+ this();
+ constPool = cp;
+ maxStack = stacksize;
+ maxLocals = localvars;
+ tryblocks = new ExceptionTable(cp);
+ stackDepth = 0;
}
/* used in add().
*/
private Bytecode() {
- buffer = new byte[bufsize];
- num = 0;
- next = null;
+ buffer = new byte[bufsize];
+ num = 0;
+ next = null;
}
/**
@@ -113,40 +102,40 @@ public class Bytecode implements Opcode {
* Converts to a <code>CodeAttribute</code>.
*/
public CodeAttribute toCodeAttribute() {
- return new CodeAttribute(constPool, maxStack, maxLocals,
- get(), tryblocks);
+ return new CodeAttribute(constPool, maxStack, maxLocals,
+ get(), tryblocks);
}
/**
* Returns the length of the bytecode sequence.
*/
public int length() {
- int len = 0;
- Bytecode b = this;
- while (b != null) {
- len += b.num;
- b = b.next;
- }
+ int len = 0;
+ Bytecode b = this;
+ while (b != null) {
+ len += b.num;
+ b = b.next;
+ }
- return len;
+ return len;
}
private void copy(byte[] dest, int index) {
- Bytecode b = this;
- while (b != null) {
- System.arraycopy(b.buffer, 0, dest, index, b.num);
- index += b.num;
- b = b.next;
- }
+ Bytecode b = this;
+ while (b != null) {
+ System.arraycopy(b.buffer, 0, dest, index, b.num);
+ index += b.num;
+ b = b.next;
+ }
}
/**
* Returns the produced bytecode sequence.
*/
public byte[] get() {
- byte[] b = new byte[length()];
- copy(b, 0);
- return b;
+ byte[] b = new byte[length()];
+ copy(b, 0);
+ return b;
}
/**
@@ -169,7 +158,7 @@ public class Bytecode implements Opcode {
* @see #addOpcode(int)
*/
public void setMaxStack(int size) {
- maxStack = size;
+ maxStack = size;
}
/**
@@ -181,7 +170,7 @@ public class Bytecode implements Opcode {
* Sets <code>max_locals</code>.
*/
public void setMaxLocals(int size) {
- maxLocals = size;
+ maxLocals = size;
}
/**
@@ -191,55 +180,55 @@ public class Bytecode implements Opcode {
* used to pass method parameters and sets <code>max_locals</code>
* to that number plus <code>locals</code>.
*
- * @param isStatic true if <code>params</code> must be
- * interpreted as parameters to a static method.
- * @param params parameter types.
- * @param locals the number of local variables excluding
- * ones used to pass parameters.
+ * @param isStatic true if <code>params</code> must be
+ * interpreted as parameters to a static method.
+ * @param params parameter types.
+ * @param locals the number of local variables excluding
+ * ones used to pass parameters.
*/
public void setMaxLocals(boolean isStatic, CtClass[] params,
- int locals) {
- if (!isStatic)
- ++locals;
+ int locals) {
+ if (!isStatic)
+ ++locals;
- if (params != null) {
- CtClass doubleType = CtClass.doubleType;
- CtClass longType = CtClass.longType;
- int n = params.length;
- for (int i = 0; i < n; ++i) {
- CtClass type = params[i];
- if (type == doubleType || type == longType)
- locals += 2;
- else
- ++locals;
- }
- }
+ if (params != null) {
+ CtClass doubleType = CtClass.doubleType;
+ CtClass longType = CtClass.longType;
+ int n = params.length;
+ for (int i = 0; i < n; ++i) {
+ CtClass type = params[i];
+ if (type == doubleType || type == longType)
+ locals += 2;
+ else
+ ++locals;
+ }
+ }
- maxLocals = locals;
+ maxLocals = locals;
}
/**
* Increments <code>max_locals</code>.
*/
public void incMaxLocals(int diff) {
- maxLocals += diff;
+ maxLocals += diff;
}
/**
* Adds a new entry of <code>exception_table</code>.
*/
public void addExceptionHandler(int start, int end,
- int handler, CtClass type) {
- addExceptionHandler(start, end, handler,
- constPool.addClassInfo(type));
+ int handler, CtClass type) {
+ addExceptionHandler(start, end, handler,
+ constPool.addClassInfo(type));
}
/**
* Adds a new entry of <code>exception_table</code>.
*/
public void addExceptionHandler(int start, int end,
- int handler, int type) {
- tryblocks.add(start, end, handler, type);
+ int handler, int type) {
+ tryblocks.add(start, end, handler, type);
}
/**
@@ -247,34 +236,34 @@ public class Bytecode implements Opcode {
* that have been added so far.
*/
public int currentPc() {
- int n = 0;
- Bytecode b = this;
- while (b != null) {
- n += b.num;
- b = b.next;
- }
+ int n = 0;
+ Bytecode b = this;
+ while (b != null) {
+ n += b.num;
+ b = b.next;
+ }
- return n;
+ return n;
}
/**
* Reads a signed 8bit value at the offset from the beginning of the
* bytecode sequence.
*
- * @throws ArrayIndexOutOfBoundsException if offset is invalid.
+ * @throws ArrayIndexOutOfBoundsException if offset is invalid.
*/
public int read(int offset) {
- if (offset < 0)
- return Opcode.NOP;
- else if (offset < num)
- return buffer[offset];
- else
- try {
- return next.read(offset - num);
- }
- catch (NullPointerException e) {
- throw new ArrayIndexOutOfBoundsException(offset);
- }
+ if (offset < 0)
+ return Opcode.NOP;
+ else if (offset < num)
+ return buffer[offset];
+ else
+ try {
+ return next.read(offset - num);
+ }
+ catch (NullPointerException e) {
+ throw new ArrayIndexOutOfBoundsException(offset);
+ }
}
/**
@@ -282,27 +271,27 @@ public class Bytecode implements Opcode {
* bytecode sequence.
*/
public int read16bit(int offset) {
- int v1 = read(offset);
- int v2 = read(offset + 1);
- return (v1 << 8) + (v2 & 0xff);
+ int v1 = read(offset);
+ int v2 = read(offset + 1);
+ return (v1 << 8) + (v2 & 0xff);
}
/**
* Writes an 8bit value at the offset from the beginning of the
* bytecode sequence.
*
- * @throws ArrayIndexOutOfBoundsException if offset is invalid.
+ * @throws ArrayIndexOutOfBoundsException if offset is invalid.
*/
public void write(int offset, int value) {
- if (offset < num)
- buffer[offset] = (byte)value;
- else
- try {
- next.write(offset - num, value);
- }
- catch (NullPointerException e) {
- throw new ArrayIndexOutOfBoundsException(offset);
- }
+ if (offset < num)
+ buffer[offset] = (byte)value;
+ else
+ try {
+ next.write(offset - num, value);
+ }
+ catch (NullPointerException e) {
+ throw new ArrayIndexOutOfBoundsException(offset);
+ }
}
/**
@@ -310,22 +299,22 @@ public class Bytecode implements Opcode {
* bytecode sequence.
*/
public void write16bit(int offset, int value) {
- write(offset, value >>> 8);
- write(offset + 1, value);
+ write(offset, value >>> 8);
+ write(offset + 1, value);
}
/**
* Appends an 8bit value to the end of the bytecode sequence.
*/
public void add(int code) {
- if (num < bufsize)
- buffer[num++] = (byte)code;
- else {
- if (next == null)
- next = new Bytecode();
+ if (num < bufsize)
+ buffer[num++] = (byte)code;
+ else {
+ if (next == null)
+ next = new Bytecode();
- next.add(code);
- }
+ next.add(code);
+ }
}
/**
@@ -340,8 +329,8 @@ public class Bytecode implements Opcode {
* <code>growStack()</code> must be explicitly called.
*/
public void addOpcode(int code) {
- add(code);
- growStack(STACK_GROW[code]);
+ add(code);
+ growStack(STACK_GROW[code]);
}
/**
@@ -349,10 +338,10 @@ public class Bytecode implements Opcode {
* It also updates <code>max_stack</code> if the current stack depth
* is the deepest so far.
*
- * @param diff the number added to the current stack depth.
+ * @param diff the number added to the current stack depth.
*/
public void growStack(int diff) {
- setStackDepth(stackDepth + diff);
+ setStackDepth(stackDepth + diff);
}
/**
@@ -365,12 +354,12 @@ public class Bytecode implements Opcode {
* It also updates <code>max_stack</code> if the current stack depth
* is the deepest so far.
*
- * @param depth new value.
+ * @param depth new value.
*/
public void setStackDepth(int depth) {
- stackDepth = depth;
- if (stackDepth > maxStack)
- maxStack = stackDepth;
+ stackDepth = depth;
+ if (stackDepth > maxStack)
+ maxStack = stackDepth;
}
/**
@@ -378,321 +367,321 @@ public class Bytecode implements Opcode {
* It never changes the current stack depth.
*/
public void addIndex(int index) {
- add(index >> 8);
- add(index);
+ add(index >> 8);
+ add(index);
}
/**
* Appends ALOAD or (WIDE) ALOAD_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addAload(int n) {
- if (n < 4)
- addOpcode(42 + n); // aload_<n>
- else if (n < 0x100) {
- addOpcode(ALOAD); // aload
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(ALOAD);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(42 + n); // aload_<n>
+ else if (n < 0x100) {
+ addOpcode(ALOAD); // aload
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(ALOAD);
+ addIndex(n);
+ }
}
/**
* Appends ASTORE or (WIDE) ASTORE_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addAstore(int n) {
- if (n < 4)
- addOpcode(75 + n); // astore_<n>
- else if (n < 0x100) {
- addOpcode(ASTORE); // astore
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(ASTORE);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(75 + n); // astore_<n>
+ else if (n < 0x100) {
+ addOpcode(ASTORE); // astore
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(ASTORE);
+ addIndex(n);
+ }
}
/**
* Appends ICONST or ICONST_&lt;n&gt;
*
- * @param n the pushed integer constant.
+ * @param n the pushed integer constant.
*/
public void addIconst(int n) {
- if (n < 6 && -2 < n)
- addOpcode(3 + n); // iconst_<i> -1..5
- else if (n <= 127 && -128 <= n) {
- addOpcode(16); // bipush
- add(n);
- }
- else if (n <= 32767 && -32768 <= n) {
- addOpcode(17); // sipush
- add(n >> 8);
- add(n);
- }
- else
- addLdc(constPool.addIntegerInfo(n));
+ if (n < 6 && -2 < n)
+ addOpcode(3 + n); // iconst_<i> -1..5
+ else if (n <= 127 && -128 <= n) {
+ addOpcode(16); // bipush
+ add(n);
+ }
+ else if (n <= 32767 && -32768 <= n) {
+ addOpcode(17); // sipush
+ add(n >> 8);
+ add(n);
+ }
+ else
+ addLdc(constPool.addIntegerInfo(n));
}
/**
* Appends ILOAD or (WIDE) ILOAD_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addIload(int n) {
- if (n < 4)
- addOpcode(26 + n); // iload_<n>
- else if (n < 0x100) {
- addOpcode(ILOAD); // iload
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(ILOAD);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(26 + n); // iload_<n>
+ else if (n < 0x100) {
+ addOpcode(ILOAD); // iload
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(ILOAD);
+ addIndex(n);
+ }
}
/**
* Appends ISTORE or (WIDE) ISTORE_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addIstore(int n) {
- if (n < 4)
- addOpcode(59 + n); // istore_<n>
- else if (n < 0x100) {
- addOpcode(ISTORE); // istore
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(ISTORE);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(59 + n); // istore_<n>
+ else if (n < 0x100) {
+ addOpcode(ISTORE); // istore
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(ISTORE);
+ addIndex(n);
+ }
}
/**
* Appends LCONST or LCONST_&lt;n&gt;
*
- * @param n the pushed long integer constant.
+ * @param n the pushed long integer constant.
*/
public void addLconst(long n) {
- if (n == 0 || n == 1)
- addOpcode(9 + (int)n); // lconst_<n>
- else
- addLdc2w(n);
+ if (n == 0 || n == 1)
+ addOpcode(9 + (int)n); // lconst_<n>
+ else
+ addLdc2w(n);
}
/**
* Appends LLOAD or (WIDE) LLOAD_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addLload(int n) {
- if (n < 4)
- addOpcode(30 + n); // lload_<n>
- else if (n < 0x100) {
- addOpcode(LLOAD); // lload
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(LLOAD);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(30 + n); // lload_<n>
+ else if (n < 0x100) {
+ addOpcode(LLOAD); // lload
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(LLOAD);
+ addIndex(n);
+ }
}
/**
* Appends LSTORE or LSTORE_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addLstore(int n) {
- if (n < 4)
- addOpcode(63 + n); // lstore_<n>
- else if (n < 0x100) {
- addOpcode(LSTORE); // lstore
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(LSTORE);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(63 + n); // lstore_<n>
+ else if (n < 0x100) {
+ addOpcode(LSTORE); // lstore
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(LSTORE);
+ addIndex(n);
+ }
}
/**
* Appends DCONST or DCONST_&lt;n&gt;
*
- * @param d the pushed double constant.
+ * @param d the pushed double constant.
*/
public void addDconst(double d) {
- if (d == 0.0 || d == 1.0)
- addOpcode(14 + (int)d); // dconst_<n>
- else
- addLdc2w(d);
+ if (d == 0.0 || d == 1.0)
+ addOpcode(14 + (int)d); // dconst_<n>
+ else
+ addLdc2w(d);
}
/**
* Appends DLOAD or (WIDE) DLOAD_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addDload(int n) {
- if (n < 4)
- addOpcode(38 + n); // dload_<n>
- else if (n < 0x100) {
- addOpcode(DLOAD); // dload
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(DLOAD);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(38 + n); // dload_<n>
+ else if (n < 0x100) {
+ addOpcode(DLOAD); // dload
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(DLOAD);
+ addIndex(n);
+ }
}
/**
* Appends DSTORE or (WIDE) DSTORE_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addDstore(int n) {
- if (n < 4)
- addOpcode(71 + n); // dstore_<n>
- else if (n < 0x100) {
- addOpcode(DSTORE); // dstore
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(DSTORE);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(71 + n); // dstore_<n>
+ else if (n < 0x100) {
+ addOpcode(DSTORE); // dstore
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(DSTORE);
+ addIndex(n);
+ }
}
/**
* Appends FCONST or FCONST_&lt;n&gt;
*
- * @param f the pushed float constant.
+ * @param f the pushed float constant.
*/
public void addFconst(float f) {
- if (f == 0.0f || f == 1.0f || f == 2.0f)
- addOpcode(11 + (int)f); // fconst_<n>
- else
- addLdc(constPool.addFloatInfo(f));
+ if (f == 0.0f || f == 1.0f || f == 2.0f)
+ addOpcode(11 + (int)f); // fconst_<n>
+ else
+ addLdc(constPool.addFloatInfo(f));
}
/**
* Appends FLOAD or (WIDE) FLOAD_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addFload(int n) {
- if (n < 4)
- addOpcode(34 + n); // fload_<n>
- else if (n < 0x100) {
- addOpcode(FLOAD); // fload
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(FLOAD);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(34 + n); // fload_<n>
+ else if (n < 0x100) {
+ addOpcode(FLOAD); // fload
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(FLOAD);
+ addIndex(n);
+ }
}
/**
* Appends FSTORE or FSTORE_&lt;n&gt;
*
- * @param n an index into the local variable array.
+ * @param n an index into the local variable array.
*/
public void addFstore(int n) {
- if (n < 4)
- addOpcode(67 + n); // fstore_<n>
- else if (n < 0x100) {
- addOpcode(FSTORE); // fstore
- add(n);
- }
- else {
- addOpcode(WIDE);
- addOpcode(FSTORE);
- addIndex(n);
- }
+ if (n < 4)
+ addOpcode(67 + n); // fstore_<n>
+ else if (n < 0x100) {
+ addOpcode(FSTORE); // fstore
+ add(n);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(FSTORE);
+ addIndex(n);
+ }
}
/**
* Appends an instruction for loading a value from the
* local variable at the index <code>n</code>.
*
- * @param n the index.
- * @param type the type of the loaded value.
- * @return the size of the value (1 or 2 word).
+ * @param n the index.
+ * @param type the type of the loaded value.
+ * @return the size of the value (1 or 2 word).
*/
public int addLoad(int n, CtClass type) {
- if (type.isPrimitive()) {
- if (type == CtClass.booleanType || type == CtClass.charType
- || type == CtClass.byteType || type == CtClass.shortType
- || type == CtClass.intType)
- addIload(n);
- else if (type == CtClass.longType) {
- addLload(n);
- return 2;
- }
- else if(type == CtClass.floatType)
- addFload(n);
- else if(type == CtClass.doubleType) {
- addDload(n);
- return 2;
- }
- else
- throw new RuntimeException("void type?");
- }
- else
- addAload(n);
-
- return 1;
+ if (type.isPrimitive()) {
+ if (type == CtClass.booleanType || type == CtClass.charType
+ || type == CtClass.byteType || type == CtClass.shortType
+ || type == CtClass.intType)
+ addIload(n);
+ else if (type == CtClass.longType) {
+ addLload(n);
+ return 2;
+ }
+ else if(type == CtClass.floatType)
+ addFload(n);
+ else if(type == CtClass.doubleType) {
+ addDload(n);
+ return 2;
+ }
+ else
+ throw new RuntimeException("void type?");
+ }
+ else
+ addAload(n);
+
+ return 1;
}
/**
* Appends an instruction for storing a value into the
* local variable at the index <code>n</code>.
*
- * @param n the index.
- * @param type the type of the stored value.
- * @return 2 if the type is long or double. Otherwise 1.
+ * @param n the index.
+ * @param type the type of the stored value.
+ * @return 2 if the type is long or double. Otherwise 1.
*/
public int addStore(int n, CtClass type) {
- if (type.isPrimitive()) {
- if (type == CtClass.booleanType || type == CtClass.charType
- || type == CtClass.byteType || type == CtClass.shortType
- || type == CtClass.intType)
- addIstore(n);
- else if (type == CtClass.longType) {
- addLstore(n);
- return 2;
- }
- else if(type == CtClass.floatType)
- addFstore(n);
- else if(type == CtClass.doubleType) {
- addDstore(n);
- return 2;
- }
- else
- throw new RuntimeException("void type?");
- }
- else
- addAstore(n);
-
- return 1;
+ if (type.isPrimitive()) {
+ if (type == CtClass.booleanType || type == CtClass.charType
+ || type == CtClass.byteType || type == CtClass.shortType
+ || type == CtClass.intType)
+ addIstore(n);
+ else if (type == CtClass.longType) {
+ addLstore(n);
+ return 2;
+ }
+ else if(type == CtClass.floatType)
+ addFstore(n);
+ else if(type == CtClass.doubleType) {
+ addDstore(n);
+ return 2;
+ }
+ else
+ throw new RuntimeException("void type?");
+ }
+ else
+ addAstore(n);
+
+ return 1;
}
/**
@@ -700,207 +689,207 @@ public class Bytecode implements Opcode {
* operand stack.
*/
public int addLoadParameters(CtClass[] params) {
- int stacksize = 0;
- if (params != null) {
- int n = params.length;
- for (int i = 0; i < n; ++i)
- stacksize += addLoad(stacksize + 1, params[i]);
- }
+ int stacksize = 0;
+ if (params != null) {
+ int n = params.length;
+ for (int i = 0; i < n; ++i)
+ stacksize += addLoad(stacksize + 1, params[i]);
+ }
- return stacksize;
+ return stacksize;
}
/**
* Appends CHECKCAST.
*
- * @param c the type.
+ * @param c the type.
*/
public void addCheckcast(CtClass c) {
- addOpcode(CHECKCAST);
- addIndex(constPool.addClassInfo(c));
+ addOpcode(CHECKCAST);
+ addIndex(constPool.addClassInfo(c));
}
/**
* Appends CHECKCAST.
*
- * @param classname a fully-qualified class name.
+ * @param classname a fully-qualified class name.
*/
public void addCheckcast(String classname) {
- addOpcode(CHECKCAST);
- addIndex(constPool.addClassInfo(classname));
+ addOpcode(CHECKCAST);
+ addIndex(constPool.addClassInfo(classname));
}
/**
* Appends INSTANCEOF.
*
- * @param classname the class name.
+ * @param classname the class name.
*/
public void addInstanceof(String classname) {
- addOpcode(INSTANCEOF);
- addIndex(constPool.addClassInfo(classname));
+ addOpcode(INSTANCEOF);
+ addIndex(constPool.addClassInfo(classname));
}
/**
* Appends GETFIELD.
*
- * @param c the class
- * @param name the field name
- * @param type the descriptor of the field type.
+ * @param c the class
+ * @param name the field name
+ * @param type the descriptor of the field type.
*
* @see Descriptor#of(CtClass)
*/
public void addGetfield(CtClass c, String name, String type) {
- add(GETFIELD);
- int ci = constPool.addClassInfo(c);
- addIndex(constPool.addFieldrefInfo(ci, name, type));
- growStack(Descriptor.dataSize(type) - 1);
+ add(GETFIELD);
+ int ci = constPool.addClassInfo(c);
+ addIndex(constPool.addFieldrefInfo(ci, name, type));
+ growStack(Descriptor.dataSize(type) - 1);
}
/**
* Appends GETSTATIC.
*
- * @param c the class
- * @param name the field name
- * @param type the descriptor of the field type.
+ * @param c the class
+ * @param name the field name
+ * @param type the descriptor of the field type.
*
* @see Descriptor#of(CtClass)
*/
public void addGetstatic(CtClass c, String name, String type) {
- add(GETSTATIC);
- int ci = constPool.addClassInfo(c);
- addIndex(constPool.addFieldrefInfo(ci, name, type));
- growStack(Descriptor.dataSize(type));
+ add(GETSTATIC);
+ int ci = constPool.addClassInfo(c);
+ addIndex(constPool.addFieldrefInfo(ci, name, type));
+ growStack(Descriptor.dataSize(type));
}
/**
* Appends GETSTATIC.
*
- * @param c the fully-qualified class name
- * @param name the field name
- * @param type the descriptor of the field type.
+ * @param c the fully-qualified class name
+ * @param name the field name
+ * @param type the descriptor of the field type.
*
* @see Descriptor#of(CtClass)
*/
public void addGetstatic(String c, String name, String type) {
- add(GETSTATIC);
- int ci = constPool.addClassInfo(c);
- addIndex(constPool.addFieldrefInfo(ci, name, type));
- growStack(Descriptor.dataSize(type));
+ add(GETSTATIC);
+ int ci = constPool.addClassInfo(c);
+ addIndex(constPool.addFieldrefInfo(ci, name, type));
+ growStack(Descriptor.dataSize(type));
}
/**
* Appends INVOKESPECIAL.
*
- * @param clazz the target class.
- * @param name the method name.
- * @param returnType the return type.
- * @param paramTypes the parameter types.
+ * @param clazz the target class.
+ * @param name the method name.
+ * @param returnType the return type.
+ * @param paramTypes the parameter types.
*/
public void addInvokespecial(CtClass clazz, String name,
- CtClass returnType, CtClass[] paramTypes) {
- String desc = Descriptor.ofMethod(returnType, paramTypes);
- addInvokespecial(clazz, name, desc);
+ CtClass returnType, CtClass[] paramTypes) {
+ String desc = Descriptor.ofMethod(returnType, paramTypes);
+ addInvokespecial(clazz, name, desc);
}
/**
* Appends INVOKESPECIAL.
*
- * @param clazz the target class.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
* @see Descriptor#ofConstructor(CtClass[])
*/
public void addInvokespecial(CtClass clazz, String name, String desc) {
- addInvokespecial(constPool.addClassInfo(clazz), name, desc);
+ addInvokespecial(constPool.addClassInfo(clazz), name, desc);
}
/**
* Appends INVOKESPECIAL.
*
- * @param clazz the fully-qualified class name.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the fully-qualified class name.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
* @see Descriptor#ofConstructor(CtClass[])
*/
public void addInvokespecial(String clazz, String name, String desc) {
- addInvokespecial(constPool.addClassInfo(clazz), name, desc);
+ addInvokespecial(constPool.addClassInfo(clazz), name, desc);
}
/**
* Appends INVOKESPECIAL.
*
- * @param clazz the index of <code>CONSTANT_Class_info</code>
- * structure.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the index of <code>CONSTANT_Class_info</code>
+ * structure.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
* @see Descriptor#ofConstructor(CtClass[])
*/
public void addInvokespecial(int clazz, String name, String desc) {
- add(INVOKESPECIAL);
- addIndex(constPool.addMethodrefInfo(clazz, name, desc));
- growStack(Descriptor.dataSize(desc) - 1);
+ add(INVOKESPECIAL);
+ addIndex(constPool.addMethodrefInfo(clazz, name, desc));
+ growStack(Descriptor.dataSize(desc) - 1);
}
/**
* Appends INVOKESTATIC.
*
- * @param clazz the target class.
- * @param name the method name
- * @param returnType the return type.
- * @param paramTypes the parameter types.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param returnType the return type.
+ * @param paramTypes the parameter types.
*/
public void addInvokestatic(CtClass clazz, String name,
- CtClass returnType, CtClass[] paramTypes) {
- String desc = Descriptor.ofMethod(returnType, paramTypes);
- addInvokestatic(clazz, name, desc);
+ CtClass returnType, CtClass[] paramTypes) {
+ String desc = Descriptor.ofMethod(returnType, paramTypes);
+ addInvokestatic(clazz, name, desc);
}
/**
* Appends INVOKESTATIC.
*
- * @param clazz the target class.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(CtClass clazz, String name, String desc) {
- addInvokestatic(constPool.addClassInfo(clazz), name, desc);
+ addInvokestatic(constPool.addClassInfo(clazz), name, desc);
}
/**
* Appends INVOKESTATIC.
*
- * @param classname the fully-qualified class name.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param classname the fully-qualified class name.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(String classname, String name, String desc) {
- addInvokestatic(constPool.addClassInfo(classname), name, desc);
+ addInvokestatic(constPool.addClassInfo(classname), name, desc);
}
/**
* Appends INVOKESTATIC.
*
- * @param clazz the index of <code>CONSTANT_Class_info</code>
- * structure.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the index of <code>CONSTANT_Class_info</code>
+ * structure.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokestatic(int clazz, String name, String desc) {
- add(INVOKESTATIC);
- addIndex(constPool.addMethodrefInfo(clazz, name, desc));
- growStack(Descriptor.dataSize(desc));
+ add(INVOKESTATIC);
+ addIndex(constPool.addMethodrefInfo(clazz, name, desc));
+ growStack(Descriptor.dataSize(desc));
}
/**
@@ -910,15 +899,15 @@ public class Bytecode implements Opcode {
* It must be directly declared in the class specified
* in <code>clazz</code>.
*
- * @param clazz the target class.
- * @param name the method name
- * @param returnType the return type.
- * @param paramTypes the parameter types.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param returnType the return type.
+ * @param paramTypes the parameter types.
*/
public void addInvokevirtual(CtClass clazz, String name,
- CtClass returnType, CtClass[] paramTypes) {
- String desc = Descriptor.ofMethod(returnType, paramTypes);
- addInvokevirtual(clazz, name, desc);
+ CtClass returnType, CtClass[] paramTypes) {
+ String desc = Descriptor.ofMethod(returnType, paramTypes);
+ addInvokevirtual(clazz, name, desc);
}
/**
@@ -928,14 +917,14 @@ public class Bytecode implements Opcode {
* It must be directly declared in the class specified
* in <code>clazz</code>.
*
- * @param clazz the target class.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokevirtual(CtClass clazz, String name, String desc) {
- addInvokevirtual(constPool.addClassInfo(clazz), name, desc);
+ addInvokevirtual(constPool.addClassInfo(clazz), name, desc);
}
/**
@@ -945,14 +934,14 @@ public class Bytecode implements Opcode {
* It must be directly declared in the class specified
* in <code>classname</code>.
*
- * @param classname the fully-qualified class name.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param classname the fully-qualified class name.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokevirtual(String classname, String name, String desc) {
- addInvokevirtual(constPool.addClassInfo(classname), name, desc);
+ addInvokevirtual(constPool.addClassInfo(classname), name, desc);
}
/**
@@ -962,301 +951,301 @@ public class Bytecode implements Opcode {
* It must be directly declared in the class specified
* by <code>clazz</code>.
*
- * @param clazz the index of <code>CONSTANT_Class_info</code>
- * structure.
- * @param name the method name
- * @param desc the descriptor of the method signature.
+ * @param clazz the index of <code>CONSTANT_Class_info</code>
+ * structure.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokevirtual(int clazz, String name, String desc) {
- add(INVOKEVIRTUAL);
- addIndex(constPool.addMethodrefInfo(clazz, name, desc));
- growStack(Descriptor.dataSize(desc) - 1);
+ add(INVOKEVIRTUAL);
+ addIndex(constPool.addMethodrefInfo(clazz, name, desc));
+ growStack(Descriptor.dataSize(desc) - 1);
}
/**
* Appends INVOKEINTERFACE.
*
- * @param clazz the target class.
- * @param name the method name
- * @param returnType the return type.
- * @param paramTypes the parameter types.
- * @param count the count operand of the instruction.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param returnType the return type.
+ * @param paramTypes the parameter types.
+ * @param count the count operand of the instruction.
*/
public void addInvokeinterface(CtClass clazz, String name,
- CtClass returnType, CtClass[] paramTypes,
- int count) {
- String desc = Descriptor.ofMethod(returnType, paramTypes);
- addInvokeinterface(clazz, name, desc, count);
+ CtClass returnType, CtClass[] paramTypes,
+ int count) {
+ String desc = Descriptor.ofMethod(returnType, paramTypes);
+ addInvokeinterface(clazz, name, desc, count);
}
/**
* Appends INVOKEINTERFACE.
*
- * @param clazz the target class.
- * @param name the method name
- * @param desc the descriptor of the method signature.
- * @param count the count operand of the instruction.
+ * @param clazz the target class.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
+ * @param count the count operand of the instruction.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokeinterface(CtClass clazz, String name,
- String desc, int count) {
- addInvokeinterface(constPool.addClassInfo(clazz), name, desc,
- count);
+ String desc, int count) {
+ addInvokeinterface(constPool.addClassInfo(clazz), name, desc,
+ count);
}
/**
* Appends INVOKEINTERFACE.
*
- * @param classname the fully-qualified class name.
- * @param name the method name
- * @param desc the descriptor of the method signature.
- * @param count the count operand of the instruction.
+ * @param classname the fully-qualified class name.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
+ * @param count the count operand of the instruction.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokeinterface(String classname, String name,
- String desc, int count) {
- addInvokeinterface(constPool.addClassInfo(classname), name, desc,
- count);
+ String desc, int count) {
+ addInvokeinterface(constPool.addClassInfo(classname), name, desc,
+ count);
}
/**
* Appends INVOKEINTERFACE.
*
- * @param clazz the index of <code>CONSTANT_Class_info</code>
- * structure.
- * @param name the method name
- * @param desc the descriptor of the method signature.
- * @param count the count operand of the instruction.
+ * @param clazz the index of <code>CONSTANT_Class_info</code>
+ * structure.
+ * @param name the method name
+ * @param desc the descriptor of the method signature.
+ * @param count the count operand of the instruction.
*
* @see Descriptor#ofMethod(CtClass,CtClass[])
*/
public void addInvokeinterface(int clazz, String name,
- String desc, int count) {
- add(INVOKEINTERFACE);
- addIndex(constPool.addInterfaceMethodrefInfo(clazz, name, desc));
- add(count);
- add(0);
- growStack(Descriptor.dataSize(desc) - 1);
+ String desc, int count) {
+ add(INVOKEINTERFACE);
+ addIndex(constPool.addInterfaceMethodrefInfo(clazz, name, desc));
+ add(count);
+ add(0);
+ growStack(Descriptor.dataSize(desc) - 1);
}
/**
* Appends LDC or LDC_W. The pushed item is a <code>String</code>
* object.
*
- * @param s the character string pushed by LDC or LDC_W.
+ * @param s the character string pushed by LDC or LDC_W.
*/
public void addLdc(String s) {
- addLdc(constPool.addStringInfo(s));
+ addLdc(constPool.addStringInfo(s));
}
/**
* Appends LDC or LDC_W.
*
- * @param i index into the constant pool.
+ * @param i index into the constant pool.
*/
public void addLdc(int i) {
- if (i > 0xFF) {
- addOpcode(LDC_W);
- addIndex(i);
- }
- else {
- addOpcode(LDC);
- add(i);
- }
+ if (i > 0xFF) {
+ addOpcode(LDC_W);
+ addIndex(i);
+ }
+ else {
+ addOpcode(LDC);
+ add(i);
+ }
}
/**
* Appends LDC2_W. The pushed item is a long value.
*/
public void addLdc2w(long l) {
- addOpcode(LDC2_W);
- addIndex(constPool.addLongInfo(l));
+ addOpcode(LDC2_W);
+ addIndex(constPool.addLongInfo(l));
}
/**
* Appends LDC2_W. The pushed item is a double value.
*/
public void addLdc2w(double d) {
- addOpcode(LDC2_W);
- addIndex(constPool.addDoubleInfo(d));
+ addOpcode(LDC2_W);
+ addIndex(constPool.addDoubleInfo(d));
}
/**
* Appends NEW.
*
- * @param clazz the class of the created instance.
+ * @param clazz the class of the created instance.
*/
public void addNew(CtClass clazz) {
- addOpcode(NEW);
- addIndex(constPool.addClassInfo(clazz));
+ addOpcode(NEW);
+ addIndex(constPool.addClassInfo(clazz));
}
/**
* Appends NEW.
*
- * @param classname the fully-qualified class name.
+ * @param classname the fully-qualified class name.
*/
public void addNew(String classname) {
- addOpcode(NEW);
- addIndex(constPool.addClassInfo(classname));
+ addOpcode(NEW);
+ addIndex(constPool.addClassInfo(classname));
}
/**
* Appends ANEWARRAY.
*
- * @param classname the qualified class name of the element type.
+ * @param classname the qualified class name of the element type.
*/
public void addAnewarray(String classname) {
- addOpcode(ANEWARRAY);
- addIndex(constPool.addClassInfo(classname));
+ addOpcode(ANEWARRAY);
+ addIndex(constPool.addClassInfo(classname));
}
/**
* Appends ICONST and ANEWARRAY.
*
- * @param clazz the elememnt type.
- * @param length the array length.
+ * @param clazz the elememnt type.
+ * @param length the array length.
*/
public void addAnewarray(CtClass clazz, int length) {
- addIconst(length);
- addOpcode(ANEWARRAY);
- addIndex(constPool.addClassInfo(clazz));
+ addIconst(length);
+ addOpcode(ANEWARRAY);
+ addIndex(constPool.addClassInfo(clazz));
}
/**
* Appends NEWARRAY for primitive types.
*
- * @param atype <code>T_BOOLEAN</code>, <code>T_CHAR</code>, ...
+ * @param atype <code>T_BOOLEAN</code>, <code>T_CHAR</code>, ...
* @see Opcode
*/
public void addNewarray(int atype, int length) {
- addIconst(length);
- addOpcode(NEWARRAY);
- add(atype);
+ addIconst(length);
+ addOpcode(NEWARRAY);
+ add(atype);
}
/**
* Appends MULTINEWARRAY.
*
- * @param clazz the array type.
- * @param dimensions the sizes of all dimensions.
- * @return the length of <code>dimensions</code>.
+ * @param clazz the array type.
+ * @param dimensions the sizes of all dimensions.
+ * @return the length of <code>dimensions</code>.
*/
public int addMultiNewarray(CtClass clazz, int[] dimensions) {
- int len = dimensions.length;
- for (int i = 0; i < len; ++i)
- addIconst(dimensions[i]);
+ int len = dimensions.length;
+ for (int i = 0; i < len; ++i)
+ addIconst(dimensions[i]);
- growStack(len);
- return addMultiNewarray(clazz, len);
+ growStack(len);
+ return addMultiNewarray(clazz, len);
}
/**
* Appends MULTINEWARRAY. The size of every dimension must have been
* already pushed on the stack.
*
- * @param clazz the array type.
- * @param dim the number of the dimensions.
- * @return the value of <code>dim</code>.
+ * @param clazz the array type.
+ * @param dim the number of the dimensions.
+ * @return the value of <code>dim</code>.
*/
public int addMultiNewarray(CtClass clazz, int dim) {
- add(MULTIANEWARRAY);
- addIndex(constPool.addClassInfo(clazz));
- add(dim);
- growStack(1 - dim);
- return dim;
+ add(MULTIANEWARRAY);
+ addIndex(constPool.addClassInfo(clazz));
+ add(dim);
+ growStack(1 - dim);
+ return dim;
}
/**
* Appends MULTINEWARRAY.
*
- * @param desc the type descriptor of the created array.
- * @param dim dimensions.
- * @return the value of <code>dim</code>.
+ * @param desc the type descriptor of the created array.
+ * @param dim dimensions.
+ * @return the value of <code>dim</code>.
*/
public int addMultiNewarray(String desc, int dim) {
- add(MULTIANEWARRAY);
- addIndex(constPool.addClassInfo(desc));
- add(dim);
- growStack(1 - dim);
- return dim;
+ add(MULTIANEWARRAY);
+ addIndex(constPool.addClassInfo(desc));
+ add(dim);
+ growStack(1 - dim);
+ return dim;
}
/**
* Appends PUTFIELD.
*
- * @param c the target class.
- * @param name the field name.
- * @param desc the descriptor of the field type.
+ * @param c the target class.
+ * @param name the field name.
+ * @param desc the descriptor of the field type.
*/
public void addPutfield(CtClass c, String name, String desc) {
- add(PUTFIELD);
- int ci = constPool.addClassInfo(c);
- addIndex(constPool.addFieldrefInfo(ci, name, desc));
- growStack(-1 - Descriptor.dataSize(desc));
+ add(PUTFIELD);
+ int ci = constPool.addClassInfo(c);
+ addIndex(constPool.addFieldrefInfo(ci, name, desc));
+ growStack(-1 - Descriptor.dataSize(desc));
}
/**
* Appends PUTSTATIC.
*
- * @param c the target class.
- * @param name the field name.
- * @param desc the descriptor of the field type.
+ * @param c the target class.
+ * @param name the field name.
+ * @param desc the descriptor of the field type.
*/
public void addPutstatic(CtClass c, String name, String desc) {
- add(PUTSTATIC);
- int ci = constPool.addClassInfo(c);
- addIndex(constPool.addFieldrefInfo(ci, name, desc));
- growStack(-Descriptor.dataSize(desc));
+ add(PUTSTATIC);
+ int ci = constPool.addClassInfo(c);
+ addIndex(constPool.addFieldrefInfo(ci, name, desc));
+ growStack(-Descriptor.dataSize(desc));
}
/**
* Appends ARETURN, IRETURN, .., or RETURN.
*
- * @param type the return type.
+ * @param type the return type.
*/
public void addReturn(CtClass type) {
- if (type == null)
- addOpcode(RETURN);
- else if (type.isPrimitive()) {
- CtPrimitiveType ptype = (CtPrimitiveType)type;
- addOpcode(ptype.getReturnOp());
- }
- else
- addOpcode(ARETURN);
+ if (type == null)
+ addOpcode(RETURN);
+ else if (type.isPrimitive()) {
+ CtPrimitiveType ptype = (CtPrimitiveType)type;
+ addOpcode(ptype.getReturnOp());
+ }
+ else
+ addOpcode(ARETURN);
}
/**
* Appends RET.
*
- * @param var local variable
+ * @param var local variable
*/
public void addRet(int var) {
- if (var < 0x100) {
- addOpcode(RET);
- add(var);
- }
- else {
- addOpcode(WIDE);
- addOpcode(RET);
- addIndex(var);
- }
+ if (var < 0x100) {
+ addOpcode(RET);
+ add(var);
+ }
+ else {
+ addOpcode(WIDE);
+ addOpcode(RET);
+ addIndex(var);
+ }
}
/**
* Appends instructions for executing
* <code>java.lang.System.println(<i>message</i>)</code>.
*
- * @param message printed message.
+ * @param message printed message.
*/
public void addPrintln(String message) {
- addGetstatic("java.lang.System", "err", "Ljava/io/PrintStream;");
- addLdc(message);
- addInvokevirtual("java.io.PrintStream",
- "println", "(Ljava/lang/String;)V");
+ addGetstatic("java.lang.System", "err", "Ljava/io/PrintStream;");
+ addLdc(message);
+ addInvokevirtual("java.io.PrintStream",
+ "println", "(Ljava/lang/String;)V");
}
}
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java
index 063caa59..38e50087 100644
--- a/src/main/javassist/bytecode/ClassFile.java
+++ b/src/main/javassist/bytecode/ClassFile.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -49,85 +38,85 @@ public final class ClassFile {
LinkedList methods;
LinkedList attributes;
- String thisclassname; // not JVM-internal name
+ String thisclassname; // not JVM-internal name
/**
* Constructs a class file from a byte stream.
*/
public ClassFile(DataInputStream in) throws IOException {
- read(in);
+ read(in);
}
/**
* Constructs a class file including no members.
*
- * @param isInterface true if this is an interface.
- * false if this is a class.
- * @param classname a fully-qualified class name
- * @param superclass a fully-qualified super class name
+ * @param isInterface true if this is an interface.
+ * false if this is a class.
+ * @param classname a fully-qualified class name
+ * @param superclass a fully-qualified super class name
*/
public ClassFile(boolean isInterface,
- String classname, String superclass) {
- constPool = new ConstPool(classname);
- thisClass = constPool.getThisClassInfo();
- if (isInterface)
- accessFlags = AccessFlag.SUPER | AccessFlag.INTERFACE
- | AccessFlag.ABSTRACT;
- else
- accessFlags = AccessFlag.SUPER;
-
- initSuperclass(superclass);
- interfaces = null;
- fields = new LinkedList();
- methods = new LinkedList();
- thisclassname = classname;
-
- attributes = new LinkedList();
- attributes.add(new SourceFileAttribute(constPool,
- getSourcefileName(thisclassname)));
+ String classname, String superclass) {
+ constPool = new ConstPool(classname);
+ thisClass = constPool.getThisClassInfo();
+ if (isInterface)
+ accessFlags = AccessFlag.SUPER | AccessFlag.INTERFACE
+ | AccessFlag.ABSTRACT;
+ else
+ accessFlags = AccessFlag.SUPER;
+
+ initSuperclass(superclass);
+ interfaces = null;
+ fields = new LinkedList();
+ methods = new LinkedList();
+ thisclassname = classname;
+
+ attributes = new LinkedList();
+ attributes.add(new SourceFileAttribute(constPool,
+ getSourcefileName(thisclassname)));
}
private void initSuperclass(String superclass) {
- if (superclass != null)
- superClass = constPool.addClassInfo(superclass);
- else
- superClass = constPool.addClassInfo("java.lang.Object");
+ if (superclass != null)
+ superClass = constPool.addClassInfo(superclass);
+ else
+ superClass = constPool.addClassInfo("java.lang.Object");
}
private static String getSourcefileName(String qname) {
- int index = qname.lastIndexOf('.');
- if (index >= 0)
- qname = qname.substring(index + 1);
+ int index = qname.lastIndexOf('.');
+ if (index >= 0)
+ qname = qname.substring(index + 1);
- return qname + ".java";
+ return qname + ".java";
}
/**
* Returns a constant pool table.
*/
public ConstPool getConstPool() {
- return constPool;
+ return constPool;
}
/**
* Returns true if this is an interface.
*/
public boolean isInterface() {
- return (accessFlags & AccessFlag.INTERFACE) != 0;
+ return (accessFlags & AccessFlag.INTERFACE) != 0;
}
/**
* Returns true if this is a final class or interface.
*/
public boolean isFinal() {
- return (accessFlags & AccessFlag.FINAL) != 0;
+ return (accessFlags & AccessFlag.FINAL) != 0;
}
/**
* Returns true if this is an abstract class or an interface.
*/
public boolean isAbstract() {
- return (accessFlags & AccessFlag.ABSTRACT) != 0;
+ return (accessFlags & AccessFlag.ABSTRACT) != 0;
}
/**
@@ -136,7 +125,7 @@ public final class ClassFile {
* @see javassist.bytecode.AccessFlag
*/
public int getAccessFlags() {
- return accessFlags;
+ return accessFlags;
}
/**
@@ -145,14 +134,14 @@ public final class ClassFile {
* @see javassist.bytecode.AccessFlag
*/
public void setAccessFlags(int acc) {
- accessFlags = acc | AccessFlag.SUPER;
+ accessFlags = acc | AccessFlag.SUPER;
}
/**
* Returns the class name.
*/
public String getName() {
- return thisclassname;
+ return thisclassname;
}
/**
@@ -160,14 +149,14 @@ public final class ClassFile {
* for all occurrences of the old class name in the class file.
*/
public void setName(String name) {
- renameClass(thisclassname, name);
+ renameClass(thisclassname, name);
}
/**
* Returns the super class name.
*/
public String getSuperclass() {
- return constPool.getClassInfo(superClass);
+ return constPool.getClassInfo(superClass);
}
/**
@@ -175,7 +164,7 @@ public final class ClassFile {
* the super class.
*/
public int getSuperclassId() {
- return superClass;
+ return superClass;
}
/**
@@ -188,24 +177,24 @@ public final class ClassFile {
* only the calls to a super constructor are modified.
*/
public void setSuperclass(String superclass)
- throws CannotCompileException
+ throws CannotCompileException
{
- if (constPool.getClassInfo(superClass).equals("java.lang.Object")) {
- if (superclass != null)
- try {
- superClass = constPool.addClassInfo(superclass);
- setSuperclass2(superclass);
- }
- catch (BadBytecode e) {
- throw new CannotCompileException(e);
- }
- }
- else {
- if (superclass == null)
- superclass = "java.lang.Object";
-
- renameClass(constPool.getClassInfo(superClass), superclass);
- }
+ if (constPool.getClassInfo(superClass).equals("java.lang.Object")) {
+ if (superclass != null)
+ try {
+ superClass = constPool.addClassInfo(superclass);
+ setSuperclass2(superclass);
+ }
+ catch (BadBytecode e) {
+ throw new CannotCompileException(e);
+ }
+ }
+ else {
+ if (superclass == null)
+ superclass = "java.lang.Object";
+
+ renameClass(constPool.getClassInfo(superClass), superclass);
+ }
}
/* If the original super class is java.lang.Object, a special
@@ -216,12 +205,12 @@ public final class ClassFile {
* where X is the new super class.
*/
private void setSuperclass2(String superclass) throws BadBytecode {
- LinkedList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
- minfo.setSuperclass(superclass);
- }
+ LinkedList list = methods;
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ minfo.setSuperclass(superclass);
+ }
}
/**
@@ -233,104 +222,104 @@ public final class ClassFile {
* If this fact is not guaranteed, the bytecode verifier may cause
* an error.
*
- * @param oldname the replaced class name
- * @param newname the substituted class name
+ * @param oldname the replaced class name
+ * @param newname the substituted class name
*/
public final void renameClass(String oldname, String newname) {
- LinkedList list;
- int n;
-
- if (oldname.equals(newname))
- return;
-
- if (oldname.equals(thisclassname))
- thisclassname = newname;
-
- oldname = Descriptor.toJvmName(oldname);
- newname = Descriptor.toJvmName(newname);
- constPool.renameClass(oldname, newname);
-
- list = methods;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
- String desc = minfo.getDescriptor();
- minfo.setDescriptor(Descriptor.rename(desc, oldname, newname));
- }
-
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
- String desc = finfo.getDescriptor();
- finfo.setDescriptor(Descriptor.rename(desc, oldname, newname));
- }
+ LinkedList list;
+ int n;
+
+ if (oldname.equals(newname))
+ return;
+
+ if (oldname.equals(thisclassname))
+ thisclassname = newname;
+
+ oldname = Descriptor.toJvmName(oldname);
+ newname = Descriptor.toJvmName(newname);
+ constPool.renameClass(oldname, newname);
+
+ list = methods;
+ n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ String desc = minfo.getDescriptor();
+ minfo.setDescriptor(Descriptor.rename(desc, oldname, newname));
+ }
+
+ list = fields;
+ n = list.size();
+ for (int i = 0; i < n; ++i) {
+ FieldInfo finfo = (FieldInfo)list.get(i);
+ String desc = finfo.getDescriptor();
+ finfo.setDescriptor(Descriptor.rename(desc, oldname, newname));
+ }
}
/**
* Replaces all occurrences of several class names in the class file.
*
- * @param classnames specifies which class name is replaced
- * with which new name. Class names must
- * be described with the JVM-internal
- * representation like
- * <code>java/lang/Object</code>.
+ * @param classnames specifies which class name is replaced
+ * with which new name. Class names must
+ * be described with the JVM-internal
+ * representation like
+ * <code>java/lang/Object</code>.
*
* @see #renameClass(String,String)
*/
public final void renameClass(Map classnames) {
- String jvmNewThisName
- = (String)classnames.get(Descriptor.toJvmName(thisclassname));
- if (jvmNewThisName != null)
- thisclassname = Descriptor.toJavaName(jvmNewThisName);
-
- constPool.renameClass(classnames);
-
- LinkedList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
- String desc = minfo.getDescriptor();
- minfo.setDescriptor(Descriptor.rename(desc, classnames));
- }
-
- list = fields;
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
- String desc = finfo.getDescriptor();
- finfo.setDescriptor(Descriptor.rename(desc, classnames));
- }
+ String jvmNewThisName
+ = (String)classnames.get(Descriptor.toJvmName(thisclassname));
+ if (jvmNewThisName != null)
+ thisclassname = Descriptor.toJavaName(jvmNewThisName);
+
+ constPool.renameClass(classnames);
+
+ LinkedList list = methods;
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ String desc = minfo.getDescriptor();
+ minfo.setDescriptor(Descriptor.rename(desc, classnames));
+ }
+
+ list = fields;
+ n = list.size();
+ for (int i = 0; i < n; ++i) {
+ FieldInfo finfo = (FieldInfo)list.get(i);
+ String desc = finfo.getDescriptor();
+ finfo.setDescriptor(Descriptor.rename(desc, classnames));
+ }
}
/**
* Returns the names of the interfaces implemented by the class.
*/
public String[] getInterfaces() {
- if (interfaces == null)
- return new String[0];
- else {
- int n = interfaces.length;
- String[] list = new String[n];
- for (int i = 0; i < n; ++i)
- list[i] = constPool.getClassInfo(interfaces[i]);
-
- return list;
- }
+ if (interfaces == null)
+ return new String[0];
+ else {
+ int n = interfaces.length;
+ String[] list = new String[n];
+ for (int i = 0; i < n; ++i)
+ list[i] = constPool.getClassInfo(interfaces[i]);
+
+ return list;
+ }
}
/**
* Sets the interfaces.
*
- * @param nameList the names of the interfaces.
+ * @param nameList the names of the interfaces.
*/
public void setInterfaces(String[] nameList) {
- if (nameList != null) {
- int n = nameList.length;
- interfaces = new int[n];
- for (int i = 0; i < n; ++i)
- interfaces[i] = constPool.addClassInfo(nameList[i]);
- }
+ if (nameList != null) {
+ int n = nameList.length;
+ interfaces = new int[n];
+ for (int i = 0; i < n; ++i)
+ interfaces[i] = constPool.addClassInfo(nameList[i]);
+ }
}
/**
@@ -338,18 +327,18 @@ public final class ClassFile {
* interfaces implemented by the class.
*/
public void addInterface(String name) {
- int info = constPool.addClassInfo(name);
- if (interfaces == null) {
- interfaces = new int[1];
- interfaces[0] = info;
- }
- else {
- int n = interfaces.length;
- int[] newarray = new int[n + 1];
- System.arraycopy(interfaces, 0, newarray, 0, n);
- newarray[n] = info;
- interfaces = newarray;
- }
+ int info = constPool.addClassInfo(name);
+ if (interfaces == null) {
+ interfaces = new int[1];
+ interfaces[0] = info;
+ }
+ else {
+ int n = interfaces.length;
+ int[] newarray = new int[n + 1];
+ System.arraycopy(interfaces, 0, newarray, 0, n);
+ newarray[n] = info;
+ interfaces = newarray;
+ }
}
/**
@@ -364,7 +353,7 @@ public final class ClassFile {
* Appends a field to the class.
*/
public void addField(FieldInfo finfo) {
- fields.add(finfo);
+ fields.add(finfo);
}
/**
@@ -379,18 +368,18 @@ public final class ClassFile {
* Returns the method with the specified name. If there are multiple
* methods with that name, this method returns one of them.
*
- * @return null if no such a method is found.
+ * @return null if no such a method is found.
*/
public MethodInfo getMethod(String name) {
- LinkedList list = methods;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
- if (minfo.getName().equals(name))
- return minfo;
- }
-
- return null;
+ LinkedList list = methods;
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ if (minfo.getName().equals(name))
+ return minfo;
+ }
+
+ return null;
}
/**
@@ -398,14 +387,14 @@ public final class ClassFile {
* it does not exist.
*/
public MethodInfo getStaticInitializer() {
- return getMethod(MethodInfo.nameClinit);
+ return getMethod(MethodInfo.nameClinit);
}
/**
* Appends a method to the class.
*/
public void addMethod(MethodInfo minfo) {
- methods.add(minfo);
+ methods.add(minfo);
}
/**
@@ -419,18 +408,18 @@ public final class ClassFile {
/**
* Returns the attribute with the specified name.
*
- * @param name attribute name
+ * @param name attribute name
*/
public AttributeInfo getAttribute(String name) {
- LinkedList list = attributes;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo ai = (AttributeInfo)list.get(i);
- if (ai.getName().equals(name))
- return ai;
- }
-
- return null;
+ LinkedList list = attributes;
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ AttributeInfo ai = (AttributeInfo)list.get(i);
+ if (ai.getName().equals(name))
+ return ai;
+ }
+
+ return null;
}
/**
@@ -438,63 +427,63 @@ public final class ClassFile {
* the same name, the new one substitutes for it.
*/
public void addAttribute(AttributeInfo info) {
- AttributeInfo.remove(attributes, info.getName());
- attributes.add(info);
+ AttributeInfo.remove(attributes, info.getName());
+ attributes.add(info);
}
/**
* Returns the source file containing this class.
*
- * @return null if this information is not available.
+ * @return null if this information is not available.
*/
public String getSourceFile() {
- SourceFileAttribute sf
- = (SourceFileAttribute)getAttribute(SourceFileAttribute.tag);
- if (sf == null)
- return null;
- else
- return sf.getFileName();
+ SourceFileAttribute sf
+ = (SourceFileAttribute)getAttribute(SourceFileAttribute.tag);
+ if (sf == null)
+ return null;
+ else
+ return sf.getFileName();
}
private void read(DataInputStream in) throws IOException {
- int i, n;
- int magic = in.readInt();
- if (magic != 0xCAFEBABE)
- throw new IOException("non class file");
-
- int major = in.readUnsignedShort();
- int minor = in.readUnsignedShort();
- constPool = new ConstPool(in);
- accessFlags = in.readUnsignedShort();
- thisClass = in.readUnsignedShort();
- constPool.setThisClassInfo(thisClass);
- superClass = in.readUnsignedShort();
- n = in.readUnsignedShort();
- if (n == 0)
- interfaces = null;
- else {
- interfaces = new int[n];
- for (i = 0; i < n; ++i)
- interfaces[i] = in.readUnsignedShort();
- }
-
- ConstPool cp = constPool;
- n = in.readUnsignedShort();
- fields = new LinkedList();
- for (i = 0; i < n; ++i)
- addField(new FieldInfo(cp, in));
-
- n = in.readUnsignedShort();
- methods = new LinkedList();
- for (i = 0; i < n; ++i)
- addMethod(new MethodInfo(cp, in));
-
- attributes = new LinkedList();
- n = in.readUnsignedShort();
- for (i = 0; i < n; ++i)
- addAttribute(AttributeInfo.read(cp, in));
-
- thisclassname = constPool.getClassInfo(thisClass);
+ int i, n;
+ int magic = in.readInt();
+ if (magic != 0xCAFEBABE)
+ throw new IOException("non class file");
+
+ int major = in.readUnsignedShort();
+ int minor = in.readUnsignedShort();
+ constPool = new ConstPool(in);
+ accessFlags = in.readUnsignedShort();
+ thisClass = in.readUnsignedShort();
+ constPool.setThisClassInfo(thisClass);
+ superClass = in.readUnsignedShort();
+ n = in.readUnsignedShort();
+ if (n == 0)
+ interfaces = null;
+ else {
+ interfaces = new int[n];
+ for (i = 0; i < n; ++i)
+ interfaces[i] = in.readUnsignedShort();
+ }
+
+ ConstPool cp = constPool;
+ n = in.readUnsignedShort();
+ fields = new LinkedList();
+ for (i = 0; i < n; ++i)
+ addField(new FieldInfo(cp, in));
+
+ n = in.readUnsignedShort();
+ methods = new LinkedList();
+ for (i = 0; i < n; ++i)
+ addMethod(new MethodInfo(cp, in));
+
+ attributes = new LinkedList();
+ n = in.readUnsignedShort();
+ for (i = 0; i < n; ++i)
+ addAttribute(AttributeInfo.read(cp, in));
+
+ thisclassname = constPool.getClassInfo(thisClass);
}
/**
@@ -502,42 +491,42 @@ public final class ClassFile {
* into an output stream.
*/
public void write(DataOutputStream out) throws IOException {
- int i, n;
-
- out.writeInt(0xCAFEBABE); // magic
- out.writeShort(3); // major version
- out.writeShort(45); // minor version
- constPool.write(out); // constant pool
- out.writeShort(accessFlags);
- out.writeShort(thisClass);
- out.writeShort(superClass);
-
- if (interfaces == null)
- n = 0;
- else
- n = interfaces.length;
-
- out.writeShort(n);
- for (i = 0; i < n; ++i)
- out.writeShort(interfaces[i]);
-
- LinkedList list = fields;
- n = list.size();
- out.writeShort(n);
- for (i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.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);
- minfo.write(out);
- }
-
- out.writeShort(attributes.size());
- AttributeInfo.writeAll(attributes, out);
+ int i, n;
+
+ out.writeInt(0xCAFEBABE); // magic
+ out.writeShort(3); // major version
+ out.writeShort(45); // minor version
+ constPool.write(out); // constant pool
+ out.writeShort(accessFlags);
+ out.writeShort(thisClass);
+ out.writeShort(superClass);
+
+ if (interfaces == null)
+ n = 0;
+ else
+ n = interfaces.length;
+
+ out.writeShort(n);
+ for (i = 0; i < n; ++i)
+ out.writeShort(interfaces[i]);
+
+ LinkedList list = fields;
+ n = list.size();
+ out.writeShort(n);
+ for (i = 0; i < n; ++i) {
+ FieldInfo finfo = (FieldInfo)list.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);
+ minfo.write(out);
+ }
+
+ out.writeShort(attributes.size());
+ AttributeInfo.writeAll(attributes, out);
}
}
diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFileWriter.java
index 5b83a5aa..c7ddacbf 100644
--- a/src/main/javassist/bytecode/ClassFileWriter.java
+++ b/src/main/javassist/bytecode/ClassFileWriter.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.PrintWriter;
@@ -39,78 +28,78 @@ public class ClassFileWriter {
* Prints the contents of a class file to the standard output stream.
*/
public static void print(ClassFile cf) {
- print(cf, new PrintWriter(System.out, true));
+ print(cf, new PrintWriter(System.out, true));
}
/**
* Prints the contents of a class file.
*/
public static void print(ClassFile cf, PrintWriter out) {
- List list;
- int n;
+ List list;
+ int n;
- /* 0x0020 (SYNCHRONIZED) means ACC_SUPER if the modifiers
- * are of a class.
- */
- int mod
- = AccessFlag.toModifier(cf.getAccessFlags()
- & ~AccessFlag.SYNCHRONIZED);
- out.println(Modifier.toString(mod) + " class "
- + cf.getName() + " extends " + cf.getSuperclass());
- out.println();
+ /* 0x0020 (SYNCHRONIZED) means ACC_SUPER if the modifiers
+ * are of a class.
+ */
+ int mod
+ = AccessFlag.toModifier(cf.getAccessFlags()
+ & ~AccessFlag.SYNCHRONIZED);
+ out.println(Modifier.toString(mod) + " class "
+ + cf.getName() + " extends " + cf.getSuperclass());
+ out.println();
- ConstPool cp = cf.getConstPool();
- list = cf.getFields();
- n = list.size();
- for (int i = 0; i < n; ++i) {
- FieldInfo finfo = (FieldInfo)list.get(i);
- int acc = finfo.getAccessFlags();
- out.println(Modifier.toString(AccessFlag.toModifier(acc))
- + " " + finfo.getName() + "\t"
- + finfo.getDescriptor());
- printAttributes(finfo.getAttributes(), out);
- }
+ ConstPool cp = cf.getConstPool();
+ list = cf.getFields();
+ n = list.size();
+ for (int i = 0; i < n; ++i) {
+ FieldInfo finfo = (FieldInfo)list.get(i);
+ int acc = finfo.getAccessFlags();
+ out.println(Modifier.toString(AccessFlag.toModifier(acc))
+ + " " + finfo.getName() + "\t"
+ + finfo.getDescriptor());
+ printAttributes(finfo.getAttributes(), out);
+ }
- out.println();
- list = cf.getMethods();
- n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
- int acc = minfo.getAccessFlags();
- out.println(Modifier.toString(AccessFlag.toModifier(acc))
- + " " + minfo.getName() + "\t"
- + minfo.getDescriptor());
- printAttributes(minfo.getAttributes(), out);
- out.println();
- }
+ out.println();
+ list = cf.getMethods();
+ n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ int acc = minfo.getAccessFlags();
+ out.println(Modifier.toString(AccessFlag.toModifier(acc))
+ + " " + minfo.getName() + "\t"
+ + minfo.getDescriptor());
+ printAttributes(minfo.getAttributes(), out);
+ out.println();
+ }
- out.println();
- printAttributes(cf.getAttributes(), out);
+ out.println();
+ printAttributes(cf.getAttributes(), out);
}
static void printAttributes(List list, PrintWriter out) {
- if (list == null)
- return;
+ if (list == null)
+ return;
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- AttributeInfo ai = (AttributeInfo)list.get(i);
- if (ai instanceof CodeAttribute) {
- CodeAttribute ca = (CodeAttribute)ai;
- out.println("attribute: " + ai.getName() + ": "
- + ai.getClass().getName());
- out.println("max stack " + ca.getMaxStack()
- + ", max locals " + ca.getMaxLocals()
- + ", " + ca.getExceptionTable().size()
- + " catch blocks");
- out.println("<code attribute begin>");
- printAttributes(ca.getAttributes(), out);
- out.println("<code attribute end>");
- }
- else
- out.println("attribute: " + ai.getName()
- + " (" + ai.get().length + " byte): "
- + ai.getClass().getName());
- }
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ AttributeInfo ai = (AttributeInfo)list.get(i);
+ if (ai instanceof CodeAttribute) {
+ CodeAttribute ca = (CodeAttribute)ai;
+ out.println("attribute: " + ai.getName() + ": "
+ + ai.getClass().getName());
+ out.println("max stack " + ca.getMaxStack()
+ + ", max locals " + ca.getMaxLocals()
+ + ", " + ca.getExceptionTable().size()
+ + " catch blocks");
+ out.println("<code attribute begin>");
+ printAttributes(ca.getAttributes(), out);
+ out.println("<code attribute end>");
+ }
+ else
+ out.println("attribute: " + ai.getName()
+ + " (" + ai.get().length + " byte): "
+ + ai.getClass().getName());
+ }
}
}
diff --git a/src/main/javassist/bytecode/CodeAttribute.java b/src/main/javassist/bytecode/CodeAttribute.java
index 6f45c03e..84511f58 100644
--- a/src/main/javassist/bytecode/CodeAttribute.java
+++ b/src/main/javassist/bytecode/CodeAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -58,100 +47,100 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
/**
* Constructs a <code>Code_attribute</code>.
*
- * @param cp constant pool table
- * @param stack <code>max_stack</code>
- * @param locals <code>max_locals</code>
- * @param code <code>code[]</code>
- * @param etable <code>exception_table[]</code>
+ * @param cp constant pool table
+ * @param stack <code>max_stack</code>
+ * @param locals <code>max_locals</code>
+ * @param code <code>code[]</code>
+ * @param etable <code>exception_table[]</code>
*/
public CodeAttribute(ConstPool cp, int stack, int locals, byte[] code,
- ExceptionTable etable)
+ ExceptionTable etable)
{
- super(cp, tag);
- maxStack = stack;
- maxLocals = locals;
- info = code;
- exceptions = etable;
- attributes = new LinkedList();
+ super(cp, tag);
+ maxStack = stack;
+ maxLocals = locals;
+ info = code;
+ exceptions = etable;
+ attributes = new LinkedList();
}
/**
* Constructs a copy of <code>Code_attribute</code>.
* Specified class names are replaced during the copy.
*
- * @param cp constant pool table.
- * @param src source Code attribute.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param cp constant pool table.
+ * @param src source Code attribute.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
private CodeAttribute(ConstPool cp, CodeAttribute src, Map classnames)
- throws BadBytecode
+ throws BadBytecode
{
- super(cp, tag);
-
- maxStack = src.getMaxStack();
- maxLocals = src.getMaxLocals();
- exceptions = src.getExceptionTable().copy(cp, classnames);
- info = src.copyCode(cp, classnames, exceptions);
- attributes = new LinkedList();
-
- /* Since an index into the source constant pool table may not
- be translated, we don't copy the attributes.
- */
- /*
- List src_attr = src.getAttributes();
- int num = src_attr.size();
- for (int i = 0; i < num; ++i) {
- AttributeInfo ai = (AttributeInfo)src_attr.get(i);
- attributes.add(ai.copy(cp, classnames));
- }
- */
+ super(cp, tag);
+
+ maxStack = src.getMaxStack();
+ maxLocals = src.getMaxLocals();
+ exceptions = src.getExceptionTable().copy(cp, classnames);
+ info = src.copyCode(cp, classnames, exceptions);
+ attributes = new LinkedList();
+
+ /* Since an index into the source constant pool table may not
+ be translated, we don't copy the attributes.
+ */
+ /*
+ List src_attr = src.getAttributes();
+ int num = src_attr.size();
+ for (int i = 0; i < num; ++i) {
+ AttributeInfo ai = (AttributeInfo)src_attr.get(i);
+ attributes.add(ai.copy(cp, classnames));
+ }
+ */
}
CodeAttribute(ConstPool cp, int name_id, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, name_id, (byte[])null);
- int attr_len = in.readInt();
+ super(cp, name_id, (byte[])null);
+ int attr_len = in.readInt();
- maxStack = in.readUnsignedShort();
- maxLocals = in.readUnsignedShort();
+ maxStack = in.readUnsignedShort();
+ maxLocals = in.readUnsignedShort();
- int code_len = in.readInt();
- info = new byte[code_len];
- in.readFully(info);
+ int code_len = in.readInt();
+ info = new byte[code_len];
+ in.readFully(info);
- exceptions = new ExceptionTable(cp, in);
+ exceptions = new ExceptionTable(cp, in);
- attributes = new LinkedList();
- int num = in.readUnsignedShort();
- for (int i = 0; i < num; ++i)
- attributes.add(AttributeInfo.read(cp, in));
+ attributes = new LinkedList();
+ int num = in.readUnsignedShort();
+ for (int i = 0; i < num; ++i)
+ attributes.add(AttributeInfo.read(cp, in));
}
/**
* Makes a copy. Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
- * @exception RuntimeCopyException if a <code>BadBytecode</code>
- * exception is thrown, it is
- * converted into
- * <code>RuntimeCopyException</code>.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
+ * @exception RuntimeCopyException if a <code>BadBytecode</code>
+ * exception is thrown, it is
+ * converted into
+ * <code>RuntimeCopyException</code>.
*
* @return <code>CodeAttribute</code> object.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames)
- throws RuntimeCopyException
+ throws RuntimeCopyException
{
- try {
- return new CodeAttribute(newCp, this, classnames);
- }
- catch (BadBytecode e) {
- throw new RuntimeCopyException("bad bytecode. fatal?");
- }
+ try {
+ return new CodeAttribute(newCp, this, classnames);
+ }
+ catch (BadBytecode e) {
+ throw new RuntimeCopyException("bad bytecode. fatal?");
+ }
}
/**
@@ -159,12 +148,12 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* in <code>CodeAttribute</code>.
*/
public static class RuntimeCopyException extends RuntimeException {
- /**
- * Constructs an exception.
- */
- public RuntimeCopyException(String s) {
- super(s);
- }
+ /**
+ * Constructs an exception.
+ */
+ public RuntimeCopyException(String s) {
+ super(s);
+ }
}
/**
@@ -173,38 +162,38 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* The returned value is <code>attribute_length + 6</code>.
*/
public int length() {
- return 18 + info.length + exceptions.size() * 8
- + AttributeInfo.getLength(attributes);
+ return 18 + info.length + exceptions.size() * 8
+ + AttributeInfo.getLength(attributes);
}
void write(DataOutputStream out) throws IOException {
- out.writeShort(name); // attribute_name_index
- out.writeInt(length() - 6); // attribute_length
- out.writeShort(maxStack); // max_stack
- out.writeShort(maxLocals); // max_locals
- out.writeInt(info.length); // code_length
- out.write(info); // code
- exceptions.write(out);
- out.writeShort(attributes.size()); // attributes_count
- AttributeInfo.writeAll(attributes, out); // attributes
+ out.writeShort(name); // attribute_name_index
+ out.writeInt(length() - 6); // attribute_length
+ out.writeShort(maxStack); // max_stack
+ out.writeShort(maxLocals); // max_locals
+ out.writeInt(info.length); // code_length
+ out.write(info); // code
+ exceptions.write(out);
+ out.writeShort(attributes.size()); // attributes_count
+ AttributeInfo.writeAll(attributes, out); // attributes
}
/**
* This method is not available.
*
- * @throws java.lang.UnsupportedOperationException always thrown.
+ * @throws java.lang.UnsupportedOperationException always thrown.
*/
public byte[] get() {
- throw new UnsupportedOperationException("CodeAttribute.get()");
+ throw new UnsupportedOperationException("CodeAttribute.get()");
}
/**
* This method is not available.
*
- * @throws java.lang.UnsupportedOperationException always thrown.
+ * @throws java.lang.UnsupportedOperationException always thrown.
*/
public void set(byte[] newinfo) {
- throw new UnsupportedOperationException("CodeAttribute.set()");
+ throw new UnsupportedOperationException("CodeAttribute.set()");
}
/**
@@ -212,50 +201,50 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* this code attribute.
*/
public String getDeclaringClass() {
- ConstPool cp = getConstPool();
- return cp.getClassName();
+ ConstPool cp = getConstPool();
+ return cp.getClassName();
}
/**
* Returns <code>max_stack</code>.
*/
public int getMaxStack() {
- return maxStack;
+ return maxStack;
}
/**
* Sets <code>max_stack</code>.
*/
public void setMaxStack(int value) {
- maxStack = value;
+ maxStack = value;
}
/**
* Returns <code>max_locals</code>.
*/
public int getMaxLocals() {
- return maxLocals;
+ return maxLocals;
}
/**
* Sets <code>max_locals</code>.
*/
public void setMaxLocals(int value) {
- maxLocals = value;
+ maxLocals = value;
}
/**
* Returns <code>code_length</code>.
*/
public int getCodeLength() {
- return info.length;
+ return info.length;
}
/**
* Returns <code>code[]</code>.
*/
public byte[] getCode() {
- return info;
+ return info;
}
/**
@@ -267,7 +256,7 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* Makes a new iterator for reading this code attribute.
*/
public CodeIterator iterator() {
- return new CodeIterator(this);
+ return new CodeIterator(this);
}
/**
@@ -287,99 +276,99 @@ public class CodeAttribute extends AttributeInfo implements Opcode {
* Returns the attribute with the specified name.
* If it is not found, this method returns null.
*
- * @param name attribute name
- * @return an <code>AttributeInfo</code> object or null.
+ * @param name attribute name
+ * @return an <code>AttributeInfo</code> object or null.
*/
public AttributeInfo getAttribute(String name) {
- return AttributeInfo.lookup(attributes, name);
+ return AttributeInfo.lookup(attributes, name);
}
/**
* Copies code.
*/
private byte[] copyCode(ConstPool destCp, Map classnames,
- ExceptionTable etable)
- throws BadBytecode
+ ExceptionTable etable)
+ throws BadBytecode
{
- int len = getCodeLength();
- byte[] newCode = new byte[len];
+ int len = getCodeLength();
+ byte[] newCode = new byte[len];
- LdcEntry ldc = copyCode(this.info, 0, len, this.getConstPool(),
- newCode, destCp, classnames);
- return LdcEntry.doit(newCode, ldc, etable);
+ LdcEntry ldc = copyCode(this.info, 0, len, this.getConstPool(),
+ newCode, destCp, classnames);
+ return LdcEntry.doit(newCode, ldc, etable);
}
private static LdcEntry copyCode(byte[] code, int beginPos, int endPos,
- ConstPool srcCp, byte[] newcode,
- ConstPool destCp, Map classnameMap)
- throws BadBytecode
+ ConstPool srcCp, byte[] newcode,
+ ConstPool destCp, Map classnameMap)
+ throws BadBytecode
{
- int i2, index;
- LdcEntry ldcEntry = null;
-
- for (int i = beginPos; i < endPos; i = i2) {
- i2 = CodeIterator.nextOpcode(code, i);
- byte c = code[i];
- newcode[i] = c;
- switch (c & 0xff) {
- case LDC_W :
- case LDC2_W :
- case GETSTATIC :
- case PUTSTATIC :
- case GETFIELD :
- case PUTFIELD :
- case INVOKEVIRTUAL :
- case INVOKESPECIAL :
- case INVOKESTATIC :
- case NEW :
- case ANEWARRAY :
- case CHECKCAST :
- case INSTANCEOF :
- copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp,
- classnameMap);
- break;
- case LDC :
- index = code[i + 1] & 0xff;
- index = srcCp.copy(index, destCp, classnameMap);
- if (index < 0x100)
- newcode[i + 1] = (byte)index;
- else {
- LdcEntry ldc = new LdcEntry();
- ldc.where = i;
- ldc.index = index;
- ldc.next = ldcEntry;
- ldcEntry = ldc;
- }
- break;
- case INVOKEINTERFACE :
- copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp,
- classnameMap);
- newcode[i + 3] = code[i + 3];
- newcode[i + 4] = code[i + 4];
- break;
- case MULTIANEWARRAY :
- copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp,
- classnameMap);
- newcode[i + 3] = code[i + 3];
- break;
- default :
- while (++i < i2)
- newcode[i] = code[i];
-
- break;
- }
- }
-
- return ldcEntry;
+ int i2, index;
+ LdcEntry ldcEntry = null;
+
+ for (int i = beginPos; i < endPos; i = i2) {
+ i2 = CodeIterator.nextOpcode(code, i);
+ byte c = code[i];
+ newcode[i] = c;
+ switch (c & 0xff) {
+ case LDC_W :
+ case LDC2_W :
+ case GETSTATIC :
+ case PUTSTATIC :
+ case GETFIELD :
+ case PUTFIELD :
+ case INVOKEVIRTUAL :
+ case INVOKESPECIAL :
+ case INVOKESTATIC :
+ case NEW :
+ case ANEWARRAY :
+ case CHECKCAST :
+ case INSTANCEOF :
+ copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp,
+ classnameMap);
+ break;
+ case LDC :
+ index = code[i + 1] & 0xff;
+ index = srcCp.copy(index, destCp, classnameMap);
+ if (index < 0x100)
+ newcode[i + 1] = (byte)index;
+ else {
+ LdcEntry ldc = new LdcEntry();
+ ldc.where = i;
+ ldc.index = index;
+ ldc.next = ldcEntry;
+ ldcEntry = ldc;
+ }
+ break;
+ case INVOKEINTERFACE :
+ copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp,
+ classnameMap);
+ newcode[i + 3] = code[i + 3];
+ newcode[i + 4] = code[i + 4];
+ break;
+ case MULTIANEWARRAY :
+ copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp,
+ classnameMap);
+ newcode[i + 3] = code[i + 3];
+ break;
+ default :
+ while (++i < i2)
+ newcode[i] = code[i];
+
+ break;
+ }
+ }
+
+ return ldcEntry;
}
private static void copyConstPoolInfo(int i, byte[] code, ConstPool srcCp,
- byte[] newcode, ConstPool destCp,
- Map classnameMap) {
- int index = ((code[i] & 0xff) << 8) | (code[i + 1] & 0xff);
- index = srcCp.copy(index, destCp, classnameMap);
- newcode[i] = (byte)(index >> 8);
- newcode[i + 1] = (byte)index;
+ byte[] newcode, ConstPool destCp,
+ Map classnameMap) {
+ int index = ((code[i] & 0xff) << 8) | (code[i + 1] & 0xff);
+ index = srcCp.copy(index, destCp, classnameMap);
+ newcode[i] = (byte)(index >> 8);
+ newcode[i + 1] = (byte)index;
}
}
@@ -389,16 +378,16 @@ final class LdcEntry {
int index;
static byte[] doit(byte[] code, LdcEntry ldc, ExceptionTable etable)
- throws BadBytecode
+ throws BadBytecode
{
- while (ldc != null) {
- int where = ldc.where;
- code = CodeIterator.insertGap(code, where, 1, false, etable);
- code[where] = (byte)Opcode.LDC_W;
- ByteArray.write16bit(ldc.index, code, where + 1);
- ldc = ldc.next;
- }
-
- return code;
+ while (ldc != null) {
+ int where = ldc.where;
+ code = CodeIterator.insertGap(code, where, 1, false, etable);
+ code[where] = (byte)Opcode.LDC_W;
+ ByteArray.write16bit(ldc.index, code, where + 1);
+ ldc = ldc.next;
+ }
+
+ return code;
}
}
diff --git a/src/main/javassist/bytecode/CodeIterator.java b/src/main/javassist/bytecode/CodeIterator.java
index 09735e27..f2923488 100644
--- a/src/main/javassist/bytecode/CodeIterator.java
+++ b/src/main/javassist/bytecode/CodeIterator.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
/**
@@ -41,17 +30,17 @@ public class CodeIterator implements Opcode {
protected int currentPos;
CodeIterator(CodeAttribute ca) {
- codeAttr = ca;
- bytecode = ca.getCode();
- begin();
+ codeAttr = ca;
+ bytecode = ca.getCode();
+ begin();
}
/**
* Moves to the first instruction.
*/
public void begin() {
- currentPos = 0;
- endPos = getCodeLength();
+ currentPos = 0;
+ endPos = getCodeLength();
}
/**
@@ -67,21 +56,21 @@ public class CodeIterator implements Opcode {
* @see CodeAttribute#getCode()
*/
public void move(int index) {
- currentPos = index;
+ currentPos = index;
}
/**
* Returns a Code attribute read with this iterator.
*/
public CodeAttribute get() {
- return codeAttr;
+ return codeAttr;
}
/**
* Returns <code>code_length</code> of <code>Code_attribute</code>.
*/
public int getCodeLength() {
- return bytecode.length;
+ return bytecode.length;
}
/**
@@ -93,51 +82,51 @@ public class CodeIterator implements Opcode {
* Writes an 8bit value at the given index.
*/
public void writeByte(int value, int index) {
- bytecode[index] = (byte)value;
+ bytecode[index] = (byte)value;
}
/**
* Returns the unsigned 16bit value at the given index.
*/
public int u16bitAt(int index) {
- return ByteArray.readU16bit(bytecode, index);
+ return ByteArray.readU16bit(bytecode, index);
}
/**
* Returns the signed 16bit value at the given index.
*/
public int s16bitAt(int index) {
- return ByteArray.readS16bit(bytecode, index);
+ return ByteArray.readS16bit(bytecode, index);
}
/**
* Writes a 16 bit integer at the index.
*/
public void write16bit(int value, int index) {
- ByteArray.write16bit(value, bytecode, index);
+ ByteArray.write16bit(value, bytecode, index);
}
/**
* Returns the signed 32bit value at the given index.
*/
public int s32bitAt(int index) {
- return ByteArray.read32bit(bytecode, index);
+ return ByteArray.read32bit(bytecode, index);
}
/**
* Writes a 32bit integer at the index.
*/
public void write32bit(int value, int index) {
- ByteArray.write32bit(value, bytecode, index);
+ ByteArray.write32bit(value, bytecode, index);
}
/**
* Writes a byte array at the index.
*/
public void write(byte[] code, int index) {
- int len = code.length;
- for (int j = 0; j < len; ++j)
- bytecode[index++] = code[j];
+ int len = code.length;
+ for (int j = 0; j < len; ++j)
+ bytecode[index++] = code[j];
}
/**
@@ -156,9 +145,9 @@ public class CodeIterator implements Opcode {
* @see CodeIterator#byteAt(int)
*/
public int next() throws BadBytecode {
- int pos = currentPos;
- currentPos = nextOpcode(bytecode, pos);
- return pos;
+ int pos = currentPos;
+ currentPos = nextOpcode(bytecode, pos);
+ return pos;
}
/**
@@ -176,11 +165,11 @@ public class CodeIterator implements Opcode {
*
* <p>This method works only for a constructor.
*
- * @return the index of the INVOKESPECIAL instruction, or -1
- * if a constructor invocation is not found.
+ * @return the index of the INVOKESPECIAL instruction, or -1
+ * if a constructor invocation is not found.
*/
public int skipConstructor() throws BadBytecode {
- return skipSuperConstructor0(-1);
+ return skipSuperConstructor0(-1);
}
/**
@@ -198,12 +187,12 @@ public class CodeIterator implements Opcode {
*
* <p>This method works only for a constructor.
*
- * @return the index of the INVOKESPECIAL instruction, or -1
- * if a super constructor invocation is not found
- * but <code>this()</code> is found.
+ * @return the index of the INVOKESPECIAL instruction, or -1
+ * if a super constructor invocation is not found
+ * but <code>this()</code> is found.
*/
public int skipSuperConstructor() throws BadBytecode {
- return skipSuperConstructor0(0);
+ return skipSuperConstructor0(0);
}
/**
@@ -221,44 +210,44 @@ public class CodeIterator implements Opcode {
*
* <p>This method works only for a constructor.
*
- * @return the index of the INVOKESPECIAL instruction, or -1
- * if a explicit constructor invocation is not found
- * but <code>super()</code> is found.
+ * @return the index of the INVOKESPECIAL instruction, or -1
+ * if a explicit constructor invocation is not found
+ * but <code>super()</code> is found.
*/
public int skipThisConstructor() throws BadBytecode {
- return skipSuperConstructor0(1);
+ return skipSuperConstructor0(1);
}
- /* skipSuper 1: this(), 0: super(), -1: both.
+ /* skipSuper 1: this(), 0: super(), -1: both.
*/
private int skipSuperConstructor0(int skipThis) throws BadBytecode {
- begin();
- ConstPool cp = codeAttr.getConstPool();
- String thisClassName = codeAttr.getDeclaringClass();
- int nested = 0;
- while (hasNext()) {
- int index = next();
- int c = byteAt(index);
- if (c == NEW)
- ++nested;
- else if (c == INVOKESPECIAL) {
- int mref = ByteArray.readU16bit(bytecode, index + 1);
- if (cp.getMethodrefName(mref).equals(MethodInfo.nameInit))
- if (--nested < 0) {
- if (skipThis < 0)
- return index;
-
- String cname = cp.getMethodrefClassName(mref);
- if (cname.equals(thisClassName) == (skipThis > 0))
- return index;
- else
- break;
- }
- }
- }
-
- begin();
- return -1;
+ begin();
+ ConstPool cp = codeAttr.getConstPool();
+ String thisClassName = codeAttr.getDeclaringClass();
+ int nested = 0;
+ while (hasNext()) {
+ int index = next();
+ int c = byteAt(index);
+ if (c == NEW)
+ ++nested;
+ else if (c == INVOKESPECIAL) {
+ int mref = ByteArray.readU16bit(bytecode, index + 1);
+ if (cp.getMethodrefName(mref).equals(MethodInfo.nameInit))
+ if (--nested < 0) {
+ if (skipThis < 0)
+ return index;
+
+ String cname = cp.getMethodrefClassName(mref);
+ if (cname.equals(thisClassName) == (skipThis > 0))
+ return index;
+ else
+ break;
+ }
+ }
+ }
+
+ begin();
+ return -1;
}
/**
@@ -275,16 +264,16 @@ public class CodeIterator implements Opcode {
* bytecode sequence for adjusting alignment if the code attribute
* includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
*
- * @param code inserted bytecode sequence.
- * @return the index indicating the first byte of the
- * inserted byte sequence.
+ * @param code inserted bytecode sequence.
+ * @return the index indicating the first byte of the
+ * inserted byte sequence.
*/
public int insert(byte[] code)
- throws BadBytecode
+ throws BadBytecode
{
- int pos = currentPos;
- insert0(currentPos, code, false);
- return pos;
+ int pos = currentPos;
+ insert0(currentPos, code, false);
+ return pos;
}
/**
@@ -300,11 +289,11 @@ public class CodeIterator implements Opcode {
* bytecode sequence for adjusting alignment if the code attribute
* includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
*
- * @param pos the index at which a byte sequence is inserted.
- * @param code inserted bytecode sequence.
+ * @param pos the index at which a byte sequence is inserted.
+ * @param code inserted bytecode sequence.
*/
public void insert(int pos, byte[] code) throws BadBytecode {
- insert0(pos, code, false);
+ insert0(pos, code, false);
}
/**
@@ -321,16 +310,16 @@ public class CodeIterator implements Opcode {
* bytecode sequence for adjusting alignment if the code attribute
* includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
*
- * @param code inserted bytecode sequence.
- * @return the index indicating the first byte of the
- * inserted byte sequence.
+ * @param code inserted bytecode sequence.
+ * @return the index indicating the first byte of the
+ * inserted byte sequence.
*/
public int insertEx(byte[] code)
- throws BadBytecode
+ throws BadBytecode
{
- int pos = currentPos;
- insert0(currentPos, code, true);
- return pos;
+ int pos = currentPos;
+ insert0(currentPos, code, true);
+ return pos;
}
/**
@@ -346,23 +335,23 @@ public class CodeIterator implements Opcode {
* bytecode sequence for adjusting alignment if the code attribute
* includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
*
- * @param pos the index at which a byte sequence is inserted.
- * @param code inserted bytecode sequence.
+ * @param pos the index at which a byte sequence is inserted.
+ * @param code inserted bytecode sequence.
*/
public void insertEx(int pos, byte[] code) throws BadBytecode {
- insert0(pos, code, true);
+ insert0(pos, code, true);
}
private void insert0(int pos, byte[] code, boolean exclusive)
- throws BadBytecode
+ throws BadBytecode
{
- int len = code.length;
- if (len <= 0)
- return;
+ int len = code.length;
+ if (len <= 0)
+ return;
- insertGapCore(pos, len, exclusive); // currentPos will change.
- for (int j = 0; j < len; ++j)
- bytecode[pos++] = code[j];
+ insertGapCore(pos, len, exclusive); // currentPos will change.
+ for (int j = 0; j < len; ++j)
+ bytecode[pos++] = code[j];
}
/**
@@ -377,13 +366,13 @@ public class CodeIterator implements Opcode {
* <p>If the next instruction is at the beginning of a block statement,
* then the gap is inserted within that block.
*
- * @param length gap length
- * @return the index indicating the first byte of the inserted gap.
+ * @param length gap length
+ * @return the index indicating the first byte of the inserted gap.
*/
public int insertGap(int length) throws BadBytecode {
- int pos = currentPos;
- insertGapCore(currentPos, length, false);
- return pos;
+ int pos = currentPos;
+ insertGapCore(currentPos, length, false);
+ return pos;
}
/**
@@ -397,11 +386,13 @@ public class CodeIterator implements Opcode {
* of a block statement,
* then the gap is inserted within that block.
*
- * @param pos the index at which a gap is inserted.
- * @param length gap length.
+ * @param pos the index at which a gap is inserted.
+ * @param length gap length.
+ * @return the length of the inserted gap.
+ * It might be bigger than <code>length</code>.
*/
- public void insertGap(int pos, int length) throws BadBytecode {
- insertGapCore(pos, length, false);
+ public int insertGap(int pos, int length) throws BadBytecode {
+ return insertGapCore(pos, length, false);
}
/**
@@ -416,13 +407,13 @@ public class CodeIterator implements Opcode {
* <p>If the next instruction is at the beginning of a block statement,
* then the gap is excluded from that block.
*
- * @param length gap length
- * @return the index indicating the first byte of the inserted gap.
+ * @param length gap length
+ * @return the index indicating the first byte of the inserted gap.
*/
public int insertExGap(int length) throws BadBytecode {
- int pos = currentPos;
- insertGapCore(currentPos, length, true);
- return pos;
+ int pos = currentPos;
+ insertGapCore(currentPos, length, true);
+ return pos;
}
/**
@@ -436,28 +427,35 @@ public class CodeIterator implements Opcode {
* of a block statement,
* then the gap is excluded from that block.
*
- * @param pos the index at which a gap is inserted.
- * @param length gap length.
+ * @param pos the index at which a gap is inserted.
+ * @param length gap length.
+ * @return the length of the inserted gap.
+ * It might be bigger than <code>length</code>.
*/
- public void insertExGap(int pos, int length) throws BadBytecode {
- insertGapCore(pos, length, true);
+ public int insertExGap(int pos, int length) throws BadBytecode {
+ return insertGapCore(pos, length, true);
}
- private void insertGapCore(int pos, int length, boolean exclusive)
- throws BadBytecode
+ /**
+ * @return the length of the really inserted gap.
+ */
+ private int insertGapCore(int pos, int length, boolean exclusive)
+ throws BadBytecode
{
- if (length <= 0)
- return;
+ if (length <= 0)
+ return 0;
- int cur = currentPos;
- byte[] c = insertGap(bytecode, pos, length, exclusive,
- get().getExceptionTable());
- if (cur >= pos)
- currentPos = cur + (c.length - bytecode.length);
+ int cur = currentPos;
+ byte[] c = insertGap(bytecode, pos, length, exclusive,
+ get().getExceptionTable());
+ int length2 = c.length - bytecode.length;
+ if (cur >= pos)
+ currentPos = cur + length2;
- codeAttr.setCode(c);
- bytecode = c;
- endPos = getCodeLength();
+ codeAttr.setCode(c);
+ bytecode = c;
+ endPos = getCodeLength();
+ return length2;
}
/**
@@ -465,53 +463,53 @@ public class CodeIterator implements Opcode {
* at the beginning of the exception table in the code attribute
* edited by this object.
*
- * @param offset the value added to the code positions included
- * in the entries.
+ * @param offset the value added to the code positions included
+ * in the entries.
*/
public void insert(ExceptionTable et, int offset) {
- codeAttr.getExceptionTable().add(0, et, offset);
+ codeAttr.getExceptionTable().add(0, et, offset);
}
/**
* Appends the given bytecode sequence at the end.
*
- * @param code the bytecode appended.
- * @return the position of the first byte of the appended bytecode.
+ * @param code the bytecode appended.
+ * @return the position of the first byte of the appended bytecode.
*/
public int append(byte[] code) {
- int size = getCodeLength();
- int len = code.length;
- if (len <= 0)
- return size;
+ int size = getCodeLength();
+ int len = code.length;
+ if (len <= 0)
+ return size;
- appendGap(len);
- byte[] dest = bytecode;
- for (int i = 0; i < len; ++i)
- dest[i + size] = code[i];
+ appendGap(len);
+ byte[] dest = bytecode;
+ for (int i = 0; i < len; ++i)
+ dest[i + size] = code[i];
- return size;
+ return size;
}
/**
* Appends a gap at the end of the bytecode sequence.
*
- * @param length gap length
+ * @param length gap length
*/
public void appendGap(int gapLength) {
- byte[] code = bytecode;
- int codeLength = code.length;
- byte[] newcode = new byte[codeLength + gapLength];
+ byte[] code = bytecode;
+ int codeLength = code.length;
+ byte[] newcode = new byte[codeLength + gapLength];
- int i;
- for (i = 0; i < codeLength; ++i)
- newcode[i] = code[i];
+ int i;
+ for (i = 0; i < codeLength; ++i)
+ newcode[i] = code[i];
- for (i = codeLength; i < codeLength + gapLength; ++i)
- newcode[i] = NOP;
+ for (i = codeLength; i < codeLength + gapLength; ++i)
+ newcode[i] = NOP;
- codeAttr.setCode(newcode);
- bytecode = newcode;
- endPos = getCodeLength();
+ codeAttr.setCode(newcode);
+ bytecode = newcode;
+ endPos = getCodeLength();
}
/**
@@ -519,28 +517,28 @@ public class CodeIterator implements Opcode {
* at the end of the exception table in the code attribute
* edited by this object.
*
- * @param offset the value added to the code positions included
- * in the entries.
+ * @param offset the value added to the code positions included
+ * in the entries.
*/
public void append(ExceptionTable et, int offset) {
- ExceptionTable table = codeAttr.getExceptionTable();
- table.add(table.size(), et, offset);
+ ExceptionTable table = codeAttr.getExceptionTable();
+ table.add(table.size(), et, offset);
}
/* opcodeLegth is used for implementing nextOpcode().
*/
private static final int opcodeLength[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 3,
- 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 1, 1, 1, 1, 1, 1, 3, 3,
- 3, 3, 3, 3, 3, 5, 0, 3, 2, 3, 1, 1, 3, 3, 1, 1, 0, 4, 3, 3,
- 5, 5
+ 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 1, 1, 1, 1, 1, 1, 3, 3,
+ 3, 3, 3, 3, 3, 5, 0, 3, 2, 3, 1, 1, 3, 3, 1, 1, 0, 4, 3, 3,
+ 5, 5
};
// 0 .. UNUSED (186), LOOKUPSWITCH, TABLESWITCH, WIDE
@@ -548,45 +546,45 @@ public class CodeIterator implements Opcode {
* Calculates the index of the next opcode.
*/
static int nextOpcode(byte[] code, int index)
- throws BadBytecode
+ throws BadBytecode
{
- int opcode;
- try {
- opcode = code[index] & 0xff;
- }
- catch (IndexOutOfBoundsException e) {
- throw new BadBytecode("invalid opcode address");
- }
-
- try {
- int len = opcodeLength[opcode];
- if (len > 0)
- return index + len;
- else if (opcode == WIDE)
- if (code[index + 1] == (byte)IINC) // WIDE IINC
- 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);
- }
- }
- catch (IndexOutOfBoundsException e) {
- }
-
- // opcode is UNUSED or an IndexOutOfBoundsException was thrown.
- throw new BadBytecode(opcode);
+ int opcode;
+ try {
+ opcode = code[index] & 0xff;
+ }
+ catch (IndexOutOfBoundsException e) {
+ throw new BadBytecode("invalid opcode address");
+ }
+
+ try {
+ int len = opcodeLength[opcode];
+ if (len > 0)
+ return index + len;
+ else if (opcode == WIDE)
+ if (code[index + 1] == (byte)IINC) // WIDE IINC
+ 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);
+ }
+ }
+ catch (IndexOutOfBoundsException e) {
+ }
+
+ // opcode is UNUSED or an IndexOutOfBoundsException was thrown.
+ throw new BadBytecode(opcode);
}
// methods for implementing insertGap().
@@ -598,143 +596,143 @@ public class CodeIterator implements Opcode {
* a multiple of 4.
*/
static byte[] insertGap(byte[] code, int where, int gapLength,
- boolean exclusive, ExceptionTable etable)
- throws BadBytecode
+ boolean exclusive, ExceptionTable etable)
+ throws BadBytecode
{
- if (gapLength <= 0)
- return code;
-
- try {
- return insertGap0(code, where, gapLength, exclusive, etable);
- }
- catch (AlignmentException e) {
- try {
- return insertGap0(code, where, (gapLength + 3) & ~3,
- exclusive, etable);
- }
- catch (AlignmentException e2) {
- throw new RuntimeException("fatal error?");
- }
- }
+ if (gapLength <= 0)
+ return code;
+
+ try {
+ return insertGap0(code, where, gapLength, exclusive, etable);
+ }
+ catch (AlignmentException e) {
+ try {
+ return insertGap0(code, where, (gapLength + 3) & ~3,
+ exclusive, etable);
+ }
+ catch (AlignmentException e2) {
+ throw new RuntimeException("fatal error?");
+ }
+ }
}
private static byte[] insertGap0(byte[] code, int where, int gapLength,
- boolean exclusive, ExceptionTable etable)
- throws BadBytecode, AlignmentException
+ boolean exclusive, ExceptionTable etable)
+ throws BadBytecode, AlignmentException
{
- int codeLength = code.length;
- byte[] newcode = new byte[codeLength + gapLength];
- insertGap2(code, where, gapLength, codeLength, newcode, exclusive);
- etable.shiftPc(where, gapLength, exclusive);
- return newcode;
+ int codeLength = code.length;
+ byte[] newcode = new byte[codeLength + gapLength];
+ insertGap2(code, where, gapLength, codeLength, newcode, exclusive);
+ etable.shiftPc(where, gapLength, exclusive);
+ return newcode;
}
private static void insertGap2(byte[] code, int where, int gapLength,
- int endPos, byte[] newcode, boolean exclusive)
- throws BadBytecode, AlignmentException
+ int endPos, byte[] newcode, boolean exclusive)
+ throws BadBytecode, AlignmentException
{
- int nextPos;
- int i = 0;
- int j = 0;
- for (; i < endPos; i = nextPos) {
- if (i == where) {
- int j2 = j + gapLength;
- while (j < j2)
- newcode[j++] = NOP;
- }
-
- nextPos = nextOpcode(code, i);
- int inst = code[i] & 0xff;
- // if<cond>, if_icmp<cond>, if_acmp<cond>, goto, jsr
- if ((153 <= inst && inst <= 168)
- || inst == IFNULL || inst == IFNONNULL) {
- /* 2bytes *signed* offset */
- int offset = (code[i + 1] << 8) | (code[i + 2] & 0xff);
- offset = newOffset(i, offset, where, gapLength, exclusive);
- newcode[j] = code[i];
- ByteArray.write16bit(offset, newcode, j + 1);
- j += 3;
- }
- else if (inst == GOTO_W || inst == JSR_W) {
- /* 4bytes offset */
- int offset = ByteArray.read32bit(code, i + 1);
- offset = newOffset(i, offset, where, gapLength, exclusive);
- newcode[j++] = code[i];
- ByteArray.write32bit(offset, newcode, j);
- j += 4;
- }
- else if (inst == TABLESWITCH) {
- if ((gapLength & 3) != 0)
- throw new AlignmentException();
-
- int i0 = i;
- int i2 = (i & ~3) + 4; // 0-3 byte padding
- while (i0 < i2)
- newcode[j++] = code[i0++];
-
- int defaultbyte = newOffset(i, ByteArray.read32bit(code, i2),
- where, gapLength, exclusive);
- ByteArray.write32bit(defaultbyte, newcode, j);
- int lowbyte = ByteArray.read32bit(code, i2 + 4);
- ByteArray.write32bit(lowbyte, newcode, j + 4);
- int highbyte = ByteArray.read32bit(code, i2 + 8);
- ByteArray.write32bit(highbyte, newcode, j + 8);
- j += 12;
- i0 = i2 + 12;
- i2 = i0 + (highbyte - lowbyte + 1) * 4;
- while (i0 < i2) {
- int offset = newOffset(i, ByteArray.read32bit(code, i0),
- where, gapLength, exclusive);
- ByteArray.write32bit(offset, newcode, j);
- j += 4;
- i0 += 4;
- }
- }
- else if (inst == LOOKUPSWITCH) {
- if ((gapLength & 3) != 0)
- throw new AlignmentException();
-
- int i0 = i;
- int i2 = (i & ~3) + 4; // 0-3 byte padding
- while (i0 < i2)
- newcode[j++] = code[i0++];
-
- int defaultbyte = newOffset(i, ByteArray.read32bit(code, i2),
- where, gapLength, exclusive);
- ByteArray.write32bit(defaultbyte, newcode, j);
- int npairs = ByteArray.read32bit(code, i2 + 4);
- ByteArray.write32bit(npairs, newcode, j + 4);
- j += 8;
- i0 = i2 + 8;
- i2 = i0 + npairs * 8;
- while (i0 < i2) {
- ByteArray.copy32bit(code, i0, newcode, j);
- int offset = newOffset(i,
- ByteArray.read32bit(code, i0 + 4),
- where, gapLength, exclusive);
- ByteArray.write32bit(offset, newcode, j + 4);
- j += 8;
- i0 += 8;
- }
- }
- else
- while (i < nextPos)
- newcode[j++] = code[i++];
- }
+ int nextPos;
+ int i = 0;
+ int j = 0;
+ for (; i < endPos; i = nextPos) {
+ if (i == where) {
+ int j2 = j + gapLength;
+ while (j < j2)
+ newcode[j++] = NOP;
+ }
+
+ nextPos = nextOpcode(code, i);
+ int inst = code[i] & 0xff;
+ // if<cond>, if_icmp<cond>, if_acmp<cond>, goto, jsr
+ if ((153 <= inst && inst <= 168)
+ || inst == IFNULL || inst == IFNONNULL) {
+ /* 2bytes *signed* offset */
+ int offset = (code[i + 1] << 8) | (code[i + 2] & 0xff);
+ offset = newOffset(i, offset, where, gapLength, exclusive);
+ newcode[j] = code[i];
+ ByteArray.write16bit(offset, newcode, j + 1);
+ j += 3;
+ }
+ else if (inst == GOTO_W || inst == JSR_W) {
+ /* 4bytes offset */
+ int offset = ByteArray.read32bit(code, i + 1);
+ offset = newOffset(i, offset, where, gapLength, exclusive);
+ newcode[j++] = code[i];
+ ByteArray.write32bit(offset, newcode, j);
+ j += 4;
+ }
+ else if (inst == TABLESWITCH) {
+ if (i != j && (gapLength & 3) != 0)
+ throw new AlignmentException();
+
+ int i0 = i;
+ int i2 = (i & ~3) + 4; // 0-3 byte padding
+ while (i0 < i2)
+ newcode[j++] = code[i0++];
+
+ int defaultbyte = newOffset(i, ByteArray.read32bit(code, i2),
+ where, gapLength, exclusive);
+ ByteArray.write32bit(defaultbyte, newcode, j);
+ int lowbyte = ByteArray.read32bit(code, i2 + 4);
+ ByteArray.write32bit(lowbyte, newcode, j + 4);
+ int highbyte = ByteArray.read32bit(code, i2 + 8);
+ ByteArray.write32bit(highbyte, newcode, j + 8);
+ j += 12;
+ i0 = i2 + 12;
+ i2 = i0 + (highbyte - lowbyte + 1) * 4;
+ while (i0 < i2) {
+ int offset = newOffset(i, ByteArray.read32bit(code, i0),
+ where, gapLength, exclusive);
+ ByteArray.write32bit(offset, newcode, j);
+ j += 4;
+ i0 += 4;
+ }
+ }
+ else if (inst == LOOKUPSWITCH) {
+ if (i != j && (gapLength & 3) != 0)
+ throw new AlignmentException();
+
+ int i0 = i;
+ int i2 = (i & ~3) + 4; // 0-3 byte padding
+ while (i0 < i2)
+ newcode[j++] = code[i0++];
+
+ int defaultbyte = newOffset(i, ByteArray.read32bit(code, i2),
+ where, gapLength, exclusive);
+ ByteArray.write32bit(defaultbyte, newcode, j);
+ int npairs = ByteArray.read32bit(code, i2 + 4);
+ ByteArray.write32bit(npairs, newcode, j + 4);
+ j += 8;
+ i0 = i2 + 8;
+ i2 = i0 + npairs * 8;
+ while (i0 < i2) {
+ ByteArray.copy32bit(code, i0, newcode, j);
+ int offset = newOffset(i,
+ ByteArray.read32bit(code, i0 + 4),
+ where, gapLength, exclusive);
+ ByteArray.write32bit(offset, newcode, j + 4);
+ j += 8;
+ i0 += 8;
+ }
+ }
+ else
+ while (i < nextPos)
+ newcode[j++] = code[i++];
+ }
}
private static int newOffset(int i, int offset, int where,
- int gapLength, boolean exclusive) {
- int target = i + offset;
- if (i < where) {
- if (where < target || (exclusive && where == target))
- offset += gapLength;
- }
- else
- if (target < where || (!exclusive && where == target))
- offset -= gapLength;
-
- return offset;
+ int gapLength, boolean exclusive) {
+ int target = i + offset;
+ if (i < where) {
+ if (where < target || (exclusive && where == target))
+ offset += gapLength;
+ }
+ else
+ if (target < where || (!exclusive && where == target))
+ offset -= gapLength;
+
+ return offset;
}
}
diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java
index 5d079e3a..2a0f4c81 100644
--- a/src/main/javassist/bytecode/ConstPool.java
+++ b/src/main/javassist/bytecode/ConstPool.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,10 +28,10 @@ import javassist.CtClass;
*/
public final class ConstPool {
LongVector items;
- int numOfItems;
+ int numOfItems;
Hashtable classes;
Hashtable strings;
- int thisClassInfo;
+ int thisClassInfo;
private static final int SIZE = 128;
/**
@@ -64,7 +53,7 @@ public final class ConstPool {
* <code>CONSTANT_InterfaceMethodref</code>
*/
public static final int CONST_InterfaceMethodref
- = InterfaceMethodrefInfo.tag;
+ = InterfaceMethodrefInfo.tag;
/**
* <code>CONSTANT_String</code>
@@ -109,38 +98,38 @@ public final class ConstPool {
/**
* Constructs a constant pool table.
*
- * @param thisclass the name of the class using this constant
- * pool table
+ * @param thisclass the name of the class using this constant
+ * pool table
*/
public ConstPool(String thisclass) {
- this();
- thisClassInfo = addClassInfo(thisclass);
+ this();
+ thisClassInfo = addClassInfo(thisclass);
}
/**
* Constructs a constant pool table from the given byte stream.
*
- * @param in byte stream.
+ * @param in byte stream.
*/
public ConstPool(DataInputStream in) throws IOException {
- this();
- read(in);
+ this();
+ read(in);
}
private ConstPool() {
- items = new LongVector(SIZE);
- numOfItems = 0;
- addItem(null); // index 0 is reserved by the JVM.
- classes = new Hashtable();
- strings = new Hashtable();
- thisClassInfo = 0;
+ items = new LongVector(SIZE);
+ numOfItems = 0;
+ addItem(null); // index 0 is reserved by the JVM.
+ classes = new Hashtable();
+ strings = new Hashtable();
+ thisClassInfo = 0;
}
/**
* Returns the name of the class using this constant pool table.
*/
public String getClassName() {
- return getClassInfo(thisClassInfo);
+ return getClassInfo(thisClassInfo);
}
/**
@@ -148,15 +137,15 @@ public final class ConstPool {
* specifying the class using this constant pool table.
*/
public int getThisClassInfo() {
- return thisClassInfo;
+ return thisClassInfo;
}
void setThisClassInfo(int i) {
- thisClassInfo = i;
+ thisClassInfo = i;
}
ConstInfo getItem(int n) {
- return (ConstInfo)items.elementAt(n);
+ return (ConstInfo)items.elementAt(n);
}
/**
@@ -164,22 +153,22 @@ public final class ConstPool {
* entry at the given index.
*/
public int getTag(int index) {
- return getItem(index).getTag();
+ return getItem(index).getTag();
}
/**
* Reads <code>CONSTANT_Class_info</code> structure
* at the given index.
*
- * @return a fully-qualified class or interface name specified
- * by <code>name_index</code>.
+ * @return a fully-qualified class or interface name specified
+ * by <code>name_index</code>.
*/
public String getClassInfo(int index) {
- ClassInfo c = (ClassInfo)getItem(index);
- if (c == null)
- return null;
- else
- return Descriptor.toJavaName(getUtf8Info(c.name));
+ ClassInfo c = (ClassInfo)getItem(index);
+ if (c == null)
+ return null;
+ else
+ return Descriptor.toJavaName(getUtf8Info(c.name));
}
/**
@@ -188,8 +177,8 @@ public final class ConstPool {
* at the given index.
*/
public int getNameAndTypeName(int index) {
- NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
- return ntinfo.memberName;
+ NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
+ return ntinfo.memberName;
}
/**
@@ -198,8 +187,8 @@ public final class ConstPool {
* at the given index.
*/
public int getNameAndTypeDescriptor(int index) {
- NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
- return ntinfo.typeDescriptor;
+ NameAndTypeInfo ntinfo = (NameAndTypeInfo)getItem(index);
+ return ntinfo.typeDescriptor;
}
/**
@@ -208,8 +197,8 @@ public final class ConstPool {
* at the given index.
*/
public int getFieldrefClass(int index) {
- FieldrefInfo finfo = (FieldrefInfo)getItem(index);
- return finfo.classIndex;
+ FieldrefInfo finfo = (FieldrefInfo)getItem(index);
+ return finfo.classIndex;
}
/**
@@ -220,11 +209,11 @@ public final class ConstPool {
* @return the name of the class at that <code>class_index</code>.
*/
public String getFieldrefClassName(int index) {
- FieldrefInfo f = (FieldrefInfo)getItem(index);
- if (f == null)
- return null;
- else
- return getClassInfo(f.classIndex);
+ FieldrefInfo f = (FieldrefInfo)getItem(index);
+ if (f == null)
+ return null;
+ else
+ return getClassInfo(f.classIndex);
}
/**
@@ -233,8 +222,8 @@ public final class ConstPool {
* at the given index.
*/
public int getFieldrefNameAndType(int index) {
- FieldrefInfo finfo = (FieldrefInfo)getItem(index);
- return finfo.nameAndTypeIndex;
+ FieldrefInfo finfo = (FieldrefInfo)getItem(index);
+ return finfo.nameAndTypeIndex;
}
/**
@@ -242,20 +231,20 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
- * @param index an index to a <code>CONSTANT_Fieldref_info</code>.
- * @return the name of the field.
+ * @param index an index to a <code>CONSTANT_Fieldref_info</code>.
+ * @return the name of the field.
*/
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);
- }
+ 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);
+ }
}
/**
@@ -263,20 +252,20 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
- * @param index an index to a <code>CONSTANT_Fieldref_info</code>.
- * @return the type descriptor of the field.
+ * @param index an index to a <code>CONSTANT_Fieldref_info</code>.
+ * @return the type descriptor of the field.
*/
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);
- }
+ 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);
+ }
}
/**
@@ -285,8 +274,8 @@ public final class ConstPool {
* at the given index.
*/
public int getMethodrefClass(int index) {
- MethodrefInfo minfo = (MethodrefInfo)getItem(index);
- return minfo.classIndex;
+ MethodrefInfo minfo = (MethodrefInfo)getItem(index);
+ return minfo.classIndex;
}
/**
@@ -297,11 +286,11 @@ public final class ConstPool {
* @return the name of the class at that <code>class_index</code>.
*/
public String getMethodrefClassName(int index) {
- MethodrefInfo minfo = (MethodrefInfo)getItem(index);
- if (minfo == null)
- return null;
- else
- return getClassInfo(minfo.classIndex);
+ MethodrefInfo minfo = (MethodrefInfo)getItem(index);
+ if (minfo == null)
+ return null;
+ else
+ return getClassInfo(minfo.classIndex);
}
/**
@@ -310,8 +299,8 @@ public final class ConstPool {
* at the given index.
*/
public int getMethodrefNameAndType(int index) {
- MethodrefInfo minfo = (MethodrefInfo)getItem(index);
- return minfo.nameAndTypeIndex;
+ MethodrefInfo minfo = (MethodrefInfo)getItem(index);
+ return minfo.nameAndTypeIndex;
}
/**
@@ -319,21 +308,21 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
- * @param index an index to a <code>CONSTANT_Methodref_info</code>.
- * @return the name of the method.
+ * @param index an index to a <code>CONSTANT_Methodref_info</code>.
+ * @return the name of the method.
*/
public String getMethodrefName(int index) {
- MethodrefInfo minfo = (MethodrefInfo)getItem(index);
- if (minfo == null)
- return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.memberName);
- }
+ MethodrefInfo minfo = (MethodrefInfo)getItem(index);
+ if (minfo == null)
+ return null;
+ else {
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ else
+ return getUtf8Info(n.memberName);
+ }
}
/**
@@ -341,21 +330,21 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
- * @param index an index to a <code>CONSTANT_Methodref_info</code>.
- * @return the descriptor of the method.
+ * @param index an index to a <code>CONSTANT_Methodref_info</code>.
+ * @return the descriptor of the method.
*/
public String getMethodrefType(int index) {
- MethodrefInfo minfo = (MethodrefInfo)getItem(index);
- if (minfo == null)
- return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.typeDescriptor);
- }
+ MethodrefInfo minfo = (MethodrefInfo)getItem(index);
+ if (minfo == null)
+ return null;
+ else {
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ else
+ return getUtf8Info(n.typeDescriptor);
+ }
}
/**
@@ -364,9 +353,9 @@ public final class ConstPool {
* at the given index.
*/
public int getInterfaceMethodrefClass(int index) {
- InterfaceMethodrefInfo minfo
- = (InterfaceMethodrefInfo)getItem(index);
- return minfo.classIndex;
+ InterfaceMethodrefInfo minfo
+ = (InterfaceMethodrefInfo)getItem(index);
+ return minfo.classIndex;
}
/**
@@ -377,9 +366,9 @@ public final class ConstPool {
* @return the name of the class at that <code>class_index</code>.
*/
public String getInterfaceMethodrefClassName(int index) {
- InterfaceMethodrefInfo minfo
- = (InterfaceMethodrefInfo)getItem(index);
- return getClassInfo(minfo.classIndex);
+ InterfaceMethodrefInfo minfo
+ = (InterfaceMethodrefInfo)getItem(index);
+ return getClassInfo(minfo.classIndex);
}
/**
@@ -388,9 +377,9 @@ public final class ConstPool {
* at the given index.
*/
public int getInterfaceMethodrefNameAndType(int index) {
- InterfaceMethodrefInfo minfo
- = (InterfaceMethodrefInfo)getItem(index);
- return minfo.nameAndTypeIndex;
+ InterfaceMethodrefInfo minfo
+ = (InterfaceMethodrefInfo)getItem(index);
+ return minfo.nameAndTypeIndex;
}
/**
@@ -398,23 +387,23 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
- * @param index an index to
- * a <code>CONSTANT_InterfaceMethodref_info</code>.
- * @return the name of the method.
+ * @param index an index to
+ * a <code>CONSTANT_InterfaceMethodref_info</code>.
+ * @return the name of the method.
*/
public String getInterfaceMethodrefName(int index) {
- InterfaceMethodrefInfo minfo
- = (InterfaceMethodrefInfo)getItem(index);
- if (minfo == null)
- return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.memberName);
- }
+ InterfaceMethodrefInfo minfo
+ = (InterfaceMethodrefInfo)getItem(index);
+ if (minfo == null)
+ return null;
+ else {
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ else
+ return getUtf8Info(n.memberName);
+ }
}
/**
@@ -422,23 +411,23 @@ public final class ConstPool {
* <code>CONSTANT_NameAndType_info</code> structure
* indirectly specified by the given index.
*
- * @param index an index to
- * a <code>CONSTANT_InterfaceMethodref_info</code>.
- * @return the descriptor of the method.
+ * @param index an index to
+ * a <code>CONSTANT_InterfaceMethodref_info</code>.
+ * @return the descriptor of the method.
*/
public String getInterfaceMethodrefType(int index) {
- InterfaceMethodrefInfo minfo
- = (InterfaceMethodrefInfo)getItem(index);
- if (minfo == null)
- return null;
- else {
- NameAndTypeInfo n
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if(n == null)
- return null;
- else
- return getUtf8Info(n.typeDescriptor);
- }
+ InterfaceMethodrefInfo minfo
+ = (InterfaceMethodrefInfo)getItem(index);
+ if (minfo == null)
+ return null;
+ else {
+ NameAndTypeInfo n
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if(n == null)
+ return null;
+ else
+ return getUtf8Info(n.typeDescriptor);
+ }
}
/**
* Reads <code>CONSTANT_Integer_info</code>, <code>_Float_info</code>,
@@ -450,22 +439,22 @@ public final class ConstPool {
* value.
*/
public Object getLdcValue(int index) {
- ConstInfo constInfo = this.getItem(index);
- Object value = null;
- if (constInfo instanceof StringInfo)
- value = this.getStringInfo(index);
- else if (constInfo instanceof FloatInfo)
- value = new Float(getFloatInfo(index));
- else if (constInfo instanceof IntegerInfo)
- value = new Integer(getIntegerInfo(index));
- else if (constInfo instanceof LongInfo)
- value = new Long(getLongInfo(index));
- else if (constInfo instanceof DoubleInfo)
- value = new Double(getDoubleInfo(index));
- else
- value = null;
+ ConstInfo constInfo = this.getItem(index);
+ Object value = null;
+ if (constInfo instanceof StringInfo)
+ value = this.getStringInfo(index);
+ else if (constInfo instanceof FloatInfo)
+ value = new Float(getFloatInfo(index));
+ else if (constInfo instanceof IntegerInfo)
+ value = new Integer(getIntegerInfo(index));
+ else if (constInfo instanceof LongInfo)
+ value = new Long(getLongInfo(index));
+ else if (constInfo instanceof DoubleInfo)
+ value = new Double(getDoubleInfo(index));
+ else
+ value = null;
- return value;
+ return value;
}
/**
@@ -475,8 +464,8 @@ public final class ConstPool {
* @return the value specified by this entry.
*/
public int getIntegerInfo(int index) {
- IntegerInfo i = (IntegerInfo)getItem(index);
- return i.value;
+ IntegerInfo i = (IntegerInfo)getItem(index);
+ return i.value;
}
/**
@@ -486,8 +475,8 @@ public final class ConstPool {
* @return the value specified by this entry.
*/
public float getFloatInfo(int index) {
- FloatInfo i = (FloatInfo)getItem(index);
- return i.value;
+ FloatInfo i = (FloatInfo)getItem(index);
+ return i.value;
}
/**
@@ -497,8 +486,8 @@ public final class ConstPool {
* @return the value specified by this entry.
*/
public long getLongInfo(int index) {
- LongInfo i = (LongInfo)getItem(index);
- return i.value;
+ LongInfo i = (LongInfo)getItem(index);
+ return i.value;
}
/**
@@ -508,8 +497,8 @@ public final class ConstPool {
* @return the value specified by this entry.
*/
public double getDoubleInfo(int index) {
- DoubleInfo i = (DoubleInfo)getItem(index);
- return i.value;
+ DoubleInfo i = (DoubleInfo)getItem(index);
+ return i.value;
}
/**
@@ -519,8 +508,8 @@ public final class ConstPool {
* @return the string specified by <code>string_index</code>.
*/
public String getStringInfo(int index) {
- StringInfo si = (StringInfo)getItem(index);
- return getUtf8Info(si.string);
+ StringInfo si = (StringInfo)getItem(index);
+ return getUtf8Info(si.string);
}
/**
@@ -530,8 +519,8 @@ public final class ConstPool {
* @return the string specified by this entry.
*/
public String getUtf8Info(int index) {
- Utf8Info utf = (Utf8Info)getItem(index);
- return utf.string;
+ Utf8Info utf = (Utf8Info)getItem(index);
+ return utf.string;
}
/**
@@ -539,13 +528,13 @@ public final class ConstPool {
* structure at the given index represents the constructor
* of the given class.
*
- * @return the <code>descriptor_index</code> specifying
- * the type descriptor of the that constructor.
- * If it is not that constructor,
- * <code>isConstructor()</code> returns 0.
+ * @return the <code>descriptor_index</code> specifying
+ * the type descriptor of the that constructor.
+ * If it is not that constructor,
+ * <code>isConstructor()</code> returns 0.
*/
public int isConstructor(String classname, int index) {
- return isMember(classname, MethodInfo.nameInit, index);
+ return isMember(classname, MethodInfo.nameInit, index);
}
/**
@@ -555,30 +544,30 @@ public final class ConstPool {
* at the given index represents the member with the specified
* name and declaring class.
*
- * @param classname the class declaring the member
- * @param membername the member name
- * @param index the index into the constant pool table
+ * @param classname the class declaring the member
+ * @param membername the member name
+ * @param index the index into the constant pool table
*
- * @return the <code>descriptor_index</code> specifying
- * the type descriptor of that member.
- * If it is not that member,
- * <code>isMember()</code> returns 0.
+ * @return the <code>descriptor_index</code> specifying
+ * the type descriptor of that member.
+ * If it is not that member,
+ * <code>isMember()</code> returns 0.
*/
public int isMember(String classname, String membername, int index) {
- MemberrefInfo minfo = (MemberrefInfo)getItem(index);
- if (getClassInfo(minfo.classIndex).equals(classname)) {
- NameAndTypeInfo ntinfo
- = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
- if (getUtf8Info(ntinfo.memberName).equals(membername))
- return ntinfo.typeDescriptor;
- }
+ MemberrefInfo minfo = (MemberrefInfo)getItem(index);
+ if (getClassInfo(minfo.classIndex).equals(classname)) {
+ NameAndTypeInfo ntinfo
+ = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+ if (getUtf8Info(ntinfo.memberName).equals(membername))
+ return ntinfo.typeDescriptor;
+ }
- return 0; // false
+ return 0; // false
}
private int addItem(ConstInfo info) {
- items.addElement(info);
- return numOfItems++;
+ items.addElement(info);
+ return numOfItems++;
}
/**
@@ -587,20 +576,20 @@ public final class ConstPool {
* The class names that the item refers to are renamed according
* to the given map.
*
- * @param n the <i>n</i>-th item
- * @param dest destination constant pool table
- * @param classnames the map or null.
+ * @param n the <i>n</i>-th item
+ * @param dest destination constant pool table
+ * @param classnames the map or null.
*/
public int copy(int n, ConstPool dest, Map classnames) {
- if (n == 0)
- return 0;
+ if (n == 0)
+ return 0;
- ConstInfo info = getItem(n);
- return info.copy(this, dest, classnames);
+ ConstInfo info = getItem(n);
+ return info.copy(this, dest, classnames);
}
int addConstInfoPadding() {
- return addItem(new ConstInfoPadding());
+ return addItem(new ConstInfoPadding());
}
/**
@@ -609,21 +598,21 @@ public final class ConstPool {
* <p>This also adds a <code>CONSTANT_Utf8_info</code> structure
* for storing the class name.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addClassInfo(CtClass c) {
- if (c == THIS)
- return thisClassInfo;
- else if (!c.isArray())
- return addClassInfo(c.getName());
- else {
- // an array type is recorded in the hashtable with
- // the key "[L<classname>;" instead of "<classname>".
- //
- // note: toJvmName(toJvmName(c)) is equal to toJvmName(c).
+ if (c == THIS)
+ return thisClassInfo;
+ else if (!c.isArray())
+ return addClassInfo(c.getName());
+ else {
+ // an array type is recorded in the hashtable with
+ // the key "[L<classname>;" instead of "<classname>".
+ //
+ // note: toJvmName(toJvmName(c)) is equal to toJvmName(c).
- return addClassInfo(Descriptor.toJvmName(c));
- }
+ return addClassInfo(Descriptor.toJvmName(c));
+ }
}
/**
@@ -632,20 +621,20 @@ public final class ConstPool {
* <p>This also adds a <code>CONSTANT_Utf8_info</code> structure
* for storing the class name.
*
- * @param qname a fully-qualified class name
- * (or the JVM-internal representation of that name).
- * @return the index of the added entry.
+ * @param qname a fully-qualified class name
+ * (or the JVM-internal representation of that name).
+ * @return the index of the added entry.
*/
public int addClassInfo(String qname) {
- ClassInfo info = (ClassInfo)classes.get(qname);
- if (info != null)
- return info.index;
- else {
- int utf8 = addUtf8Info(Descriptor.toJvmName(qname));
- info = new ClassInfo(utf8, numOfItems);
- classes.put(qname, info);
- return addItem(info);
- }
+ ClassInfo info = (ClassInfo)classes.get(qname);
+ if (info != null)
+ return info.index;
+ else {
+ int utf8 = addUtf8Info(Descriptor.toJvmName(qname));
+ info = new ClassInfo(utf8, numOfItems);
+ classes.put(qname, info);
+ return addItem(info);
+ }
}
/**
@@ -653,23 +642,23 @@ public final class ConstPool {
*
* <p>This also adds <code>CONSTANT_Utf8_info</code> structures.
*
- * @param name <code>name_index</code>
- * @param type <code>descriptor_index</code>
- * @return the index of the added entry.
+ * @param name <code>name_index</code>
+ * @param type <code>descriptor_index</code>
+ * @return the index of the added entry.
*/
public int addNameAndTypeInfo(String name, String type) {
- return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type));
+ return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type));
}
/**
* Adds a new <code>CONSTANT_NameAndType_info</code> structure.
*
- * @param name <code>name_index</code>
- * @param type <code>descriptor_index</code>
- * @return the index of the added entry.
+ * @param name <code>name_index</code>
+ * @param type <code>descriptor_index</code>
+ * @return the index of the added entry.
*/
public int addNameAndTypeInfo(int name, int type) {
- return addItem(new NameAndTypeInfo(name, type));
+ return addItem(new NameAndTypeInfo(name, type));
}
/**
@@ -678,27 +667,27 @@ public final class ConstPool {
* <p>This also adds a new <code>CONSTANT_NameAndType_info</code>
* structure.
*
- * @param classInfo <code>class_index</code>
- * @param name <code>name_index</code>
- * of <code>CONSTANT_NameAndType_info</code>.
- * @param type <code>descriptor_index</code>
- * of <code>CONSTANT_NameAndType_info</code>.
- * @return the index of the added entry.
+ * @param classInfo <code>class_index</code>
+ * @param name <code>name_index</code>
+ * of <code>CONSTANT_NameAndType_info</code>.
+ * @param type <code>descriptor_index</code>
+ * of <code>CONSTANT_NameAndType_info</code>.
+ * @return the index of the added entry.
*/
public int addFieldrefInfo(int classInfo, String name, String type) {
- int nt = addNameAndTypeInfo(name, type);
- return addFieldrefInfo(classInfo, nt);
+ int nt = addNameAndTypeInfo(name, type);
+ return addFieldrefInfo(classInfo, nt);
}
/**
* Adds a new <code>CONSTANT_Fieldref_info</code> structure.
*
- * @param classInfo <code>class_index</code>
- * @param nameandtypeinfo <code>name_and_type_index</code>.
- * @return the index of the added entry.
+ * @param classInfo <code>class_index</code>
+ * @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));
+ return addItem(new FieldrefInfo(classInfo, nameAndTypeInfo));
}
/**
@@ -707,27 +696,27 @@ public final class ConstPool {
* <p>This also adds a new <code>CONSTANT_NameAndType_info</code>
* structure.
*
- * @param classInfo <code>class_index</code>
- * @param name <code>name_index</code>
- * of <code>CONSTANT_NameAndType_info</code>.
- * @param type <code>descriptor_index</code>
- * of <code>CONSTANT_NameAndType_info</code>.
- * @return the index of the added entry.
+ * @param classInfo <code>class_index</code>
+ * @param name <code>name_index</code>
+ * of <code>CONSTANT_NameAndType_info</code>.
+ * @param type <code>descriptor_index</code>
+ * of <code>CONSTANT_NameAndType_info</code>.
+ * @return the index of the added entry.
*/
public int addMethodrefInfo(int classInfo, String name, String type) {
- int nt = addNameAndTypeInfo(name, type);
- return addMethodrefInfo(classInfo, nt);
+ int nt = addNameAndTypeInfo(name, type);
+ return addMethodrefInfo(classInfo, nt);
}
/**
* Adds a new <code>CONSTANT_Methodref_info</code> structure.
*
- * @param classInfo <code>class_index</code>
- * @param nameandtypeinfo <code>name_and_type_index</code>.
- * @return the index of the added entry.
+ * @param classInfo <code>class_index</code>
+ * @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));
+ return addItem(new MethodrefInfo(classInfo, nameAndTypeInfo));
}
/**
@@ -737,31 +726,31 @@ public final class ConstPool {
* <p>This also adds a new <code>CONSTANT_NameAndType_info</code>
* structure.
*
- * @param classInfo <code>class_index</code>
- * @param name <code>name_index</code>
- * of <code>CONSTANT_NameAndType_info</code>.
- * @param type <code>descriptor_index</code>
- * of <code>CONSTANT_NameAndType_info</code>.
- * @return the index of the added entry.
+ * @param classInfo <code>class_index</code>
+ * @param name <code>name_index</code>
+ * of <code>CONSTANT_NameAndType_info</code>.
+ * @param type <code>descriptor_index</code>
+ * of <code>CONSTANT_NameAndType_info</code>.
+ * @return the index of the added entry.
*/
public int addInterfaceMethodrefInfo(int classInfo, String name,
- String type) {
- int nt = addNameAndTypeInfo(name, type);
- return addInterfaceMethodrefInfo(classInfo, nt);
+ String type) {
+ int nt = addNameAndTypeInfo(name, type);
+ return addInterfaceMethodrefInfo(classInfo, nt);
}
/**
* Adds a new <code>CONSTANT_InterfaceMethodref_info</code>
* structure.
*
- * @param classInfo <code>class_index</code>
- * @param nameandtypeinfo <code>name_and_type_index</code>.
- * @return the index of the added entry.
+ * @param classInfo <code>class_index</code>
+ * @param nameandtypeinfo <code>name_and_type_index</code>.
+ * @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));
}
/**
@@ -771,54 +760,54 @@ public final class ConstPool {
* <p>This also adds a new <code>CONSTANT_Utf8_info</code>
* structure.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addStringInfo(String str) {
- return addItem(new StringInfo(addUtf8Info(str)));
+ return addItem(new StringInfo(addUtf8Info(str)));
}
/**
* Adds a new <code>CONSTANT_Integer_info</code>
* structure.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addIntegerInfo(int i) {
- return addItem(new IntegerInfo(i));
+ return addItem(new IntegerInfo(i));
}
/**
* Adds a new <code>CONSTANT_Float_info</code>
* structure.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addFloatInfo(float f) {
- return addItem(new FloatInfo(f));
+ return addItem(new FloatInfo(f));
}
/**
* Adds a new <code>CONSTANT_Long_info</code>
* structure.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addLongInfo(long l) {
- int i = addItem(new LongInfo(l));
- addItem(new ConstInfoPadding());
- return i;
+ int i = addItem(new LongInfo(l));
+ addItem(new ConstInfoPadding());
+ return i;
}
/**
* Adds a new <code>CONSTANT_Double_info</code>
* structure.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addDoubleInfo(double d) {
- int i = addItem(new DoubleInfo(d));
- addItem(new ConstInfoPadding());
- return i;
+ int i = addItem(new DoubleInfo(d));
+ addItem(new ConstInfoPadding());
+ return i;
}
/**
@@ -830,131 +819,131 @@ public final class ConstPool {
* a duplicated entry.
* Instead, it returns the index of the entry already recorded.
*
- * @return the index of the added entry.
+ * @return the index of the added entry.
*/
public int addUtf8Info(String utf8) {
- Utf8Info info = (Utf8Info)strings.get(utf8);
- if (info != null)
- return info.index;
- else {
- info = new Utf8Info(utf8, numOfItems);
- strings.put(utf8, info);
- return addItem(info);
- }
+ Utf8Info info = (Utf8Info)strings.get(utf8);
+ if (info != null)
+ return info.index;
+ else {
+ info = new Utf8Info(utf8, numOfItems);
+ strings.put(utf8, info);
+ return addItem(info);
+ }
}
/**
* Replaces all occurrences of a class name.
*
- * @param oldName the replaced name
- * @param newName the substituted name.
+ * @param oldName the replaced name
+ * @param newName the substituted name.
*/
public void renameClass(String oldName, String newName) {
- LongVector v = items;
- int size = numOfItems;
- for (int i = 1; i < size; ++i)
- ((ConstInfo)v.elementAt(i)).renameClass(this, oldName, newName);
+ LongVector v = items;
+ int size = numOfItems;
+ for (int i = 1; i < size; ++i)
+ ((ConstInfo)v.elementAt(i)).renameClass(this, oldName, newName);
}
/**
* Replaces all occurrences of class names.
*
- * @param classnames specifies pairs of replaced and substituted
- * name.
+ * @param classnames specifies pairs of replaced and substituted
+ * name.
*/
public void renameClass(Map classnames) {
- LongVector v = items;
- int size = numOfItems;
- for (int i = 1; i < size; ++i)
- ((ConstInfo)v.elementAt(i)).renameClass(this, classnames);
+ LongVector v = items;
+ int size = numOfItems;
+ for (int i = 1; i < size; ++i)
+ ((ConstInfo)v.elementAt(i)).renameClass(this, classnames);
}
private void read(DataInputStream in) throws IOException {
- int n = in.readUnsignedShort();
- while (--n > 0) { // index 0 is reserved by JVM
- int tag = readOne(in);
- if ((tag == LongInfo.tag) || (tag == DoubleInfo.tag)) {
- addItem(new ConstInfoPadding());
- --n;
- }
- }
+ int n = in.readUnsignedShort();
+ while (--n > 0) { // index 0 is reserved by JVM
+ int tag = readOne(in);
+ if ((tag == LongInfo.tag) || (tag == DoubleInfo.tag)) {
+ addItem(new ConstInfoPadding());
+ --n;
+ }
+ }
}
private int readOne(DataInputStream in) throws IOException {
- ConstInfo info;
- int tag = in.readUnsignedByte();
- switch (tag) {
- case Utf8Info.tag : // 1
- info = new Utf8Info(in, numOfItems);
- strings.put(((Utf8Info)info).string, info);
- break;
- case IntegerInfo.tag : // 3
- info = new IntegerInfo(in);
- break;
- case FloatInfo.tag : // 4
- info = new FloatInfo(in);
- break;
- case LongInfo.tag : // 5
- info = new LongInfo(in);
- break;
- case DoubleInfo.tag : // 6
- info = new DoubleInfo(in);
- break;
- case ClassInfo.tag : // 7
- info = new ClassInfo(in, numOfItems);
- // classes.put(<classname>, info);
- break;
- case StringInfo.tag : // 8
- info = new StringInfo(in);
- break;
- case FieldrefInfo.tag : // 9
- info = new FieldrefInfo(in);
- break;
- case MethodrefInfo.tag : // 10
- info = new MethodrefInfo(in);
- break;
- case InterfaceMethodrefInfo.tag : // 11
- info = new InterfaceMethodrefInfo(in);
- break;
- case NameAndTypeInfo.tag : // 12
- info = new NameAndTypeInfo(in);
- break;
- default :
- throw new IOException("invalid constant type: " + tag);
- }
-
- addItem(info);
- return tag;
+ ConstInfo info;
+ int tag = in.readUnsignedByte();
+ switch (tag) {
+ case Utf8Info.tag : // 1
+ info = new Utf8Info(in, numOfItems);
+ strings.put(((Utf8Info)info).string, info);
+ break;
+ case IntegerInfo.tag : // 3
+ info = new IntegerInfo(in);
+ break;
+ case FloatInfo.tag : // 4
+ info = new FloatInfo(in);
+ break;
+ case LongInfo.tag : // 5
+ info = new LongInfo(in);
+ break;
+ case DoubleInfo.tag : // 6
+ info = new DoubleInfo(in);
+ break;
+ case ClassInfo.tag : // 7
+ info = new ClassInfo(in, numOfItems);
+ // classes.put(<classname>, info);
+ break;
+ case StringInfo.tag : // 8
+ info = new StringInfo(in);
+ break;
+ case FieldrefInfo.tag : // 9
+ info = new FieldrefInfo(in);
+ break;
+ case MethodrefInfo.tag : // 10
+ info = new MethodrefInfo(in);
+ break;
+ case InterfaceMethodrefInfo.tag : // 11
+ info = new InterfaceMethodrefInfo(in);
+ break;
+ case NameAndTypeInfo.tag : // 12
+ info = new NameAndTypeInfo(in);
+ break;
+ default :
+ throw new IOException("invalid constant type: " + tag);
+ }
+
+ addItem(info);
+ return tag;
}
/**
* Writes the contents of the constant pool table.
*/
public void write(DataOutputStream out) throws IOException {
- out.writeShort(numOfItems);
- LongVector v = items;
- int size = numOfItems;
- for (int i = 1; i < size; ++i)
- ((ConstInfo)v.elementAt(i)).write(out);
+ out.writeShort(numOfItems);
+ LongVector v = items;
+ int size = numOfItems;
+ for (int i = 1; i < size; ++i)
+ ((ConstInfo)v.elementAt(i)).write(out);
}
/**
* Prints the contents of the constant pool table.
*/
public void print() {
- print(new PrintWriter(System.out, true));
+ print(new PrintWriter(System.out, true));
}
/**
* Prints the contents of the constant pool table.
*/
public void print(PrintWriter out) {
- int size = numOfItems;
- for (int i = 1; i < size; ++i) {
- out.print(i);
- out.print(" ");
- ((ConstInfo)items.elementAt(i)).print(out);
- }
+ int size = numOfItems;
+ for (int i = 1; i < size; ++i) {
+ out.print(i);
+ out.print(" ");
+ ((ConstInfo)items.elementAt(i)).print(out);
+ }
}
}
@@ -964,16 +953,16 @@ abstract class ConstInfo {
public void renameClass(ConstPool cp, String oldName, String newName) {}
public void renameClass(ConstPool cp, Map classnames) {}
public abstract int copy(ConstPool src, ConstPool dest, Map classnames);
- // ** classnames is a mapping between JVM names.
+ // ** classnames is a mapping between JVM names.
public abstract void write(DataOutputStream out) throws IOException;
public abstract void print(PrintWriter out);
public String toString() {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- PrintWriter out = new PrintWriter(bout);
- print(out);
- return bout.toString();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ PrintWriter out = new PrintWriter(bout);
+ print(out);
+ return bout.toString();
}
}
@@ -983,13 +972,13 @@ class ConstInfoPadding extends ConstInfo {
public int getTag() { return 0; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addConstInfoPadding();
+ return dest.addConstInfoPadding();
}
public void write(DataOutputStream out) throws IOException {}
public void print(PrintWriter out) {
- out.println("padding");
+ out.println("padding");
}
}
@@ -999,48 +988,48 @@ class ClassInfo extends ConstInfo {
int index;
public ClassInfo(int className, int i) {
- name = className;
- index = i;
+ name = className;
+ index = i;
}
public ClassInfo(DataInputStream in, int i) throws IOException {
- name = in.readUnsignedShort();
- index = i;
+ name = in.readUnsignedShort();
+ index = i;
}
public int getTag() { return tag; }
public void renameClass(ConstPool cp, String oldName, String newName) {
- if (cp.getUtf8Info(name).equals(oldName))
- name = cp.addUtf8Info(newName);
+ if (cp.getUtf8Info(name).equals(oldName))
+ name = cp.addUtf8Info(newName);
}
public void renameClass(ConstPool cp, Map map) {
- String oldName = cp.getUtf8Info(name);
- String newName = (String)map.get(oldName);
- if (newName != null && !newName.equals(oldName))
- name = cp.addUtf8Info(newName);
+ String oldName = cp.getUtf8Info(name);
+ String newName = (String)map.get(oldName);
+ if (newName != null && !newName.equals(oldName))
+ name = cp.addUtf8Info(newName);
}
public int copy(ConstPool src, ConstPool dest, Map map) {
- String classname = src.getUtf8Info(name);
- if (map != null) {
- String newname = (String)map.get(classname);
- if (newname != null)
- classname = newname;
- }
+ String classname = src.getUtf8Info(name);
+ if (map != null) {
+ String newname = (String)map.get(classname);
+ if (newname != null)
+ classname = newname;
+ }
- return dest.addClassInfo(classname);
+ return dest.addClassInfo(classname);
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeShort(name);
+ out.writeByte(tag);
+ out.writeShort(name);
}
public void print(PrintWriter out) {
- out.print("Class #");
- out.println(name);
+ out.print("Class #");
+ out.println(name);
}
}
@@ -1050,50 +1039,50 @@ class NameAndTypeInfo extends ConstInfo {
int typeDescriptor;
public NameAndTypeInfo(int name, int type) {
- memberName = name;
- typeDescriptor = type;
+ memberName = name;
+ typeDescriptor = type;
}
public NameAndTypeInfo(DataInputStream in) throws IOException {
- memberName = in.readUnsignedShort();
- typeDescriptor = in.readUnsignedShort();
+ memberName = in.readUnsignedShort();
+ typeDescriptor = in.readUnsignedShort();
}
public int getTag() { return tag; }
public void renameClass(ConstPool cp, String oldName, String newName) {
- String type = cp.getUtf8Info(typeDescriptor);
- String type2 = Descriptor.rename(type, oldName, newName);
- if (type != type2)
- typeDescriptor = cp.addUtf8Info(type2);
+ String type = cp.getUtf8Info(typeDescriptor);
+ String type2 = Descriptor.rename(type, oldName, newName);
+ if (type != type2)
+ typeDescriptor = cp.addUtf8Info(type2);
}
public void renameClass(ConstPool cp, Map map) {
- String type = cp.getUtf8Info(typeDescriptor);
- String type2 = Descriptor.rename(type, map);
- if (type != type2)
- typeDescriptor = cp.addUtf8Info(type2);
+ String type = cp.getUtf8Info(typeDescriptor);
+ String type2 = Descriptor.rename(type, map);
+ if (type != type2)
+ typeDescriptor = cp.addUtf8Info(type2);
}
public int copy(ConstPool src, ConstPool dest, Map map) {
- String mname = src.getUtf8Info(memberName);
- String tdesc = src.getUtf8Info(typeDescriptor);
- tdesc = Descriptor.rename(tdesc, map);
- return dest.addNameAndTypeInfo(dest.addUtf8Info(mname),
- dest.addUtf8Info(tdesc));
+ String mname = src.getUtf8Info(memberName);
+ String tdesc = src.getUtf8Info(typeDescriptor);
+ tdesc = Descriptor.rename(tdesc, map);
+ return dest.addNameAndTypeInfo(dest.addUtf8Info(mname),
+ dest.addUtf8Info(tdesc));
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeShort(memberName);
- out.writeShort(typeDescriptor);
+ out.writeByte(tag);
+ out.writeShort(memberName);
+ out.writeShort(typeDescriptor);
}
public void print(PrintWriter out) {
- out.print("NameAndType #");
- out.print(memberName);
- out.print(", type #");
- out.println(typeDescriptor);
+ out.print("NameAndType #");
+ out.print(memberName);
+ out.print(", type #");
+ out.println(typeDescriptor);
}
}
@@ -1102,34 +1091,34 @@ abstract class MemberrefInfo extends ConstInfo {
int nameAndTypeIndex;
public MemberrefInfo(int cindex, int ntindex) {
- classIndex = cindex;
- nameAndTypeIndex = ntindex;
+ classIndex = cindex;
+ nameAndTypeIndex = ntindex;
}
public MemberrefInfo(DataInputStream in) throws IOException {
- classIndex = in.readUnsignedShort();
- nameAndTypeIndex = in.readUnsignedShort();
+ classIndex = in.readUnsignedShort();
+ nameAndTypeIndex = in.readUnsignedShort();
}
public int copy(ConstPool src, ConstPool dest, Map map) {
- int classIndex2 = src.getItem(classIndex).copy(src, dest, map);
- int ntIndex2 = src.getItem(nameAndTypeIndex).copy(src, dest, map);
- return copy2(dest, classIndex2, ntIndex2);
+ int classIndex2 = src.getItem(classIndex).copy(src, dest, map);
+ int ntIndex2 = src.getItem(nameAndTypeIndex).copy(src, dest, map);
+ return copy2(dest, classIndex2, ntIndex2);
}
abstract protected int copy2(ConstPool dest, int cindex, int ntindex);
public void write(DataOutputStream out) throws IOException {
- out.writeByte(getTag());
- out.writeShort(classIndex);
- out.writeShort(nameAndTypeIndex);
+ out.writeByte(getTag());
+ out.writeShort(classIndex);
+ out.writeShort(nameAndTypeIndex);
}
public void print(PrintWriter out) {
- out.print(getTagName() + " #");
- out.print(classIndex);
- out.print(", name&type #");
- out.println(nameAndTypeIndex);
+ out.print(getTagName() + " #");
+ out.print(classIndex);
+ out.print(", name&type #");
+ out.println(nameAndTypeIndex);
}
public abstract String getTagName();
@@ -1139,11 +1128,11 @@ class FieldrefInfo extends MemberrefInfo {
static final int tag = 9;
public FieldrefInfo(int cindex, int ntindex) {
- super(cindex, ntindex);
+ super(cindex, ntindex);
}
public FieldrefInfo(DataInputStream in) throws IOException {
- super(in);
+ super(in);
}
public int getTag() { return tag; }
@@ -1151,7 +1140,7 @@ class FieldrefInfo extends MemberrefInfo {
public String getTagName() { return "Field"; }
protected int copy2(ConstPool dest, int cindex, int ntindex) {
- return dest.addFieldrefInfo(cindex, ntindex);
+ return dest.addFieldrefInfo(cindex, ntindex);
}
}
@@ -1159,11 +1148,11 @@ class MethodrefInfo extends MemberrefInfo {
static final int tag = 10;
public MethodrefInfo(int cindex, int ntindex) {
- super(cindex, ntindex);
+ super(cindex, ntindex);
}
public MethodrefInfo(DataInputStream in) throws IOException {
- super(in);
+ super(in);
}
public int getTag() { return tag; }
@@ -1171,7 +1160,7 @@ class MethodrefInfo extends MemberrefInfo {
public String getTagName() { return "Method"; }
protected int copy2(ConstPool dest, int cindex, int ntindex) {
- return dest.addMethodrefInfo(cindex, ntindex);
+ return dest.addMethodrefInfo(cindex, ntindex);
}
}
@@ -1179,11 +1168,11 @@ class InterfaceMethodrefInfo extends MemberrefInfo {
static final int tag = 11;
public InterfaceMethodrefInfo(int cindex, int ntindex) {
- super(cindex, ntindex);
+ super(cindex, ntindex);
}
public InterfaceMethodrefInfo(DataInputStream in) throws IOException {
- super(in);
+ super(in);
}
public int getTag() { return tag; }
@@ -1191,7 +1180,7 @@ class InterfaceMethodrefInfo extends MemberrefInfo {
public String getTagName() { return "Interface"; }
protected int copy2(ConstPool dest, int cindex, int ntindex) {
- return dest.addInterfaceMethodrefInfo(cindex, ntindex);
+ return dest.addInterfaceMethodrefInfo(cindex, ntindex);
}
}
@@ -1200,27 +1189,27 @@ class StringInfo extends ConstInfo {
int string;
public StringInfo(int str) {
- string = str;
+ string = str;
}
public StringInfo(DataInputStream in) throws IOException {
- string = in.readUnsignedShort();
+ string = in.readUnsignedShort();
}
public int getTag() { return tag; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addStringInfo(src.getUtf8Info(string));
+ return dest.addStringInfo(src.getUtf8Info(string));
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeShort(string);
+ out.writeByte(tag);
+ out.writeShort(string);
}
public void print(PrintWriter out) {
- out.print("String #");
- out.println(string);
+ out.print("String #");
+ out.println(string);
}
}
@@ -1229,27 +1218,27 @@ class IntegerInfo extends ConstInfo {
int value;
public IntegerInfo(int i) {
- value = i;
+ value = i;
}
public IntegerInfo(DataInputStream in) throws IOException {
- value = in.readInt();
+ value = in.readInt();
}
public int getTag() { return tag; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addIntegerInfo(value);
+ return dest.addIntegerInfo(value);
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeInt(value);
+ out.writeByte(tag);
+ out.writeInt(value);
}
public void print(PrintWriter out) {
- out.print("Integer ");
- out.println(value);
+ out.print("Integer ");
+ out.println(value);
}
}
@@ -1258,27 +1247,27 @@ class FloatInfo extends ConstInfo {
float value;
public FloatInfo(float f) {
- value = f;
+ value = f;
}
public FloatInfo(DataInputStream in) throws IOException {
- value = in.readFloat();
+ value = in.readFloat();
}
public int getTag() { return tag; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addFloatInfo(value);
+ return dest.addFloatInfo(value);
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeFloat(value);
+ out.writeByte(tag);
+ out.writeFloat(value);
}
public void print(PrintWriter out) {
- out.print("Float ");
- out.println(value);
+ out.print("Float ");
+ out.println(value);
}
}
@@ -1287,27 +1276,27 @@ class LongInfo extends ConstInfo {
long value;
public LongInfo(long l) {
- value = l;
+ value = l;
}
public LongInfo(DataInputStream in) throws IOException {
- value = in.readLong();
+ value = in.readLong();
}
public int getTag() { return tag; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addLongInfo(value);
+ return dest.addLongInfo(value);
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeLong(value);
+ out.writeByte(tag);
+ out.writeLong(value);
}
public void print(PrintWriter out) {
- out.print("Long ");
- out.println(value);
+ out.print("Long ");
+ out.println(value);
}
}
@@ -1316,27 +1305,27 @@ class DoubleInfo extends ConstInfo {
double value;
public DoubleInfo(double d) {
- value = d;
+ value = d;
}
public DoubleInfo(DataInputStream in) throws IOException {
- value = in.readDouble();
+ value = in.readDouble();
}
public int getTag() { return tag; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addDoubleInfo(value);
+ return dest.addDoubleInfo(value);
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeDouble(value);
+ out.writeByte(tag);
+ out.writeDouble(value);
}
public void print(PrintWriter out) {
- out.print("Double ");
- out.println(value);
+ out.print("Double ");
+ out.println(value);
}
}
@@ -1346,29 +1335,29 @@ class Utf8Info extends ConstInfo {
int index;
public Utf8Info(String utf8, int i) {
- string = utf8;
- index = i;
+ string = utf8;
+ index = i;
}
public Utf8Info(DataInputStream in, int i) throws IOException {
- string = in.readUTF();
- index = i;
+ string = in.readUTF();
+ index = i;
}
public int getTag() { return tag; }
public int copy(ConstPool src, ConstPool dest, Map map) {
- return dest.addUtf8Info(string);
+ return dest.addUtf8Info(string);
}
public void write(DataOutputStream out) throws IOException {
- out.writeByte(tag);
- out.writeUTF(string);
+ out.writeByte(tag);
+ out.writeUTF(string);
}
public void print(PrintWriter out) {
- out.print("UTF8 \"");
- out.print(string);
- out.println("\"");
+ out.print("UTF8 \"");
+ out.print(string);
+ out.println("\"");
}
}
diff --git a/src/main/javassist/bytecode/ConstantAttribute.java b/src/main/javassist/bytecode/ConstantAttribute.java
index 4d913e15..3658b92f 100644
--- a/src/main/javassist/bytecode/ConstantAttribute.java
+++ b/src/main/javassist/bytecode/ConstantAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,44 +28,44 @@ public class ConstantAttribute extends AttributeInfo {
public static final String tag = "ConstantValue";
ConstantAttribute(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, n, in);
+ super(cp, n, in);
}
/**
* Constructs a ConstantValue attribute.
*
- * @param cp a constant pool table.
- * @param index <code>constantvalue_index</code>
- * of <code>ConstantValue_attribute</code>.
+ * @param cp a constant pool table.
+ * @param index <code>constantvalue_index</code>
+ * of <code>ConstantValue_attribute</code>.
*/
public ConstantAttribute(ConstPool cp, int index) {
- super(cp, tag);
- byte[] bvalue = new byte[2];
- bvalue[0] = (byte)(index >>> 8);
- bvalue[1] = (byte)index;
- set(bvalue);
+ super(cp, tag);
+ byte[] bvalue = new byte[2];
+ bvalue[0] = (byte)(index >>> 8);
+ bvalue[1] = (byte)index;
+ set(bvalue);
}
/**
* Returns <code>constantvalue_index</code>.
*/
public int getConstantValue() {
- return ByteArray.readU16bit(get(), 0);
+ return ByteArray.readU16bit(get(), 0);
}
/**
* Makes a copy. Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- int index = getConstPool().copy(getConstantValue(), newCp,
- classnames);
- return new ConstantAttribute(newCp, index);
+ int index = getConstPool().copy(getConstantValue(), newCp,
+ classnames);
+ return new ConstantAttribute(newCp, index);
}
}
diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java
index 065fbccf..badec6b4 100644
--- a/src/main/javassist/bytecode/Descriptor.java
+++ b/src/main/javassist/bytecode/Descriptor.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.util.Map;
@@ -45,7 +34,7 @@ public class Descriptor {
* to <code>toJvmName(s)</code>.
*/
public static String toJvmName(String classname) {
- return classname.replace('.', '/');
+ return classname.replace('.', '/');
}
/**
@@ -53,7 +42,7 @@ public class Descriptor {
* the JVM to the normal one used in Java.
*/
public static String toJavaName(String classname) {
- return classname.replace('/', '.');
+ return classname.replace('/', '.');
}
/**
@@ -61,172 +50,172 @@ public class Descriptor {
* JVM.
*/
public static String toJvmName(CtClass clazz) {
- if (clazz.isArray())
- return of(clazz);
- else
- return toJvmName(clazz.getName());
+ if (clazz.isArray())
+ return of(clazz);
+ else
+ return toJvmName(clazz.getName());
}
/**
* Substitutes a class name
* in the given descriptor string.
*
- * @param desc descriptor string
- * @param oldname replaced JVM class name
- * @param newname substituted JVM class name
+ * @param desc descriptor string
+ * @param oldname replaced JVM class name
+ * @param newname substituted JVM class name
*
* @see Descriptor#toJvmName(String)
*/
public static String rename(String desc,
- String oldname, String newname) {
- if (desc.indexOf(oldname) < 0)
- return desc;
-
- StringBuffer newdesc = new StringBuffer();
- int head = 0;
- int i = 0;
- for (;;) {
- int j = desc.indexOf('L', i);
- if (j < 0)
- break;
- else if (desc.startsWith(oldname, j + 1)
- && desc.charAt(j + oldname.length() + 1) == ';') {
- newdesc.append(desc.substring(head, j));
- newdesc.append('L');
- newdesc.append(newname);
- newdesc.append(';');
- head = i = j + oldname.length() + 2;
- }
- else {
- i = desc.indexOf(';', j) + 1;
- if (i < 1)
- break; // ';' was not found.
- }
- }
-
- if (head == 0)
- return desc;
- else {
- int len = desc.length();
- if (head < len)
- newdesc.append(desc.substring(head, len));
-
- return newdesc.toString();
- }
+ String oldname, String newname) {
+ if (desc.indexOf(oldname) < 0)
+ return desc;
+
+ StringBuffer newdesc = new StringBuffer();
+ int head = 0;
+ int i = 0;
+ for (;;) {
+ int j = desc.indexOf('L', i);
+ if (j < 0)
+ break;
+ else if (desc.startsWith(oldname, j + 1)
+ && desc.charAt(j + oldname.length() + 1) == ';') {
+ newdesc.append(desc.substring(head, j));
+ newdesc.append('L');
+ newdesc.append(newname);
+ newdesc.append(';');
+ head = i = j + oldname.length() + 2;
+ }
+ else {
+ i = desc.indexOf(';', j) + 1;
+ if (i < 1)
+ break; // ';' was not found.
+ }
+ }
+
+ if (head == 0)
+ return desc;
+ else {
+ int len = desc.length();
+ if (head < len)
+ newdesc.append(desc.substring(head, len));
+
+ return newdesc.toString();
+ }
}
/**
* Substitutes class names in the given descriptor string
* according to the given <code>map</code>.
*
- * @param map a map between replaced and substituted
- * JVM class names.
+ * @param map a map between replaced and substituted
+ * JVM class names.
*
* @see Descriptor#toJvmName(String)
*/
public static String rename(String desc, Map map) {
- if (map == null)
- return desc;
-
- StringBuffer newdesc = new StringBuffer();
- int head = 0;
- int i = 0;
- for (;;) {
- int j = desc.indexOf('L', i);
- if (j < 0)
- break;
-
- int k = desc.indexOf(';', j);
- if (k < 0)
- break;
-
- i = k + 1;
- String name = desc.substring(j + 1, k);
- String name2 = (String)map.get(name);
- if (name2 != null) {
- newdesc.append(desc.substring(head, j));
- newdesc.append('L');
- newdesc.append(name2);
- newdesc.append(';');
- head = i;
- }
- }
-
- if (head == 0)
- return desc;
- else {
- int len = desc.length();
- if (head < len)
- newdesc.append(desc.substring(head, len));
-
- return newdesc.toString();
- }
+ if (map == null)
+ return desc;
+
+ StringBuffer newdesc = new StringBuffer();
+ int head = 0;
+ int i = 0;
+ for (;;) {
+ int j = desc.indexOf('L', i);
+ if (j < 0)
+ break;
+
+ int k = desc.indexOf(';', j);
+ if (k < 0)
+ break;
+
+ i = k + 1;
+ String name = desc.substring(j + 1, k);
+ String name2 = (String)map.get(name);
+ if (name2 != null) {
+ newdesc.append(desc.substring(head, j));
+ newdesc.append('L');
+ newdesc.append(name2);
+ newdesc.append(';');
+ head = i;
+ }
+ }
+
+ if (head == 0)
+ return desc;
+ else {
+ int len = desc.length();
+ if (head < len)
+ newdesc.append(desc.substring(head, len));
+
+ return newdesc.toString();
+ }
}
/**
* Returns the descriptor representing the given type.
*/
public static String of(CtClass type) {
- StringBuffer sbuf = new StringBuffer();
- toDescriptor(sbuf, type);
- return sbuf.toString();
+ StringBuffer sbuf = new StringBuffer();
+ toDescriptor(sbuf, type);
+ return sbuf.toString();
}
private static void toDescriptor(StringBuffer desc, CtClass type) {
- if (type.isArray()) {
- desc.append('[');
- try {
- toDescriptor(desc, type.getComponentType());
- }
- catch (NotFoundException e) {
- desc.append('L');
- String name = type.getName();
- desc.append(toJvmName(name.substring(0, name.length() - 2)));
- desc.append(';');
- }
- }
- else if (type.isPrimitive()) {
- CtPrimitiveType pt = (CtPrimitiveType)type;
- desc.append(pt.getDescriptor());
- }
- else { // class type
- desc.append('L');
- desc.append(type.getName().replace('.', '/'));
- desc.append(';');
- }
+ if (type.isArray()) {
+ desc.append('[');
+ try {
+ toDescriptor(desc, type.getComponentType());
+ }
+ catch (NotFoundException e) {
+ desc.append('L');
+ String name = type.getName();
+ desc.append(toJvmName(name.substring(0, name.length() - 2)));
+ desc.append(';');
+ }
+ }
+ else if (type.isPrimitive()) {
+ CtPrimitiveType pt = (CtPrimitiveType)type;
+ desc.append(pt.getDescriptor());
+ }
+ else { // class type
+ desc.append('L');
+ desc.append(type.getName().replace('.', '/'));
+ desc.append(';');
+ }
}
/**
* Returns the descriptor representing a constructor receiving
* the given parameter types.
*
- * @param paramTypes parameter types
+ * @param paramTypes parameter types
*/
public static String ofConstructor(CtClass[] paramTypes) {
- return ofMethod(CtClass.voidType, paramTypes);
+ return ofMethod(CtClass.voidType, paramTypes);
}
/**
* Returns the descriptor representing a method that receives
* the given parameter types and returns the given type.
*
- * @param returnType return type
- * @param paramTypes parameter types
+ * @param returnType return type
+ * @param paramTypes parameter types
*/
public static String ofMethod(CtClass returnType, CtClass[] paramTypes) {
- StringBuffer desc = new StringBuffer();
- desc.append('(');
- if (paramTypes != null) {
- int n = paramTypes.length;
- for (int i = 0; i < n; ++i)
- toDescriptor(desc, paramTypes[i]);
- }
-
- desc.append(')');
- if (returnType != null)
- toDescriptor(desc, returnType);
-
- return desc.toString();
+ StringBuffer desc = new StringBuffer();
+ desc.append('(');
+ if (paramTypes != null) {
+ int n = paramTypes.length;
+ for (int i = 0; i < n; ++i)
+ toDescriptor(desc, paramTypes[i]);
+ }
+
+ desc.append(')');
+ if (returnType != null)
+ toDescriptor(desc, returnType);
+
+ return desc.toString();
}
/**
@@ -234,10 +223,10 @@ public class Descriptor {
* For example, if the given parameter types are two <code>int</code>,
* then this method returns <code>"(II)"</code>.
*
- * @param paramTypes parameter types
+ * @param paramTypes parameter types
*/
public static String ofParameters(CtClass[] paramTypes) {
- return ofMethod(null, paramTypes);
+ return ofMethod(null, paramTypes);
}
/**
@@ -246,23 +235,23 @@ public class Descriptor {
*
* <p><code>classname</code> must not be an array type.
*
- * @param classname parameter type (not primitive type)
- * @param desc descriptor
+ * @param classname parameter type (not primitive type)
+ * @param desc descriptor
*/
public static String appendParameter(String classname,
- String desc) {
- 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();
- }
+ String desc) {
+ 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();
+ }
}
/**
@@ -272,16 +261,16 @@ public class Descriptor {
*
* <p><code>classname</code> must not be an array type.
*
- * @param classname parameter type (not primitive type)
- * @param desc descriptor
+ * @param classname parameter type (not primitive type)
+ * @param desc descriptor
*/
public static String insertParameter(String classname,
- String desc) {
- if (desc.charAt(0) != '(')
- return desc;
- else
- return "(L" + classname.replace('.', '/') + ';'
- + desc.substring(1);
+ String desc) {
+ if (desc.charAt(0) != '(')
+ return desc;
+ else
+ return "(L" + classname.replace('.', '/') + ';'
+ + desc.substring(1);
}
/**
@@ -289,98 +278,98 @@ public class Descriptor {
*
* <p><code>classname</code> must not be an array type.
*
- * @param classname return type
- * @param desc descriptor
+ * @param classname return type
+ * @param desc descriptor
*/
public static String changeReturnType(String classname, String desc) {
- 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();
- }
+ 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();
+ }
}
/**
* Returns the <code>CtClass</code> objects representing the parameter
* types specified by the given descriptor.
*
- * @param desc descriptor
- * @param cp the class pool used for obtaining
- * a <code>CtClass</code> object.
+ * @param desc descriptor
+ * @param cp the class pool used for obtaining
+ * a <code>CtClass</code> object.
*/
public static CtClass[] getParameterTypes(String desc, ClassPool cp)
- throws NotFoundException
+ throws NotFoundException
{
- 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;
- }
+ 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;
+ }
}
/**
* Returns the <code>CtClass</code> object representing the return
* type specified by the given descriptor.
*
- * @param desc descriptor
- * @param cp the class pool used for obtaining
- * a <code>CtClass</code> object.
+ * @param desc descriptor
+ * @param cp the class pool used for obtaining
+ * a <code>CtClass</code> object.
*/
public static CtClass getReturnType(String desc, ClassPool cp)
- throws NotFoundException
+ throws NotFoundException
{
- 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];
- }
+ 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];
+ }
}
/**
* Returns the number of the prameters included in the given
* descriptor.
*
- * @param desc descriptor
+ * @param desc descriptor
*/
public static int numOfParameters(String desc) {
- int n = 0;
- int i = 1;
- for (;;) {
- char c = desc.charAt(i);
- if (c == ')')
- break;
-
- while (c == '[')
- c = desc.charAt(++i);
-
- if (c == 'L') {
- i = desc.indexOf(';', i) + 1;
- if (i <= 0)
- throw new IndexOutOfBoundsException("bad descriptor");
- }
- else
- ++i;
-
- ++n;
- }
-
- return n;
+ int n = 0;
+ int i = 1;
+ for (;;) {
+ char c = desc.charAt(i);
+ if (c == ')')
+ break;
+
+ while (c == '[')
+ c = desc.charAt(++i);
+
+ if (c == 'L') {
+ i = desc.indexOf(';', i) + 1;
+ if (i <= 0)
+ throw new IndexOutOfBoundsException("bad descriptor");
+ }
+ else
+ ++i;
+
+ ++n;
+ }
+
+ return n;
}
/**
@@ -392,101 +381,101 @@ public class Descriptor {
* it accepts <code>Ljava.lang.Object;</code>
* as well as <code>Ljava/lang/Object;</code>.
*
- * @param desc descriptor
- * @param cp the class pool used for obtaining
- * a <code>CtClass</code> object.
+ * @param desc descriptor
+ * @param cp the class pool used for obtaining
+ * a <code>CtClass</code> object.
*/
public static CtClass toCtClass(String desc, ClassPool cp)
- throws NotFoundException
+ throws NotFoundException
{
- CtClass[] clazz = new CtClass[1];
- 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('/', '.'));
- }
+ CtClass[] clazz = new CtClass[1];
+ 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('/', '.'));
+ }
}
private static int toCtClass(ClassPool cp, String desc, int i,
- CtClass[] args, int n)
- throws NotFoundException
+ CtClass[] args, int n)
+ throws NotFoundException
{
- int i2;
- String name;
-
- int arrayDim = 0;
- char c = desc.charAt(i);
- while (c == '[') {
- ++arrayDim;
- c = desc.charAt(++i);
- }
-
- if (c == 'L') {
- i2 = desc.indexOf(';', ++i);
- name = desc.substring(i, i2++).replace('/', '.');
- }
- else {
- CtClass type = toPrimitiveClass(c);
- if (type == null)
- return -1; // error
-
- i2 = i + 1;
- if (arrayDim == 0) {
- args[n] = type;
- return i2; // neither an array type or a class type
- }
- else
- name = type.getName();
- }
-
- if (arrayDim > 0) {
- StringBuffer sbuf = new StringBuffer(name);
- while (arrayDim-- > 0)
- sbuf.append("[]");
-
- name = sbuf.toString();
- }
-
- args[n] = cp.get(name);
- return i2;
+ int i2;
+ String name;
+
+ int arrayDim = 0;
+ char c = desc.charAt(i);
+ while (c == '[') {
+ ++arrayDim;
+ c = desc.charAt(++i);
+ }
+
+ if (c == 'L') {
+ i2 = desc.indexOf(';', ++i);
+ name = desc.substring(i, i2++).replace('/', '.');
+ }
+ else {
+ CtClass type = toPrimitiveClass(c);
+ if (type == null)
+ return -1; // error
+
+ i2 = i + 1;
+ if (arrayDim == 0) {
+ args[n] = type;
+ return i2; // neither an array type or a class type
+ }
+ else
+ name = type.getName();
+ }
+
+ if (arrayDim > 0) {
+ StringBuffer sbuf = new StringBuffer(name);
+ while (arrayDim-- > 0)
+ sbuf.append("[]");
+
+ name = sbuf.toString();
+ }
+
+ args[n] = cp.get(name);
+ return i2;
}
private static CtClass toPrimitiveClass(char c) {
- CtClass type = null;
- switch (c) {
- case 'Z' :
- type = CtClass.booleanType;
- break;
- case 'C' :
- type = CtClass.charType;
- break;
- case 'B' :
- type = CtClass.byteType;
- break;
- case 'S' :
- type = CtClass.shortType;
- break;
- case 'I' :
- type = CtClass.intType;
- break;
- case 'J' :
- type = CtClass.longType;
- break;
- case 'F' :
- type = CtClass.floatType;
- break;
- case 'D' :
- type = CtClass.doubleType;
- break;
- case 'V' :
- type = CtClass.voidType;
- break;
- }
-
- return type;
+ CtClass type = null;
+ switch (c) {
+ case 'Z' :
+ type = CtClass.booleanType;
+ break;
+ case 'C' :
+ type = CtClass.charType;
+ break;
+ case 'B' :
+ type = CtClass.byteType;
+ break;
+ case 'S' :
+ type = CtClass.shortType;
+ break;
+ case 'I' :
+ type = CtClass.intType;
+ break;
+ case 'J' :
+ type = CtClass.longType;
+ break;
+ case 'F' :
+ type = CtClass.floatType;
+ break;
+ case 'D' :
+ type = CtClass.doubleType;
+ break;
+ case 'V' :
+ type = CtClass.voidType;
+ break;
+ }
+
+ return type;
}
/**
@@ -498,46 +487,46 @@ public class Descriptor {
* of all the parameters). For example, if the descriptor is
* "(I)D", then this method returns 1 (= 2 - 1).
*
- * @param desc descriptor
+ * @param desc descriptor
*/
public static int dataSize(String desc) {
- int n = 0;
- char c = desc.charAt(0);
- if (c == '(') {
- int i = 1;
- for (;;) {
- c = desc.charAt(i);
- if (c == ')') {
- c = desc.charAt(i + 1);
- break;
- }
-
- boolean array = false;
- while (c == '[') {
- array = true;
- c = desc.charAt(++i);
- }
-
- if (c == 'L') {
- i = desc.indexOf(';', i) + 1;
- if (i <= 0)
- throw new IndexOutOfBoundsException("bad descriptor");
- }
- else
- ++i;
-
- if (!array && (c == 'J' || c == 'D'))
- n -= 2;
- else
- --n;
- }
- }
-
- if (c == 'J' || c == 'D')
- n += 2;
- else if (c != 'V')
- ++n;
-
- return n;
+ int n = 0;
+ char c = desc.charAt(0);
+ if (c == '(') {
+ int i = 1;
+ for (;;) {
+ c = desc.charAt(i);
+ if (c == ')') {
+ c = desc.charAt(i + 1);
+ break;
+ }
+
+ boolean array = false;
+ while (c == '[') {
+ array = true;
+ c = desc.charAt(++i);
+ }
+
+ if (c == 'L') {
+ i = desc.indexOf(';', i) + 1;
+ if (i <= 0)
+ throw new IndexOutOfBoundsException("bad descriptor");
+ }
+ else
+ ++i;
+
+ if (!array && (c == 'J' || c == 'D'))
+ n -= 2;
+ else
+ --n;
+ }
+ }
+
+ if (c == 'J' || c == 'D')
+ n += 2;
+ else if (c != 'V')
+ ++n;
+
+ return n;
}
}
diff --git a/src/main/javassist/bytecode/ExceptionTable.java b/src/main/javassist/bytecode/ExceptionTable.java
index 71baa3b5..ce9765d6 100644
--- a/src/main/javassist/bytecode/ExceptionTable.java
+++ b/src/main/javassist/bytecode/ExceptionTable.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -38,10 +27,10 @@ class ExceptionTableEntry {
int catchType;
ExceptionTableEntry(int start, int end, int handle, int type) {
- startPc = start;
- endPc = end;
- handlerPc = handle;
- catchType = type;
+ startPc = start;
+ endPc = end;
+ handlerPc = handle;
+ catchType = type;
}
}
@@ -55,26 +44,26 @@ public class ExceptionTable {
/**
* Constructs an <code>exception_table[]</code>.
*
- * @param cp constant pool table.
+ * @param cp constant pool table.
*/
public ExceptionTable(ConstPool cp) {
- constPool = cp;
- entries = new ArrayList();
+ constPool = cp;
+ entries = new ArrayList();
}
ExceptionTable(ConstPool cp, DataInputStream in) throws IOException {
- constPool = cp;
- int length = in.readUnsignedShort();
- ArrayList list = new ArrayList(length);
- for (int i = 0; i < length; ++i) {
- int start = in.readUnsignedShort();
- int end = in.readUnsignedShort();
- int handle = in.readUnsignedShort();
- int type = in.readUnsignedShort();
- list.add(new ExceptionTableEntry(start, end, handle, type));
- }
+ constPool = cp;
+ int length = in.readUnsignedShort();
+ ArrayList list = new ArrayList(length);
+ for (int i = 0; i < length; ++i) {
+ int start = in.readUnsignedShort();
+ int end = in.readUnsignedShort();
+ int handle = in.readUnsignedShort();
+ int type = in.readUnsignedShort();
+ list.add(new ExceptionTableEntry(start, end, handle, type));
+ }
- entries = list;
+ entries = list;
}
/**
@@ -82,143 +71,143 @@ public class ExceptionTable {
* of entries in the <code>exception_table[]</code>.
*/
public int size() {
- return entries.size();
+ return entries.size();
}
/**
* Returns <code>startPc</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param nth the <i>n</i>-th (&gt;= 0).
*/
public int startPc(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.startPc;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ return e.startPc;
}
/**
* Sets <code>startPc</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
- * @param value new value.
+ * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param value new value.
*/
public void setStartPc(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.startPc = value;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ e.startPc = value;
}
/**
* Returns <code>endPc</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param nth the <i>n</i>-th (&gt;= 0).
*/
public int endPc(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.endPc;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ return e.endPc;
}
/**
* Sets <code>endPc</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
- * @param value new value.
+ * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param value new value.
*/
public void setEndPc(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.endPc = value;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ e.endPc = value;
}
/**
* Returns <code>handlerPc</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param nth the <i>n</i>-th (&gt;= 0).
*/
public int handlerPc(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.handlerPc;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ return e.handlerPc;
}
/**
* Sets <code>handlerPc</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
- * @param value new value.
+ * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param value new value.
*/
public void setHandlerPc(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.handlerPc = value;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ e.handlerPc = value;
}
/**
* Returns <code>catchType</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param nth the <i>n</i>-th (&gt;= 0).
*/
public int catchType(int nth) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- return e.catchType;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ return e.catchType;
}
/**
* Sets <code>catchType</code> of the <i>n</i>-th entry.
*
- * @param nth the <i>n</i>-th (&gt;= 0).
- * @param value new value.
+ * @param nth the <i>n</i>-th (&gt;= 0).
+ * @param value new value.
*/
public void setCatchType(int nth, int value) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
- e.catchType = value;
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(nth);
+ e.catchType = value;
}
/**
* Copies the given exception table at the specified position
* in the table.
*
- * @param index index (&gt;= 0) at which the entry is to be inserted.
- * @param offset the offset added to the code position.
+ * @param index index (&gt;= 0) at which the entry is to be inserted.
+ * @param offset the offset added to the code position.
*/
public void add(int index, ExceptionTable table, int offset) {
- int len = table.size();
- while (--len >= 0) {
- ExceptionTableEntry e
- = (ExceptionTableEntry)table.entries.get(len);
- add(index, e.startPc + offset, e.endPc + offset,
- e.handlerPc + offset, e.catchType);
- }
+ int len = table.size();
+ while (--len >= 0) {
+ ExceptionTableEntry e
+ = (ExceptionTableEntry)table.entries.get(len);
+ add(index, e.startPc + offset, e.endPc + offset,
+ e.handlerPc + offset, e.catchType);
+ }
}
/**
* Adds a new entry at the specified position in the table.
*
- * @param index index (&gt;= 0) at which the entry is to be inserted.
- * @param start <code>startPc</code>
- * @param end <code>endPc</code>
- * @param handler <code>handlerPc</code>
- * @param type <code>catchType</code>
+ * @param index index (&gt;= 0) at which the entry is to be inserted.
+ * @param start <code>startPc</code>
+ * @param end <code>endPc</code>
+ * @param handler <code>handlerPc</code>
+ * @param type <code>catchType</code>
*/
public void add(int index, int start, int end, int handler, int type) {
- entries.add(index,
- new ExceptionTableEntry(start, end, handler, type));
+ entries.add(index,
+ new ExceptionTableEntry(start, end, handler, type));
}
/**
* Appends a new entry at the end of the table.
*
- * @param start <code>startPc</code>
- * @param end <code>endPc</code>
- * @param handler <code>handlerPc</code>
- * @param type <code>catchType</code>
+ * @param start <code>startPc</code>
+ * @param end <code>endPc</code>
+ * @param handler <code>handlerPc</code>
+ * @param type <code>catchType</code>
*/
public void add(int start, int end, int handler, int type) {
- entries.add(new ExceptionTableEntry(start, end, handler, type));
+ entries.add(new ExceptionTableEntry(start, end, handler, type));
}
/**
* Removes the entry at the specified position in the table.
*
- * @param index the index of the removed entry.
+ * @param index the index of the removed entry.
*/
public void remove(int index) {
- entries.remove(index);
+ entries.remove(index);
}
/**
@@ -226,50 +215,50 @@ public class ExceptionTable {
* Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
public ExceptionTable copy(ConstPool newCp, Map 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);
- int type = srcCp.copy(e.catchType, newCp, classnames);
- et.add(e.startPc, e.endPc, e.handlerPc, type);
- }
+ ExceptionTable et = new ExceptionTable(newCp);
+ ConstPool srcCp = constPool;
+ int len = size();
+ for (int i = 0; i < len; ++i) {
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
+ int type = srcCp.copy(e.catchType, newCp, classnames);
+ et.add(e.startPc, e.endPc, e.handlerPc, type);
+ }
- return et;
+ return et;
}
void shiftPc(int where, int gapLength, boolean exclusive) {
- int len = size();
- for (int i = 0; i < len; ++i) {
- ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
- e.startPc = shiftPc(e.startPc, where, gapLength, exclusive);
- e.endPc = shiftPc(e.endPc, where, gapLength, exclusive);
- e.handlerPc = shiftPc(e.handlerPc, where, gapLength, exclusive);
- }
+ int len = size();
+ for (int i = 0; i < len; ++i) {
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
+ e.startPc = shiftPc(e.startPc, where, gapLength, exclusive);
+ e.endPc = shiftPc(e.endPc, where, gapLength, exclusive);
+ e.handlerPc = shiftPc(e.handlerPc, where, gapLength, exclusive);
+ }
}
private static int shiftPc(int pc, int where, int gapLength,
- boolean exclusive) {
- if (pc > where || (exclusive && pc == where))
- pc += gapLength;
+ boolean exclusive) {
+ if (pc > where || (exclusive && pc == where))
+ pc += gapLength;
- return pc;
+ return pc;
}
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(e.startPc);
- out.writeShort(e.endPc);
- out.writeShort(e.handlerPc);
- out.writeShort(e.catchType);
- }
+ int len = size();
+ out.writeShort(len); // exception_table_length
+ for (int i = 0; i < len; ++i) {
+ ExceptionTableEntry e = (ExceptionTableEntry)entries.get(i);
+ out.writeShort(e.startPc);
+ out.writeShort(e.endPc);
+ out.writeShort(e.handlerPc);
+ out.writeShort(e.catchType);
+ }
}
}
diff --git a/src/main/javassist/bytecode/ExceptionsAttribute.java b/src/main/javassist/bytecode/ExceptionsAttribute.java
index db304e71..cde680f6 100644
--- a/src/main/javassist/bytecode/ExceptionsAttribute.java
+++ b/src/main/javassist/bytecode/ExceptionsAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,133 +28,133 @@ public class ExceptionsAttribute extends AttributeInfo {
public static final String tag = "Exceptions";
ExceptionsAttribute(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, n, in);
+ super(cp, n, in);
}
/**
* Constructs a copy of an exceptions attribute.
*
- * @param cp constant pool table.
- * @param src source attribute.
+ * @param cp constant pool table.
+ * @param src source attribute.
*/
private ExceptionsAttribute(ConstPool cp, ExceptionsAttribute src,
- Map classnames) {
- super(cp, tag);
- copyFrom(src, classnames);
+ Map classnames) {
+ super(cp, tag);
+ copyFrom(src, classnames);
}
/**
* Constructs a new exceptions attribute.
*
- * @param cp constant pool table.
+ * @param cp constant pool table.
*/
public ExceptionsAttribute(ConstPool cp) {
- super(cp, tag);
- byte[] data = new byte[2];
- data[0] = data[1] = 0; // empty
- this.info = data;
+ super(cp, tag);
+ byte[] data = new byte[2];
+ data[0] = data[1] = 0; // empty
+ this.info = data;
}
/**
* Makes a copy. Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- return new ExceptionsAttribute(newCp, this, classnames);
+ return new ExceptionsAttribute(newCp, this, classnames);
}
/**
* Copies the contents from a source attribute.
* Specified class names are replaced during the copy.
*
- * @param srcAttr source Exceptions attribute
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param srcAttr source Exceptions attribute
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
private void copyFrom(ExceptionsAttribute srcAttr, Map classnames) {
- ConstPool srcCp = srcAttr.constPool;
- ConstPool destCp = this.constPool;
- byte[] src = srcAttr.info;
- int num = src.length;
- byte[] dest = new byte[num];
- dest[0] = src[0];
- dest[1] = src[1]; // the number of elements.
- for (int i = 2; i < num; i += 2) {
- int index = ByteArray.readU16bit(src, i);
- ByteArray.write16bit(srcCp.copy(index, destCp, classnames),
- dest, i);
- }
-
- this.info = dest;
+ ConstPool srcCp = srcAttr.constPool;
+ ConstPool destCp = this.constPool;
+ byte[] src = srcAttr.info;
+ int num = src.length;
+ byte[] dest = new byte[num];
+ dest[0] = src[0];
+ dest[1] = src[1]; // the number of elements.
+ for (int i = 2; i < num; i += 2) {
+ int index = ByteArray.readU16bit(src, i);
+ ByteArray.write16bit(srcCp.copy(index, destCp, classnames),
+ dest, i);
+ }
+
+ this.info = dest;
}
/**
* Returns <code>exception_index_table[]</code>.
*/
public int[] getExceptionIndexes() {
- byte[] blist = info;
- int n = blist.length;
- if (n <= 2)
- return null;
+ byte[] blist = info;
+ int n = blist.length;
+ if (n <= 2)
+ return null;
- int[] elist = new int[n / 2 - 1];
- int k = 0;
- for (int j = 2; j < n; j += 2)
- elist[k++] = ((blist[j] & 0xff) << 8) | (blist[j + 1] & 0xff);
+ int[] elist = new int[n / 2 - 1];
+ int k = 0;
+ for (int j = 2; j < n; j += 2)
+ elist[k++] = ((blist[j] & 0xff) << 8) | (blist[j + 1] & 0xff);
- return elist;
+ return elist;
}
/**
* Returns the names of exceptions that the method may throw.
*/
public String[] getExceptions() {
- byte[] blist = info;
- int n = blist.length;
- if (n <= 2)
- return null;
-
- String[] elist = new String[n / 2 - 1];
- int k = 0;
- for (int j = 2; j < n; j += 2) {
- int index = ((blist[j] & 0xff) << 8) | (blist[j + 1] & 0xff);
- elist[k++] = constPool.getClassInfo(index);
- }
-
- return elist;
+ byte[] blist = info;
+ int n = blist.length;
+ if (n <= 2)
+ return null;
+
+ String[] elist = new String[n / 2 - 1];
+ int k = 0;
+ for (int j = 2; j < n; j += 2) {
+ int index = ((blist[j] & 0xff) << 8) | (blist[j + 1] & 0xff);
+ elist[k++] = constPool.getClassInfo(index);
+ }
+
+ return elist;
}
/**
* Sets <code>exception_index_table[]</code>.
*/
public void setExceptionIndexes(int[] elist) {
- int n = elist.length;
- byte[] blist = new byte[n * 2 + 2];
- ByteArray.write16bit(n, blist, 0);
- for (int i = 0; i < n; ++i)
- ByteArray.write16bit(elist[i], blist, i * 2 + 2);
+ int n = elist.length;
+ byte[] blist = new byte[n * 2 + 2];
+ ByteArray.write16bit(n, blist, 0);
+ for (int i = 0; i < n; ++i)
+ ByteArray.write16bit(elist[i], blist, i * 2 + 2);
- info = blist;
+ info = blist;
}
/**
* Sets the names of exceptions that the method may throw.
*/
public void setExceptions(String[] elist) {
- int n = elist.length;
- byte[] blist = new byte[n * 2 + 2];
- ByteArray.write16bit(n, blist, 0);
- for (int i = 0; i < n; ++i)
- ByteArray.write16bit(constPool.addClassInfo(elist[i]),
- blist, i * 2 + 2);
-
- info = blist;
+ int n = elist.length;
+ byte[] blist = new byte[n * 2 + 2];
+ ByteArray.write16bit(n, blist, 0);
+ for (int i = 0; i < n; ++i)
+ ByteArray.write16bit(constPool.addClassInfo(elist[i]),
+ blist, i * 2 + 2);
+
+ info = blist;
}
/**
@@ -177,7 +166,7 @@ public class ExceptionsAttribute extends AttributeInfo {
* Returns the value of <code>exception_index_table[nth]</code>.
*/
public int getException(int nth) {
- int index = nth * 2 + 2; // nth >= 0
- return ((info[index] & 0xff) << 8) | (info[index + 1] & 0xff);
+ int index = nth * 2 + 2; // nth >= 0
+ return ((info[index] & 0xff) << 8) | (info[index + 1] & 0xff);
}
}
diff --git a/src/main/javassist/bytecode/FieldInfo.java b/src/main/javassist/bytecode/FieldInfo.java
index d5e3591c..89f2cb2c 100644
--- a/src/main/javassist/bytecode/FieldInfo.java
+++ b/src/main/javassist/bytecode/FieldInfo.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -42,32 +31,32 @@ public final class FieldInfo {
int accessFlags;
int name;
int descriptor;
- LinkedList attribute; // may be null.
+ LinkedList attribute; // may be null.
private FieldInfo(ConstPool cp) {
- constPool = cp;
- accessFlags = 0;
- attribute = null;
+ constPool = cp;
+ accessFlags = 0;
+ attribute = null;
}
/**
* Constructs a <code>field_info</code> structure.
*
- * @param cp a constant pool table
- * @param fieldName field name
- * @param desc field descriptor
+ * @param cp a constant pool table
+ * @param fieldName field name
+ * @param desc field descriptor
*
* @see Descriptor
*/
public FieldInfo(ConstPool cp, String fieldName, String desc) {
- this(cp);
- name = cp.addUtf8Info(fieldName);
- descriptor = cp.addUtf8Info(desc);
+ this(cp);
+ name = cp.addUtf8Info(fieldName);
+ descriptor = cp.addUtf8Info(desc);
}
FieldInfo(ConstPool cp, DataInputStream in) throws IOException {
- this(cp);
- read(in);
+ this(cp);
+ read(in);
}
/**
@@ -80,14 +69,14 @@ public final class FieldInfo {
* Returns the field name.
*/
public String getName() {
- return constPool.getUtf8Info(name);
+ return constPool.getUtf8Info(name);
}
/**
* Sets the field name.
*/
public void setName(String newName) {
- name = constPool.addUtf8Info(newName);
+ name = constPool.addUtf8Info(newName);
}
/**
@@ -96,7 +85,7 @@ public final class FieldInfo {
* @see AccessFlag
*/
public int getAccessFlags() {
- return accessFlags;
+ return accessFlags;
}
/**
@@ -105,7 +94,7 @@ public final class FieldInfo {
* @see AccessFlag
*/
public void setAccessFlags(int acc) {
- accessFlags = acc;
+ accessFlags = acc;
}
/**
@@ -114,7 +103,7 @@ public final class FieldInfo {
* @see Descriptor
*/
public String getDescriptor() {
- return constPool.getUtf8Info(descriptor);
+ return constPool.getUtf8Info(descriptor);
}
/**
@@ -123,8 +112,8 @@ public final class FieldInfo {
* @see Descriptor
*/
public void setDescriptor(String desc) {
- if (!desc.equals(getDescriptor()))
- descriptor = constPool.addUtf8Info(desc);
+ if (!desc.equals(getDescriptor()))
+ descriptor = constPool.addUtf8Info(desc);
}
/**
@@ -134,19 +123,19 @@ public final class FieldInfo {
* @see AttributeInfo
*/
public List getAttributes() {
- if (attribute == null)
- attribute = new LinkedList();
+ if (attribute == null)
+ attribute = new LinkedList();
- return attribute;
+ return attribute;
}
/**
* Returns the attribute with the specified name.
*
- * @param name attribute name
+ * @param name attribute name
*/
public AttributeInfo getAttribute(String name) {
- return AttributeInfo.lookup(attribute, name);
+ return AttributeInfo.lookup(attribute, name);
}
/**
@@ -154,32 +143,32 @@ public final class FieldInfo {
* the same name, the new one substitutes for it.
*/
public void addAttribute(AttributeInfo info) {
- if (attribute == null)
- attribute = new LinkedList();
+ if (attribute == null)
+ attribute = new LinkedList();
- AttributeInfo.remove(attribute, info.getName());
- attribute.add(info);
+ AttributeInfo.remove(attribute, info.getName());
+ attribute.add(info);
}
private void read(DataInputStream in) throws IOException {
- accessFlags = in.readUnsignedShort();
- name = in.readUnsignedShort();
- descriptor = in.readUnsignedShort();
- int n = in.readUnsignedShort();
- attribute = new LinkedList();
- for (int i = 0; i < n; ++i)
- attribute.add(AttributeInfo.read(constPool, in));
+ accessFlags = in.readUnsignedShort();
+ name = in.readUnsignedShort();
+ descriptor = in.readUnsignedShort();
+ int n = in.readUnsignedShort();
+ attribute = new LinkedList();
+ for (int i = 0; i < n; ++i)
+ attribute.add(AttributeInfo.read(constPool, in));
}
void write(DataOutputStream out) throws IOException {
- out.writeShort(accessFlags);
- out.writeShort(name);
- out.writeShort(descriptor);
- if (attribute == null)
- out.writeShort(0);
- else {
- out.writeShort(attribute.size());
- AttributeInfo.writeAll(attribute, out);
- }
+ out.writeShort(accessFlags);
+ out.writeShort(name);
+ out.writeShort(descriptor);
+ if (attribute == null)
+ out.writeShort(0);
+ else {
+ out.writeShort(attribute.size());
+ AttributeInfo.writeAll(attribute, out);
+ }
}
}
diff --git a/src/main/javassist/bytecode/InnerClassesAttribute.java b/src/main/javassist/bytecode/InnerClassesAttribute.java
index 954a166b..86adf1a9 100644
--- a/src/main/javassist/bytecode/InnerClassesAttribute.java
+++ b/src/main/javassist/bytecode/InnerClassesAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,13 +28,13 @@ public class InnerClassesAttribute extends AttributeInfo {
public static final String tag = "InnerClasses";
InnerClassesAttribute(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, n, in);
+ super(cp, n, in);
}
private InnerClassesAttribute(ConstPool cp, byte[] info) {
- super(cp, tag, info);
+ super(cp, tag, info);
}
/**
@@ -57,70 +46,70 @@ public class InnerClassesAttribute extends AttributeInfo {
* Returns <code>classes[nth].inner_class_info_index</code>.
*/
public int innerClass(int nth) {
- return ByteArray.readU16bit(get(), nth * 8 + 2);
+ return ByteArray.readU16bit(get(), nth * 8 + 2);
}
/**
* Returns <code>classes[nth].outer_class_info_index</code>.
*/
public int outerClass(int nth) {
- return ByteArray.readU16bit(get(), nth * 8 + 4);
+ return ByteArray.readU16bit(get(), nth * 8 + 4);
}
/**
* Returns <code>classes[nth].inner_name_index</code>.
*/
public int innerName(int nth) {
- return ByteArray.readU16bit(get(), nth * 8 + 6);
+ return ByteArray.readU16bit(get(), nth * 8 + 6);
}
/**
* Returns <code>classes[nth].inner_class_access_flags</code>.
*/
public int accessFlags(int nth) {
- return ByteArray.readU16bit(get(), nth * 8 + 8);
+ return ByteArray.readU16bit(get(), nth * 8 + 8);
}
/**
* Makes a copy. Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- byte[] src = get();
- byte[] dest = new byte[src.length];
- ConstPool cp = getConstPool();
- InnerClassesAttribute attr = new InnerClassesAttribute(newCp, dest);
- int n = ByteArray.readU16bit(src, 0);
- ByteArray.write16bit(n, dest, 0);
- int j = 2;
- for (int i = 0; i < n; ++i) {
- int innerClass = ByteArray.readU16bit(src, j);
- int outerClass = ByteArray.readU16bit(src, j + 2);
- int innerName = ByteArray.readU16bit(src, j + 4);
- int innerAccess = ByteArray.readU16bit(src, j + 6);
-
- if (innerClass != 0)
- innerClass = cp.copy(innerClass, newCp, classnames);
-
- ByteArray.write16bit(innerClass, dest, j);
-
- if (outerClass != 0)
- outerClass = cp.copy(outerClass, newCp, classnames);
-
- ByteArray.write16bit(outerClass, dest, j + 2);
-
- if (innerName != 0)
- innerName = cp.copy(innerName, newCp, classnames);
-
- ByteArray.write16bit(innerName, dest, j + 4);
- ByteArray.write16bit(innerAccess, dest, j + 6);
- j += 8;
- }
-
- return attr;
+ byte[] src = get();
+ byte[] dest = new byte[src.length];
+ ConstPool cp = getConstPool();
+ InnerClassesAttribute attr = new InnerClassesAttribute(newCp, dest);
+ int n = ByteArray.readU16bit(src, 0);
+ ByteArray.write16bit(n, dest, 0);
+ int j = 2;
+ for (int i = 0; i < n; ++i) {
+ int innerClass = ByteArray.readU16bit(src, j);
+ int outerClass = ByteArray.readU16bit(src, j + 2);
+ int innerName = ByteArray.readU16bit(src, j + 4);
+ int innerAccess = ByteArray.readU16bit(src, j + 6);
+
+ if (innerClass != 0)
+ innerClass = cp.copy(innerClass, newCp, classnames);
+
+ ByteArray.write16bit(innerClass, dest, j);
+
+ if (outerClass != 0)
+ outerClass = cp.copy(outerClass, newCp, classnames);
+
+ ByteArray.write16bit(outerClass, dest, j + 2);
+
+ if (innerName != 0)
+ innerName = cp.copy(innerName, newCp, classnames);
+
+ ByteArray.write16bit(innerName, dest, j + 4);
+ ByteArray.write16bit(innerAccess, dest, j + 6);
+ j += 8;
+ }
+
+ return attr;
}
}
diff --git a/src/main/javassist/bytecode/LineNumberAttribute.java b/src/main/javassist/bytecode/LineNumberAttribute.java
index 35f1a020..eb597f84 100644
--- a/src/main/javassist/bytecode/LineNumberAttribute.java
+++ b/src/main/javassist/bytecode/LineNumberAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,13 +28,13 @@ public class LineNumberAttribute extends AttributeInfo {
public static final String tag = "LineNumberTable";
LineNumberAttribute(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, n, in);
+ super(cp, n, in);
}
private LineNumberAttribute(ConstPool cp, byte[] i) {
- super(cp, tag, i);
+ super(cp, tag, i);
}
/**
@@ -53,7 +42,7 @@ public class LineNumberAttribute extends AttributeInfo {
* This represents the number of entries in the table.
*/
public int tableLength() {
- return ByteArray.readU16bit(info, 0);
+ return ByteArray.readU16bit(info, 0);
}
/**
@@ -61,10 +50,10 @@ public class LineNumberAttribute extends AttributeInfo {
* This represents the index into the code array at which the code
* for a new line in the original source file begins.
*
- * @param i the i-th entry.
+ * @param i the i-th entry.
*/
public int startPc(int i) {
- return ByteArray.readU16bit(info, i * 4 + 2);
+ return ByteArray.readU16bit(info, i * 4 + 2);
}
/**
@@ -72,60 +61,60 @@ public class LineNumberAttribute extends AttributeInfo {
* This represents the corresponding line number in the original
* source file.
*
- * @param i the i-th entry.
+ * @param i the i-th entry.
*/
public int lineNumber(int i) {
- return ByteArray.readU16bit(info, i * 4 + 4);
+ return ByteArray.readU16bit(info, i * 4 + 4);
}
/**
* Returns the line number corresponding to the specified bytecode.
*
- * @param pc the index into the code array.
+ * @param pc the index into the code array.
*/
public int toLineNumber(int pc) {
- int n = tableLength();
- int i = 0;
- for (; i < n; ++i)
- if (pc < startPc(i))
- if (i == 0)
- return lineNumber(0);
- else
- break;
+ int n = tableLength();
+ int i = 0;
+ for (; i < n; ++i)
+ if (pc < startPc(i))
+ if (i == 0)
+ return lineNumber(0);
+ else
+ break;
- return lineNumber(i - 1);
+ return lineNumber(i - 1);
}
/**
* Returns the index into the code array at which the code for
* the specified line begins.
*
- * @param line the line number.
- * @return -1 if the specified line is not found.
+ * @param line the line number.
+ * @return -1 if the specified line is not found.
*/
public int toStartPc(int line) {
- int n = tableLength();
- for (int i = 0; i < n; ++i)
- if (line == lineNumber(i))
- return startPc(i);
+ int n = tableLength();
+ for (int i = 0; i < n; ++i)
+ if (line == lineNumber(i))
+ return startPc(i);
- return -1;
+ return -1;
}
/**
* Makes a copy.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames should be null.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames should be null.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- byte[] src = info;
- int num = src.length;
- byte[] dest = new byte[num];
- for (int i = 0; i < num; ++i)
- dest[i] = src[i];
+ byte[] src = info;
+ int num = src.length;
+ byte[] dest = new byte[num];
+ for (int i = 0; i < num; ++i)
+ dest[i] = src[i];
- LineNumberAttribute attr = new LineNumberAttribute(newCp, dest);
- return attr;
+ LineNumberAttribute attr = new LineNumberAttribute(newCp, dest);
+ return attr;
}
}
diff --git a/src/main/javassist/bytecode/LongVector.java b/src/main/javassist/bytecode/LongVector.java
index 86ba7938..ff6a4613 100644
--- a/src/main/javassist/bytecode/LongVector.java
+++ b/src/main/javassist/bytecode/LongVector.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
final class LongVector {
@@ -31,60 +20,60 @@ final class LongVector {
private LongVector next;
public LongVector(int initialSize) {
- num = 0;
- objects = new Object[initialSize];
- next = null;
+ num = 0;
+ objects = new Object[initialSize];
+ next = null;
}
public void addElement(Object obj) {
- LongVector p = this;
- while (p.next != null)
- p = p.next;
+ LongVector p = this;
+ while (p.next != null)
+ p = p.next;
- if (p.num < p.objects.length)
- p.objects[p.num++] = obj;
- else {
- LongVector q = p.next = new LongVector(p.objects.length);
- q.objects[q.num++] = obj;
- }
+ if (p.num < p.objects.length)
+ p.objects[p.num++] = obj;
+ else {
+ LongVector q = p.next = new LongVector(p.objects.length);
+ q.objects[q.num++] = obj;
+ }
}
public int size() {
- LongVector p = this;
- int s = 0;
- while (p != null) {
- s += p.num;
- p = p.next;
- }
+ LongVector p = this;
+ int s = 0;
+ while (p != null) {
+ s += p.num;
+ p = p.next;
+ }
- return s;
+ return s;
}
public Object elementAt(int i) {
- LongVector p = this;
- while (p != null)
- if (i < p.num)
- return p.objects[i];
- else {
- i -= p.num;
- p = p.next;
- }
+ LongVector p = this;
+ while (p != null)
+ if (i < p.num)
+ return p.objects[i];
+ else {
+ i -= p.num;
+ p = p.next;
+ }
- return null;
+ return null;
}
/*
public static void main(String [] args) {
- LongVector v = new LongVector(4);
- int i;
- for (i = 0; i < 128; ++i)
- v.addElement(new Integer(i));
+ LongVector v = new LongVector(4);
+ int i;
+ for (i = 0; i < 128; ++i)
+ v.addElement(new Integer(i));
- System.out.println(v.size());
- for (i = 0; i < v.size(); ++i) {
- System.out.print(v.elementAt(i));
- System.out.print(", ");
- }
+ System.out.println(v.size());
+ for (i = 0; i < v.size(); ++i) {
+ System.out.print(v.elementAt(i));
+ System.out.print(", ");
+ }
}
*/
}
diff --git a/src/main/javassist/bytecode/MethodInfo.java b/src/main/javassist/bytecode/MethodInfo.java
index 567529a3..1773b9e9 100644
--- a/src/main/javassist/bytecode/MethodInfo.java
+++ b/src/main/javassist/bytecode/MethodInfo.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -44,7 +33,7 @@ public final class MethodInfo {
int accessFlags;
int name;
int descriptor;
- LinkedList attribute; // may be null
+ LinkedList attribute; // may be null
/**
* The name of constructors: <code>&lt;init&gt</code>.
@@ -58,29 +47,29 @@ public final class MethodInfo {
public static final String nameClinit = "<clinit>";
private MethodInfo(ConstPool cp) {
- constPool = cp;
- attribute = null;
+ constPool = cp;
+ attribute = null;
}
/**
* Constructs a <code>method_info</code> structure.
*
- * @param cp a constant pool table
- * @param methodname method name
- * @param desc method descriptor
+ * @param cp a constant pool table
+ * @param methodname method name
+ * @param desc method descriptor
*
* @see Descriptor
*/
public MethodInfo(ConstPool cp, String methodname, String desc) {
- this(cp);
- accessFlags = 0;
- name = cp.addUtf8Info(methodname);
- descriptor = constPool.addUtf8Info(desc);
+ this(cp);
+ accessFlags = 0;
+ name = cp.addUtf8Info(methodname);
+ descriptor = constPool.addUtf8Info(desc);
}
MethodInfo(ConstPool cp, DataInputStream in) throws IOException {
- this(cp);
- read(in);
+ this(cp);
+ read(in);
}
/**
@@ -92,32 +81,32 @@ public final class MethodInfo {
* attributes are copied from the source. The other attributes
* are ignored.
*
- * @param cp a constant pool table
- * @param methodname a method name
- * @param src a source <code>method_info</code>
- * @param classnameMap specifies pairs of replaced and substituted
- * name.
+ * @param cp a constant pool table
+ * @param methodname a method name
+ * @param src a source <code>method_info</code>
+ * @param classnameMap specifies pairs of replaced and substituted
+ * name.
* @see Descriptor
*/
public MethodInfo(ConstPool cp, String methodname, MethodInfo src,
- Map classnameMap) throws BadBytecode
+ Map classnameMap) throws BadBytecode
{
- this(cp);
- read(src, methodname, classnameMap);
+ this(cp);
+ read(src, methodname, classnameMap);
}
/**
* Returns a method name.
*/
public String getName() {
- return constPool.getUtf8Info(name);
+ return constPool.getUtf8Info(name);
}
/**
* Sets a method name.
*/
public void setName(String newName) {
- name = constPool.addUtf8Info(newName);
+ name = constPool.addUtf8Info(newName);
}
/**
@@ -125,8 +114,8 @@ public final class MethodInfo {
* (static initializer).
*/
public boolean isMethod() {
- String n = getName();
- return !n.equals(nameInit) && !n.equals(nameClinit);
+ String n = getName();
+ return !n.equals(nameInit) && !n.equals(nameClinit);
}
/**
@@ -143,7 +132,7 @@ public final class MethodInfo {
* Returns true if this is a class initializer (static initializer).
*/
public boolean isStaticInitializer() {
- return getName().equals(nameClinit);
+ return getName().equals(nameClinit);
}
/**
@@ -152,7 +141,7 @@ public final class MethodInfo {
* @see AccessFlag
*/
public int getAccessFlags() {
- return accessFlags;
+ return accessFlags;
}
/**
@@ -161,7 +150,7 @@ public final class MethodInfo {
* @see AccessFlag
*/
public void setAccessFlags(int acc) {
- accessFlags = acc;
+ accessFlags = acc;
}
/**
@@ -170,7 +159,7 @@ public final class MethodInfo {
* @see Descriptor
*/
public String getDescriptor() {
- return constPool.getUtf8Info(descriptor);
+ return constPool.getUtf8Info(descriptor);
}
/**
@@ -179,8 +168,8 @@ public final class MethodInfo {
* @see Descriptor
*/
public void setDescriptor(String desc) {
- if (!desc.equals(getDescriptor()))
- descriptor = constPool.addUtf8Info(desc);
+ if (!desc.equals(getDescriptor()))
+ descriptor = constPool.addUtf8Info(desc);
}
/**
@@ -190,21 +179,21 @@ public final class MethodInfo {
* @see AttributeInfo
*/
public List getAttributes() {
- if (attribute == null)
- attribute = new LinkedList();
+ if (attribute == null)
+ attribute = new LinkedList();
- return attribute;
+ return attribute;
}
/**
* Returns the attribute with the specified name.
* If it is not found, this method returns null.
*
- * @param name attribute name
- * @return an <code>AttributeInfo</code> object or null.
+ * @param name attribute name
+ * @return an <code>AttributeInfo</code> object or null.
*/
public AttributeInfo getAttribute(String name) {
- return AttributeInfo.lookup(attribute, name);
+ return AttributeInfo.lookup(attribute, name);
}
/**
@@ -212,42 +201,42 @@ public final class MethodInfo {
* the same name, the new one substitutes for it.
*/
public void addAttribute(AttributeInfo info) {
- if (attribute == null)
- attribute = new LinkedList();
+ if (attribute == null)
+ attribute = new LinkedList();
- AttributeInfo.remove(attribute, info.getName());
- attribute.add(info);
+ AttributeInfo.remove(attribute, info.getName());
+ attribute.add(info);
}
/**
* Returns an Exceptions attribute.
*
- * @return an Exceptions attribute
- * or null if it is not specified.
+ * @return an Exceptions attribute
+ * or null if it is not specified.
*/
public ExceptionsAttribute getExceptionsAttribute() {
- AttributeInfo info
- = AttributeInfo.lookup(attribute, ExceptionsAttribute.class);
- return (ExceptionsAttribute)info;
+ AttributeInfo info
+ = AttributeInfo.lookup(attribute, ExceptionsAttribute.class);
+ return (ExceptionsAttribute)info;
}
/**
* Returns a Code attribute.
*
- * @return a Code attribute
- * or null if it is not specified.
+ * @return a Code attribute
+ * or null if it is not specified.
*/
public CodeAttribute getCodeAttribute() {
- AttributeInfo info
- = AttributeInfo.lookup(attribute, CodeAttribute.class);
- return (CodeAttribute)info;
+ AttributeInfo info
+ = AttributeInfo.lookup(attribute, CodeAttribute.class);
+ return (CodeAttribute)info;
}
/**
* Removes an Exception attribute.
*/
public void removeExceptionsAttribute() {
- AttributeInfo.remove(attribute, ExceptionsAttribute.class);
+ AttributeInfo.remove(attribute, ExceptionsAttribute.class);
}
/**
@@ -257,18 +246,18 @@ public final class MethodInfo {
* as this <code>method_info</code> structure.
*/
public void setExceptionsAttribute(ExceptionsAttribute cattr) {
- removeExceptionsAttribute();
- if (attribute == null)
- attribute = new LinkedList();
+ removeExceptionsAttribute();
+ if (attribute == null)
+ attribute = new LinkedList();
- attribute.add(cattr);
+ attribute.add(cattr);
}
/**
* Removes a Code attribute.
*/
public void removeCodeAttribute() {
- AttributeInfo.remove(attribute, CodeAttribute.class);
+ AttributeInfo.remove(attribute, CodeAttribute.class);
}
/**
@@ -278,32 +267,32 @@ public final class MethodInfo {
* as this <code>method_info</code> structure.
*/
public void setCodeAttribute(CodeAttribute cattr) {
- removeCodeAttribute();
- if (attribute == null)
- attribute = new LinkedList();
+ removeCodeAttribute();
+ if (attribute == null)
+ attribute = new LinkedList();
- attribute.add(cattr);
+ attribute.add(cattr);
}
/**
* Returns the line number of the source line corresponding to the
* specified bytecode contained in this method.
*
- * @param pos the position of the bytecode (&gt;= 0).
- * an index into the code array.
- * @return -1 if this information is not available.
+ * @param pos the position of the bytecode (&gt;= 0).
+ * an index into the code array.
+ * @return -1 if this information is not available.
*/
public int getLineNumber(int pos) {
- CodeAttribute ca = getCodeAttribute();
- if (ca == null)
- return -1;
+ CodeAttribute ca = getCodeAttribute();
+ if (ca == null)
+ return -1;
- LineNumberAttribute ainfo
- = (LineNumberAttribute)ca.getAttribute(LineNumberAttribute.tag);
- if (ainfo == null)
- return -1;
+ LineNumberAttribute ainfo
+ = (LineNumberAttribute)ca.getAttribute(LineNumberAttribute.tag);
+ if (ainfo == null)
+ return -1;
- return ainfo.toLineNumber(pos);
+ return ainfo.toLineNumber(pos);
}
/**
@@ -322,68 +311,68 @@ public final class MethodInfo {
* <p>This method does not perform anything unless this
* <code>MethodInfo</code> represents a constructor.
*
- * @param superclass the new super class
+ * @param superclass the new super class
*/
public void setSuperclass(String superclass) throws BadBytecode {
- if (!isConstructor())
- return;
-
- CodeAttribute ca = getCodeAttribute();
- byte[] code = ca.getCode();
- CodeIterator iterator = ca.iterator();
- int pos = iterator.skipSuperConstructor();
- if (pos >= 0) { // not this()
- ConstPool cp = constPool;
- int mref = ByteArray.readU16bit(code, pos + 1);
- int nt = cp.getMethodrefNameAndType(mref);
- int sc = cp.addClassInfo(superclass);
- int mref2 = cp.addMethodrefInfo(sc, nt);
- ByteArray.write16bit(mref2, code, pos + 1);
- }
+ if (!isConstructor())
+ return;
+
+ CodeAttribute ca = getCodeAttribute();
+ byte[] code = ca.getCode();
+ CodeIterator iterator = ca.iterator();
+ int pos = iterator.skipSuperConstructor();
+ if (pos >= 0) { // not this()
+ ConstPool cp = constPool;
+ int mref = ByteArray.readU16bit(code, pos + 1);
+ int nt = cp.getMethodrefNameAndType(mref);
+ int sc = cp.addClassInfo(superclass);
+ int mref2 = cp.addMethodrefInfo(sc, nt);
+ ByteArray.write16bit(mref2, code, pos + 1);
+ }
}
private void read(MethodInfo src, String methodname, Map classnames)
- throws BadBytecode
+ throws BadBytecode
{
- ConstPool destCp = constPool;
- accessFlags = src.accessFlags;
- name = destCp.addUtf8Info(methodname);
-
- ConstPool srcCp = src.constPool;
- String desc = srcCp.getUtf8Info(src.descriptor);
- String desc2 = Descriptor.rename(desc, classnames);
- descriptor = destCp.addUtf8Info(desc2);
-
- attribute = new LinkedList();
- ExceptionsAttribute eattr = src.getExceptionsAttribute();
- if (eattr != null)
- attribute.add(eattr.copy(destCp, classnames));
-
- CodeAttribute cattr = src.getCodeAttribute();
- if (cattr != null)
- attribute.add(cattr.copy(destCp, classnames));
+ ConstPool destCp = constPool;
+ accessFlags = src.accessFlags;
+ name = destCp.addUtf8Info(methodname);
+
+ ConstPool srcCp = src.constPool;
+ String desc = srcCp.getUtf8Info(src.descriptor);
+ String desc2 = Descriptor.rename(desc, classnames);
+ descriptor = destCp.addUtf8Info(desc2);
+
+ attribute = new LinkedList();
+ ExceptionsAttribute eattr = src.getExceptionsAttribute();
+ if (eattr != null)
+ attribute.add(eattr.copy(destCp, classnames));
+
+ CodeAttribute cattr = src.getCodeAttribute();
+ if (cattr != null)
+ attribute.add(cattr.copy(destCp, classnames));
}
private void read(DataInputStream in) throws IOException {
- accessFlags = in.readUnsignedShort();
- name = in.readUnsignedShort();
- descriptor = in.readUnsignedShort();
- int n = in.readUnsignedShort();
- attribute = new LinkedList();
- for (int i = 0; i < n; ++i)
- attribute.add(AttributeInfo.read(constPool, in));
+ accessFlags = in.readUnsignedShort();
+ name = in.readUnsignedShort();
+ descriptor = in.readUnsignedShort();
+ int n = in.readUnsignedShort();
+ attribute = new LinkedList();
+ for (int i = 0; i < n; ++i)
+ attribute.add(AttributeInfo.read(constPool, in));
}
void write(DataOutputStream out) throws IOException {
- out.writeShort(accessFlags);
- out.writeShort(name);
- out.writeShort(descriptor);
-
- if (attribute == null)
- out.writeShort(0);
- else {
- out.writeShort(attribute.size());
- AttributeInfo.writeAll(attribute, out);
- }
+ out.writeShort(accessFlags);
+ out.writeShort(name);
+ out.writeShort(descriptor);
+
+ if (attribute == null)
+ out.writeShort(0);
+ else {
+ out.writeShort(attribute.size());
+ AttributeInfo.writeAll(attribute, out);
+ }
}
}
diff --git a/src/main/javassist/bytecode/Mnemonic.java b/src/main/javassist/bytecode/Mnemonic.java
index 5fa4fd5c..1819ad1f 100644
--- a/src/main/javassist/bytecode/Mnemonic.java
+++ b/src/main/javassist/bytecode/Mnemonic.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
/**
@@ -45,207 +34,207 @@ public interface Mnemonic {
* assigned to 186.
*/
String[] OPCODE = {
- "nop", /* 0*/
- "aconst_null", /* 1*/
- "iconst_m1", /* 2*/
- "iconst_0", /* 3*/
- "iconst_1", /* 4*/
- "iconst_2", /* 5*/
- "iconst_3", /* 6*/
- "iconst_4", /* 7*/
- "iconst_5", /* 8*/
- "lconst_0", /* 9*/
- "lconst_1", /* 10*/
- "fconst_0", /* 11*/
- "fconst_1", /* 12*/
- "fconst_2", /* 13*/
- "dconst_0", /* 14*/
- "dconst_1", /* 15*/
- "bipush", /* 16*/
- "sipush", /* 17*/
- "ldc", /* 18*/
- "ldc_w", /* 19*/
- "ldc2_w", /* 20*/
- "iload", /* 21*/
- "lload", /* 22*/
- "fload", /* 23*/
- "dload", /* 24*/
- "aload", /* 25*/
- "iload_0", /* 26*/
- "iload_1", /* 27*/
- "iload_2", /* 28*/
- "iload_3", /* 29*/
- "lload_0", /* 30*/
- "lload_1", /* 31*/
- "lload_2", /* 32*/
- "lload_3", /* 33*/
- "fload_0", /* 34*/
- "fload_1", /* 35*/
- "fload_2", /* 36*/
- "fload_3", /* 37*/
- "dload_0", /* 38*/
- "dload_1", /* 39*/
- "dload_2", /* 40*/
- "dload_3", /* 41*/
- "aload_0", /* 42*/
- "aload_1", /* 43*/
- "aload_2", /* 44*/
- "aload_3", /* 45*/
- "iaload", /* 46*/
- "laload", /* 47*/
- "faload", /* 48*/
- "daload", /* 49*/
- "aaload", /* 50*/
- "baload", /* 51*/
- "caload", /* 52*/
- "saload", /* 53*/
- "istore", /* 54*/
- "lstore", /* 55*/
- "fstore", /* 56*/
- "dstore", /* 57*/
- "astore", /* 58*/
- "istore_0", /* 59*/
- "istore_1", /* 60*/
- "istore_2", /* 61*/
- "istore_3", /* 62*/
- "lstore_0", /* 63*/
- "lstore_1", /* 64*/
- "lstore_2", /* 65*/
- "lstore_3", /* 66*/
- "fstore_0", /* 67*/
- "fstore_1", /* 68*/
- "fstore_2", /* 69*/
- "fstore_3", /* 70*/
- "dstore_0", /* 71*/
- "dstore_1", /* 72*/
- "dstore_2", /* 73*/
- "dstore_3", /* 74*/
- "astore_0", /* 75*/
- "astore_1", /* 76*/
- "astore_2", /* 77*/
- "astore_3", /* 78*/
- "iastore", /* 79*/
- "lastore", /* 80*/
- "fastore", /* 81*/
- "dastore", /* 82*/
- "aastore", /* 83*/
- "bastore", /* 84*/
- "castore", /* 85*/
- "sastore", /* 86*/
- "pop", /* 87*/
- "pop2", /* 88*/
- "dup", /* 89*/
- "dup_x1", /* 90*/
- "dup_x2", /* 91*/
- "dup2", /* 92*/
- "dup2_x1", /* 93*/
- "dup2_x2", /* 94*/
- "swap", /* 95*/
- "iadd", /* 96*/
- "ladd", /* 97*/
- "fadd", /* 98*/
- "dadd", /* 99*/
- "isub", /* 100*/
- "lsub", /* 101*/
- "fsub", /* 102*/
- "dsub", /* 103*/
- "imul", /* 104*/
- "lmul", /* 105*/
- "fmul", /* 106*/
- "dmul", /* 107*/
- "idiv", /* 108*/
- "ldiv", /* 109*/
- "fdiv", /* 110*/
- "ddiv", /* 111*/
- "irem", /* 112*/
- "lrem", /* 113*/
- "frem", /* 114*/
- "drem", /* 115*/
- "ineg", /* 116*/
- "lneg", /* 117*/
- "fneg", /* 118*/
- "dneg", /* 119*/
- "ishl", /* 120*/
- "lshl", /* 121*/
- "ishr", /* 122*/
- "lshr", /* 123*/
- "iushr", /* 124*/
- "lushr", /* 125*/
- "iand", /* 126*/
- "land", /* 127*/
- "ior", /* 128*/
- "lor", /* 129*/
- "ixor", /* 130*/
- "lxor", /* 131*/
- "iinc", /* 132*/
- "i2l", /* 133*/
- "i2f", /* 134*/
- "i2d", /* 135*/
- "l2i", /* 136*/
- "l2f", /* 137*/
- "l2d", /* 138*/
- "f2i", /* 139*/
- "f2l", /* 140*/
- "f2d", /* 141*/
- "d2i", /* 142*/
- "d2l", /* 143*/
- "d2f", /* 144*/
- "i2b", /* 145*/
- "i2c", /* 146*/
- "i2s", /* 147*/
- "lcmp", /* 148*/
- "fcmpl", /* 149*/
- "fcmpg", /* 150*/
- "dcmpl", /* 151*/
- "dcmpg", /* 152*/
- "ifeq", /* 153*/
- "ifne", /* 154*/
- "iflt", /* 155*/
- "ifge", /* 156*/
- "ifgt", /* 157*/
- "ifle", /* 158*/
- "if_icmpeq", /* 159*/
- "if_icmpne", /* 160*/
- "if_icmplt", /* 161*/
- "if_icmpge", /* 162*/
- "if_icmpgt", /* 163*/
- "if_icmple", /* 164*/
- "if_acmpeq", /* 165*/
- "if_acmpne", /* 166*/
- "goto", /* 167*/
- "jsr", /* 168*/
- "ret", /* 169*/
- "tableswitch", /* 170*/
- "lookupswitch", /* 171*/
- "ireturn", /* 172*/
- "lreturn", /* 173*/
- "freturn", /* 174*/
- "dreturn", /* 175*/
- "areturn", /* 176*/
- "return", /* 177*/
- "getstatic", /* 178*/
- "putstatic", /* 179*/
- "getfield", /* 180*/
- "putfield", /* 181*/
- "invokevirtual", /* 182*/
- "invokespecial", /* 183*/
- "invokestatic", /* 184*/
- "invokeinterface", /* 185*/
- null,
- "new", /* 187*/
- "newarray", /* 188*/
- "anewarray", /* 189*/
- "arraylength", /* 190*/
- "athrow", /* 191*/
- "checkcast", /* 192*/
- "instanceof", /* 193*/
- "monitorenter", /* 194*/
- "monitorexit", /* 195*/
- "wide", /* 196*/
- "multianewarray", /* 197*/
- "ifnull", /* 198*/
- "ifnonnull", /* 199*/
- "goto_w", /* 200*/
- "jsr_w" /* 201*/
+ "nop", /* 0*/
+ "aconst_null", /* 1*/
+ "iconst_m1", /* 2*/
+ "iconst_0", /* 3*/
+ "iconst_1", /* 4*/
+ "iconst_2", /* 5*/
+ "iconst_3", /* 6*/
+ "iconst_4", /* 7*/
+ "iconst_5", /* 8*/
+ "lconst_0", /* 9*/
+ "lconst_1", /* 10*/
+ "fconst_0", /* 11*/
+ "fconst_1", /* 12*/
+ "fconst_2", /* 13*/
+ "dconst_0", /* 14*/
+ "dconst_1", /* 15*/
+ "bipush", /* 16*/
+ "sipush", /* 17*/
+ "ldc", /* 18*/
+ "ldc_w", /* 19*/
+ "ldc2_w", /* 20*/
+ "iload", /* 21*/
+ "lload", /* 22*/
+ "fload", /* 23*/
+ "dload", /* 24*/
+ "aload", /* 25*/
+ "iload_0", /* 26*/
+ "iload_1", /* 27*/
+ "iload_2", /* 28*/
+ "iload_3", /* 29*/
+ "lload_0", /* 30*/
+ "lload_1", /* 31*/
+ "lload_2", /* 32*/
+ "lload_3", /* 33*/
+ "fload_0", /* 34*/
+ "fload_1", /* 35*/
+ "fload_2", /* 36*/
+ "fload_3", /* 37*/
+ "dload_0", /* 38*/
+ "dload_1", /* 39*/
+ "dload_2", /* 40*/
+ "dload_3", /* 41*/
+ "aload_0", /* 42*/
+ "aload_1", /* 43*/
+ "aload_2", /* 44*/
+ "aload_3", /* 45*/
+ "iaload", /* 46*/
+ "laload", /* 47*/
+ "faload", /* 48*/
+ "daload", /* 49*/
+ "aaload", /* 50*/
+ "baload", /* 51*/
+ "caload", /* 52*/
+ "saload", /* 53*/
+ "istore", /* 54*/
+ "lstore", /* 55*/
+ "fstore", /* 56*/
+ "dstore", /* 57*/
+ "astore", /* 58*/
+ "istore_0", /* 59*/
+ "istore_1", /* 60*/
+ "istore_2", /* 61*/
+ "istore_3", /* 62*/
+ "lstore_0", /* 63*/
+ "lstore_1", /* 64*/
+ "lstore_2", /* 65*/
+ "lstore_3", /* 66*/
+ "fstore_0", /* 67*/
+ "fstore_1", /* 68*/
+ "fstore_2", /* 69*/
+ "fstore_3", /* 70*/
+ "dstore_0", /* 71*/
+ "dstore_1", /* 72*/
+ "dstore_2", /* 73*/
+ "dstore_3", /* 74*/
+ "astore_0", /* 75*/
+ "astore_1", /* 76*/
+ "astore_2", /* 77*/
+ "astore_3", /* 78*/
+ "iastore", /* 79*/
+ "lastore", /* 80*/
+ "fastore", /* 81*/
+ "dastore", /* 82*/
+ "aastore", /* 83*/
+ "bastore", /* 84*/
+ "castore", /* 85*/
+ "sastore", /* 86*/
+ "pop", /* 87*/
+ "pop2", /* 88*/
+ "dup", /* 89*/
+ "dup_x1", /* 90*/
+ "dup_x2", /* 91*/
+ "dup2", /* 92*/
+ "dup2_x1", /* 93*/
+ "dup2_x2", /* 94*/
+ "swap", /* 95*/
+ "iadd", /* 96*/
+ "ladd", /* 97*/
+ "fadd", /* 98*/
+ "dadd", /* 99*/
+ "isub", /* 100*/
+ "lsub", /* 101*/
+ "fsub", /* 102*/
+ "dsub", /* 103*/
+ "imul", /* 104*/
+ "lmul", /* 105*/
+ "fmul", /* 106*/
+ "dmul", /* 107*/
+ "idiv", /* 108*/
+ "ldiv", /* 109*/
+ "fdiv", /* 110*/
+ "ddiv", /* 111*/
+ "irem", /* 112*/
+ "lrem", /* 113*/
+ "frem", /* 114*/
+ "drem", /* 115*/
+ "ineg", /* 116*/
+ "lneg", /* 117*/
+ "fneg", /* 118*/
+ "dneg", /* 119*/
+ "ishl", /* 120*/
+ "lshl", /* 121*/
+ "ishr", /* 122*/
+ "lshr", /* 123*/
+ "iushr", /* 124*/
+ "lushr", /* 125*/
+ "iand", /* 126*/
+ "land", /* 127*/
+ "ior", /* 128*/
+ "lor", /* 129*/
+ "ixor", /* 130*/
+ "lxor", /* 131*/
+ "iinc", /* 132*/
+ "i2l", /* 133*/
+ "i2f", /* 134*/
+ "i2d", /* 135*/
+ "l2i", /* 136*/
+ "l2f", /* 137*/
+ "l2d", /* 138*/
+ "f2i", /* 139*/
+ "f2l", /* 140*/
+ "f2d", /* 141*/
+ "d2i", /* 142*/
+ "d2l", /* 143*/
+ "d2f", /* 144*/
+ "i2b", /* 145*/
+ "i2c", /* 146*/
+ "i2s", /* 147*/
+ "lcmp", /* 148*/
+ "fcmpl", /* 149*/
+ "fcmpg", /* 150*/
+ "dcmpl", /* 151*/
+ "dcmpg", /* 152*/
+ "ifeq", /* 153*/
+ "ifne", /* 154*/
+ "iflt", /* 155*/
+ "ifge", /* 156*/
+ "ifgt", /* 157*/
+ "ifle", /* 158*/
+ "if_icmpeq", /* 159*/
+ "if_icmpne", /* 160*/
+ "if_icmplt", /* 161*/
+ "if_icmpge", /* 162*/
+ "if_icmpgt", /* 163*/
+ "if_icmple", /* 164*/
+ "if_acmpeq", /* 165*/
+ "if_acmpne", /* 166*/
+ "goto", /* 167*/
+ "jsr", /* 168*/
+ "ret", /* 169*/
+ "tableswitch", /* 170*/
+ "lookupswitch", /* 171*/
+ "ireturn", /* 172*/
+ "lreturn", /* 173*/
+ "freturn", /* 174*/
+ "dreturn", /* 175*/
+ "areturn", /* 176*/
+ "return", /* 177*/
+ "getstatic", /* 178*/
+ "putstatic", /* 179*/
+ "getfield", /* 180*/
+ "putfield", /* 181*/
+ "invokevirtual", /* 182*/
+ "invokespecial", /* 183*/
+ "invokestatic", /* 184*/
+ "invokeinterface", /* 185*/
+ null,
+ "new", /* 187*/
+ "newarray", /* 188*/
+ "anewarray", /* 189*/
+ "arraylength", /* 190*/
+ "athrow", /* 191*/
+ "checkcast", /* 192*/
+ "instanceof", /* 193*/
+ "monitorenter", /* 194*/
+ "monitorexit", /* 195*/
+ "wide", /* 196*/
+ "multianewarray", /* 197*/
+ "ifnull", /* 198*/
+ "ifnonnull", /* 199*/
+ "goto_w", /* 200*/
+ "jsr_w" /* 201*/
};
}
diff --git a/src/main/javassist/bytecode/Opcode.java b/src/main/javassist/bytecode/Opcode.java
index e0c21b3c..fd3a7f90 100644
--- a/src/main/javassist/bytecode/Opcode.java
+++ b/src/main/javassist/bytecode/Opcode.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
/**
@@ -251,207 +240,207 @@ public interface Opcode {
/* how many values are pushed on the operand stack. */
int[] STACK_GROW = {
- 0, // nop, 0
- 1, // aconst_null, 1
- 1, // iconst_m1, 2
- 1, // iconst_0, 3
- 1, // iconst_1, 4
- 1, // iconst_2, 5
- 1, // iconst_3, 6
- 1, // iconst_4, 7
- 1, // iconst_5, 8
- 2, // lconst_0, 9
- 2, // lconst_1, 10
- 1, // fconst_0, 11
- 1, // fconst_1, 12
- 1, // fconst_2, 13
- 2, // dconst_0, 14
- 2, // dconst_1, 15
- 1, // bipush, 16
- 1, // sipush, 17
- 1, // ldc, 18
- 1, // ldc_w, 19
- 2, // ldc2_w, 20
- 1, // iload, 21
- 2, // lload, 22
- 1, // fload, 23
- 2, // dload, 24
- 1, // aload, 25
- 1, // iload_0, 26
- 1, // iload_1, 27
- 1, // iload_2, 28
- 1, // iload_3, 29
- 2, // lload_0, 30
- 2, // lload_1, 31
- 2, // lload_2, 32
- 2, // lload_3, 33
- 1, // fload_0, 34
- 1, // fload_1, 35
- 1, // fload_2, 36
- 1, // fload_3, 37
- 2, // dload_0, 38
- 2, // dload_1, 39
- 2, // dload_2, 40
- 2, // dload_3, 41
- 1, // aload_0, 42
- 1, // aload_1, 43
- 1, // aload_2, 44
- 1, // aload_3, 45
- -1, // iaload, 46
- 0, // laload, 47
- -1, // faload, 48
- 0, // daload, 49
- -1, // aaload, 50
- -1, // baload, 51
- -1, // caload, 52
- -1, // saload, 53
- -1, // istore, 54
- -2, // lstore, 55
- -1, // fstore, 56
- -2, // dstore, 57
- -1, // astore, 58
- -1, // istore_0, 59
- -1, // istore_1, 60
- -1, // istore_2, 61
- -1, // istore_3, 62
- -2, // lstore_0, 63
- -2, // lstore_1, 64
- -2, // lstore_2, 65
- -2, // lstore_3, 66
- -1, // fstore_0, 67
- -1, // fstore_1, 68
- -1, // fstore_2, 69
- -1, // fstore_3, 70
- -2, // dstore_0, 71
- -2, // dstore_1, 72
- -2, // dstore_2, 73
- -2, // dstore_3, 74
- -1, // astore_0, 75
- -1, // astore_1, 76
- -1, // astore_2, 77
- -1, // astore_3, 78
- -3, // iastore, 79
- -4, // lastore, 80
- -3, // fastore, 81
- -4, // dastore, 82
- -3, // aastore, 83
- -3, // bastore, 84
- -3, // castore, 85
- -3, // sastore, 86
- -1, // pop, 87
- -2, // pop2, 88
- 1, // dup, 89
- 1, // dup_x1, 90
- 1, // dup_x2, 91
- 2, // dup2, 92
- 2, // dup2_x1, 93
- 2, // dup2_x2, 94
- 0, // swap, 95
- -1, // iadd, 96
- -2, // ladd, 97
- -1, // fadd, 98
- -2, // dadd, 99
- -1, // isub, 100
- -2, // lsub, 101
- -1, // fsub, 102
- -2, // dsub, 103
- -1, // imul, 104
- -2, // lmul, 105
- -1, // fmul, 106
- -2, // dmul, 107
- -1, // idiv, 108
- -2, // ldiv, 109
- -1, // fdiv, 110
- -2, // ddiv, 111
- -1, // irem, 112
- -2, // lrem, 113
- -1, // frem, 114
- -2, // drem, 115
- 0, // ineg, 116
- 0, // lneg, 117
- 0, // fneg, 118
- 0, // dneg, 119
- -1, // ishl, 120
- -1, // lshl, 121
- -1, // ishr, 122
- -1, // lshr, 123
- -1, // iushr, 124
- -1, // lushr, 125
- -1, // iand, 126
- -2, // land, 127
- -1, // ior, 128
- -2, // lor, 129
- -1, // ixor, 130
- -2, // lxor, 131
- 0, // iinc, 132
- 1, // i2l, 133
- 0, // i2f, 134
- 1, // i2d, 135
- -1, // l2i, 136
- -1, // l2f, 137
- 0, // l2d, 138
- 0, // f2i, 139
- 1, // f2l, 140
- 1, // f2d, 141
- -1, // d2i, 142
- 0, // d2l, 143
- -1, // d2f, 144
- 0, // i2b, 145
- 0, // i2c, 146
- 0, // i2s, 147
- -3, // lcmp, 148
- -1, // fcmpl, 149
- -1, // fcmpg, 150
- -3, // dcmpl, 151
- -3, // dcmpg, 152
- -1, // ifeq, 153
- -1, // ifne, 154
- -1, // iflt, 155
- -1, // ifge, 156
- -1, // ifgt, 157
- -1, // ifle, 158
- -2, // if_icmpeq, 159
- -2, // if_icmpne, 160
- -2, // if_icmplt, 161
- -2, // if_icmpge, 162
- -2, // if_icmpgt, 163
- -2, // if_icmple, 164
- -2, // if_acmpeq, 165
- -2, // if_acmpne, 166
- 0, // goto, 167
- 1, // jsr, 168
- 0, // ret, 169
- -1, // tableswitch, 170
- -1, // lookupswitch, 171
- -1, // ireturn, 172
- -2, // lreturn, 173
- -1, // freturn, 174
- -2, // dreturn, 175
- -1, // areturn, 176
- 0, // return, 177
- 0, // getstatic, 178 depends on the type
- 0, // putstatic, 179 depends on the type
- 0, // getfield, 180 depends on the type
- 0, // putfield, 181 depends on the type
- 0, // invokevirtual, 182 depends on the type
- 0, // invokespecial, 183 depends on the type
- 0, // invokestatic, 184 depends on the type
- 0, // invokeinterface, 185 depends on the type
- 0, // undefined, 186
- 1, // new, 187
- 0, // newarray, 188
- 0, // anewarray, 189
- 0, // arraylength, 190
- 0, // athrow, 191 stack is cleared
- 0, // checkcast, 192
- 0, // instanceof, 193
- -1, // monitorenter, 194
- -1, // monitorexit, 195
- 0, // wide, 196 depends on the following opcode
- 0, // multianewarray, 197 depends on the dimensions
- -1, // ifnull, 198
- -1, // ifnonnull, 199
- 0, // goto_w, 200
- 1 // jsr_w, 201
+ 0, // nop, 0
+ 1, // aconst_null, 1
+ 1, // iconst_m1, 2
+ 1, // iconst_0, 3
+ 1, // iconst_1, 4
+ 1, // iconst_2, 5
+ 1, // iconst_3, 6
+ 1, // iconst_4, 7
+ 1, // iconst_5, 8
+ 2, // lconst_0, 9
+ 2, // lconst_1, 10
+ 1, // fconst_0, 11
+ 1, // fconst_1, 12
+ 1, // fconst_2, 13
+ 2, // dconst_0, 14
+ 2, // dconst_1, 15
+ 1, // bipush, 16
+ 1, // sipush, 17
+ 1, // ldc, 18
+ 1, // ldc_w, 19
+ 2, // ldc2_w, 20
+ 1, // iload, 21
+ 2, // lload, 22
+ 1, // fload, 23
+ 2, // dload, 24
+ 1, // aload, 25
+ 1, // iload_0, 26
+ 1, // iload_1, 27
+ 1, // iload_2, 28
+ 1, // iload_3, 29
+ 2, // lload_0, 30
+ 2, // lload_1, 31
+ 2, // lload_2, 32
+ 2, // lload_3, 33
+ 1, // fload_0, 34
+ 1, // fload_1, 35
+ 1, // fload_2, 36
+ 1, // fload_3, 37
+ 2, // dload_0, 38
+ 2, // dload_1, 39
+ 2, // dload_2, 40
+ 2, // dload_3, 41
+ 1, // aload_0, 42
+ 1, // aload_1, 43
+ 1, // aload_2, 44
+ 1, // aload_3, 45
+ -1, // iaload, 46
+ 0, // laload, 47
+ -1, // faload, 48
+ 0, // daload, 49
+ -1, // aaload, 50
+ -1, // baload, 51
+ -1, // caload, 52
+ -1, // saload, 53
+ -1, // istore, 54
+ -2, // lstore, 55
+ -1, // fstore, 56
+ -2, // dstore, 57
+ -1, // astore, 58
+ -1, // istore_0, 59
+ -1, // istore_1, 60
+ -1, // istore_2, 61
+ -1, // istore_3, 62
+ -2, // lstore_0, 63
+ -2, // lstore_1, 64
+ -2, // lstore_2, 65
+ -2, // lstore_3, 66
+ -1, // fstore_0, 67
+ -1, // fstore_1, 68
+ -1, // fstore_2, 69
+ -1, // fstore_3, 70
+ -2, // dstore_0, 71
+ -2, // dstore_1, 72
+ -2, // dstore_2, 73
+ -2, // dstore_3, 74
+ -1, // astore_0, 75
+ -1, // astore_1, 76
+ -1, // astore_2, 77
+ -1, // astore_3, 78
+ -3, // iastore, 79
+ -4, // lastore, 80
+ -3, // fastore, 81
+ -4, // dastore, 82
+ -3, // aastore, 83
+ -3, // bastore, 84
+ -3, // castore, 85
+ -3, // sastore, 86
+ -1, // pop, 87
+ -2, // pop2, 88
+ 1, // dup, 89
+ 1, // dup_x1, 90
+ 1, // dup_x2, 91
+ 2, // dup2, 92
+ 2, // dup2_x1, 93
+ 2, // dup2_x2, 94
+ 0, // swap, 95
+ -1, // iadd, 96
+ -2, // ladd, 97
+ -1, // fadd, 98
+ -2, // dadd, 99
+ -1, // isub, 100
+ -2, // lsub, 101
+ -1, // fsub, 102
+ -2, // dsub, 103
+ -1, // imul, 104
+ -2, // lmul, 105
+ -1, // fmul, 106
+ -2, // dmul, 107
+ -1, // idiv, 108
+ -2, // ldiv, 109
+ -1, // fdiv, 110
+ -2, // ddiv, 111
+ -1, // irem, 112
+ -2, // lrem, 113
+ -1, // frem, 114
+ -2, // drem, 115
+ 0, // ineg, 116
+ 0, // lneg, 117
+ 0, // fneg, 118
+ 0, // dneg, 119
+ -1, // ishl, 120
+ -1, // lshl, 121
+ -1, // ishr, 122
+ -1, // lshr, 123
+ -1, // iushr, 124
+ -1, // lushr, 125
+ -1, // iand, 126
+ -2, // land, 127
+ -1, // ior, 128
+ -2, // lor, 129
+ -1, // ixor, 130
+ -2, // lxor, 131
+ 0, // iinc, 132
+ 1, // i2l, 133
+ 0, // i2f, 134
+ 1, // i2d, 135
+ -1, // l2i, 136
+ -1, // l2f, 137
+ 0, // l2d, 138
+ 0, // f2i, 139
+ 1, // f2l, 140
+ 1, // f2d, 141
+ -1, // d2i, 142
+ 0, // d2l, 143
+ -1, // d2f, 144
+ 0, // i2b, 145
+ 0, // i2c, 146
+ 0, // i2s, 147
+ -3, // lcmp, 148
+ -1, // fcmpl, 149
+ -1, // fcmpg, 150
+ -3, // dcmpl, 151
+ -3, // dcmpg, 152
+ -1, // ifeq, 153
+ -1, // ifne, 154
+ -1, // iflt, 155
+ -1, // ifge, 156
+ -1, // ifgt, 157
+ -1, // ifle, 158
+ -2, // if_icmpeq, 159
+ -2, // if_icmpne, 160
+ -2, // if_icmplt, 161
+ -2, // if_icmpge, 162
+ -2, // if_icmpgt, 163
+ -2, // if_icmple, 164
+ -2, // if_acmpeq, 165
+ -2, // if_acmpne, 166
+ 0, // goto, 167
+ 1, // jsr, 168
+ 0, // ret, 169
+ -1, // tableswitch, 170
+ -1, // lookupswitch, 171
+ -1, // ireturn, 172
+ -2, // lreturn, 173
+ -1, // freturn, 174
+ -2, // dreturn, 175
+ -1, // areturn, 176
+ 0, // return, 177
+ 0, // getstatic, 178 depends on the type
+ 0, // putstatic, 179 depends on the type
+ 0, // getfield, 180 depends on the type
+ 0, // putfield, 181 depends on the type
+ 0, // invokevirtual, 182 depends on the type
+ 0, // invokespecial, 183 depends on the type
+ 0, // invokestatic, 184 depends on the type
+ 0, // invokeinterface, 185 depends on the type
+ 0, // undefined, 186
+ 1, // new, 187
+ 0, // newarray, 188
+ 0, // anewarray, 189
+ 0, // arraylength, 190
+ 0, // athrow, 191 stack is cleared
+ 0, // checkcast, 192
+ 0, // instanceof, 193
+ -1, // monitorenter, 194
+ -1, // monitorexit, 195
+ 0, // wide, 196 depends on the following opcode
+ 0, // multianewarray, 197 depends on the dimensions
+ -1, // ifnull, 198
+ -1, // ifnonnull, 199
+ 0, // goto_w, 200
+ 1 // jsr_w, 201
};
}
diff --git a/src/main/javassist/bytecode/SourceFileAttribute.java b/src/main/javassist/bytecode/SourceFileAttribute.java
index 22e6f6f9..a8c0d98d 100644
--- a/src/main/javassist/bytecode/SourceFileAttribute.java
+++ b/src/main/javassist/bytecode/SourceFileAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,42 +28,42 @@ public class SourceFileAttribute extends AttributeInfo {
public static final String tag = "SourceFile";
SourceFileAttribute(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, n, in);
+ super(cp, n, in);
}
/**
* Constructs a SourceFile attribute.
*
- * @param cp a constant pool table.
- * @param filename the name of the source file.
+ * @param cp a constant pool table.
+ * @param filename the name of the source file.
*/
public SourceFileAttribute(ConstPool cp, String filename) {
- super(cp, tag);
- int index = cp.addUtf8Info(filename);
- byte[] bvalue = new byte[2];
- bvalue[0] = (byte)(index >>> 8);
- bvalue[1] = (byte)index;
- set(bvalue);
+ super(cp, tag);
+ int index = cp.addUtf8Info(filename);
+ byte[] bvalue = new byte[2];
+ bvalue[0] = (byte)(index >>> 8);
+ bvalue[1] = (byte)index;
+ set(bvalue);
}
/**
* Returns the file name indicated by <code>sourcefile_index</code>.
*/
public String getFileName() {
- return getConstPool().getUtf8Info(ByteArray.readU16bit(get(), 0));
+ return getConstPool().getUtf8Info(ByteArray.readU16bit(get(), 0));
}
/**
* Makes a copy. Class names are replaced according to the
* given <code>Map</code> object.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames pairs of replaced and substituted
- * class names.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames pairs of replaced and substituted
+ * class names.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- return new SourceFileAttribute(newCp, getFileName());
+ return new SourceFileAttribute(newCp, getFileName());
}
}
diff --git a/src/main/javassist/bytecode/SyntheticAttribute.java b/src/main/javassist/bytecode/SyntheticAttribute.java
index 63d559ce..2b2b6a66 100644
--- a/src/main/javassist/bytecode/SyntheticAttribute.java
+++ b/src/main/javassist/bytecode/SyntheticAttribute.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.bytecode;
import java.io.DataInputStream;
@@ -39,28 +28,28 @@ public class SyntheticAttribute extends AttributeInfo {
public static final String tag = "Synthetic";
SyntheticAttribute(ConstPool cp, int n, DataInputStream in)
- throws IOException
+ throws IOException
{
- super(cp, n, in);
+ super(cp, n, in);
}
/**
* Constructs a Synthetic attribute.
*
- * @param cp a constant pool table.
- * @param filename the name of the source file.
+ * @param cp a constant pool table.
+ * @param filename the name of the source file.
*/
public SyntheticAttribute(ConstPool cp) {
- super(cp, tag, new byte[0]);
+ super(cp, tag, new byte[0]);
}
/**
* Makes a copy.
*
- * @param newCp the constant pool table used by the new copy.
- * @param classnames should be null.
+ * @param newCp the constant pool table used by the new copy.
+ * @param classnames should be null.
*/
public AttributeInfo copy(ConstPool newCp, Map classnames) {
- return new SyntheticAttribute(newCp);
+ return new SyntheticAttribute(newCp);
}
}
diff --git a/src/main/javassist/bytecode/package.html b/src/main/javassist/bytecode/package.html
new file mode 100644
index 00000000..9da3888a
--- /dev/null
+++ b/src/main/javassist/bytecode/package.html
@@ -0,0 +1,18 @@
+<html>
+<body>
+Bytecode-level API.
+
+<p>This package provides low-level API for editing a raw class file.
+It allows the users to read and modify a constant pool entry, a single
+bytecode instruction, and so on.
+
+<p>The users of this package must know the specifications of
+class file and Java bytecode. For more details, read this book:
+
+<ul>Tim Lindholm and Frank Yellin,
+"The Java Virtual Machine Specification 2nd Ed.",
+Addison-Wesley, 1999.
+</ul>
+
+</body>
+</html>