added LocalVariableAttribute. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@46 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
<ul> | <ul> | ||||
<li>ClassPool.SimpleLoader has been public. | <li>ClassPool.SimpleLoader has been public. | ||||
<li>javassist.bytecode.DeprecatedAttribute has been added. | <li>javassist.bytecode.DeprecatedAttribute has been added. | ||||
<li>javassist.bytecode.LocalVariableAttribute has been added. | |||||
</ul> | </ul> | ||||
<p>- version 2.6 in August, 2003. | <p>- version 2.6 in August, 2003. |
import javassist.compiler.CompileError; | import javassist.compiler.CompileError; | ||||
import javassist.expr.ExprEditor; | import javassist.expr.ExprEditor; | ||||
import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
import java.io.DataOutputStream; | import java.io.DataOutputStream; |
return new SourceFileAttribute(cp, name, in); | return new SourceFileAttribute(cp, name, in); | ||||
else if (nameStr.equals(LineNumberAttribute.tag)) | else if (nameStr.equals(LineNumberAttribute.tag)) | ||||
return new LineNumberAttribute(cp, name, in); | return new LineNumberAttribute(cp, name, in); | ||||
else if (nameStr.equals(LocalVariableAttribute.tag)) | |||||
return new LocalVariableAttribute(cp, name, in); | |||||
else if (nameStr.equals(SyntheticAttribute.tag)) | else if (nameStr.equals(SyntheticAttribute.tag)) | ||||
return new SyntheticAttribute(cp, name, in); | return new SyntheticAttribute(cp, name, in); | ||||
else if (nameStr.equals(DeprecatedAttribute.tag)) | else if (nameStr.equals(DeprecatedAttribute.tag)) |
package javassist.bytecode; | package javassist.bytecode; | ||||
import java.io.DataOutputStream; | |||||
import java.io.IOException; | |||||
import javassist.CannotCompileException; | |||||
import javassist.CtClass; | import javassist.CtClass; | ||||
import javassist.CtPrimitiveType; | import javassist.CtPrimitiveType; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.Map; | import java.util.Map; | ||||
import javassist.CtClass; | |||||
/** | /** | ||||
* <code>Code_attribute</code>. | * <code>Code_attribute</code>. |
/** | /** | ||||
* Returns <code>number_of_exceptions</code>. | * Returns <code>number_of_exceptions</code>. | ||||
*/ | */ | ||||
public int length() { return info.length / 2 - 1; } | |||||
public int tableLength() { return info.length / 2 - 1; } | |||||
/** | /** | ||||
* Returns the value of <code>exception_index_table[nth]</code>. | * Returns the value of <code>exception_index_table[nth]</code>. |
import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
import java.io.DataOutputStream; | import java.io.DataOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Hashtable; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
/** | /** | ||||
* Returns <code>number_of_classes</code>. | * Returns <code>number_of_classes</code>. | ||||
*/ | */ | ||||
public int length() { return ByteArray.readU16bit(get(), 0); } | |||||
public int tableLength() { return ByteArray.readU16bit(get(), 0); } | |||||
/** | /** | ||||
* Returns <code>classes[nth].inner_class_info_index</code>. | * Returns <code>classes[nth].inner_class_info_index</code>. |
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* <code>LineNumberTablec_attribute</code>. | |||||
* <code>LineNumberTable_attribute</code>. | |||||
*/ | */ | ||||
public class LineNumberAttribute extends AttributeInfo { | public class LineNumberAttribute extends AttributeInfo { | ||||
/** | /** |
/* | |||||
* 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. Alternatively, the contents of this file may be used under | |||||
* the terms of the GNU Lesser General Public License Version 2.1 or later. | |||||
* | |||||
* 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. | |||||
*/ | |||||
package javassist.bytecode; | |||||
import java.io.DataInputStream; | |||||
import java.io.IOException; | |||||
import java.util.Map; | |||||
/** | |||||
* <code>LocalVariableTable_attribute</code>. | |||||
*/ | |||||
public class LocalVariableAttribute extends AttributeInfo { | |||||
/** | |||||
* The name of this attribute <code>"LocalVariableTable"</code>. | |||||
*/ | |||||
public static final String tag = "LocalVariableTable"; | |||||
LocalVariableAttribute(ConstPool cp, int n, DataInputStream in) | |||||
throws IOException | |||||
{ | |||||
super(cp, n, in); | |||||
} | |||||
private LocalVariableAttribute(ConstPool cp, byte[] i) { | |||||
super(cp, tag, i); | |||||
} | |||||
/** | |||||
* Returns <code>local_variable_table_length</code>. | |||||
* This represents the number of entries in the table. | |||||
*/ | |||||
public int tableLength() { | |||||
return ByteArray.readU16bit(info, 0); | |||||
} | |||||
/** | |||||
* Returns <code>local_variable_table[i].start_pc</code>. | |||||
* This represents the index into the code array from which the local | |||||
* variable is effective. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public int startPc(int i) { | |||||
return ByteArray.readU16bit(info, i * 10 + 2); | |||||
} | |||||
/** | |||||
* Returns <code>local_variable_table[i].length</code>. | |||||
* This represents the length of the code region in which the local | |||||
* variable is effective. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public int codeLength(int i) { | |||||
return ByteArray.readU16bit(info, i * 10 + 4); | |||||
} | |||||
/** | |||||
* Returns <code>local_variable_table[i].name_index</code>. | |||||
* This represents the name of the local variable. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public int nameIndex(int i) { | |||||
return ByteArray.readU16bit(info, i * 10 + 6); | |||||
} | |||||
/** | |||||
* Returns the name of the local variable | |||||
* specified by <code>local_variable_table[i].name_index</code>. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public String variableName(int i) { | |||||
return getConstPool().getUtf8Info(nameIndex(i)); | |||||
} | |||||
/** | |||||
* Returns <code>local_variable_table[i].descriptor_index</code>. | |||||
* This represents the type descriptor of the local variable. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public int descriptorIndex(int i) { | |||||
return ByteArray.readU16bit(info, i * 10 + 8); | |||||
} | |||||
/** | |||||
* Returns the type descriptor of the local variable | |||||
* specified by <code>local_variable_table[i].descriptor_index</code>. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public String descriptor(int i) { | |||||
return getConstPool().getUtf8Info(descriptorIndex(i)); | |||||
} | |||||
/** | |||||
* Returns <code>local_variable_table[i].index</code>. | |||||
* This represents the index of the local variable. | |||||
* | |||||
* @param i the i-th entry. | |||||
*/ | |||||
public int index(int i) { | |||||
return ByteArray.readU16bit(info, i * 10 + 10); | |||||
} | |||||
/** | |||||
* Makes a copy. | |||||
* | |||||
* @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 = get(); | |||||
byte[] dest = new byte[src.length]; | |||||
ConstPool cp = getConstPool(); | |||||
LocalVariableAttribute attr = new LocalVariableAttribute(newCp, dest); | |||||
int n = ByteArray.readU16bit(src, 0); | |||||
ByteArray.write16bit(n, dest, 0); | |||||
int j = 2; | |||||
for (int i = 0; i < n; ++i) { | |||||
int start = ByteArray.readU16bit(src, j); | |||||
int len = ByteArray.readU16bit(src, j + 2); | |||||
int name = ByteArray.readU16bit(src, j + 4); | |||||
int type = ByteArray.readU16bit(src, j + 6); | |||||
int index = ByteArray.readU16bit(src, j + 8); | |||||
ByteArray.write16bit(start, dest, j); | |||||
ByteArray.write16bit(len, dest, j + 2); | |||||
if (name != 0) | |||||
name = cp.copy(name, newCp, null); | |||||
ByteArray.write16bit(name, dest, j + 4); | |||||
if (type != 0) | |||||
type = cp.copy(type, newCp, null); | |||||
ByteArray.write16bit(type, dest, j + 6); | |||||
ByteArray.write16bit(index, dest, j + 8); | |||||
j += 10; | |||||
} | |||||
return attr; | |||||
} | |||||
} |
import java.util.Map; | import java.util.Map; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import javassist.CannotCompileException; | |||||
/** | /** | ||||
* <code>method_info</code> structure. | * <code>method_info</code> structure. |
import javassist.CtMethod; | import javassist.CtMethod; | ||||
import javassist.CtConstructor; | import javassist.CtConstructor; | ||||
import javassist.CannotCompileException; | import javassist.CannotCompileException; | ||||
import javassist.ClassPool; | |||||
import javassist.Modifier; | import javassist.Modifier; | ||||
import javassist.bytecode.Bytecode; | import javassist.bytecode.Bytecode; | ||||
import javassist.bytecode.Opcode; | import javassist.bytecode.Opcode; | ||||
Declarator d = fd.getDeclarator(); | Declarator d = fd.getDeclarator(); | ||||
f = new CtFieldWithInit(gen.lookupClass(d), d.getVariable().get(), | f = new CtFieldWithInit(gen.lookupClass(d), d.getVariable().get(), | ||||
gen.getThisClass()); | gen.getThisClass()); | ||||
f.setModifiers(gen.getModifiers(fd.getModifiers())); | |||||
f.setModifiers(MemberCodeGen.getModifiers(fd.getModifiers())); | |||||
if (fd.getInit() != null) | if (fd.getInit() != null) | ||||
f.setInit(fd.getInit()); | f.setInit(fd.getInit()); | ||||
private CtMember compileMethod(Parser p, MethodDecl md) | private CtMember compileMethod(Parser p, MethodDecl md) | ||||
throws CompileError | throws CompileError | ||||
{ | { | ||||
int mod = gen.getModifiers(md.getModifiers()); | |||||
int mod = MemberCodeGen.getModifiers(md.getModifiers()); | |||||
CtClass[] plist = gen.makeParamList(md); | CtClass[] plist = gen.makeParamList(md); | ||||
CtClass[] tlist = gen.makeThrowsList(md); | CtClass[] tlist = gen.makeThrowsList(md); | ||||
recordParams(plist, Modifier.isStatic(mod)); | recordParams(plist, Modifier.isStatic(mod)); |
Declarator d = new Declarator(this.varType, this.arrayDim + dim); | Declarator d = new Declarator(this.varType, this.arrayDim + dim); | ||||
d.qualifiedClass = this.qualifiedClass; | d.qualifiedClass = this.qualifiedClass; | ||||
d.setLeft(sym); | d.setLeft(sym); | ||||
d.append(d, init); | |||||
append(d, init); | |||||
return d; | return d; | ||||
} | } | ||||
package javassist.convert; | package javassist.convert; | ||||
import javassist.CtClass; | |||||
import javassist.CtMethod; | import javassist.CtMethod; | ||||
import javassist.NotFoundException; | import javassist.NotFoundException; | ||||
import javassist.bytecode.*; | import javassist.bytecode.*; | ||||
import javassist.CannotCompileException; | |||||
public class TransformAfter extends TransformBefore { | public class TransformAfter extends TransformBefore { | ||||
public TransformAfter(Transformer next, | public TransformAfter(Transformer next, |
import javassist.CtMethod; | import javassist.CtMethod; | ||||
import javassist.NotFoundException; | import javassist.NotFoundException; | ||||
import javassist.bytecode.*; | import javassist.bytecode.*; | ||||
import javassist.CannotCompileException; | |||||
public class TransformBefore extends TransformCall { | public class TransformBefore extends TransformCall { | ||||
protected CtClass[] parameterTypes; | protected CtClass[] parameterTypes; |
import javassist.CtClass; | import javassist.CtClass; | ||||
import javassist.CtMethod; | import javassist.CtMethod; | ||||
import javassist.bytecode.*; | import javassist.bytecode.*; | ||||
import javassist.CannotCompileException; | |||||
public class TransformCall extends Transformer { | public class TransformCall extends Transformer { | ||||
protected String classname, methodname, methodDescriptor; | protected String classname, methodname, methodDescriptor; |
import javassist.CtClass; | import javassist.CtClass; | ||||
import javassist.CtField; | import javassist.CtField; | ||||
import javassist.Modifier; | import javassist.Modifier; | ||||
import javassist.CannotCompileException; | |||||
final public class TransformFieldAccess extends Transformer { | final public class TransformFieldAccess extends Transformer { | ||||
private String newClassname, newFieldname; | private String newClassname, newFieldname; |
import javassist.ClassPool; | import javassist.ClassPool; | ||||
import javassist.CtClass; | import javassist.CtClass; | ||||
import javassist.CtField; | import javassist.CtField; | ||||
import javassist.CannotCompileException; | |||||
import javassist.NotFoundException; | import javassist.NotFoundException; | ||||
import javassist.Modifier; | import javassist.Modifier; | ||||
import javassist.CtClass; | import javassist.CtClass; | ||||
import javassist.CtField; | import javassist.CtField; | ||||
import javassist.bytecode.*; | import javassist.bytecode.*; | ||||
import javassist.CannotCompileException; | |||||
final public class TransformWriteField extends TransformReadField { | final public class TransformWriteField extends TransformReadField { | ||||
public TransformWriteField(Transformer next, CtField field, | public TransformWriteField(Transformer next, CtField field, |
import javassist.*; | import javassist.*; | ||||
import javassist.bytecode.*; | import javassist.bytecode.*; | ||||
import javassist.compiler.*; | import javassist.compiler.*; | ||||
import javassist.compiler.ast.ASTList; | |||||
/** | /** | ||||
* Catch clause. | * Catch clause. |
import javassist.*; | import javassist.*; | ||||
import javassist.bytecode.*; | import javassist.bytecode.*; | ||||
import javassist.compiler.*; | import javassist.compiler.*; | ||||
import javassist.compiler.ast.ASTree; | |||||
import javassist.compiler.ast.ASTList; | import javassist.compiler.ast.ASTList; | ||||
/** | /** |
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.ObjectInputStream; | import java.io.ObjectInputStream; | ||||
import java.io.ObjectOutputStream; | import java.io.ObjectOutputStream; | ||||
import javassist.CtClass; | |||||
/** | /** | ||||
* A runtime class metaobject. | * A runtime class metaobject. |
package javassist.reflect; | package javassist.reflect; | ||||
import javassist.*; | import javassist.*; | ||||
import java.io.IOException; | |||||
import javassist.CtMethod.ConstParameter; | import javassist.CtMethod.ConstParameter; | ||||
/** | /** |
import java.io.*; | import java.io.*; | ||||
import java.net.*; | import java.net.*; | ||||
import java.awt.*; | |||||
import java.applet.Applet; | import java.applet.Applet; | ||||
import java.lang.reflect.*; | import java.lang.reflect.*; | ||||
package javassist.rmi; | package javassist.rmi; | ||||
import java.io.*; | |||||
import javassist.*; | import javassist.*; | ||||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
import java.util.Hashtable; | import java.util.Hashtable; |
import java.net.*; | import java.net.*; | ||||
import java.io.*; | import java.io.*; | ||||
import java.util.Hashtable; | |||||
import java.util.Date; | import java.util.Date; | ||||
import javassist.ClassPool; | import javassist.ClassPool; | ||||
import javassist.Translator; | |||||
/** | /** | ||||
* A web server for Javassist. | * A web server for Javassist. |