├── src ├── javassist │ ├── tools │ │ ├── package.html │ │ ├── web │ │ │ ├── package.html │ │ │ └── BadHttpRequest.java │ │ ├── rmi │ │ │ ├── package.html │ │ │ ├── Proxy.java │ │ │ ├── ObjectNotFoundException.java │ │ │ ├── RemoteException.java │ │ │ ├── RemoteRef.java │ │ │ └── Sample.java │ │ ├── reflect │ │ │ ├── CannotCreateException.java │ │ │ ├── Metalevel.java │ │ │ ├── package.html │ │ │ ├── CannotReflectException.java │ │ │ ├── Sample.java │ │ │ └── CannotInvokeException.java │ │ ├── framedump.java │ │ └── Dump.java │ ├── scopedpool │ │ ├── package.html │ │ ├── ScopedClassPoolFactory.java │ │ ├── ScopedClassPoolFactoryImpl.java │ │ └── ScopedClassPoolRepository.java │ ├── bytecode │ │ ├── annotation │ │ │ ├── package.html │ │ │ ├── NoSuchClassError.java │ │ │ ├── MemberValueVisitor.java │ │ │ ├── AnnotationMemberValue.java │ │ │ ├── MemberValue.java │ │ │ ├── LongMemberValue.java │ │ │ ├── ByteMemberValue.java │ │ │ ├── StringMemberValue.java │ │ │ ├── CharMemberValue.java │ │ │ ├── ShortMemberValue.java │ │ │ ├── BooleanMemberValue.java │ │ │ ├── FloatMemberValue.java │ │ │ ├── DoubleMemberValue.java │ │ │ └── IntegerMemberValue.java │ │ ├── package.html │ │ ├── analysis │ │ │ ├── package.html │ │ │ ├── IntQueue.java │ │ │ ├── Util.java │ │ │ └── Subroutine.java │ │ ├── DuplicateMemberException.java │ │ ├── BadBytecode.java │ │ ├── stackmap │ │ │ └── TypeTag.java │ │ ├── SyntheticAttribute.java │ │ ├── DeprecatedAttribute.java │ │ ├── LongVector.java │ │ ├── LocalVariableTypeAttribute.java │ │ ├── SourceFileAttribute.java │ │ ├── ConstantAttribute.java │ │ ├── ByteArray.java │ │ └── MethodParametersAttribute.java │ ├── expr │ │ ├── package.html │ │ └── ConstructorCall.java │ ├── util │ │ └── proxy │ │ │ ├── package.html │ │ │ ├── MethodFilter.java │ │ │ ├── Proxy.java │ │ │ ├── ProxyObject.java │ │ │ ├── MethodHandler.java │ │ │ └── ProxyObjectOutputStream.java │ ├── runtime │ │ ├── package.html │ │ ├── Inner.java │ │ ├── DotClass.java │ │ └── Cflow.java │ ├── package.html │ ├── compiler │ │ ├── SyntaxError.java │ │ ├── ast │ │ │ ├── ArrayInit.java │ │ │ ├── Keyword.java │ │ │ ├── StringL.java │ │ │ ├── Symbol.java │ │ │ ├── FieldDecl.java │ │ │ ├── Variable.java │ │ │ ├── InstanceOfExpr.java │ │ │ ├── Member.java │ │ │ ├── AssignExpr.java │ │ │ ├── BinExpr.java │ │ │ ├── CondExpr.java │ │ │ ├── CallExpr.java │ │ │ ├── MethodDecl.java │ │ │ ├── Pair.java │ │ │ ├── CastExpr.java │ │ │ ├── Stmnt.java │ │ │ ├── ASTree.java │ │ │ ├── Visitor.java │ │ │ ├── NewExpr.java │ │ │ ├── Expr.java │ │ │ └── DoubleConst.java │ │ ├── KeywordTable.java │ │ ├── ProceedHandler.java │ │ ├── NoFieldException.java │ │ ├── SymbolTable.java │ │ └── CompileError.java │ ├── NotFoundException.java │ ├── convert │ │ ├── TransformAfter.java │ │ ├── Transformer.java │ │ ├── TransformNewClass.java │ │ ├── TransformWriteField.java │ │ ├── TransformFieldAccess.java │ │ ├── TransformReadField.java │ │ └── TransformNew.java │ ├── ClassPath.java │ ├── CtNewNestedClass.java │ ├── Translator.java │ ├── ByteArrayClassPath.java │ ├── LoaderClassPath.java │ ├── CtArray.java │ ├── ClassClassPath.java │ └── CannotCompileException.java ├── META-INF │ └── MANIFEST.MF └── com │ └── binklac │ └── tools │ └── javadumper │ ├── OnLoadTransformer.java │ └── JavaDumper.java └── readme.md /src/javassist/tools/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Covenient tools. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/javassist/scopedpool/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

A custom class pool for several JBoss products. 4 | It is not part of Javassist. 5 |

6 | 7 | 8 | -------------------------------------------------------------------------------- /src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Premain-Class: com.binklac.tools.javadumper.JavaDumper 3 | Main-Class: com.binklac.tools.javadumper.JavaDumper 4 | Can-Redefine-Classes: true 5 | -------------------------------------------------------------------------------- /src/javassist/tools/web/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Simple web server for running sample code. 4 | 5 |

This package provides a simple web server for sample packages. 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Bytecode-level Annotations API. 4 | 5 |

This package provides low-level API for editing annotations attributes. 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/javassist/expr/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

This package contains the classes for modifying a method body. 5 | See ExprEditor (expression editor) for more details. 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/javassist/util/proxy/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dynamic proxy (similar to Enhancer of cglib). 4 | See ProxyFactory for more details. 5 | 6 | 7 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # JavaDumper 2 | 3 | Simple to dump Java class to file 4 | 5 | Useage: 6 | 7 | Java {all your javaagent, agentlib, agentpath} -javaagent:JavaDumper.jar=; {other} 8 | 9 | E.g.: 10 | 11 | java -javaagent:JavaDumper.jar=java.lang.Shutdown;Shutdown.class -jar JavaDumper.jar -------------------------------------------------------------------------------- /src/javassist/runtime/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Runtime support classes required by modified bytecode. 4 | 5 |

This package includes support classes that may be required by 6 | classes modified with Javassist. Note that most of the modified 7 | classes do not require these support classes. See the documentation 8 | of every support class to know which kind of modification needs 9 | a support class. 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/javassist/tools/rmi/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sample implementation of remote method invocation. 4 | 5 |

This package enables applets to access remote objects 6 | running on the web server with regular Java syntax. 7 | It is provided as a sample implementation with Javassist. 8 | All the programs in this package uses only the regular 9 | Javassist API; they never call any hidden methods. 10 | 11 |

The most significant class of this package is 12 | ObjectImporter. 13 | See the description of this class first. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/javassist/bytecode/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Bytecode-level API. 4 | 5 |

This package provides low-level API for editing a raw class file. 6 | It allows the users to read and modify a constant pool entry, a single 7 | bytecode instruction, and so on. 8 | 9 |

The users of this package must know the specifications of 10 | class file and Java bytecode. For more details, read this book: 11 | 12 |

16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/javassist/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Javassist Core API. 4 | 5 |

Javassist (Java programming assistant) makes bytecode 6 | engineering simple. It is a class library for editing 7 | bytecode in Java; it enables Java programs to define a new class at 8 | runtime and to modify a given class file when the JVM loads it. 9 | 10 |

The most significant class of this package is CtClass. 11 | See the description of this class first. 12 | 13 |

To know the version number of this package, type the following command: 14 | 15 |

16 | java -jar javassist.jar
17 | 
18 | 19 |

It prints the version number on the console. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/javassist/bytecode/analysis/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Bytecode Analysis API. 4 | 5 |

This package provides an API for performing data-flow analysis on a method's bytecode. 6 | This allows the user to determine the type state of the stack and local variable table 7 | at the start of every instruction. In addition this API can be used to validate 8 | bytecode, find dead bytecode, and identify unnecessary checkcasts. 9 | Look at ControlFlow class first for details. 10 | 11 |

The users of this package must know the specifications of 12 | class file and Java bytecode. For more details, read this book: 13 | 14 |

18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/javassist/tools/rmi/Proxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.rmi; 18 | 19 | /** 20 | * An interface implemented by proxy classes. 21 | * 22 | * @see javassist.tools.rmi.StubGenerator 23 | */ 24 | public interface Proxy { 25 | int _getObjectId(); 26 | } 27 | -------------------------------------------------------------------------------- /src/javassist/compiler/SyntaxError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler; 18 | 19 | public class SyntaxError extends CompileError { 20 | public SyntaxError(Lex lexer) { 21 | super("syntax error near \"" + lexer.getTextAround() + "\"", lexer); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/javassist/runtime/Inner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.runtime; 18 | 19 | /** 20 | * A support class for compiling a method declared in an inner class. 21 | * This support class is required at runtime 22 | * only if the method calls a private constructor in the enclosing class. 23 | */ 24 | public class Inner { 25 | } 26 | -------------------------------------------------------------------------------- /src/javassist/NotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | /** 20 | * Signals that something could not be found. 21 | */ 22 | public class NotFoundException extends Exception { 23 | public NotFoundException(String msg) { 24 | super(msg); 25 | } 26 | 27 | public NotFoundException(String msg, Exception e) { 28 | super(msg + " because of " + e.toString()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/javassist/tools/rmi/ObjectNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.rmi; 18 | 19 | public class ObjectNotFoundException extends Exception { 20 | public ObjectNotFoundException(String name) { 21 | super(name + " is not exported"); 22 | } 23 | 24 | public ObjectNotFoundException(String name, Exception e) { 25 | super(name + " because of " + e.toString()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/javassist/util/proxy/MethodFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.util.proxy; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | /** 22 | * Selector of the methods implemented by a handler. 23 | * 24 | * @see ProxyFactory#setFilter(MethodFilter) 25 | */ 26 | public interface MethodFilter { 27 | /** 28 | * Returns true if the given method is implemented by a handler. 29 | */ 30 | boolean isHandled(Method m); 31 | } 32 | -------------------------------------------------------------------------------- /src/javassist/tools/reflect/CannotCreateException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.reflect; 18 | 19 | /** 20 | * Signals that ClassMetaobject.newInstance() fails. 21 | */ 22 | public class CannotCreateException extends Exception { 23 | public CannotCreateException(String s) { 24 | super(s); 25 | } 26 | 27 | public CannotCreateException(Exception e) { 28 | super("by " + e.toString()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/javassist/tools/rmi/RemoteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.rmi; 18 | 19 | /** 20 | * RemoteException represents any exception thrown 21 | * during remote method invocation. 22 | */ 23 | public class RemoteException extends RuntimeException { 24 | public RemoteException(String msg) { 25 | super(msg); 26 | } 27 | 28 | public RemoteException(Exception e) { 29 | super("by " + e.toString()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/javassist/runtime/DotClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.runtime; 18 | 19 | /** 20 | * A support class for implementing .class notation. 21 | * This is required at runtime 22 | * only if .class notation is used in source code given 23 | * to the Javassist compiler. 24 | */ 25 | public class DotClass { 26 | public static NoClassDefFoundError fail(ClassNotFoundException e) { 27 | return new NoClassDefFoundError(e.getMessage()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/javassist/bytecode/DuplicateMemberException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | import javassist.CannotCompileException; 20 | 21 | /** 22 | * An exception thrown when adding a duplicate member is requested. 23 | * 24 | * @see ClassFile#addMethod(MethodInfo) 25 | * @see ClassFile#addField(FieldInfo) 26 | */ 27 | public class DuplicateMemberException extends CannotCompileException { 28 | public DuplicateMemberException(String msg) { 29 | super(msg); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/ArrayInit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Array initializer such as { 1, 2, 3 }. 23 | */ 24 | public class ArrayInit extends ASTList { 25 | public ArrayInit(ASTree firstElement) { 26 | super(firstElement); 27 | } 28 | 29 | public void accept(Visitor v) throws CompileError { v.atArrayInit(this); } 30 | 31 | public String getTag() { return "array"; } 32 | } 33 | -------------------------------------------------------------------------------- /src/javassist/util/proxy/Proxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.util.proxy; 18 | 19 | /** 20 | * The interface implemented by proxy classes. 21 | * This interface only provides a setter method. 22 | * To obtain a handler, call {@link ProxyFactory#getHandler(Proxy)}. 23 | * 24 | * @see ProxyFactory 25 | * @since 3.16 26 | */ 27 | public interface Proxy { 28 | /** 29 | * Sets a handler. It can be used for changing handlers 30 | * during runtime. 31 | */ 32 | void setHandler(MethodHandler mi); 33 | } 34 | -------------------------------------------------------------------------------- /src/javassist/compiler/KeywordTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler; 18 | 19 | public final class KeywordTable extends java.util.HashMap { 20 | public KeywordTable() { super(); } 21 | 22 | public int lookup(String name) { 23 | Object found = get(name); 24 | if (found == null) 25 | return -1; 26 | else 27 | return ((Integer)found).intValue(); 28 | } 29 | 30 | public void append(String name, int t) { 31 | put(name, Integer.valueOf(t)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/javassist/tools/web/BadHttpRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.web; 18 | 19 | /** 20 | * Thrown when receiving an invalid HTTP request. 21 | */ 22 | public class BadHttpRequest extends Exception { 23 | private Exception e; 24 | 25 | public BadHttpRequest() { e = null; } 26 | 27 | public BadHttpRequest(Exception _e) { e = _e; } 28 | 29 | public String toString() { 30 | if (e == null) 31 | return super.toString(); 32 | else 33 | return e.toString(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Keyword.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Keyword. 23 | */ 24 | public class Keyword extends ASTree { 25 | protected int tokenId; 26 | 27 | public Keyword(int token) { 28 | tokenId = token; 29 | } 30 | 31 | public int get() { return tokenId; } 32 | 33 | public String toString() { return "id:" + tokenId; } 34 | 35 | public void accept(Visitor v) throws CompileError { v.atKeyword(this); } 36 | } 37 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/StringL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * String literal. 23 | */ 24 | public class StringL extends ASTree { 25 | protected String text; 26 | 27 | public StringL(String t) { 28 | text = t; 29 | } 30 | 31 | public String get() { return text; } 32 | 33 | public String toString() { return "\"" + text + "\""; } 34 | 35 | public void accept(Visitor v) throws CompileError { v.atStringL(this); } 36 | } 37 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Symbol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Identifier. 23 | */ 24 | public class Symbol extends ASTree { 25 | protected String identifier; 26 | 27 | public Symbol(String sym) { 28 | identifier = sym; 29 | } 30 | 31 | public String get() { return identifier; } 32 | 33 | public String toString() { return identifier; } 34 | 35 | public void accept(Visitor v) throws CompileError { v.atSymbol(this); } 36 | } 37 | -------------------------------------------------------------------------------- /src/javassist/compiler/ProceedHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler; 18 | 19 | import javassist.bytecode.Bytecode; 20 | import javassist.compiler.ast.ASTList; 21 | 22 | /** 23 | * An interface to an object for implementing $proceed(). 24 | * 25 | * @see javassist.compiler.JvstCodeGen#setProceedHandler(ProceedHandler, String) 26 | */ 27 | public interface ProceedHandler { 28 | void doit(JvstCodeGen gen, Bytecode b, ASTList args) throws CompileError; 29 | void setReturnType(JvstTypeChecker c, ASTList args) throws CompileError; 30 | } 31 | -------------------------------------------------------------------------------- /src/javassist/tools/rmi/RemoteRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.rmi; 18 | 19 | /** 20 | * Remote reference. This class is internally used for sending a remote 21 | * reference through a network stream. 22 | */ 23 | public class RemoteRef implements java.io.Serializable { 24 | public int oid; 25 | public String classname; 26 | 27 | public RemoteRef(int i) { 28 | oid = i; 29 | classname = null; 30 | } 31 | 32 | public RemoteRef(int i, String name) { 33 | oid = i; 34 | classname = name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/FieldDecl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | public class FieldDecl extends ASTList { 22 | public FieldDecl(ASTree _head, ASTList _tail) { 23 | super(_head, _tail); 24 | } 25 | 26 | public ASTList getModifiers() { return (ASTList)getLeft(); } 27 | 28 | public Declarator getDeclarator() { return (Declarator)tail().head(); } 29 | 30 | public ASTree getInit() { return (ASTree)sublist(2).head(); } 31 | 32 | public void accept(Visitor v) throws CompileError { 33 | v.atFieldDecl(this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Variable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Variable. 23 | */ 24 | public class Variable extends Symbol { 25 | protected Declarator declarator; 26 | 27 | public Variable(String sym, Declarator d) { 28 | super(sym); 29 | declarator = d; 30 | } 31 | 32 | public Declarator getDeclarator() { return declarator; } 33 | 34 | public String toString() { 35 | return identifier + ":" + declarator.getType(); 36 | } 37 | 38 | public void accept(Visitor v) throws CompileError { v.atVariable(this); } 39 | } 40 | -------------------------------------------------------------------------------- /src/javassist/tools/rmi/Sample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.rmi; 18 | 19 | /** 20 | * A template used for defining a proxy class. 21 | * The class file of this class is read by the StubGenerator 22 | * class. 23 | */ 24 | public class Sample { 25 | private ObjectImporter importer; 26 | private int objectId; 27 | 28 | public Object forward(Object[] args, int identifier) { 29 | return importer.call(objectId, identifier, args); 30 | } 31 | 32 | public static Object forwardStatic(Object[] args, int identifier) 33 | throws RemoteException 34 | { 35 | throw new RemoteException("cannot call a static method."); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/javassist/tools/reflect/Metalevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.reflect; 18 | 19 | /** 20 | * An interface to access a metaobject and a class metaobject. 21 | * This interface is implicitly implemented by the reflective 22 | * class. 23 | */ 24 | public interface Metalevel { 25 | /** 26 | * Obtains the class metaobject associated with this object. 27 | */ 28 | ClassMetaobject _getClass(); 29 | 30 | /** 31 | * Obtains the metaobject associated with this object. 32 | */ 33 | Metaobject _getMetaobject(); 34 | 35 | /** 36 | * Changes the metaobject associated with this object. 37 | */ 38 | void _setMetaobject(Metaobject m); 39 | } 40 | -------------------------------------------------------------------------------- /src/javassist/tools/reflect/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Runtime Behavioral Reflection. 4 | 5 |

(also recently known as interceptors or AOP?) 6 | 7 |

This package enables a metaobject to trap method calls and field 8 | accesses on a regular Java object. It provides a class 9 | Reflection, which is a main module for implementing 10 | runtime behavioral reflection. 11 | It also provides 12 | a class Loader and Compiler 13 | as utilities for dynamically or statically 14 | translating a regular class into a reflective class. 15 | 16 |

An instance of the reflective class is associated with 17 | a runtime metaobject and a runtime class metaobject, which control 18 | the behavior of that instance. 19 | The runtime 20 | metaobject is created for every (base-level) instance but the 21 | runtime class metaobject is created for every (base-level) class. 22 | Metaobject is the root class of the runtime 23 | metaobject and ClassMetaobject is the root class 24 | of the runtime class metaobject. 25 | 26 |

This package is provided as a sample implementation of the 27 | reflection mechanism with Javassist. All the programs in this package 28 | uses only the regular Javassist API; they never call any hidden 29 | methods. 30 | 31 |

The most significant class in this package is Reflection. 32 | See the description of this class first. 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/javassist/scopedpool/ScopedClassPoolFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.scopedpool; 18 | 19 | import javassist.ClassPool; 20 | 21 | /** 22 | * A factory interface. 23 | * 24 | * @author Kabir Khan 25 | * @version $Revision: 1.4 $ 26 | */ 27 | public interface ScopedClassPoolFactory { 28 | /** 29 | * Makes an instance. 30 | */ 31 | ScopedClassPool create(ClassLoader cl, ClassPool src, 32 | ScopedClassPoolRepository repository); 33 | 34 | /** 35 | * Makes an instance. 36 | */ 37 | ScopedClassPool create(ClassPool src, 38 | ScopedClassPoolRepository repository); 39 | } 40 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/NoSuchClassError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | /** 20 | * Thrown if the linkage fails. 21 | * It keeps the name of the class that caused this error. 22 | */ 23 | public class NoSuchClassError extends Error { 24 | private String className; 25 | 26 | /** 27 | * Constructs an exception. 28 | */ 29 | public NoSuchClassError(String className, Error cause) { 30 | super(cause.toString(), cause); 31 | this.className = className; 32 | } 33 | 34 | /** 35 | * Returns the name of the class not found. 36 | */ 37 | public String getClassName() { 38 | return className; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/InstanceOfExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Instanceof expression. 23 | */ 24 | public class InstanceOfExpr extends CastExpr { 25 | public InstanceOfExpr(ASTList className, int dim, ASTree expr) { 26 | super(className, dim, expr); 27 | } 28 | 29 | public InstanceOfExpr(int type, int dim, ASTree expr) { 30 | super(type, dim, expr); 31 | } 32 | 33 | public String getTag() { 34 | return "instanceof:" + castType + ":" + arrayDim; 35 | } 36 | 37 | public void accept(Visitor v) throws CompileError { 38 | v.atInstanceOfExpr(this); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Member.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | import javassist.CtField; 21 | 22 | /** 23 | * Member name. 24 | */ 25 | public class Member extends Symbol { 26 | // cache maintained by fieldAccess() in TypeChecker. 27 | // this is used to obtain the value of a static final field. 28 | private CtField field; 29 | 30 | public Member(String name) { 31 | super(name); 32 | field = null; 33 | } 34 | 35 | public void setField(CtField f) { field = f; } 36 | 37 | public CtField getField() { return field; } 38 | 39 | public void accept(Visitor v) throws CompileError { v.atMember(this); } 40 | } 41 | -------------------------------------------------------------------------------- /src/javassist/bytecode/BadBytecode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | /** 20 | * Signals that a bad bytecode sequence has been found. 21 | */ 22 | public class BadBytecode extends Exception { 23 | public BadBytecode(int opcode) { 24 | super("bytecode " + opcode); 25 | } 26 | 27 | public BadBytecode(String msg) { 28 | super(msg); 29 | } 30 | 31 | public BadBytecode(String msg, Throwable cause) { 32 | super(msg, cause); 33 | } 34 | 35 | public BadBytecode(MethodInfo minfo, Throwable cause) { 36 | super(minfo.toString() + " in " 37 | + minfo.getConstPool().getClassName() 38 | + ": " + cause.getMessage(), cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/javassist/tools/reflect/CannotReflectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.reflect; 18 | 19 | import javassist.CannotCompileException; 20 | 21 | /** 22 | * Thrown by makeReflective() in Reflection 23 | * when there is an attempt to reflect 24 | * a class that is either an interface or a subclass of 25 | * either ClassMetaobject or Metaobject. 26 | * 27 | * @author Brett Randall 28 | * @see javassist.tools.reflect.Reflection#makeReflective(CtClass,CtClass,CtClass) 29 | * @see javassist.CannotCompileException 30 | */ 31 | public class CannotReflectException extends CannotCompileException { 32 | public CannotReflectException(String msg) { 33 | super(msg); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/javassist/bytecode/stackmap/TypeTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.stackmap; 18 | 19 | import javassist.bytecode.StackMapTable; 20 | 21 | public interface TypeTag { 22 | String TOP_TYPE = "*top*"; 23 | TypeData.BasicType TOP = new TypeData.BasicType(TOP_TYPE, StackMapTable.TOP, ' '); 24 | TypeData.BasicType INTEGER = new TypeData.BasicType("int", StackMapTable.INTEGER, 'I'); 25 | TypeData.BasicType FLOAT = new TypeData.BasicType("float", StackMapTable.FLOAT, 'F'); 26 | TypeData.BasicType DOUBLE = new TypeData.BasicType("double", StackMapTable.DOUBLE, 'D'); 27 | TypeData.BasicType LONG = new TypeData.BasicType("long", StackMapTable.LONG, 'J'); 28 | 29 | // and NULL, THIS, OBJECT, UNINIT 30 | } 31 | -------------------------------------------------------------------------------- /src/javassist/compiler/NoFieldException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler; 18 | 19 | import javassist.compiler.ast.ASTree; 20 | 21 | public class NoFieldException extends CompileError { 22 | private String fieldName; 23 | private ASTree expr; 24 | 25 | /* NAME must be JVM-internal representation. 26 | */ 27 | public NoFieldException(String name, ASTree e) { 28 | super("no such field: " + name); 29 | fieldName = name; 30 | expr = e; 31 | } 32 | 33 | /* The returned name should be JVM-internal representation. 34 | */ 35 | public String getField() { return fieldName; } 36 | 37 | /* Returns the expression where this exception is thrown. 38 | */ 39 | public ASTree getExpr() { return expr; } 40 | } 41 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/AssignExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Assignment expression. 23 | */ 24 | public class AssignExpr extends Expr { 25 | /* operator must be either of: 26 | * =, %=, &=, *=, +=, -=, /=, ^=, |=, <<=, >>=, >>>= 27 | */ 28 | 29 | private AssignExpr(int op, ASTree _head, ASTList _tail) { 30 | super(op, _head, _tail); 31 | } 32 | 33 | public static AssignExpr makeAssign(int op, ASTree oprand1, 34 | ASTree oprand2) { 35 | return new AssignExpr(op, oprand1, new ASTList(oprand2)); 36 | } 37 | 38 | public void accept(Visitor v) throws CompileError { 39 | v.atAssignExpr(this); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/BinExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Binary expression. 23 | * 24 | *

If the operator is +, the right node might be null. 25 | * See TypeChecker.atBinExpr(). 26 | */ 27 | public class BinExpr extends Expr { 28 | /* operator must be either of: 29 | * ||, &&, |, ^, &, ==, !=, <=, >=, <, >, 30 | * <<, >>, >>>, +, -, *, /, % 31 | */ 32 | 33 | private BinExpr(int op, ASTree _head, ASTList _tail) { 34 | super(op, _head, _tail); 35 | } 36 | 37 | public static BinExpr makeBin(int op, ASTree oprand1, ASTree oprand2) { 38 | return new BinExpr(op, oprand1, new ASTList(oprand2)); 39 | } 40 | 41 | public void accept(Visitor v) throws CompileError { v.atBinExpr(this); } 42 | } 43 | -------------------------------------------------------------------------------- /src/javassist/compiler/SymbolTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler; 18 | 19 | import java.util.HashMap; 20 | import javassist.compiler.ast.Declarator; 21 | 22 | public final class SymbolTable extends HashMap { 23 | private SymbolTable parent; 24 | 25 | public SymbolTable() { this(null); } 26 | 27 | public SymbolTable(SymbolTable p) { 28 | super(); 29 | parent = p; 30 | } 31 | 32 | public SymbolTable getParent() { return parent; } 33 | 34 | public Declarator lookup(String name) { 35 | Declarator found = (Declarator)get(name); 36 | if (found == null && parent != null) 37 | return parent.lookup(name); 38 | else 39 | return found; 40 | } 41 | 42 | public void append(String name, Declarator value) { 43 | put(name, value); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/binklac/tools/javadumper/OnLoadTransformer.java: -------------------------------------------------------------------------------- 1 | package com.binklac.tools.javadumper; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.lang.instrument.ClassFileTransformer; 7 | import java.lang.instrument.IllegalClassFormatException; 8 | import java.security.ProtectionDomain; 9 | 10 | public class OnLoadTransformer implements ClassFileTransformer { 11 | private String className; 12 | private String saveFile; 13 | 14 | public static void write2File(String Dst, byte[] data) throws RuntimeException { 15 | File file = null; 16 | FileOutputStream outputstream = null; 17 | 18 | try { 19 | file = new File(Dst); 20 | outputstream = new FileOutputStream(file); 21 | outputstream.write(data); 22 | } catch (IOException e) { 23 | e.printStackTrace(); 24 | } finally { 25 | try { 26 | outputstream.close(); 27 | } catch (IOException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | } 32 | 33 | public OnLoadTransformer(String className, String saveFile) { 34 | this.className = className; 35 | this.saveFile = saveFile; 36 | } 37 | 38 | @Override 39 | public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { 40 | if(className.replace("/",".").equals(this.className)){ 41 | System.out.println("Found the specified class <" + this.className + ">, save it in <" + this.saveFile + ">."); 42 | write2File(this.saveFile , classfileBuffer); 43 | } 44 | return null; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/CondExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Conditional expression. 23 | */ 24 | public class CondExpr extends ASTList { 25 | public CondExpr(ASTree cond, ASTree thenp, ASTree elsep) { 26 | super(cond, new ASTList(thenp, new ASTList(elsep))); 27 | } 28 | 29 | public ASTree condExpr() { return head(); } 30 | 31 | public void setCond(ASTree t) { setHead(t); } 32 | 33 | public ASTree thenExpr() { return tail().head(); } 34 | 35 | public void setThen(ASTree t) { tail().setHead(t); } 36 | 37 | public ASTree elseExpr() { return tail().tail().head(); } 38 | 39 | public void setElse(ASTree t) { tail().tail().setHead(t); } 40 | 41 | public String getTag() { return "?:"; } 42 | 43 | public void accept(Visitor v) throws CompileError { v.atCondExpr(this); } 44 | } 45 | -------------------------------------------------------------------------------- /src/javassist/util/proxy/ProxyObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.util.proxy; 18 | 19 | /** 20 | * The interface implemented by proxy classes. 21 | * This interface is available only if the super class of the proxy object 22 | * does not have a getHandler() method. If the super class 23 | * has getHandler, then Proxy interface is 24 | * available. 25 | * 26 | * @see ProxyFactory 27 | * @see Proxy 28 | */ 29 | public interface ProxyObject extends Proxy { 30 | /** 31 | * Sets a handler. It can be used for changing handlers 32 | * during runtime. 33 | */ 34 | void setHandler(MethodHandler mi); 35 | 36 | /** 37 | * Get the handler. 38 | * This can be used to access the underlying MethodHandler 39 | * or to serialize it properly. 40 | * 41 | * @see ProxyFactory#getHandler(Proxy) 42 | */ 43 | MethodHandler getHandler(); 44 | } 45 | -------------------------------------------------------------------------------- /src/javassist/scopedpool/ScopedClassPoolFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.scopedpool; 18 | 19 | import javassist.ClassPool; 20 | 21 | /** 22 | * An implementation of factory. 23 | * 24 | * @author Kabir Khan 25 | * @version $Revision: 1.5 $ 26 | */ 27 | public class ScopedClassPoolFactoryImpl implements ScopedClassPoolFactory { 28 | /** 29 | * Makes an instance. 30 | */ 31 | public ScopedClassPool create(ClassLoader cl, ClassPool src, 32 | ScopedClassPoolRepository repository) { 33 | return new ScopedClassPool(cl, src, repository, false); 34 | } 35 | 36 | /** 37 | * Makes an instance. 38 | */ 39 | public ScopedClassPool create(ClassPool src, 40 | ScopedClassPoolRepository repository) { 41 | return new ScopedClassPool(null, src, repository, true); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/javassist/compiler/CompileError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler; 18 | 19 | import javassist.CannotCompileException; 20 | import javassist.NotFoundException; 21 | 22 | public class CompileError extends Exception { 23 | private Lex lex; 24 | private String reason; 25 | 26 | public CompileError(String s, Lex l) { 27 | reason = s; 28 | lex = l; 29 | } 30 | 31 | public CompileError(String s) { 32 | reason = s; 33 | lex = null; 34 | } 35 | 36 | public CompileError(CannotCompileException e) { 37 | this(e.getReason()); 38 | } 39 | 40 | public CompileError(NotFoundException e) { 41 | this("cannot find " + e.getMessage()); 42 | } 43 | 44 | public Lex getLex() { return lex; } 45 | 46 | public String getMessage() { 47 | return reason; 48 | } 49 | 50 | public String toString() { 51 | return "compile error: " + reason; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/CallExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | import javassist.compiler.TokenId; 21 | import javassist.compiler.MemberResolver; 22 | 23 | /** 24 | * Method call expression. 25 | */ 26 | public class CallExpr extends Expr { 27 | private MemberResolver.Method method; // cached result of lookupMethod() 28 | 29 | private CallExpr(ASTree _head, ASTList _tail) { 30 | super(TokenId.CALL, _head, _tail); 31 | method = null; 32 | } 33 | 34 | public void setMethod(MemberResolver.Method m) { 35 | method = m; 36 | } 37 | 38 | public MemberResolver.Method getMethod() { 39 | return method; 40 | } 41 | 42 | public static CallExpr makeCall(ASTree target, ASTree args) { 43 | return new CallExpr(target, new ASTList(args)); 44 | } 45 | 46 | public void accept(Visitor v) throws CompileError { v.atCallExpr(this); } 47 | } 48 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/MethodDecl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | public class MethodDecl extends ASTList { 22 | public static final String initName = ""; 23 | 24 | public MethodDecl(ASTree _head, ASTList _tail) { 25 | super(_head, _tail); 26 | } 27 | 28 | public boolean isConstructor() { 29 | Symbol sym = getReturn().getVariable(); 30 | return sym != null && initName.equals(sym.get()); 31 | } 32 | 33 | public ASTList getModifiers() { return (ASTList)getLeft(); } 34 | 35 | public Declarator getReturn() { return (Declarator)tail().head(); } 36 | 37 | public ASTList getParams() { return (ASTList)sublist(2).head(); } 38 | 39 | public ASTList getThrows() { return (ASTList)sublist(3).head(); } 40 | 41 | public Stmnt getBody() { return (Stmnt)sublist(4).head(); } 42 | 43 | public void accept(Visitor v) throws CompileError { 44 | v.atMethodDecl(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/javassist/runtime/Cflow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.runtime; 18 | 19 | /** 20 | * A support class for implementing $cflow. 21 | * This support class is required at runtime 22 | * only if $cflow is used. 23 | * 24 | * @see javassist.CtBehavior#useCflow(String) 25 | */ 26 | public class Cflow extends ThreadLocal { 27 | private static class Depth { 28 | private int depth; 29 | Depth() { depth = 0; } 30 | int get() { return depth; } 31 | void inc() { ++depth; } 32 | void dec() { --depth; } 33 | } 34 | 35 | protected synchronized Object initialValue() { 36 | return new Depth(); 37 | } 38 | 39 | /** 40 | * Increments the counter. 41 | */ 42 | public void enter() { ((Depth)get()).inc(); } 43 | 44 | /** 45 | * Decrements the counter. 46 | */ 47 | public void exit() { ((Depth)get()).dec(); } 48 | 49 | /** 50 | * Returns the value of the counter. 51 | */ 52 | public int value() { return ((Depth)get()).get(); } 53 | } 54 | -------------------------------------------------------------------------------- /src/javassist/bytecode/analysis/IntQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.bytecode.analysis; 17 | 18 | import java.util.NoSuchElementException; 19 | 20 | class IntQueue { 21 | private static class Entry { 22 | private IntQueue.Entry next; 23 | private int value; 24 | private Entry(int value) { 25 | this.value = value; 26 | } 27 | } 28 | private IntQueue.Entry head; 29 | 30 | private IntQueue.Entry tail; 31 | 32 | void add(int value) { 33 | IntQueue.Entry entry = new Entry(value); 34 | if (tail != null) 35 | tail.next = entry; 36 | tail = entry; 37 | 38 | if (head == null) 39 | head = entry; 40 | } 41 | 42 | boolean isEmpty() { 43 | return head == null; 44 | } 45 | 46 | int take() { 47 | if (head == null) 48 | throw new NoSuchElementException(); 49 | 50 | int value = head.value; 51 | head = head.next; 52 | if (head == null) 53 | tail = null; 54 | 55 | return value; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/javassist/tools/framedump.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.tools; 17 | 18 | import javassist.ClassPool; 19 | import javassist.CtClass; 20 | import javassist.bytecode.analysis.FramePrinter; 21 | 22 | /** 23 | * framedump is a tool for viewing a merged combination of the instructions and frame state 24 | * of all methods in a class. 25 | * 26 | *

For example, 27 | *

% java javassist.tools.framedump foo.class
28 | */ 29 | public class framedump { 30 | private framedump() {} 31 | 32 | /** 33 | * Main method. 34 | * 35 | * @param args args[0] is the class file name. 36 | */ 37 | public static void main(String[] args) throws Exception { 38 | if (args.length != 1) { 39 | System.err.println("Usage: java javassist.tools.framedump "); 40 | return; 41 | } 42 | 43 | ClassPool pool = ClassPool.getDefault(); 44 | CtClass clazz = pool.get(args[0]); 45 | System.out.println("Frame Dump of " + clazz.getName() + ":"); 46 | FramePrinter.print(clazz, System.out); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/javassist/bytecode/analysis/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.bytecode.analysis; 17 | 18 | import javassist.bytecode.CodeIterator; 19 | import javassist.bytecode.Opcode; 20 | 21 | /** 22 | * A set of common utility methods. 23 | * 24 | * @author Jason T. Greene 25 | */ 26 | public class Util implements Opcode { 27 | public static int getJumpTarget(int pos, CodeIterator iter) { 28 | int opcode = iter.byteAt(pos); 29 | pos += (opcode == JSR_W || opcode == GOTO_W) ? iter.s32bitAt(pos + 1) : iter.s16bitAt(pos + 1); 30 | return pos; 31 | } 32 | 33 | public static boolean isJumpInstruction(int opcode) { 34 | return (opcode >= IFEQ && opcode <= JSR) || opcode == IFNULL || opcode == IFNONNULL || opcode == JSR_W || opcode == GOTO_W; 35 | } 36 | 37 | public static boolean isGoto(int opcode) { 38 | return opcode == GOTO || opcode == GOTO_W; 39 | } 40 | 41 | public static boolean isJsr(int opcode) { 42 | return opcode == JSR || opcode == JSR_W; 43 | } 44 | 45 | public static boolean isReturn(int opcode) { 46 | return (opcode >= IRETURN && opcode <= RETURN); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * A node of a a binary tree. This class provides concrete methods 23 | * overriding abstract methods in ASTree. 24 | */ 25 | public class Pair extends ASTree { 26 | protected ASTree left, right; 27 | 28 | public Pair(ASTree _left, ASTree _right) { 29 | left = _left; 30 | right = _right; 31 | } 32 | 33 | public void accept(Visitor v) throws CompileError { v.atPair(this); } 34 | 35 | public String toString() { 36 | StringBuffer sbuf = new StringBuffer(); 37 | sbuf.append("( "); 38 | sbuf.append(left == null ? "" : left.toString()); 39 | sbuf.append(" . "); 40 | sbuf.append(right == null ? "" : right.toString()); 41 | sbuf.append(')'); 42 | return sbuf.toString(); 43 | } 44 | 45 | public ASTree getLeft() { return left; } 46 | 47 | public ASTree getRight() { return right; } 48 | 49 | public void setLeft(ASTree _left) { left = _left; } 50 | 51 | public void setRight(ASTree _right) { right = _right; } 52 | } 53 | -------------------------------------------------------------------------------- /src/javassist/convert/TransformAfter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.CtMethod; 20 | import javassist.NotFoundException; 21 | import javassist.bytecode.*; 22 | 23 | public class TransformAfter extends TransformBefore { 24 | public TransformAfter(Transformer next, 25 | CtMethod origMethod, CtMethod afterMethod) 26 | throws NotFoundException 27 | { 28 | super(next, origMethod, afterMethod); 29 | } 30 | 31 | protected int match2(int pos, CodeIterator iterator) throws BadBytecode { 32 | iterator.move(pos); 33 | iterator.insert(saveCode); 34 | iterator.insert(loadCode); 35 | int p = iterator.insertGap(3); 36 | iterator.setMark(p); 37 | iterator.insert(loadCode); 38 | pos = iterator.next(); 39 | p = iterator.getMark(); 40 | iterator.writeByte(iterator.byteAt(pos), p); 41 | iterator.write16bit(iterator.u16bitAt(pos + 1), p + 1); 42 | iterator.writeByte(INVOKESTATIC, pos); 43 | iterator.write16bit(newIndex, pos + 1); 44 | iterator.move(p); 45 | return iterator.next(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/javassist/bytecode/SyntheticAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | import java.io.DataInputStream; 20 | import java.io.IOException; 21 | import java.util.Map; 22 | 23 | /** 24 | * Synthetic_attribute. 25 | */ 26 | public class SyntheticAttribute extends AttributeInfo { 27 | /** 28 | * The name of this attribute "Synthetic". 29 | */ 30 | public static final String tag = "Synthetic"; 31 | 32 | SyntheticAttribute(ConstPool cp, int n, DataInputStream in) 33 | throws IOException 34 | { 35 | super(cp, n, in); 36 | } 37 | 38 | /** 39 | * Constructs a Synthetic attribute. 40 | * 41 | * @param cp a constant pool table. 42 | */ 43 | public SyntheticAttribute(ConstPool cp) { 44 | super(cp, tag, new byte[0]); 45 | } 46 | 47 | /** 48 | * Makes a copy. 49 | * 50 | * @param newCp the constant pool table used by the new copy. 51 | * @param classnames should be null. 52 | */ 53 | public AttributeInfo copy(ConstPool newCp, Map classnames) { 54 | return new SyntheticAttribute(newCp); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/javassist/bytecode/DeprecatedAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | import java.io.DataInputStream; 20 | import java.io.IOException; 21 | import java.util.Map; 22 | 23 | /** 24 | * Deprecated_attribute. 25 | */ 26 | public class DeprecatedAttribute extends AttributeInfo { 27 | /** 28 | * The name of this attribute "Deprecated". 29 | */ 30 | public static final String tag = "Deprecated"; 31 | 32 | DeprecatedAttribute(ConstPool cp, int n, DataInputStream in) 33 | throws IOException 34 | { 35 | super(cp, n, in); 36 | } 37 | 38 | /** 39 | * Constructs a Deprecated attribute. 40 | * 41 | * @param cp a constant pool table. 42 | */ 43 | public DeprecatedAttribute(ConstPool cp) { 44 | super(cp, tag, new byte[0]); 45 | } 46 | 47 | /** 48 | * Makes a copy. 49 | * 50 | * @param newCp the constant pool table used by the new copy. 51 | * @param classnames should be null. 52 | */ 53 | public AttributeInfo copy(ConstPool newCp, Map classnames) { 54 | return new DeprecatedAttribute(newCp); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/MemberValueVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | /** 20 | * Visitor for traversing member values included in an annotation. 21 | * 22 | * @see MemberValue#accept(MemberValueVisitor) 23 | * @author Bill Burke 24 | */ 25 | public interface MemberValueVisitor { 26 | public void visitAnnotationMemberValue(AnnotationMemberValue node); 27 | public void visitArrayMemberValue(ArrayMemberValue node); 28 | public void visitBooleanMemberValue(BooleanMemberValue node); 29 | public void visitByteMemberValue(ByteMemberValue node); 30 | public void visitCharMemberValue(CharMemberValue node); 31 | public void visitDoubleMemberValue(DoubleMemberValue node); 32 | public void visitEnumMemberValue(EnumMemberValue node); 33 | public void visitFloatMemberValue(FloatMemberValue node); 34 | public void visitIntegerMemberValue(IntegerMemberValue node); 35 | public void visitLongMemberValue(LongMemberValue node); 36 | public void visitShortMemberValue(ShortMemberValue node); 37 | public void visitStringMemberValue(StringMemberValue node); 38 | public void visitClassMemberValue(ClassMemberValue node); 39 | } 40 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/CastExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.TokenId; 20 | import javassist.compiler.CompileError; 21 | 22 | /** 23 | * Cast expression. 24 | */ 25 | public class CastExpr extends ASTList implements TokenId { 26 | protected int castType; 27 | protected int arrayDim; 28 | 29 | public CastExpr(ASTList className, int dim, ASTree expr) { 30 | super(className, new ASTList(expr)); 31 | castType = CLASS; 32 | arrayDim = dim; 33 | } 34 | 35 | public CastExpr(int type, int dim, ASTree expr) { 36 | super(null, new ASTList(expr)); 37 | castType = type; 38 | arrayDim = dim; 39 | } 40 | 41 | /* Returns CLASS, BOOLEAN, INT, or ... 42 | */ 43 | public int getType() { return castType; } 44 | 45 | public int getArrayDim() { return arrayDim; } 46 | 47 | public ASTList getClassName() { return (ASTList)getLeft(); } 48 | 49 | public ASTree getOprand() { return getRight().getLeft(); } 50 | 51 | public void setOprand(ASTree t) { getRight().setLeft(t); } 52 | 53 | public String getTag() { return "cast:" + castType + ":" + arrayDim; } 54 | 55 | public void accept(Visitor v) throws CompileError { v.atCastExpr(this); } 56 | } 57 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Stmnt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.TokenId; 20 | import javassist.compiler.CompileError; 21 | 22 | /** 23 | * Statement. 24 | */ 25 | public class Stmnt extends ASTList implements TokenId { 26 | protected int operatorId; 27 | 28 | public Stmnt(int op, ASTree _head, ASTList _tail) { 29 | super(_head, _tail); 30 | operatorId = op; 31 | } 32 | 33 | public Stmnt(int op, ASTree _head) { 34 | super(_head); 35 | operatorId = op; 36 | } 37 | 38 | public Stmnt(int op) { 39 | this(op, null); 40 | } 41 | 42 | public static Stmnt make(int op, ASTree oprand1, ASTree oprand2) { 43 | return new Stmnt(op, oprand1, new ASTList(oprand2)); 44 | } 45 | 46 | public static Stmnt make(int op, ASTree op1, ASTree op2, ASTree op3) { 47 | return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3))); 48 | } 49 | 50 | public void accept(Visitor v) throws CompileError { v.atStmnt(this); } 51 | 52 | public int getOperator() { return operatorId; } 53 | 54 | protected String getTag() { 55 | if (operatorId < 128) 56 | return "stmnt:" + (char)operatorId; 57 | else 58 | return "stmnt:" + operatorId; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/javassist/convert/Transformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.CannotCompileException; 20 | import javassist.CtClass; 21 | import javassist.bytecode.BadBytecode; 22 | import javassist.bytecode.CodeAttribute; 23 | import javassist.bytecode.CodeIterator; 24 | import javassist.bytecode.ConstPool; 25 | import javassist.bytecode.MethodInfo; 26 | import javassist.bytecode.Opcode; 27 | 28 | /** 29 | * Transformer and its subclasses are used for executing 30 | * code transformation specified by CodeConverter. 31 | * 32 | * @see javassist.CodeConverter 33 | */ 34 | public abstract class Transformer implements Opcode { 35 | private Transformer next; 36 | 37 | public Transformer(Transformer t) { 38 | next = t; 39 | } 40 | 41 | public Transformer getNext() { return next; } 42 | 43 | public void initialize(ConstPool cp, CodeAttribute attr) {} 44 | 45 | public void initialize(ConstPool cp, CtClass clazz, MethodInfo minfo) throws CannotCompileException { 46 | initialize(cp, minfo.getCodeAttribute()); 47 | } 48 | 49 | public void clean() {} 50 | 51 | public abstract int transform(CtClass clazz, int pos, CodeIterator it, 52 | ConstPool cp) throws CannotCompileException, BadBytecode; 53 | 54 | public int extraLocals() { return 0; } 55 | 56 | public int extraStack() { return 0; } 57 | } 58 | -------------------------------------------------------------------------------- /src/javassist/tools/reflect/Sample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.reflect; 18 | 19 | /** 20 | * A template used for defining a reflective class. 21 | */ 22 | public class Sample { 23 | private Metaobject _metaobject; 24 | private static ClassMetaobject _classobject; 25 | 26 | public Object trap(Object[] args, int identifier) throws Throwable { 27 | Metaobject mobj; 28 | mobj = _metaobject; 29 | if (mobj == null) 30 | return ClassMetaobject.invoke(this, identifier, args); 31 | else 32 | return mobj.trapMethodcall(identifier, args); 33 | } 34 | 35 | public static Object trapStatic(Object[] args, int identifier) 36 | throws Throwable 37 | { 38 | return _classobject.trapMethodcall(identifier, args); 39 | } 40 | 41 | public static Object trapRead(Object[] args, String name) { 42 | if (args[0] == null) 43 | return _classobject.trapFieldRead(name); 44 | else 45 | return ((Metalevel)args[0])._getMetaobject().trapFieldRead(name); 46 | } 47 | 48 | public static Object trapWrite(Object[] args, String name) { 49 | Metalevel base = (Metalevel)args[0]; 50 | if (base == null) 51 | _classobject.trapFieldWrite(name, args[1]); 52 | else 53 | base._getMetaobject().trapFieldWrite(name, args[1]); 54 | 55 | return null; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/javassist/bytecode/analysis/Subroutine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.bytecode.analysis; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | import java.util.HashSet; 21 | import java.util.List; 22 | import java.util.Set; 23 | 24 | /** 25 | * Represents a nested method subroutine (marked by JSR and RET). 26 | * 27 | * @author Jason T. Greene 28 | */ 29 | public class Subroutine { 30 | //private Set callers = new HashSet(); 31 | private List callers = new ArrayList(); 32 | private Set access = new HashSet(); 33 | private int start; 34 | 35 | public Subroutine(int start, int caller) { 36 | this.start = start; 37 | callers.add(Integer.valueOf(caller)); 38 | } 39 | 40 | public void addCaller(int caller) { 41 | callers.add(Integer.valueOf(caller)); 42 | } 43 | 44 | public int start() { 45 | return start; 46 | } 47 | 48 | public void access(int index) { 49 | access.add(Integer.valueOf(index)); 50 | } 51 | 52 | public boolean isAccessed(int index) { 53 | return access.contains(Integer.valueOf(index)); 54 | } 55 | 56 | public Collection accessed() { 57 | return access; 58 | } 59 | 60 | public Collection callers() { 61 | return callers; 62 | } 63 | 64 | public String toString() { 65 | return "start = " + start + " callers = " + callers.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/javassist/tools/Dump.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools; 18 | 19 | import java.io.*; 20 | import javassist.bytecode.ClassFile; 21 | import javassist.bytecode.ClassFilePrinter; 22 | 23 | /** 24 | * Dump is a tool for viewing the class definition in the given 25 | * class file. Unlike the JDK javap tool, Dump works even if 26 | * the class file is broken. 27 | * 28 | *

For example, 29 | *

% java javassist.tools.Dump foo.class
30 | * 31 | *

prints the contents of the constant pool and the list of methods 32 | * and fields. 33 | */ 34 | public class Dump { 35 | private Dump() {} 36 | 37 | /** 38 | * Main method. 39 | * 40 | * @param args args[0] is the class file name. 41 | */ 42 | public static void main(String[] args) throws Exception { 43 | if (args.length != 1) { 44 | System.err.println("Usage: java Dump "); 45 | return; 46 | } 47 | 48 | DataInputStream in = new DataInputStream( 49 | new FileInputStream(args[0])); 50 | ClassFile w = new ClassFile(in); 51 | PrintWriter out = new PrintWriter(System.out, true); 52 | out.println("*** constant pool ***"); 53 | w.getConstPool().print(out); 54 | out.println(); 55 | out.println("*** members ***"); 56 | ClassFilePrinter.print(w, out); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/ASTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import java.io.Serializable; 20 | import javassist.compiler.CompileError; 21 | 22 | /** 23 | * Abstract Syntax Tree. An ASTree object represents a node of 24 | * a binary tree. If the node is a leaf node, both getLeft() 25 | * and getRight() returns null. 26 | */ 27 | public abstract class ASTree implements Serializable { 28 | public ASTree getLeft() { return null; } 29 | 30 | public ASTree getRight() { return null; } 31 | 32 | public void setLeft(ASTree _left) {} 33 | 34 | public void setRight(ASTree _right) {} 35 | 36 | /** 37 | * Is a method for the visitor pattern. It calls 38 | * atXXX() on the given visitor, where 39 | * XXX is the class name of the node object. 40 | */ 41 | public abstract void accept(Visitor v) throws CompileError; 42 | 43 | public String toString() { 44 | StringBuffer sbuf = new StringBuffer(); 45 | sbuf.append('<'); 46 | sbuf.append(getTag()); 47 | sbuf.append('>'); 48 | return sbuf.toString(); 49 | } 50 | 51 | /** 52 | * Returns the type of this node. This method is used by 53 | * toString(). 54 | */ 55 | protected String getTag() { 56 | String name = getClass().getName(); 57 | return name.substring(name.lastIndexOf('.') + 1); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/javassist/bytecode/LongVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | final class LongVector { 20 | static final int ASIZE = 128; 21 | static final int ABITS = 7; // ASIZE = 2^ABITS 22 | static final int VSIZE = 8; 23 | private ConstInfo[][] objects; 24 | private int elements; 25 | 26 | public LongVector() { 27 | objects = new ConstInfo[VSIZE][]; 28 | elements = 0; 29 | } 30 | 31 | public LongVector(int initialSize) { 32 | int vsize = ((initialSize >> ABITS) & ~(VSIZE - 1)) + VSIZE; 33 | objects = new ConstInfo[vsize][]; 34 | elements = 0; 35 | } 36 | 37 | public int size() { return elements; } 38 | 39 | public int capacity() { return objects.length * ASIZE; } 40 | 41 | public ConstInfo elementAt(int i) { 42 | if (i < 0 || elements <= i) 43 | return null; 44 | 45 | return objects[i >> ABITS][i & (ASIZE - 1)]; 46 | } 47 | 48 | public void addElement(ConstInfo value) { 49 | int nth = elements >> ABITS; 50 | int offset = elements & (ASIZE - 1); 51 | int len = objects.length; 52 | if (nth >= len) { 53 | ConstInfo[][] newObj = new ConstInfo[len + VSIZE][]; 54 | System.arraycopy(objects, 0, newObj, 0, len); 55 | objects = newObj; 56 | } 57 | 58 | if (objects[nth] == null) 59 | objects[nth] = new ConstInfo[ASIZE]; 60 | 61 | objects[nth][offset] = value; 62 | elements++; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/javassist/bytecode/LocalVariableTypeAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | import java.io.DataInputStream; 20 | import java.io.IOException; 21 | import java.util.Map; 22 | 23 | /** 24 | * LocalVariableTypeTable_attribute. 25 | * 26 | * @since 3.11 27 | */ 28 | public class LocalVariableTypeAttribute extends LocalVariableAttribute { 29 | /** 30 | * The name of the attribute "LocalVariableTypeTable". 31 | */ 32 | public static final String tag = LocalVariableAttribute.typeTag; 33 | 34 | /** 35 | * Constructs an empty LocalVariableTypeTable. 36 | */ 37 | public LocalVariableTypeAttribute(ConstPool cp) { 38 | super(cp, tag, new byte[2]); 39 | ByteArray.write16bit(0, info, 0); 40 | } 41 | 42 | LocalVariableTypeAttribute(ConstPool cp, int n, DataInputStream in) 43 | throws IOException 44 | { 45 | super(cp, n, in); 46 | } 47 | 48 | private LocalVariableTypeAttribute(ConstPool cp, byte[] dest) { 49 | super(cp, tag, dest); 50 | } 51 | 52 | String renameEntry(String desc, String oldname, String newname) { 53 | return SignatureAttribute.renameClass(desc, oldname, newname); 54 | } 55 | 56 | String renameEntry(String desc, Map classnames) { 57 | return SignatureAttribute.renameClass(desc, classnames); 58 | } 59 | 60 | LocalVariableAttribute makeThisAttr(ConstPool cp, byte[] dest) { 61 | return new LocalVariableTypeAttribute(cp, dest); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/javassist/util/proxy/MethodHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.util.proxy; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | /** 22 | * The interface implemented by the invocation handler of a proxy 23 | * instance. 24 | * 25 | * @see Proxy#setHandler(MethodHandler) 26 | */ 27 | public interface MethodHandler { 28 | /** 29 | * Is called when a method is invoked on a proxy instance associated 30 | * with this handler. This method must process that method invocation. 31 | * 32 | * @param self the proxy instance. 33 | * @param thisMethod the overridden method declared in the super 34 | * class or interface. 35 | * @param proceed the forwarder method for invoking the overridden 36 | * method. It is null if the overridden method is 37 | * abstract or declared in the interface. 38 | * @param args an array of objects containing the values of 39 | * the arguments passed in the method invocation 40 | * on the proxy instance. If a parameter type is 41 | * a primitive type, the type of the array element 42 | * is a wrapper class. 43 | * @return the resulting value of the method invocation. 44 | * 45 | * @throws Throwable if the method invocation fails. 46 | */ 47 | Object invoke(Object self, Method thisMethod, Method proceed, 48 | Object[] args) throws Throwable; 49 | } 50 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Visitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * The visitor pattern. 23 | * 24 | * @see ASTree#accept(Visitor) 25 | */ 26 | public class Visitor { 27 | public void atASTList(ASTList n) throws CompileError {} 28 | public void atPair(Pair n) throws CompileError {} 29 | 30 | public void atFieldDecl(FieldDecl n) throws CompileError {} 31 | public void atMethodDecl(MethodDecl n) throws CompileError {} 32 | public void atStmnt(Stmnt n) throws CompileError {} 33 | public void atDeclarator(Declarator n) throws CompileError {} 34 | 35 | public void atAssignExpr(AssignExpr n) throws CompileError {} 36 | public void atCondExpr(CondExpr n) throws CompileError {} 37 | public void atBinExpr(BinExpr n) throws CompileError {} 38 | public void atExpr(Expr n) throws CompileError {} 39 | public void atCallExpr(CallExpr n) throws CompileError {} 40 | public void atCastExpr(CastExpr n) throws CompileError {} 41 | public void atInstanceOfExpr(InstanceOfExpr n) throws CompileError {} 42 | public void atNewExpr(NewExpr n) throws CompileError {} 43 | 44 | public void atSymbol(Symbol n) throws CompileError {} 45 | public void atMember(Member n) throws CompileError {} 46 | public void atVariable(Variable n) throws CompileError {} 47 | public void atKeyword(Keyword n) throws CompileError {} 48 | public void atStringL(StringL n) throws CompileError {} 49 | public void atIntConst(IntConst n) throws CompileError {} 50 | public void atDoubleConst(DoubleConst n) throws CompileError {} 51 | public void atArrayInit(ArrayInit n) throws CompileError {} 52 | } 53 | -------------------------------------------------------------------------------- /src/javassist/expr/ConstructorCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.expr; 18 | 19 | import javassist.CtClass; 20 | import javassist.CtConstructor; 21 | import javassist.CtMethod; 22 | import javassist.NotFoundException; 23 | import javassist.bytecode.CodeIterator; 24 | import javassist.bytecode.MethodInfo; 25 | 26 | /** 27 | * Constructor call such as this() and super() 28 | * within a constructor body. 29 | * 30 | * @see NewExpr 31 | */ 32 | public class ConstructorCall extends MethodCall { 33 | /** 34 | * Undocumented constructor. Do not use; internal-use only. 35 | */ 36 | protected ConstructorCall(int pos, CodeIterator i, CtClass decl, MethodInfo m) { 37 | super(pos, i, decl, m); 38 | } 39 | 40 | /** 41 | * Returns "super" or ""this". 42 | */ 43 | public String getMethodName() { 44 | return isSuper() ? "super" : "this"; 45 | } 46 | 47 | /** 48 | * Always throws a NotFoundException. 49 | * 50 | * @see #getConstructor() 51 | */ 52 | public CtMethod getMethod() throws NotFoundException { 53 | throw new NotFoundException("this is a constructor call. Call getConstructor()."); 54 | } 55 | 56 | /** 57 | * Returns the called constructor. 58 | */ 59 | public CtConstructor getConstructor() throws NotFoundException { 60 | return getCtClass().getConstructor(getSignature()); 61 | } 62 | 63 | /** 64 | * Returns true if the called constructor is not this() 65 | * but super() (a constructor declared in the super class). 66 | */ 67 | public boolean isSuper() { 68 | return super.isSuper(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/javassist/tools/reflect/CannotInvokeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.tools.reflect; 18 | 19 | import java.lang.reflect.InvocationTargetException; 20 | import java.lang.IllegalAccessException; 21 | 22 | /** 23 | * Thrown when method invocation using the reflection API has thrown 24 | * an exception. 25 | * 26 | * @see javassist.tools.reflect.Metaobject#trapMethodcall(int, Object[]) 27 | * @see javassist.tools.reflect.ClassMetaobject#trapMethodcall(int, Object[]) 28 | * @see javassist.tools.reflect.ClassMetaobject#invoke(Object, int, Object[]) 29 | */ 30 | public class CannotInvokeException extends RuntimeException { 31 | 32 | private Throwable err = null; 33 | 34 | /** 35 | * Returns the cause of this exception. It may return null. 36 | */ 37 | public Throwable getReason() { return err; } 38 | 39 | /** 40 | * Constructs a CannotInvokeException with an error message. 41 | */ 42 | public CannotInvokeException(String reason) { 43 | super(reason); 44 | } 45 | 46 | /** 47 | * Constructs a CannotInvokeException with an InvocationTargetException. 48 | */ 49 | public CannotInvokeException(InvocationTargetException e) { 50 | super("by " + e.getTargetException().toString()); 51 | err = e.getTargetException(); 52 | } 53 | 54 | /** 55 | * Constructs a CannotInvokeException with an IllegalAccessException. 56 | */ 57 | public CannotInvokeException(IllegalAccessException e) { 58 | super("by " + e.toString()); 59 | err = e; 60 | } 61 | 62 | /** 63 | * Constructs a CannotInvokeException with an ClassNotFoundException. 64 | */ 65 | public CannotInvokeException(ClassNotFoundException e) { 66 | super("by " + e.toString()); 67 | err = e; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/javassist/bytecode/SourceFileAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | import java.io.DataInputStream; 20 | import java.io.IOException; 21 | import java.util.Map; 22 | 23 | /** 24 | * SourceFile_attribute. 25 | */ 26 | public class SourceFileAttribute extends AttributeInfo { 27 | /** 28 | * The name of this attribute "SourceFile". 29 | */ 30 | public static final String tag = "SourceFile"; 31 | 32 | SourceFileAttribute(ConstPool cp, int n, DataInputStream in) 33 | throws IOException 34 | { 35 | super(cp, n, in); 36 | } 37 | 38 | /** 39 | * Constructs a SourceFile attribute. 40 | * 41 | * @param cp a constant pool table. 42 | * @param filename the name of the source file. 43 | */ 44 | public SourceFileAttribute(ConstPool cp, String filename) { 45 | super(cp, tag); 46 | int index = cp.addUtf8Info(filename); 47 | byte[] bvalue = new byte[2]; 48 | bvalue[0] = (byte)(index >>> 8); 49 | bvalue[1] = (byte)index; 50 | set(bvalue); 51 | } 52 | 53 | /** 54 | * Returns the file name indicated by sourcefile_index. 55 | */ 56 | public String getFileName() { 57 | return getConstPool().getUtf8Info(ByteArray.readU16bit(get(), 0)); 58 | } 59 | 60 | /** 61 | * Makes a copy. Class names are replaced according to the 62 | * given Map object. 63 | * 64 | * @param newCp the constant pool table used by the new copy. 65 | * @param classnames pairs of replaced and substituted 66 | * class names. 67 | */ 68 | public AttributeInfo copy(ConstPool newCp, Map classnames) { 69 | return new SourceFileAttribute(newCp, getFileName()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/javassist/bytecode/ConstantAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | import java.io.DataInputStream; 20 | import java.util.Map; 21 | import java.io.IOException; 22 | 23 | /** 24 | * ConstantValue_attribute. 25 | */ 26 | public class ConstantAttribute extends AttributeInfo { 27 | /** 28 | * The name of this attribute "ConstantValue". 29 | */ 30 | public static final String tag = "ConstantValue"; 31 | 32 | ConstantAttribute(ConstPool cp, int n, DataInputStream in) 33 | throws IOException 34 | { 35 | super(cp, n, in); 36 | } 37 | 38 | /** 39 | * Constructs a ConstantValue attribute. 40 | * 41 | * @param cp a constant pool table. 42 | * @param index constantvalue_index 43 | * of ConstantValue_attribute. 44 | */ 45 | public ConstantAttribute(ConstPool cp, int index) { 46 | super(cp, tag); 47 | byte[] bvalue = new byte[2]; 48 | bvalue[0] = (byte)(index >>> 8); 49 | bvalue[1] = (byte)index; 50 | set(bvalue); 51 | } 52 | 53 | /** 54 | * Returns constantvalue_index. 55 | */ 56 | public int getConstantValue() { 57 | return ByteArray.readU16bit(get(), 0); 58 | } 59 | 60 | /** 61 | * Makes a copy. Class names are replaced according to the 62 | * given Map object. 63 | * 64 | * @param newCp the constant pool table used by the new copy. 65 | * @param classnames pairs of replaced and substituted 66 | * class names. 67 | */ 68 | public AttributeInfo copy(ConstPool newCp, Map classnames) { 69 | int index = getConstPool().copy(getConstantValue(), newCp, 70 | classnames); 71 | return new ConstantAttribute(newCp, index); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/NewExpr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.TokenId; 20 | import javassist.compiler.CompileError; 21 | 22 | /** 23 | * New Expression. 24 | */ 25 | public class NewExpr extends ASTList implements TokenId { 26 | protected boolean newArray; 27 | protected int arrayType; 28 | 29 | public NewExpr(ASTList className, ASTList args) { 30 | super(className, new ASTList(args)); 31 | newArray = false; 32 | arrayType = CLASS; 33 | } 34 | 35 | public NewExpr(int type, ASTList arraySize, ArrayInit init) { 36 | super(null, new ASTList(arraySize)); 37 | newArray = true; 38 | arrayType = type; 39 | if (init != null) 40 | append(this, init); 41 | } 42 | 43 | public static NewExpr makeObjectArray(ASTList className, 44 | ASTList arraySize, ArrayInit init) { 45 | NewExpr e = new NewExpr(className, arraySize); 46 | e.newArray = true; 47 | if (init != null) 48 | append(e, init); 49 | 50 | return e; 51 | } 52 | 53 | public boolean isArray() { return newArray; } 54 | 55 | /* TokenId.CLASS, TokenId.INT, ... 56 | */ 57 | public int getArrayType() { return arrayType; } 58 | 59 | public ASTList getClassName() { return (ASTList)getLeft(); } 60 | 61 | public ASTList getArguments() { return (ASTList)getRight().getLeft(); } 62 | 63 | public ASTList getArraySize() { return getArguments(); } 64 | 65 | public ArrayInit getInitializer() { 66 | ASTree t = getRight().getRight(); 67 | if (t == null) 68 | return null; 69 | else 70 | return (ArrayInit)t.getLeft(); 71 | } 72 | 73 | public void accept(Visitor v) throws CompileError { v.atNewExpr(this); } 74 | 75 | protected String getTag() { 76 | return newArray ? "new[]" : "new"; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/javassist/ClassPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | import java.io.InputStream; 20 | import java.net.URL; 21 | 22 | /** 23 | * ClassPath is an interface implemented by objects 24 | * representing a class search path. 25 | * ClassPool uses those objects for reading class files. 26 | * 27 | *

The users can define a class implementing this interface so that 28 | * a class file is obtained from a non-standard source. 29 | * 30 | * @see ClassPool#insertClassPath(ClassPath) 31 | * @see ClassPool#appendClassPath(ClassPath) 32 | * @see ClassPool#removeClassPath(ClassPath) 33 | */ 34 | public interface ClassPath { 35 | /** 36 | * Opens a class file. 37 | * This method may be called just to examine whether the class file 38 | * exists as well as to read the contents of the file. 39 | * 40 | *

This method can return null if the specified class file is not 41 | * found. If null is returned, the next search path is examined. 42 | * However, if an error happens, this method must throw an exception 43 | * so that the search will be terminated. 44 | * 45 | *

This method should not modify the contents of the class file. 46 | * 47 | * @param classname a fully-qualified class name 48 | * @return the input stream for reading a class file 49 | * @see javassist.Translator 50 | */ 51 | InputStream openClassfile(String classname) throws NotFoundException; 52 | 53 | /** 54 | * Returns the uniform resource locator (URL) of the class file 55 | * with the specified name. 56 | * 57 | * @param classname a fully-qualified class name. 58 | * @return null if the specified class file could not be found. 59 | */ 60 | URL find(String classname); 61 | 62 | /** 63 | * This method is invoked when the ClassPath object is 64 | * detached from the search path. It will be an empty method in most of 65 | * classes. 66 | */ 67 | void close(); 68 | } 69 | -------------------------------------------------------------------------------- /src/javassist/CtNewNestedClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | import javassist.bytecode.ClassFile; 20 | import javassist.bytecode.AccessFlag; 21 | import javassist.bytecode.InnerClassesAttribute; 22 | 23 | /** 24 | * A newly created public nested class. 25 | */ 26 | class CtNewNestedClass extends CtNewClass { 27 | CtNewNestedClass(String realName, ClassPool cp, boolean isInterface, 28 | CtClass superclass) { 29 | super(realName, cp, isInterface, superclass); 30 | } 31 | 32 | /** 33 | * This method does not change the STATIC bit. The original value is kept. 34 | */ 35 | public void setModifiers(int mod) { 36 | mod = mod & ~Modifier.STATIC; 37 | super.setModifiers(mod); 38 | updateInnerEntry(mod, getName(), this, true); 39 | } 40 | 41 | private static void updateInnerEntry(int mod, String name, CtClass clazz, boolean outer) { 42 | ClassFile cf = clazz.getClassFile2(); 43 | InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute( 44 | InnerClassesAttribute.tag); 45 | if (ica == null) 46 | return; 47 | 48 | int n = ica.tableLength(); 49 | for (int i = 0; i < n; i++) 50 | if (name.equals(ica.innerClass(i))) { 51 | int acc = ica.accessFlags(i) & AccessFlag.STATIC; 52 | ica.setAccessFlags(i, mod | acc); 53 | String outName = ica.outerClass(i); 54 | if (outName != null && outer) 55 | try { 56 | CtClass parent = clazz.getClassPool().get(outName); 57 | updateInnerEntry(mod, name, parent, false); 58 | } 59 | catch (NotFoundException e) { 60 | throw new RuntimeException("cannot find the declaring class: " 61 | + outName); 62 | } 63 | 64 | break; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/Expr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.TokenId; 20 | import javassist.compiler.CompileError; 21 | 22 | /** 23 | * Expression. 24 | */ 25 | public class Expr extends ASTList implements TokenId { 26 | /* operator must be either of: 27 | * (unary) +, (unary) -, ++, --, !, ~, 28 | * ARRAY, . (dot), MEMBER (static member access). 29 | * Otherwise, the object should be an instance of a subclass. 30 | */ 31 | 32 | protected int operatorId; 33 | 34 | Expr(int op, ASTree _head, ASTList _tail) { 35 | super(_head, _tail); 36 | operatorId = op; 37 | } 38 | 39 | Expr(int op, ASTree _head) { 40 | super(_head); 41 | operatorId = op; 42 | } 43 | 44 | public static Expr make(int op, ASTree oprand1, ASTree oprand2) { 45 | return new Expr(op, oprand1, new ASTList(oprand2)); 46 | } 47 | 48 | public static Expr make(int op, ASTree oprand1) { 49 | return new Expr(op, oprand1); 50 | } 51 | 52 | public int getOperator() { return operatorId; } 53 | 54 | public void setOperator(int op) { operatorId = op; } 55 | 56 | public ASTree oprand1() { return getLeft(); } 57 | 58 | public void setOprand1(ASTree expr) { 59 | setLeft(expr); 60 | } 61 | 62 | public ASTree oprand2() { return getRight().getLeft(); } 63 | 64 | public void setOprand2(ASTree expr) { 65 | getRight().setLeft(expr); 66 | } 67 | 68 | public void accept(Visitor v) throws CompileError { v.atExpr(this); } 69 | 70 | public String getName() { 71 | int id = operatorId; 72 | if (id < 128) 73 | return String.valueOf((char)id); 74 | else if (NEQ <= id && id <= ARSHIFT_E) 75 | return opNames[id - NEQ]; 76 | else if (id == INSTANCEOF) 77 | return "instanceof"; 78 | else 79 | return String.valueOf(id); 80 | } 81 | 82 | protected String getTag() { 83 | return "op:" + getName(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/javassist/bytecode/ByteArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode; 18 | 19 | /** 20 | * A collection of static methods for reading and writing a byte array. 21 | */ 22 | public class ByteArray { 23 | /** 24 | * Reads an unsigned 16bit integer at the index. 25 | */ 26 | public static int readU16bit(byte[] code, int index) { 27 | return ((code[index] & 0xff) << 8) | (code[index + 1] & 0xff); 28 | } 29 | 30 | /** 31 | * Reads a signed 16bit integer at the index. 32 | */ 33 | public static int readS16bit(byte[] code, int index) { 34 | return (code[index] << 8) | (code[index + 1] & 0xff); 35 | } 36 | 37 | /** 38 | * Writes a 16bit integer at the index. 39 | */ 40 | public static void write16bit(int value, byte[] code, int index) { 41 | code[index] = (byte)(value >>> 8); 42 | code[index + 1] = (byte)value; 43 | } 44 | 45 | /** 46 | * Reads a 32bit integer at the index. 47 | */ 48 | public static int read32bit(byte[] code, int index) { 49 | return (code[index] << 24) | ((code[index + 1] & 0xff) << 16) 50 | | ((code[index + 2] & 0xff) << 8) | (code[index + 3] & 0xff); 51 | } 52 | 53 | /** 54 | * Writes a 32bit integer at the index. 55 | */ 56 | public static void write32bit(int value, byte[] code, int index) { 57 | code[index] = (byte)(value >>> 24); 58 | code[index + 1] = (byte)(value >>> 16); 59 | code[index + 2] = (byte)(value >>> 8); 60 | code[index + 3] = (byte)value; 61 | } 62 | 63 | /** 64 | * Copies a 32bit integer. 65 | * 66 | * @param src the source byte array. 67 | * @param isrc the index into the source byte array. 68 | * @param dest the destination byte array. 69 | * @param idest the index into the destination byte array. 70 | */ 71 | static void copy32bit(byte[] src, int isrc, byte[] dest, int idest) { 72 | dest[idest] = src[isrc]; 73 | dest[idest + 1] = src[isrc + 1]; 74 | dest[idest + 2] = src[isrc + 2]; 75 | dest[idest + 3] = src[isrc + 3]; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/javassist/bytecode/MethodParametersAttribute.java: -------------------------------------------------------------------------------- 1 | package javassist.bytecode; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | import java.util.Map; 6 | 7 | /** 8 | * MethodParameters_attribute. 9 | */ 10 | public class MethodParametersAttribute extends AttributeInfo { 11 | /** 12 | * The name of this attribute "MethodParameters". 13 | */ 14 | public static final String tag = "MethodParameters"; 15 | 16 | MethodParametersAttribute(ConstPool cp, int n, DataInputStream in) 17 | throws IOException 18 | { 19 | super(cp, n, in); 20 | } 21 | 22 | /** 23 | * Constructs an attribute. 24 | * 25 | * @param cp a constant pool table. 26 | * @param names an array of parameter names. 27 | * The i-th element is the name of the i-th parameter. 28 | * @param flags an array of parameter access flags. 29 | */ 30 | public MethodParametersAttribute(ConstPool cp, String[] names, int[] flags) { 31 | super(cp, tag); 32 | byte[] data = new byte[names.length * 4 + 1]; 33 | data[0] = (byte)names.length; 34 | for (int i = 0; i < names.length; i++) { 35 | ByteArray.write16bit(cp.addUtf8Info(names[i]), data, i * 4 + 1); 36 | ByteArray.write16bit(flags[i], data, i * 4 + 3); 37 | } 38 | 39 | set(data); 40 | } 41 | 42 | /** 43 | * Returns parameters_count, which is the number of 44 | * parameters. 45 | */ 46 | public int size() { 47 | return info[0] & 0xff; 48 | } 49 | 50 | /** 51 | * Returns the value of name_index of the i-th element of parameters. 52 | * 53 | * @param i the position of the parameter. 54 | */ 55 | public int name(int i) { 56 | return ByteArray.readU16bit(info, i * 4 + 1); 57 | } 58 | 59 | /** 60 | * Returns the value of access_flags of the i-th element of parameters. 61 | * 62 | * @param i the position of the parameter. 63 | * @see AccessFlag 64 | */ 65 | public int accessFlags(int i) { 66 | return ByteArray.readU16bit(info, i * 4 + 3); 67 | } 68 | 69 | /** 70 | * Makes a copy. 71 | * 72 | * @param newCp the constant pool table used by the new copy. 73 | * @param classnames ignored. 74 | */ 75 | public AttributeInfo copy(ConstPool newCp, Map classnames) { 76 | int s = size(); 77 | ConstPool cp = getConstPool(); 78 | String[] names = new String[s]; 79 | int[] flags = new int[s]; 80 | for (int i = 0; i < s; i++) { 81 | names[i] = cp.getUtf8Info(name(i)); 82 | flags[i] = accessFlags(i); 83 | } 84 | 85 | return new MethodParametersAttribute(newCp, names, flags); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/AnnotationMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.bytecode.annotation; 17 | 18 | import javassist.ClassPool; 19 | import javassist.bytecode.ConstPool; 20 | import java.io.IOException; 21 | import java.lang.reflect.Method; 22 | 23 | /** 24 | * Nested annotation. 25 | * 26 | * @author Bill Burke 27 | * @author Shigeru Chiba 28 | */ 29 | public class AnnotationMemberValue extends MemberValue { 30 | Annotation value; 31 | 32 | /** 33 | * Constructs an annotation member. The initial value is not specified. 34 | */ 35 | public AnnotationMemberValue(ConstPool cp) { 36 | this(null, cp); 37 | } 38 | 39 | /** 40 | * Constructs an annotation member. The initial value is specified by 41 | * the first parameter. 42 | */ 43 | public AnnotationMemberValue(Annotation a, ConstPool cp) { 44 | super('@', cp); 45 | value = a; 46 | } 47 | 48 | Object getValue(ClassLoader cl, ClassPool cp, Method m) 49 | throws ClassNotFoundException 50 | { 51 | return AnnotationImpl.make(cl, getType(cl), cp, value); 52 | } 53 | 54 | Class getType(ClassLoader cl) throws ClassNotFoundException { 55 | if (value == null) 56 | throw new ClassNotFoundException("no type specified"); 57 | else 58 | return loadClass(cl, value.getTypeName()); 59 | } 60 | 61 | /** 62 | * Obtains the value. 63 | */ 64 | public Annotation getValue() { 65 | return value; 66 | } 67 | 68 | /** 69 | * Sets the value of this member. 70 | */ 71 | public void setValue(Annotation newValue) { 72 | value = newValue; 73 | } 74 | 75 | /** 76 | * Obtains the string representation of this object. 77 | */ 78 | public String toString() { 79 | return value.toString(); 80 | } 81 | 82 | /** 83 | * Writes the value. 84 | */ 85 | public void write(AnnotationsWriter writer) throws IOException { 86 | writer.annotationValue(); 87 | value.write(writer); 88 | } 89 | 90 | /** 91 | * Accepts a visitor. 92 | */ 93 | public void accept(MemberValueVisitor visitor) { 94 | visitor.visitAnnotationMemberValue(this); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/javassist/scopedpool/ScopedClassPoolRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.scopedpool; 18 | 19 | import java.util.Map; 20 | 21 | import javassist.ClassPool; 22 | 23 | /** 24 | * An interface to ScopedClassPoolRepositoryImpl. 25 | * 26 | * @author Kabir Khan 27 | * @version $Revision: 1.4 $ 28 | */ 29 | public interface ScopedClassPoolRepository { 30 | /** 31 | * Records a factory. 32 | */ 33 | void setClassPoolFactory(ScopedClassPoolFactory factory); 34 | 35 | /** 36 | * Obtains the recorded factory. 37 | */ 38 | ScopedClassPoolFactory getClassPoolFactory(); 39 | 40 | /** 41 | * Returns whether or not the class pool is pruned. 42 | * 43 | * @return the prune. 44 | */ 45 | boolean isPrune(); 46 | 47 | /** 48 | * Sets the prune flag. 49 | * 50 | * @param prune a new value. 51 | */ 52 | void setPrune(boolean prune); 53 | 54 | /** 55 | * Create a scoped classpool. 56 | * 57 | * @param cl the classloader. 58 | * @param src the original classpool. 59 | * @return the classpool. 60 | */ 61 | ScopedClassPool createScopedClassPool(ClassLoader cl, ClassPool src); 62 | 63 | /** 64 | * Finds a scoped classpool registered under the passed in classloader. 65 | * 66 | * @param cl the classloader. 67 | * @return the classpool. 68 | */ 69 | ClassPool findClassPool(ClassLoader cl); 70 | 71 | /** 72 | * Register a classloader. 73 | * 74 | * @param ucl the classloader. 75 | * @return the classpool. 76 | */ 77 | ClassPool registerClassLoader(ClassLoader ucl); 78 | 79 | /** 80 | * Get the registered classloaders. 81 | * 82 | * @return the registered classloaders. 83 | */ 84 | Map getRegisteredCLs(); 85 | 86 | /** 87 | * This method will check to see if a register classloader has been 88 | * undeployed (as in JBoss). 89 | */ 90 | void clearUnregisteredClassLoaders(); 91 | 92 | /** 93 | * Unregisters a classpool and unregisters its classloader. 94 | * 95 | * @param cl the classloader the pool is stored under. 96 | */ 97 | void unregisterClassLoader(ClassLoader cl); 98 | } 99 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/MemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import javassist.bytecode.Descriptor; 22 | 23 | import java.io.IOException; 24 | import java.lang.reflect.Array; 25 | import java.lang.reflect.Method; 26 | 27 | /** 28 | * The value of a member declared in an annotation. 29 | * 30 | * @see Annotation#getMemberValue(String) 31 | * @author Bill Burke 32 | * @author Shigeru Chiba 33 | */ 34 | public abstract class MemberValue { 35 | ConstPool cp; 36 | char tag; 37 | 38 | MemberValue(char tag, ConstPool cp) { 39 | this.cp = cp; 40 | this.tag = tag; 41 | } 42 | 43 | /** 44 | * Returns the value. If the value type is a primitive type, the 45 | * returned value is boxed. 46 | */ 47 | abstract Object getValue(ClassLoader cl, ClassPool cp, Method m) 48 | throws ClassNotFoundException; 49 | 50 | abstract Class getType(ClassLoader cl) throws ClassNotFoundException; 51 | 52 | static Class loadClass(ClassLoader cl, String classname) 53 | throws ClassNotFoundException, NoSuchClassError 54 | { 55 | try { 56 | return Class.forName(convertFromArray(classname), true, cl); 57 | } 58 | catch (LinkageError e) { 59 | throw new NoSuchClassError(classname, e); 60 | } 61 | } 62 | 63 | private static String convertFromArray(String classname) 64 | { 65 | int index = classname.indexOf("[]"); 66 | if (index != -1) { 67 | String rawType = classname.substring(0, index); 68 | StringBuffer sb = new StringBuffer(Descriptor.of(rawType)); 69 | while (index != -1) { 70 | sb.insert(0, "["); 71 | index = classname.indexOf("[]", index + 1); 72 | } 73 | return sb.toString().replace('/', '.'); 74 | } 75 | return classname; 76 | } 77 | 78 | /** 79 | * Accepts a visitor. 80 | */ 81 | public abstract void accept(MemberValueVisitor visitor); 82 | 83 | /** 84 | * Writes the value. 85 | */ 86 | public abstract void write(AnnotationsWriter w) throws IOException; 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/com/binklac/tools/javadumper/JavaDumper.java: -------------------------------------------------------------------------------- 1 | package com.binklac.tools.javadumper; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.instrument.Instrumentation; 6 | 7 | import javassist.CannotCompileException; 8 | import javassist.ClassPool; 9 | import javassist.CtClass; 10 | import javassist.NotFoundException; 11 | 12 | public class JavaDumper { 13 | private static final String helpMessage = "\nUseage: \n\tJava {all your javaagent, agentlib, agentpath} -javaagent:JavaDumper.jar=; {other} \nE.g.:\n\tjava -javaagent:JavaDumper.jar=java.lang.Shutdown;Shutdown.class -jar JavaDumper.jar"; 14 | 15 | private static boolean checkArgs(String[] Args){ 16 | File file = null; 17 | 18 | if(Args == null || Args.length != 2){ 19 | System.err.println("Parameter error : You must provide two parameters."); 20 | return false; 21 | } 22 | file = new File(Args[1]); 23 | if(file.exists()){ 24 | if(file.isDirectory()){ 25 | System.err.println("Parameter error : The save location can not be a folder."); 26 | return false; 27 | } else { 28 | if(!file.canWrite()){ 29 | System.err.println("IO error : Attempt to modify target file failed."); 30 | return false; 31 | }else{ 32 | if(!file.delete()){ 33 | System.err.println("IO error : Can not delete existing files."); 34 | return false; 35 | } 36 | } 37 | } 38 | } else { 39 | try { 40 | if(!file.getCanonicalFile().getParentFile().exists()){ 41 | if(!file.getCanonicalFile().getParentFile().mkdirs()){ 42 | System.err.println("IO error : Can not create parent path."); 43 | return false; 44 | } 45 | } 46 | if(!file.createNewFile()){ 47 | System.err.println("IO error : Can not create target file."); 48 | return false; 49 | } 50 | 51 | } catch (IOException e) { 52 | System.err.println("IO error : " + e.getMessage()); 53 | return false; 54 | } 55 | } 56 | return true; 57 | 58 | } 59 | 60 | public static void main(String[] args) { 61 | System.out.println(helpMessage); 62 | } 63 | 64 | public static void premain(String agentArgs, Instrumentation inst){ 65 | String[] Args = agentArgs.split(";"); 66 | 67 | if(checkArgs(Args)){ 68 | for(@SuppressWarnings("rawtypes") Class clazz :inst.getAllLoadedClasses()){ 69 | if(clazz.getName().equals(Args[0])){ 70 | ClassPool classPool = ClassPool.getDefault(); 71 | try { 72 | CtClass getedClass = classPool.getCtClass(Args[0]); 73 | OnLoadTransformer.write2File(Args[1], getedClass.toBytecode()); 74 | System.out.println("The class <" + Args[0] + "> already loaded, save it to <" + Args[1] + ">"); 75 | } catch (NotFoundException | RuntimeException | IOException | CannotCompileException e) { 76 | e.printStackTrace(); 77 | } 78 | return; 79 | } 80 | 81 | } 82 | System.out.println("Waiting for class <" + Args[0] + "> load ..."); 83 | inst.addTransformer(new OnLoadTransformer(Args[0], Args[1])); 84 | } else { 85 | System.out.println(helpMessage); 86 | } 87 | 88 | } 89 | 90 | } 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/javassist/util/proxy/ProxyObjectOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.util.proxy; 18 | 19 | import java.io.IOException; 20 | import java.io.ObjectOutputStream; 21 | import java.io.ObjectStreamClass; 22 | import java.io.OutputStream; 23 | 24 | /** 25 | * An input stream class which knows how to serialize proxies created via {@link ProxyFactory}. It must 26 | * be used when serialising proxies created from a proxy factory configured with 27 | * {@link ProxyFactory#useWriteReplace} set to false. Subsequent deserialization of the serialized data 28 | * must employ a {@link ProxyObjectInputStream} 29 | * 30 | * @author Andrew Dinn 31 | */ 32 | public class ProxyObjectOutputStream extends ObjectOutputStream 33 | { 34 | /** 35 | * create an output stream which can be used to serialize an object graph which includes proxies created 36 | * using class ProxyFactory 37 | * @param out 38 | * @throws IOException whenever ObjectOutputStream would also do so 39 | * @throws SecurityException whenever ObjectOutputStream would also do so 40 | * @throws NullPointerException if out is null 41 | */ 42 | public ProxyObjectOutputStream(OutputStream out) throws IOException 43 | { 44 | super(out); 45 | } 46 | 47 | protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { 48 | Class cl = desc.forClass(); 49 | if (ProxyFactory.isProxyClass(cl)) { 50 | writeBoolean(true); 51 | Class superClass = cl.getSuperclass(); 52 | Class[] interfaces = cl.getInterfaces(); 53 | byte[] signature = ProxyFactory.getFilterSignature(cl); 54 | String name = superClass.getName(); 55 | writeObject(name); 56 | // we don't write the marker interface ProxyObject 57 | writeInt(interfaces.length - 1); 58 | for (int i = 0; i < interfaces.length; i++) { 59 | Class interfaze = interfaces[i]; 60 | if (interfaze != ProxyObject.class && interfaze != Proxy.class) { 61 | name = interfaces[i].getName(); 62 | writeObject(name); 63 | } 64 | } 65 | writeInt(signature.length); 66 | write(signature); 67 | } else { 68 | writeBoolean(false); 69 | super.writeClassDescriptor(desc); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/javassist/Translator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | /** 20 | * An observer of Loader. 21 | * The users can define a class implementing this 22 | * interface and attach an instance of that class to a 23 | * Loader object so that it can translate a class file 24 | * when the class file is loaded into the JVM. 25 | * 26 | * @see Loader#addTranslator(ClassPool, Translator) 27 | */ 28 | public interface Translator { 29 | /** 30 | * Is invoked by a Loader for initialization 31 | * when the object is attached to the Loader object. 32 | * This method can be used for getting (for caching) some 33 | * CtClass objects that will be accessed 34 | * in onLoad() in Translator. 35 | * 36 | * @param pool the ClassPool that this translator 37 | * should use. 38 | * @see Loader 39 | * @throws NotFoundException if a CtClass cannot be found. 40 | * @throws CannotCompileException if the initialization by this method 41 | * fails. 42 | */ 43 | void start(ClassPool pool) 44 | throws NotFoundException, CannotCompileException; 45 | 46 | /** 47 | * Is invoked by a Loader for notifying that 48 | * a class is loaded. The Loader calls 49 | * 50 | *

51 |      * pool.get(classname).toBytecode()
52 | * 53 | * to read the class file after onLoad() returns. 54 | * 55 | *

classname may be the name of a class 56 | * that has not been created yet. 57 | * If so, onLoad() must create that class so that 58 | * the Loader can read it after onLoad() 59 | * returns. 60 | * 61 | * @param pool the ClassPool that this translator 62 | * should use. 63 | * @param classname the name of the class being loaded. 64 | * @see Loader 65 | * @throws NotFoundException if a CtClass cannot be found. 66 | * @throws CannotCompileException if the code transformation 67 | * by this method fails. 68 | */ 69 | void onLoad(ClassPool pool, String classname) 70 | throws NotFoundException, CannotCompileException; 71 | } 72 | -------------------------------------------------------------------------------- /src/javassist/convert/TransformNewClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.bytecode.*; 20 | import javassist.CtClass; 21 | import javassist.CannotCompileException; 22 | 23 | final public class TransformNewClass extends Transformer { 24 | private int nested; 25 | private String classname, newClassName; 26 | private int newClassIndex, newMethodNTIndex, newMethodIndex; 27 | 28 | public TransformNewClass(Transformer next, 29 | String classname, String newClassName) { 30 | super(next); 31 | this.classname = classname; 32 | this.newClassName = newClassName; 33 | } 34 | 35 | public void initialize(ConstPool cp, CodeAttribute attr) { 36 | nested = 0; 37 | newClassIndex = newMethodNTIndex = newMethodIndex = 0; 38 | } 39 | 40 | /** 41 | * Modifies a sequence of 42 | * NEW classname 43 | * DUP 44 | * ... 45 | * INVOKESPECIAL classname:method 46 | */ 47 | public int transform(CtClass clazz, int pos, CodeIterator iterator, 48 | ConstPool cp) throws CannotCompileException 49 | { 50 | int index; 51 | int c = iterator.byteAt(pos); 52 | if (c == NEW) { 53 | index = iterator.u16bitAt(pos + 1); 54 | if (cp.getClassInfo(index).equals(classname)) { 55 | if (iterator.byteAt(pos + 3) != DUP) 56 | throw new CannotCompileException( 57 | "NEW followed by no DUP was found"); 58 | 59 | if (newClassIndex == 0) 60 | newClassIndex = cp.addClassInfo(newClassName); 61 | 62 | iterator.write16bit(newClassIndex, pos + 1); 63 | ++nested; 64 | } 65 | } 66 | else if (c == INVOKESPECIAL) { 67 | index = iterator.u16bitAt(pos + 1); 68 | int typedesc = cp.isConstructor(classname, index); 69 | if (typedesc != 0 && nested > 0) { 70 | int nt = cp.getMethodrefNameAndType(index); 71 | if (newMethodNTIndex != nt) { 72 | newMethodNTIndex = nt; 73 | newMethodIndex = cp.addMethodrefInfo(newClassIndex, nt); 74 | } 75 | 76 | iterator.write16bit(newMethodIndex, pos + 1); 77 | --nested; 78 | } 79 | } 80 | 81 | return pos; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/javassist/compiler/ast/DoubleConst.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.compiler.ast; 18 | 19 | import javassist.compiler.CompileError; 20 | import javassist.compiler.TokenId; 21 | 22 | /** 23 | * Double constant. 24 | */ 25 | public class DoubleConst extends ASTree { 26 | protected double value; 27 | protected int type; 28 | 29 | public DoubleConst(double v, int tokenId) { value = v; type = tokenId; } 30 | 31 | public double get() { return value; } 32 | 33 | public void set(double v) { value = v; } 34 | 35 | /* Returns DoubleConstant or FloatConstant 36 | */ 37 | public int getType() { return type; } 38 | 39 | public String toString() { return Double.toString(value); } 40 | 41 | public void accept(Visitor v) throws CompileError { 42 | v.atDoubleConst(this); 43 | } 44 | 45 | public ASTree compute(int op, ASTree right) { 46 | if (right instanceof IntConst) 47 | return compute0(op, (IntConst)right); 48 | else if (right instanceof DoubleConst) 49 | return compute0(op, (DoubleConst)right); 50 | else 51 | return null; 52 | } 53 | 54 | private DoubleConst compute0(int op, DoubleConst right) { 55 | int newType; 56 | if (this.type == TokenId.DoubleConstant 57 | || right.type == TokenId.DoubleConstant) 58 | newType = TokenId.DoubleConstant; 59 | else 60 | newType = TokenId.FloatConstant; 61 | 62 | return compute(op, this.value, right.value, newType); 63 | } 64 | 65 | private DoubleConst compute0(int op, IntConst right) { 66 | return compute(op, this.value, (double)right.value, this.type); 67 | } 68 | 69 | private static DoubleConst compute(int op, double value1, double value2, 70 | int newType) 71 | { 72 | double newValue; 73 | switch (op) { 74 | case '+' : 75 | newValue = value1 + value2; 76 | break; 77 | case '-' : 78 | newValue = value1 - value2; 79 | break; 80 | case '*' : 81 | newValue = value1 * value2; 82 | break; 83 | case '/' : 84 | newValue = value1 / value2; 85 | break; 86 | case '%' : 87 | newValue = value1 % value2; 88 | break; 89 | default : 90 | return null; 91 | } 92 | 93 | return new DoubleConst(newValue, newType); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/javassist/convert/TransformWriteField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.CtClass; 20 | import javassist.CtField; 21 | import javassist.bytecode.*; 22 | 23 | final public class TransformWriteField extends TransformReadField { 24 | public TransformWriteField(Transformer next, CtField field, 25 | String methodClassname, String methodName) 26 | { 27 | super(next, field, methodClassname, methodName); 28 | } 29 | 30 | public int transform(CtClass tclazz, int pos, CodeIterator iterator, 31 | ConstPool cp) throws BadBytecode 32 | { 33 | int c = iterator.byteAt(pos); 34 | if (c == PUTFIELD || c == PUTSTATIC) { 35 | int index = iterator.u16bitAt(pos + 1); 36 | String typedesc = isField(tclazz.getClassPool(), cp, 37 | fieldClass, fieldname, isPrivate, index); 38 | if (typedesc != null) { 39 | if (c == PUTSTATIC) { 40 | CodeAttribute ca = iterator.get(); 41 | iterator.move(pos); 42 | char c0 = typedesc.charAt(0); 43 | if (c0 == 'J' || c0 == 'D') { // long or double 44 | // insertGap() may insert 4 bytes. 45 | pos = iterator.insertGap(3); 46 | iterator.writeByte(ACONST_NULL, pos); 47 | iterator.writeByte(DUP_X2, pos + 1); 48 | iterator.writeByte(POP, pos + 2); 49 | ca.setMaxStack(ca.getMaxStack() + 2); 50 | } 51 | else { 52 | // insertGap() may insert 4 bytes. 53 | pos = iterator.insertGap(2); 54 | iterator.writeByte(ACONST_NULL, pos); 55 | iterator.writeByte(SWAP, pos + 1); 56 | ca.setMaxStack(ca.getMaxStack() + 1); 57 | } 58 | 59 | pos = iterator.next(); 60 | } 61 | 62 | int mi = cp.addClassInfo(methodClassname); 63 | String type = "(Ljava/lang/Object;" + typedesc + ")V"; 64 | int methodref = cp.addMethodrefInfo(mi, methodName, type); 65 | iterator.writeByte(INVOKESTATIC, pos); 66 | iterator.write16bit(methodref, pos + 1); 67 | } 68 | } 69 | 70 | return pos; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/javassist/convert/TransformFieldAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.bytecode.*; 20 | import javassist.CtClass; 21 | import javassist.CtField; 22 | import javassist.Modifier; 23 | 24 | final public class TransformFieldAccess extends Transformer { 25 | private String newClassname, newFieldname; 26 | private String fieldname; 27 | private CtClass fieldClass; 28 | private boolean isPrivate; 29 | 30 | /* cache */ 31 | private int newIndex; 32 | private ConstPool constPool; 33 | 34 | public TransformFieldAccess(Transformer next, CtField field, 35 | String newClassname, String newFieldname) 36 | { 37 | super(next); 38 | this.fieldClass = field.getDeclaringClass(); 39 | this.fieldname = field.getName(); 40 | this.isPrivate = Modifier.isPrivate(field.getModifiers()); 41 | this.newClassname = newClassname; 42 | this.newFieldname = newFieldname; 43 | this.constPool = null; 44 | } 45 | 46 | public void initialize(ConstPool cp, CodeAttribute attr) { 47 | if (constPool != cp) 48 | newIndex = 0; 49 | } 50 | 51 | /** 52 | * Modify GETFIELD, GETSTATIC, PUTFIELD, and PUTSTATIC so that 53 | * a different field is accessed. The new field must be declared 54 | * in a superclass of the class in which the original field is 55 | * declared. 56 | */ 57 | public int transform(CtClass clazz, int pos, 58 | CodeIterator iterator, ConstPool cp) 59 | { 60 | int c = iterator.byteAt(pos); 61 | if (c == GETFIELD || c == GETSTATIC 62 | || c == PUTFIELD || c == PUTSTATIC) { 63 | int index = iterator.u16bitAt(pos + 1); 64 | String typedesc 65 | = TransformReadField.isField(clazz.getClassPool(), cp, 66 | fieldClass, fieldname, isPrivate, index); 67 | if (typedesc != null) { 68 | if (newIndex == 0) { 69 | int nt = cp.addNameAndTypeInfo(newFieldname, 70 | typedesc); 71 | newIndex = cp.addFieldrefInfo( 72 | cp.addClassInfo(newClassname), nt); 73 | constPool = cp; 74 | } 75 | 76 | iterator.write16bit(newIndex, pos + 1); 77 | } 78 | } 79 | 80 | return pos; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/LongMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Long integer constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | */ 30 | public class LongMemberValue extends MemberValue { 31 | int valueIndex; 32 | 33 | /** 34 | * Constructs a long constant value. The initial value is specified 35 | * by the constant pool entry at the given index. 36 | * 37 | * @param index the index of a CONSTANT_Long_info structure. 38 | */ 39 | public LongMemberValue(int index, ConstPool cp) { 40 | super('J', cp); 41 | this.valueIndex = index; 42 | } 43 | 44 | /** 45 | * Constructs a long constant value. 46 | * 47 | * @param j the initial value. 48 | */ 49 | public LongMemberValue(long j, ConstPool cp) { 50 | super('J', cp); 51 | setValue(j); 52 | } 53 | 54 | /** 55 | * Constructs a long constant value. The initial value is 0. 56 | */ 57 | public LongMemberValue(ConstPool cp) { 58 | super('J', cp); 59 | setValue(0L); 60 | } 61 | 62 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 63 | return Long.valueOf(getValue()); 64 | } 65 | 66 | Class getType(ClassLoader cl) { 67 | return long.class; 68 | } 69 | 70 | /** 71 | * Obtains the value of the member. 72 | */ 73 | public long getValue() { 74 | return cp.getLongInfo(valueIndex); 75 | } 76 | 77 | /** 78 | * Sets the value of the member. 79 | */ 80 | public void setValue(long newValue) { 81 | valueIndex = cp.addLongInfo(newValue); 82 | } 83 | 84 | /** 85 | * Obtains the string representation of this object. 86 | */ 87 | public String toString() { 88 | return Long.toString(getValue()); 89 | } 90 | 91 | /** 92 | * Writes the value. 93 | */ 94 | public void write(AnnotationsWriter writer) throws IOException { 95 | writer.constValueIndex(getValue()); 96 | } 97 | 98 | /** 99 | * Accepts a visitor. 100 | */ 101 | public void accept(MemberValueVisitor visitor) { 102 | visitor.visitLongMemberValue(this); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/ByteMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.bytecode.annotation; 17 | 18 | import javassist.ClassPool; 19 | import javassist.bytecode.ConstPool; 20 | import java.io.IOException; 21 | import java.lang.reflect.Method; 22 | 23 | /** 24 | * Byte constant value. 25 | * 26 | * @author Bill Burke 27 | * @author Shigeru Chiba 28 | */ 29 | public class ByteMemberValue extends MemberValue { 30 | int valueIndex; 31 | 32 | /** 33 | * Constructs a byte constant value. The initial value is specified 34 | * by the constant pool entry at the given index. 35 | * 36 | * @param index the index of a CONSTANT_Integer_info structure. 37 | */ 38 | public ByteMemberValue(int index, ConstPool cp) { 39 | super('B', cp); 40 | this.valueIndex = index; 41 | } 42 | 43 | /** 44 | * Constructs a byte constant value. 45 | * 46 | * @param b the initial value. 47 | */ 48 | public ByteMemberValue(byte b, ConstPool cp) { 49 | super('B', cp); 50 | setValue(b); 51 | } 52 | 53 | /** 54 | * Constructs a byte constant value. The initial value is 0. 55 | */ 56 | public ByteMemberValue(ConstPool cp) { 57 | super('B', cp); 58 | setValue((byte)0); 59 | } 60 | 61 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 62 | return Byte.valueOf(getValue()); 63 | } 64 | 65 | Class getType(ClassLoader cl) { 66 | return byte.class; 67 | } 68 | 69 | /** 70 | * Obtains the value of the member. 71 | */ 72 | public byte getValue() { 73 | return (byte)cp.getIntegerInfo(valueIndex); 74 | } 75 | 76 | /** 77 | * Sets the value of the member. 78 | */ 79 | public void setValue(byte newValue) { 80 | valueIndex = cp.addIntegerInfo(newValue); 81 | } 82 | 83 | /** 84 | * Obtains the string representation of this object. 85 | */ 86 | public String toString() { 87 | return Byte.toString(getValue()); 88 | } 89 | 90 | /** 91 | * Writes the value. 92 | */ 93 | public void write(AnnotationsWriter writer) throws IOException { 94 | writer.constValueIndex(getValue()); 95 | } 96 | 97 | /** 98 | * Accepts a visitor. 99 | */ 100 | public void accept(MemberValueVisitor visitor) { 101 | visitor.visitByteMemberValue(this); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/StringMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * String constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | */ 30 | public class StringMemberValue extends MemberValue { 31 | int valueIndex; 32 | 33 | /** 34 | * Constructs a string constant value. The initial value is specified 35 | * by the constant pool entry at the given index. 36 | * 37 | * @param index the index of a CONSTANT_Utf8_info structure. 38 | */ 39 | public StringMemberValue(int index, ConstPool cp) { 40 | super('s', cp); 41 | this.valueIndex = index; 42 | } 43 | 44 | /** 45 | * Constructs a string constant value. 46 | * 47 | * @param str the initial value. 48 | */ 49 | public StringMemberValue(String str, ConstPool cp) { 50 | super('s', cp); 51 | setValue(str); 52 | } 53 | 54 | /** 55 | * Constructs a string constant value. The initial value is "". 56 | */ 57 | public StringMemberValue(ConstPool cp) { 58 | super('s', cp); 59 | setValue(""); 60 | } 61 | 62 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 63 | return getValue(); 64 | } 65 | 66 | Class getType(ClassLoader cl) { 67 | return String.class; 68 | } 69 | 70 | /** 71 | * Obtains the value of the member. 72 | */ 73 | public String getValue() { 74 | return cp.getUtf8Info(valueIndex); 75 | } 76 | 77 | /** 78 | * Sets the value of the member. 79 | */ 80 | public void setValue(String newValue) { 81 | valueIndex = cp.addUtf8Info(newValue); 82 | } 83 | 84 | /** 85 | * Obtains the string representation of this object. 86 | */ 87 | public String toString() { 88 | return "\"" + getValue() + "\""; 89 | } 90 | 91 | /** 92 | * Writes the value. 93 | */ 94 | public void write(AnnotationsWriter writer) throws IOException { 95 | writer.constValueIndex(getValue()); 96 | } 97 | 98 | /** 99 | * Accepts a visitor. 100 | */ 101 | public void accept(MemberValueVisitor visitor) { 102 | visitor.visitStringMemberValue(this); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/CharMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Char constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | */ 30 | public class CharMemberValue extends MemberValue { 31 | int valueIndex; 32 | 33 | /** 34 | * Constructs a char constant value. The initial value is specified 35 | * by the constant pool entry at the given index. 36 | * 37 | * @param index the index of a CONSTANT_Integer_info structure. 38 | */ 39 | public CharMemberValue(int index, ConstPool cp) { 40 | super('C', cp); 41 | this.valueIndex = index; 42 | } 43 | 44 | /** 45 | * Constructs a char constant value. 46 | * 47 | * @param c the initial value. 48 | */ 49 | public CharMemberValue(char c, ConstPool cp) { 50 | super('C', cp); 51 | setValue(c); 52 | } 53 | 54 | /** 55 | * Constructs a char constant value. The initial value is '\0'. 56 | */ 57 | public CharMemberValue(ConstPool cp) { 58 | super('C', cp); 59 | setValue('\0'); 60 | } 61 | 62 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 63 | return Character.valueOf(getValue()); 64 | } 65 | 66 | Class getType(ClassLoader cl) { 67 | return char.class; 68 | } 69 | 70 | /** 71 | * Obtains the value of the member. 72 | */ 73 | public char getValue() { 74 | return (char)cp.getIntegerInfo(valueIndex); 75 | } 76 | 77 | /** 78 | * Sets the value of the member. 79 | */ 80 | public void setValue(char newValue) { 81 | valueIndex = cp.addIntegerInfo(newValue); 82 | } 83 | 84 | /** 85 | * Obtains the string representation of this object. 86 | */ 87 | public String toString() { 88 | return Character.toString(getValue()); 89 | } 90 | 91 | /** 92 | * Writes the value. 93 | */ 94 | public void write(AnnotationsWriter writer) throws IOException { 95 | writer.constValueIndex(getValue()); 96 | } 97 | 98 | /** 99 | * Accepts a visitor. 100 | */ 101 | public void accept(MemberValueVisitor visitor) { 102 | visitor.visitCharMemberValue(this); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/ShortMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Short integer constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | */ 30 | public class ShortMemberValue extends MemberValue { 31 | int valueIndex; 32 | 33 | /** 34 | * Constructs a short constant value. The initial value is specified 35 | * by the constant pool entry at the given index. 36 | * 37 | * @param index the index of a CONSTANT_Integer_info structure. 38 | */ 39 | public ShortMemberValue(int index, ConstPool cp) { 40 | super('S', cp); 41 | this.valueIndex = index; 42 | } 43 | 44 | /** 45 | * Constructs a short constant value. 46 | * 47 | * @param s the initial value. 48 | */ 49 | public ShortMemberValue(short s, ConstPool cp) { 50 | super('S', cp); 51 | setValue(s); 52 | } 53 | 54 | /** 55 | * Constructs a short constant value. The initial value is 0. 56 | */ 57 | public ShortMemberValue(ConstPool cp) { 58 | super('S', cp); 59 | setValue((short)0); 60 | } 61 | 62 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 63 | return Short.valueOf(getValue()); 64 | } 65 | 66 | Class getType(ClassLoader cl) { 67 | return short.class; 68 | } 69 | 70 | /** 71 | * Obtains the value of the member. 72 | */ 73 | public short getValue() { 74 | return (short)cp.getIntegerInfo(valueIndex); 75 | } 76 | 77 | /** 78 | * Sets the value of the member. 79 | */ 80 | public void setValue(short newValue) { 81 | valueIndex = cp.addIntegerInfo(newValue); 82 | } 83 | 84 | /** 85 | * Obtains the string representation of this object. 86 | */ 87 | public String toString() { 88 | return Short.toString(getValue()); 89 | } 90 | 91 | /** 92 | * Writes the value. 93 | */ 94 | public void write(AnnotationsWriter writer) throws IOException { 95 | writer.constValueIndex(getValue()); 96 | } 97 | 98 | /** 99 | * Accepts a visitor. 100 | */ 101 | public void accept(MemberValueVisitor visitor) { 102 | visitor.visitShortMemberValue(this); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/BooleanMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | package javassist.bytecode.annotation; 17 | 18 | import javassist.ClassPool; 19 | import javassist.bytecode.ConstPool; 20 | import java.io.IOException; 21 | import java.lang.reflect.Method; 22 | 23 | /** 24 | * Boolean constant value. 25 | * 26 | * @author Bill Burke 27 | * @author Shigeru Chiba 28 | */ 29 | public class BooleanMemberValue extends MemberValue { 30 | int valueIndex; 31 | 32 | /** 33 | * Constructs a boolean constant value. The initial value is specified 34 | * by the constant pool entry at the given index. 35 | * 36 | * @param index the index of a CONSTANT_Integer_info structure. 37 | */ 38 | public BooleanMemberValue(int index, ConstPool cp) { 39 | super('Z', cp); 40 | this.valueIndex = index; 41 | } 42 | 43 | /** 44 | * Constructs a boolean constant value. 45 | * 46 | * @param b the initial value. 47 | */ 48 | public BooleanMemberValue(boolean b, ConstPool cp) { 49 | super('Z', cp); 50 | setValue(b); 51 | } 52 | 53 | /** 54 | * Constructs a boolean constant value. The initial value is false. 55 | */ 56 | public BooleanMemberValue(ConstPool cp) { 57 | super('Z', cp); 58 | setValue(false); 59 | } 60 | 61 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 62 | return Boolean.valueOf(getValue()); 63 | } 64 | 65 | Class getType(ClassLoader cl) { 66 | return boolean.class; 67 | } 68 | 69 | /** 70 | * Obtains the value of the member. 71 | */ 72 | public boolean getValue() { 73 | return cp.getIntegerInfo(valueIndex) != 0; 74 | } 75 | 76 | /** 77 | * Sets the value of the member. 78 | */ 79 | public void setValue(boolean newValue) { 80 | valueIndex = cp.addIntegerInfo(newValue ? 1 : 0); 81 | } 82 | 83 | /** 84 | * Obtains the string representation of this object. 85 | */ 86 | public String toString() { 87 | return getValue() ? "true" : "false"; 88 | } 89 | 90 | /** 91 | * Writes the value. 92 | */ 93 | public void write(AnnotationsWriter writer) throws IOException { 94 | writer.constValueIndex(getValue()); 95 | } 96 | 97 | /** 98 | * Accepts a visitor. 99 | */ 100 | public void accept(MemberValueVisitor visitor) { 101 | visitor.visitBooleanMemberValue(this); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/FloatMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Floating-point number constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | * @version $Revision: 1.7 $ 30 | */ 31 | public class FloatMemberValue extends MemberValue { 32 | int valueIndex; 33 | 34 | /** 35 | * Constructs a float constant value. The initial value is specified 36 | * by the constant pool entry at the given index. 37 | * 38 | * @param index the index of a CONSTANT_Float_info structure. 39 | */ 40 | public FloatMemberValue(int index, ConstPool cp) { 41 | super('F', cp); 42 | this.valueIndex = index; 43 | } 44 | 45 | /** 46 | * Constructs a float constant value. 47 | * 48 | * @param f the initial value. 49 | */ 50 | public FloatMemberValue(float f, ConstPool cp) { 51 | super('F', cp); 52 | setValue(f); 53 | } 54 | 55 | /** 56 | * Constructs a float constant value. The initial value is 0.0. 57 | */ 58 | public FloatMemberValue(ConstPool cp) { 59 | super('F', cp); 60 | setValue(0.0F); 61 | } 62 | 63 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 64 | return Float.valueOf(getValue()); 65 | } 66 | 67 | Class getType(ClassLoader cl) { 68 | return float.class; 69 | } 70 | 71 | /** 72 | * Obtains the value of the member. 73 | */ 74 | public float getValue() { 75 | return cp.getFloatInfo(valueIndex); 76 | } 77 | 78 | /** 79 | * Sets the value of the member. 80 | */ 81 | public void setValue(float newValue) { 82 | valueIndex = cp.addFloatInfo(newValue); 83 | } 84 | 85 | /** 86 | * Obtains the string representation of this object. 87 | */ 88 | public String toString() { 89 | return Float.toString(getValue()); 90 | } 91 | 92 | /** 93 | * Writes the value. 94 | */ 95 | public void write(AnnotationsWriter writer) throws IOException { 96 | writer.constValueIndex(getValue()); 97 | } 98 | 99 | /** 100 | * Accepts a visitor. 101 | */ 102 | public void accept(MemberValueVisitor visitor) { 103 | visitor.visitFloatMemberValue(this); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/DoubleMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Double floating-point number constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | * @version $Revision: 1.7 $ 30 | */ 31 | public class DoubleMemberValue extends MemberValue { 32 | int valueIndex; 33 | 34 | /** 35 | * Constructs a double constant value. The initial value is specified 36 | * by the constant pool entry at the given index. 37 | * 38 | * @param index the index of a CONSTANT_Double_info structure. 39 | */ 40 | public DoubleMemberValue(int index, ConstPool cp) { 41 | super('D', cp); 42 | this.valueIndex = index; 43 | } 44 | 45 | /** 46 | * Constructs a double constant value. 47 | * 48 | * @param d the initial value. 49 | */ 50 | public DoubleMemberValue(double d, ConstPool cp) { 51 | super('D', cp); 52 | setValue(d); 53 | } 54 | 55 | /** 56 | * Constructs a double constant value. The initial value is 0.0. 57 | */ 58 | public DoubleMemberValue(ConstPool cp) { 59 | super('D', cp); 60 | setValue(0.0); 61 | } 62 | 63 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 64 | return Double.valueOf(getValue()); 65 | } 66 | 67 | Class getType(ClassLoader cl) { 68 | return double.class; 69 | } 70 | 71 | /** 72 | * Obtains the value of the member. 73 | */ 74 | public double getValue() { 75 | return cp.getDoubleInfo(valueIndex); 76 | } 77 | 78 | /** 79 | * Sets the value of the member. 80 | */ 81 | public void setValue(double newValue) { 82 | valueIndex = cp.addDoubleInfo(newValue); 83 | } 84 | 85 | /** 86 | * Obtains the string representation of this object. 87 | */ 88 | public String toString() { 89 | return Double.toString(getValue()); 90 | } 91 | 92 | /** 93 | * Writes the value. 94 | */ 95 | public void write(AnnotationsWriter writer) throws IOException { 96 | writer.constValueIndex(getValue()); 97 | } 98 | 99 | /** 100 | * Accepts a visitor. 101 | */ 102 | public void accept(MemberValueVisitor visitor) { 103 | visitor.visitDoubleMemberValue(this); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/javassist/ByteArrayClassPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | import java.io.*; 20 | import java.net.URL; 21 | import java.net.MalformedURLException; 22 | 23 | /** 24 | * A ByteArrayClassPath contains bytes that is served as 25 | * a class file to a ClassPool. It is useful to convert 26 | * a byte array to a CtClass object. 27 | * 28 | *

For example, if you want to convert a byte array b 29 | * into a CtClass object representing the class with a name 30 | * classname, then do as following: 31 | * 32 | *

 33 |  * ClassPool cp = ClassPool.getDefault();
 34 |  * cp.insertClassPath(new ByteArrayClassPath(classname, b));
 35 |  * CtClass cc = cp.get(classname);
 36 |  * 
37 | * 38 | *

The ClassPool object cp uses the created 39 | * ByteArrayClassPath object as the source of the class file. 40 | * 41 | *

A ByteArrayClassPath must be instantiated for every 42 | * class. It contains only a single class file. 43 | * 44 | * @see javassist.ClassPath 45 | * @see ClassPool#insertClassPath(ClassPath) 46 | * @see ClassPool#appendClassPath(ClassPath) 47 | * @see ClassPool#makeClass(InputStream) 48 | */ 49 | public class ByteArrayClassPath implements ClassPath { 50 | protected String classname; 51 | protected byte[] classfile; 52 | 53 | /* 54 | * Creates a ByteArrayClassPath containing the given 55 | * bytes. 56 | * 57 | * @param name a fully qualified class name 58 | * @param classfile the contents of a class file. 59 | */ 60 | public ByteArrayClassPath(String name, byte[] classfile) { 61 | this.classname = name; 62 | this.classfile = classfile; 63 | } 64 | 65 | /** 66 | * Closes this class path. 67 | */ 68 | public void close() {} 69 | 70 | public String toString() { 71 | return "byte[]:" + classname; 72 | } 73 | 74 | /** 75 | * Opens the class file. 76 | */ 77 | public InputStream openClassfile(String classname) { 78 | if(this.classname.equals(classname)) 79 | return new ByteArrayInputStream(classfile); 80 | else 81 | return null; 82 | } 83 | 84 | /** 85 | * Obtains the URL. 86 | */ 87 | public URL find(String classname) { 88 | if(this.classname.equals(classname)) { 89 | String cname = classname.replace('.', '/') + ".class"; 90 | try { 91 | // return new File(cname).toURL(); 92 | return new URL("file:/ByteArrayClassPath/" + cname); 93 | } 94 | catch (MalformedURLException e) {} 95 | } 96 | 97 | return null; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/javassist/bytecode/annotation/IntegerMemberValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.bytecode.annotation; 18 | 19 | import javassist.ClassPool; 20 | import javassist.bytecode.ConstPool; 21 | import java.io.IOException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Integer constant value. 26 | * 27 | * @author Bill Burke 28 | * @author Shigeru Chiba 29 | */ 30 | public class IntegerMemberValue extends MemberValue { 31 | int valueIndex; 32 | 33 | /** 34 | * Constructs an int constant value. The initial value is specified 35 | * by the constant pool entry at the given index. 36 | * 37 | * @param index the index of a CONSTANT_Integer_info structure. 38 | */ 39 | public IntegerMemberValue(int index, ConstPool cp) { 40 | super('I', cp); 41 | this.valueIndex = index; 42 | } 43 | 44 | /** 45 | * Constructs an int constant value. 46 | * Note that this constructor receives the initial value 47 | * as the second parameter 48 | * unlike the corresponding constructors in the sibling classes. 49 | * This is for making a difference from the constructor that receives 50 | * an index into the constant pool table as the first parameter. 51 | * Note that the index is also int type. 52 | * 53 | * @param value the initial value. 54 | */ 55 | public IntegerMemberValue(ConstPool cp, int value) { 56 | super('I', cp); 57 | setValue(value); 58 | } 59 | 60 | /** 61 | * Constructs an int constant value. The initial value is 0. 62 | */ 63 | public IntegerMemberValue(ConstPool cp) { 64 | super('I', cp); 65 | setValue(0); 66 | } 67 | 68 | Object getValue(ClassLoader cl, ClassPool cp, Method m) { 69 | return Integer.valueOf(getValue()); 70 | } 71 | 72 | Class getType(ClassLoader cl) { 73 | return int.class; 74 | } 75 | 76 | /** 77 | * Obtains the value of the member. 78 | */ 79 | public int getValue() { 80 | return cp.getIntegerInfo(valueIndex); 81 | } 82 | 83 | /** 84 | * Sets the value of the member. 85 | */ 86 | public void setValue(int newValue) { 87 | valueIndex = cp.addIntegerInfo(newValue); 88 | } 89 | 90 | /** 91 | * Obtains the string representation of this object. 92 | */ 93 | public String toString() { 94 | return Integer.toString(getValue()); 95 | } 96 | 97 | /** 98 | * Writes the value. 99 | */ 100 | public void write(AnnotationsWriter writer) throws IOException { 101 | writer.constValueIndex(getValue()); 102 | } 103 | 104 | /** 105 | * Accepts a visitor. 106 | */ 107 | public void accept(MemberValueVisitor visitor) { 108 | visitor.visitIntegerMemberValue(this); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/javassist/LoaderClassPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | import java.io.InputStream; 20 | import java.net.URL; 21 | import java.lang.ref.WeakReference; 22 | 23 | /** 24 | * A class search-path representing a class loader. 25 | * 26 | *

It is used for obtaining a class file from the given 27 | * class loader by getResourceAsStream(). 28 | * The LoaderClassPath refers to the class loader through 29 | * WeakReference. If the class loader is garbage collected, 30 | * the other search pathes are examined. 31 | * 32 | *

The given class loader must have both getResourceAsStream() 33 | * and getResource(). 34 | * 35 | *

Class files in a named module are private to that module. 36 | * This method cannot obtain class files in named modules. 37 | *

38 | * 39 | * @author Bill Burke 40 | * @author Shigeru Chiba 41 | * 42 | * @see ClassPool#insertClassPath(ClassPath) 43 | * @see ClassPool#appendClassPath(ClassPath) 44 | * @see ClassClassPath 45 | */ 46 | public class LoaderClassPath implements ClassPath { 47 | private WeakReference clref; 48 | 49 | /** 50 | * Creates a search path representing a class loader. 51 | */ 52 | public LoaderClassPath(ClassLoader cl) { 53 | clref = new WeakReference(cl); 54 | } 55 | 56 | public String toString() { 57 | Object cl = null; 58 | if (clref != null) 59 | cl = clref.get(); 60 | 61 | return cl == null ? "" : cl.toString(); 62 | } 63 | 64 | /** 65 | * Obtains a class file from the class loader. 66 | * This method calls getResourceAsStream(String) 67 | * on the class loader. 68 | */ 69 | public InputStream openClassfile(String classname) throws NotFoundException { 70 | String cname = classname.replace('.', '/') + ".class"; 71 | ClassLoader cl = (ClassLoader)clref.get(); 72 | if (cl == null) 73 | return null; // not found 74 | else { 75 | InputStream is = cl.getResourceAsStream(cname); 76 | return is; 77 | } 78 | } 79 | 80 | /** 81 | * Obtains the URL of the specified class file. 82 | * This method calls getResource(String) 83 | * on the class loader. 84 | * 85 | * @return null if the class file could not be found. 86 | */ 87 | public URL find(String classname) { 88 | String cname = classname.replace('.', '/') + ".class"; 89 | ClassLoader cl = (ClassLoader)clref.get(); 90 | if (cl == null) 91 | return null; // not found 92 | else { 93 | URL url = cl.getResource(cname); 94 | return url; 95 | } 96 | } 97 | 98 | /** 99 | * Closes this class path. 100 | */ 101 | public void close() { 102 | clref = null; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/javassist/CtArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | /** 20 | * Array types. 21 | */ 22 | final class CtArray extends CtClass { 23 | protected ClassPool pool; 24 | 25 | // the name of array type ends with "[]". 26 | CtArray(String name, ClassPool cp) { 27 | super(name); 28 | pool = cp; 29 | } 30 | 31 | public ClassPool getClassPool() { 32 | return pool; 33 | } 34 | 35 | public boolean isArray() { 36 | return true; 37 | } 38 | 39 | private CtClass[] interfaces = null; 40 | 41 | public int getModifiers() { 42 | int mod = Modifier.FINAL; 43 | try { 44 | mod |= getComponentType().getModifiers() 45 | & (Modifier.PROTECTED | Modifier.PUBLIC | Modifier.PRIVATE); 46 | } 47 | catch (NotFoundException e) {} 48 | return mod; 49 | } 50 | 51 | public CtClass[] getInterfaces() throws NotFoundException { 52 | if (interfaces == null) { 53 | Class[] intfs = Object[].class.getInterfaces(); 54 | // java.lang.Cloneable and java.io.Serializable. 55 | // If the JVM is CLDC, intfs is empty. 56 | interfaces = new CtClass[intfs.length]; 57 | for (int i = 0; i < intfs.length; i++) 58 | interfaces[i] = pool.get(intfs[i].getName()); 59 | } 60 | 61 | return interfaces; 62 | } 63 | 64 | public boolean subtypeOf(CtClass clazz) throws NotFoundException { 65 | if (super.subtypeOf(clazz)) 66 | return true; 67 | 68 | String cname = clazz.getName(); 69 | if (cname.equals(javaLangObject)) 70 | return true; 71 | 72 | CtClass[] intfs = getInterfaces(); 73 | for (int i = 0; i < intfs.length; i++) 74 | if (intfs[i].subtypeOf(clazz)) 75 | return true; 76 | 77 | return clazz.isArray() 78 | && getComponentType().subtypeOf(clazz.getComponentType()); 79 | } 80 | 81 | public CtClass getComponentType() throws NotFoundException { 82 | String name = getName(); 83 | return pool.get(name.substring(0, name.length() - 2)); 84 | } 85 | 86 | public CtClass getSuperclass() throws NotFoundException { 87 | return pool.get(javaLangObject); 88 | } 89 | 90 | public CtMethod[] getMethods() { 91 | try { 92 | return getSuperclass().getMethods(); 93 | } 94 | catch (NotFoundException e) { 95 | return super.getMethods(); 96 | } 97 | } 98 | 99 | public CtMethod getMethod(String name, String desc) 100 | throws NotFoundException 101 | { 102 | return getSuperclass().getMethod(name, desc); 103 | } 104 | 105 | public CtConstructor[] getConstructors() { 106 | try { 107 | return getSuperclass().getConstructors(); 108 | } 109 | catch (NotFoundException e) { 110 | return super.getConstructors(); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/javassist/ClassClassPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | import java.io.InputStream; 20 | import java.net.URL; 21 | 22 | import javassist.bytecode.ClassFile; 23 | 24 | /** 25 | * A search-path for obtaining a class file 26 | * by getResourceAsStream() in java.lang.Class. 27 | * 28 | *

Try adding a ClassClassPath when a program is running 29 | * with a user-defined class loader and any class files are not found with 30 | * the default ClassPool. For example, 31 | * 32 | *

 33 |  * ClassPool cp = ClassPool.getDefault();
 34 |  * cp.insertClassPath(new ClassClassPath(this.getClass()));
 35 |  * 
36 | * 37 | * This code snippet permanently adds a ClassClassPath 38 | * to the default ClassPool. Note that the default 39 | * ClassPool is a singleton. The added 40 | * ClassClassPath uses a class object representing 41 | * the class including the code snippet above. 42 | * 43 | *

Class files in a named module are private to that module. 44 | * This method cannot obtain class files in named modules. 45 | *

46 | * 47 | * @see ClassPool#insertClassPath(ClassPath) 48 | * @see ClassPool#appendClassPath(ClassPath) 49 | * @see LoaderClassPath 50 | */ 51 | public class ClassClassPath implements ClassPath { 52 | private Class thisClass; 53 | 54 | /** Creates a search path. 55 | * 56 | * @param c the Class object used to obtain a class 57 | * file. getResourceAsStream() is called on 58 | * this object. 59 | */ 60 | public ClassClassPath(Class c) { 61 | thisClass = c; 62 | } 63 | 64 | ClassClassPath() { 65 | /* The value of thisClass was this.getClass() in early versions: 66 | * 67 | * thisClass = this.getClass(); 68 | * 69 | * However, this made openClassfile() not search all the system 70 | * class paths if javassist.jar is put in jre/lib/ext/ 71 | * (with JDK1.4). 72 | */ 73 | this(java.lang.Object.class); 74 | } 75 | 76 | /** 77 | * Obtains a class file by getResourceAsStream(). 78 | */ 79 | public InputStream openClassfile(String classname) throws NotFoundException { 80 | String filename = '/' + classname.replace('.', '/') + ".class"; 81 | return thisClass.getResourceAsStream(filename); 82 | } 83 | 84 | /** 85 | * Obtains the URL of the specified class file. 86 | * 87 | * @return null if the class file could not be found. 88 | */ 89 | public URL find(String classname) { 90 | String filename = '/' + classname.replace('.', '/') + ".class"; 91 | return thisClass.getResource(filename); 92 | } 93 | 94 | /** 95 | * Does nothing. 96 | */ 97 | public void close() { 98 | } 99 | 100 | public String toString() { 101 | return thisClass.getName() + ".class"; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/javassist/convert/TransformReadField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.bytecode.*; 20 | import javassist.ClassPool; 21 | import javassist.CtClass; 22 | import javassist.CtField; 23 | import javassist.NotFoundException; 24 | import javassist.Modifier; 25 | 26 | public class TransformReadField extends Transformer { 27 | protected String fieldname; 28 | protected CtClass fieldClass; 29 | protected boolean isPrivate; 30 | protected String methodClassname, methodName; 31 | 32 | public TransformReadField(Transformer next, CtField field, 33 | String methodClassname, String methodName) 34 | { 35 | super(next); 36 | this.fieldClass = field.getDeclaringClass(); 37 | this.fieldname = field.getName(); 38 | this.methodClassname = methodClassname; 39 | this.methodName = methodName; 40 | this.isPrivate = Modifier.isPrivate(field.getModifiers()); 41 | } 42 | 43 | static String isField(ClassPool pool, ConstPool cp, CtClass fclass, 44 | String fname, boolean is_private, int index) { 45 | if (!cp.getFieldrefName(index).equals(fname)) 46 | return null; 47 | 48 | try { 49 | CtClass c = pool.get(cp.getFieldrefClassName(index)); 50 | if (c == fclass || (!is_private && isFieldInSuper(c, fclass, fname))) 51 | return cp.getFieldrefType(index); 52 | } 53 | catch (NotFoundException e) {} 54 | return null; 55 | } 56 | 57 | static boolean isFieldInSuper(CtClass clazz, CtClass fclass, String fname) { 58 | if (!clazz.subclassOf(fclass)) 59 | return false; 60 | 61 | try { 62 | CtField f = clazz.getField(fname); 63 | return f.getDeclaringClass() == fclass; 64 | } 65 | catch (NotFoundException e) {} 66 | return false; 67 | } 68 | 69 | public int transform(CtClass tclazz, int pos, CodeIterator iterator, 70 | ConstPool cp) throws BadBytecode 71 | { 72 | int c = iterator.byteAt(pos); 73 | if (c == GETFIELD || c == GETSTATIC) { 74 | int index = iterator.u16bitAt(pos + 1); 75 | String typedesc = isField(tclazz.getClassPool(), cp, 76 | fieldClass, fieldname, isPrivate, index); 77 | if (typedesc != null) { 78 | if (c == GETSTATIC) { 79 | iterator.move(pos); 80 | pos = iterator.insertGap(1); // insertGap() may insert 4 bytes. 81 | iterator.writeByte(ACONST_NULL, pos); 82 | pos = iterator.next(); 83 | } 84 | 85 | String type = "(Ljava/lang/Object;)" + typedesc; 86 | int mi = cp.addClassInfo(methodClassname); 87 | int methodref = cp.addMethodrefInfo(mi, methodName, type); 88 | iterator.writeByte(INVOKESTATIC, pos); 89 | iterator.write16bit(methodref, pos + 1); 90 | return pos; 91 | } 92 | } 93 | 94 | return pos; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/javassist/CannotCompileException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist; 18 | 19 | import javassist.compiler.CompileError; 20 | 21 | /** 22 | * Thrown when bytecode transformation has failed. 23 | */ 24 | public class CannotCompileException extends Exception { 25 | private Throwable myCause; 26 | 27 | /** 28 | * Gets the cause of this throwable. 29 | * It is for JDK 1.3 compatibility. 30 | */ 31 | public Throwable getCause() { 32 | return (myCause == this ? null : myCause); 33 | } 34 | 35 | /** 36 | * Initializes the cause of this throwable. 37 | * It is for JDK 1.3 compatibility. 38 | */ 39 | public synchronized Throwable initCause(Throwable cause) { 40 | myCause = cause; 41 | return this; 42 | } 43 | 44 | private String message; 45 | 46 | /** 47 | * Gets a long message if it is available. 48 | */ 49 | public String getReason() { 50 | if (message != null) 51 | return message; 52 | else 53 | return this.toString(); 54 | } 55 | 56 | /** 57 | * Constructs a CannotCompileException with a message. 58 | * 59 | * @param msg the message. 60 | */ 61 | public CannotCompileException(String msg) { 62 | super(msg); 63 | message = msg; 64 | initCause(null); 65 | } 66 | 67 | /** 68 | * Constructs a CannotCompileException with an Exception 69 | * representing the cause. 70 | * 71 | * @param e the cause. 72 | */ 73 | public CannotCompileException(Throwable e) { 74 | super("by " + e.toString()); 75 | message = null; 76 | initCause(e); 77 | } 78 | 79 | /** 80 | * Constructs a CannotCompileException with a detailed message 81 | * and an Exception representing the cause. 82 | * 83 | * @param msg the message. 84 | * @param e the cause. 85 | */ 86 | public CannotCompileException(String msg, Throwable e) { 87 | this(msg); 88 | initCause(e); 89 | } 90 | 91 | /** 92 | * Constructs a CannotCompileException with a 93 | * NotFoundException. 94 | */ 95 | public CannotCompileException(NotFoundException e) { 96 | this("cannot find " + e.getMessage(), e); 97 | } 98 | 99 | /** 100 | * Constructs a CannotCompileException with an CompileError. 101 | */ 102 | public CannotCompileException(CompileError e) { 103 | this("[source error] " + e.getMessage(), e); 104 | } 105 | 106 | /** 107 | * Constructs a CannotCompileException 108 | * with a ClassNotFoundException. 109 | */ 110 | public CannotCompileException(ClassNotFoundException e, String name) { 111 | this("cannot find " + name, e); 112 | } 113 | 114 | /** 115 | * Constructs a CannotCompileException with a ClassFormatError. 116 | */ 117 | public CannotCompileException(ClassFormatError e, String name) { 118 | this("invalid class format: " + name, e); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/javassist/convert/TransformNew.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Javassist, a Java-bytecode translator toolkit. 3 | * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. Alternatively, the contents of this file may be used under 8 | * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 | * or the Apache License Version 2.0. 10 | * 11 | * Software distributed under the License is distributed on an "AS IS" basis, 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing rights and limitations under the 14 | * License. 15 | */ 16 | 17 | package javassist.convert; 18 | 19 | import javassist.bytecode.*; 20 | import javassist.CtClass; 21 | import javassist.CannotCompileException; 22 | 23 | final public class TransformNew extends Transformer { 24 | private int nested; 25 | private String classname, trapClass, trapMethod; 26 | 27 | public TransformNew(Transformer next, 28 | String classname, String trapClass, String trapMethod) { 29 | super(next); 30 | this.classname = classname; 31 | this.trapClass = trapClass; 32 | this.trapMethod = trapMethod; 33 | } 34 | 35 | public void initialize(ConstPool cp, CodeAttribute attr) { 36 | nested = 0; 37 | } 38 | 39 | /** 40 | * Replace a sequence of 41 | * NEW classname 42 | * DUP 43 | * ... 44 | * INVOKESPECIAL 45 | * with 46 | * NOP 47 | * NOP 48 | * ... 49 | * INVOKESTATIC trapMethod in trapClass 50 | */ 51 | public int transform(CtClass clazz, int pos, CodeIterator iterator, 52 | ConstPool cp) throws CannotCompileException 53 | { 54 | int index; 55 | int c = iterator.byteAt(pos); 56 | if (c == NEW) { 57 | index = iterator.u16bitAt(pos + 1); 58 | if (cp.getClassInfo(index).equals(classname)) { 59 | if (iterator.byteAt(pos + 3) != DUP) 60 | throw new CannotCompileException( 61 | "NEW followed by no DUP was found"); 62 | 63 | iterator.writeByte(NOP, pos); 64 | iterator.writeByte(NOP, pos + 1); 65 | iterator.writeByte(NOP, pos + 2); 66 | iterator.writeByte(NOP, pos + 3); 67 | ++nested; 68 | 69 | StackMapTable smt 70 | = (StackMapTable)iterator.get().getAttribute(StackMapTable.tag); 71 | if (smt != null) 72 | smt.removeNew(pos); 73 | 74 | StackMap sm 75 | = (StackMap)iterator.get().getAttribute(StackMap.tag); 76 | if (sm != null) 77 | sm.removeNew(pos); 78 | } 79 | } 80 | else if (c == INVOKESPECIAL) { 81 | index = iterator.u16bitAt(pos + 1); 82 | int typedesc = cp.isConstructor(classname, index); 83 | if (typedesc != 0 && nested > 0) { 84 | int methodref = computeMethodref(typedesc, cp); 85 | iterator.writeByte(INVOKESTATIC, pos); 86 | iterator.write16bit(methodref, pos + 1); 87 | --nested; 88 | } 89 | } 90 | 91 | return pos; 92 | } 93 | 94 | private int computeMethodref(int typedesc, ConstPool cp) { 95 | int classIndex = cp.addClassInfo(trapClass); 96 | int mnameIndex = cp.addUtf8Info(trapMethod); 97 | typedesc = cp.addUtf8Info( 98 | Descriptor.changeReturnType(classname, 99 | cp.getUtf8Info(typedesc))); 100 | return cp.addMethodrefInfo(classIndex, 101 | cp.addNameAndTypeInfo(mnameIndex, typedesc)); 102 | } 103 | } 104 | --------------------------------------------------------------------------------