Clean up warnings in CGLIB fork
This commit is contained in:
parent
6ba31acf35
commit
d6d629a8eb
|
|
@ -13,9 +13,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import org.springframework.asm.Attribute;
|
||||
import org.springframework.asm.Type;
|
||||
|
||||
abstract public class ClassInfo {
|
||||
|
|
@ -28,6 +28,7 @@ abstract public class ClassInfo {
|
|||
abstract public Type[] getInterfaces();
|
||||
abstract public int getModifiers();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null)
|
||||
return false;
|
||||
|
|
@ -36,10 +37,12 @@ abstract public class ClassInfo {
|
|||
return getType().equals(((ClassInfo)o).getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getType().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: include modifiers, superType, interfaces
|
||||
return getType().getClassName();
|
||||
|
|
|
|||
|
|
@ -13,11 +13,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.springframework.asm.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.asm.Label;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Type;
|
||||
|
||||
/**
|
||||
* @author Juozas Baliuka, Chris Nokleberg
|
||||
|
|
@ -81,26 +84,26 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
argumentTypes = sig.getArgumentTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassInfo getClassInfo() {
|
||||
return classInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModifiers() {
|
||||
return access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signature getSignature() {
|
||||
return sig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getExceptionTypes() {
|
||||
return exceptionTypes;
|
||||
}
|
||||
|
||||
public Attribute getAttribute() {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
CodeEmitter(ClassEmitter ce, MethodVisitor mv, int access, Signature sig, Type[] exceptionTypes) {
|
||||
|
|
@ -309,7 +312,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
mv.visitLdcInsn(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void push(long value) {
|
||||
if (value == 0L || value == 1L) {
|
||||
mv.visitInsn(TypeUtils.LCONST(value));
|
||||
|
|
@ -317,7 +320,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
mv.visitLdcInsn(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void push(float value) {
|
||||
if (value == 0f || value == 1f || value == 2f) {
|
||||
mv.visitInsn(TypeUtils.FCONST(value));
|
||||
|
|
@ -332,7 +335,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
mv.visitLdcInsn(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void push(String value) {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
|
|
@ -348,18 +351,18 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
emit_type(Constants.ANEWARRAY, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void arraylength() {
|
||||
mv.visitInsn(Constants.ARRAYLENGTH);
|
||||
}
|
||||
|
||||
|
||||
public void load_this() {
|
||||
if (TypeUtils.isStatic(state.access)) {
|
||||
throw new IllegalStateException("no 'this' pointer within static method");
|
||||
}
|
||||
mv.visitVarInsn(Constants.ALOAD, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pushes all of the arguments of the current method onto the stack.
|
||||
*/
|
||||
|
|
@ -385,7 +388,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
pos += t.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int skipArgs(int numArgs) {
|
||||
int amount = 0;
|
||||
for (int i = 0; i < numArgs; i++) {
|
||||
|
|
@ -403,15 +406,15 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
// TODO: make t == null ok?
|
||||
mv.visitVarInsn(t.getOpcode(Constants.ISTORE), pos);
|
||||
}
|
||||
|
||||
|
||||
public void iinc(Local local, int amount) {
|
||||
mv.visitIincInsn(local.getIndex(), amount);
|
||||
}
|
||||
|
||||
|
||||
public void store_local(Local local) {
|
||||
store_local(local.getType(), local.getIndex());
|
||||
}
|
||||
|
||||
|
||||
public void load_local(Local local) {
|
||||
load_local(local.getType(), local.getIndex());
|
||||
}
|
||||
|
|
@ -425,7 +428,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
int opcode = TypeUtils.isStatic(info.access) ? Constants.GETSTATIC : Constants.GETFIELD;
|
||||
emit_field(opcode, ce.getClassType(), name, info.type);
|
||||
}
|
||||
|
||||
|
||||
public void putfield(String name) {
|
||||
ClassEmitter.FieldInfo info = ce.getFieldInfo(name);
|
||||
int opcode = TypeUtils.isStatic(info.access) ? Constants.PUTSTATIC : Constants.PUTFIELD;
|
||||
|
|
@ -435,7 +438,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void super_getfield(String name, Type type) {
|
||||
emit_field(Constants.GETFIELD, ce.getSuperType(), name, type);
|
||||
}
|
||||
|
||||
|
||||
public void super_putfield(String name, Type type) {
|
||||
emit_field(Constants.PUTFIELD, ce.getSuperType(), name, type);
|
||||
}
|
||||
|
|
@ -443,7 +446,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void super_getstatic(String name, Type type) {
|
||||
emit_field(Constants.GETSTATIC, ce.getSuperType(), name, type);
|
||||
}
|
||||
|
||||
|
||||
public void super_putstatic(String name, Type type) {
|
||||
emit_field(Constants.PUTSTATIC, ce.getSuperType(), name, type);
|
||||
}
|
||||
|
|
@ -451,7 +454,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void getfield(Type owner, String name, Type type) {
|
||||
emit_field(Constants.GETFIELD, owner, name, type);
|
||||
}
|
||||
|
||||
|
||||
public void putfield(Type owner, String name, Type type) {
|
||||
emit_field(Constants.PUTFIELD, owner, name, type);
|
||||
}
|
||||
|
|
@ -459,7 +462,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void getstatic(Type owner, String name, Type type) {
|
||||
emit_field(Constants.GETSTATIC, owner, name, type);
|
||||
}
|
||||
|
||||
|
||||
public void putstatic(Type owner, String name, Type type) {
|
||||
emit_field(Constants.PUTSTATIC, owner, name, type);
|
||||
}
|
||||
|
|
@ -487,7 +490,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void super_invoke_constructor() {
|
||||
invoke_constructor(ce.getSuperType());
|
||||
}
|
||||
|
||||
|
||||
public void invoke_constructor_this() {
|
||||
invoke_constructor(ce.getClassType());
|
||||
}
|
||||
|
|
@ -504,7 +507,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
sig.getDescriptor(),
|
||||
isInterface);
|
||||
}
|
||||
|
||||
|
||||
public void invoke_interface(Type owner, Signature sig) {
|
||||
emit_invoke(Constants.INVOKEINTERFACE, owner, sig, true);
|
||||
}
|
||||
|
|
@ -541,7 +544,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void super_invoke_constructor(Signature sig) {
|
||||
invoke_constructor(ce.getSuperType(), sig);
|
||||
}
|
||||
|
||||
|
||||
public void new_instance_this() {
|
||||
new_instance(ce.getClassType());
|
||||
}
|
||||
|
|
@ -572,11 +575,11 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public Label make_label() {
|
||||
return new Label();
|
||||
}
|
||||
|
||||
|
||||
public Local make_local() {
|
||||
return make_local(Constants.TYPE_OBJECT);
|
||||
}
|
||||
|
||||
|
||||
public Local make_local(Type type) {
|
||||
return new Local(newLocal(type.getSize()), type);
|
||||
}
|
||||
|
|
@ -584,7 +587,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void checkcast_this() {
|
||||
checkcast(ce.getClassType());
|
||||
}
|
||||
|
||||
|
||||
public void checkcast(Type type) {
|
||||
if (!type.equals(Constants.TYPE_OBJECT)) {
|
||||
emit_type(Constants.CHECKCAST, type);
|
||||
|
|
@ -594,7 +597,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
public void instance_of(Type type) {
|
||||
emit_type(Constants.INSTANCEOF, type);
|
||||
}
|
||||
|
||||
|
||||
public void instance_of_this() {
|
||||
instance_of(ce.getClassType());
|
||||
}
|
||||
|
|
@ -728,7 +731,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If the argument is a primitive class, replaces the object
|
||||
* on the top of the stack with the unwrapped (primitive)
|
||||
|
|
@ -843,6 +846,7 @@ public class CodeEmitter extends LocalVariablesSorter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMaxs(int maxStack, int maxLocals) {
|
||||
if (!TypeUtils.isAbstract(state.access)) {
|
||||
mv.visitMaxs(0, 0);
|
||||
|
|
|
|||
|
|
@ -13,10 +13,16 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Chris Nokleberg
|
||||
|
|
@ -73,5 +79,4 @@ public class CollectionUtils {
|
|||
}
|
||||
return indexes;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,27 +13,32 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import org.springframework.asm.ClassWriter;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.springframework.asm.ClassReader;
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.Opcodes;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import org.springframework.asm.ClassWriter;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class DebuggingClassWriter extends ClassVisitor {
|
||||
|
||||
|
||||
public static final String DEBUG_LOCATION_PROPERTY = "cglib.debugLocation";
|
||||
|
||||
|
||||
private static String debugLocation;
|
||||
private static Constructor traceCtor;
|
||||
|
||||
|
||||
private String className;
|
||||
private String superName;
|
||||
|
||||
|
||||
static {
|
||||
debugLocation = System.getProperty(DEBUG_LOCATION_PROPERTY);
|
||||
if (debugLocation != null) {
|
||||
|
|
@ -45,11 +50,12 @@ public class DebuggingClassWriter extends ClassVisitor {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DebuggingClassWriter(int flags) {
|
||||
super(Constants.ASM_API, new ClassWriter(flags));
|
||||
super(Constants.ASM_API, new ClassWriter(flags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version,
|
||||
int access,
|
||||
String name,
|
||||
|
|
@ -60,17 +66,17 @@ public class DebuggingClassWriter extends ClassVisitor {
|
|||
this.superName = superName.replace('/', '.');
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
|
||||
public String getSuperName() {
|
||||
return superName;
|
||||
}
|
||||
|
||||
|
||||
public byte[] toByteArray() {
|
||||
|
||||
|
||||
byte[] b = ((ClassWriter) DebuggingClassWriter.super.cv).toByteArray();
|
||||
if (debugLocation != null) {
|
||||
String dirs = className.replace('.', File.separatorChar);
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.util.Set;
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
/**
|
||||
* The default policy used by {@link AbstractClassGenerator}.
|
||||
|
|
@ -34,7 +33,8 @@ public class DefaultNamingPolicy implements NamingPolicy {
|
|||
* This allows to test collisions of {@code key.hashCode()}.
|
||||
*/
|
||||
private final static boolean STRESS_HASH_CODE = Boolean.getBoolean("org.springframework.cglib.test.stressHashCodes");
|
||||
|
||||
|
||||
@Override
|
||||
public String getClassName(String prefix, String source, Object key, Predicate names) {
|
||||
if (prefix == null) {
|
||||
prefix = "org.springframework.cglib.empty.Object";
|
||||
|
|
@ -42,7 +42,7 @@ public class DefaultNamingPolicy implements NamingPolicy {
|
|||
prefix = "$" + prefix;
|
||||
}
|
||||
String base =
|
||||
prefix + "$$" +
|
||||
prefix + "$$" +
|
||||
source.substring(source.lastIndexOf('.') + 1) +
|
||||
getTag() + "$$" +
|
||||
Integer.toHexString(STRESS_HASH_CODE ? 0 : key.hashCode());
|
||||
|
|
@ -61,11 +61,14 @@ public class DefaultNamingPolicy implements NamingPolicy {
|
|||
return "ByCGLIB";
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getTag().hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getTag().hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof DefaultNamingPolicy) && ((DefaultNamingPolicy) o).getTag().equals(getTag());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof DefaultNamingPolicy defaultNamingPolicy) &&
|
||||
defaultNamingPolicy.getTag().equals(getTag());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,24 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.cglib.core.internal.CustomizerRegistry;
|
||||
import org.springframework.asm.Label;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.internal.CustomizerRegistry;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked", "static", "fallthrough", "deprecation"})
|
||||
public class EmitUtils {
|
||||
|
|
@ -68,8 +77,8 @@ public class EmitUtils {
|
|||
TypeUtils.parseSignature("void setLength(int)");
|
||||
private static final Signature GET_DECLARED_METHOD =
|
||||
TypeUtils.parseSignature("java.lang.reflect.Method getDeclaredMethod(String, Class[])");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final ArrayDelimiters DEFAULT_DELIMITERS = new ArrayDelimiters("{", ", ", "}");
|
||||
|
||||
|
|
@ -93,7 +102,7 @@ public class EmitUtils {
|
|||
e.return_value();
|
||||
e.end_method();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process an array on the stack. Assumes the top item on the stack
|
||||
* is an array of the specified type. For each element in the array,
|
||||
|
|
@ -111,21 +120,21 @@ public class EmitUtils {
|
|||
e.push(0);
|
||||
e.store_local(loopvar);
|
||||
e.goTo(checkloop);
|
||||
|
||||
|
||||
e.mark(loopbody);
|
||||
e.load_local(array);
|
||||
e.load_local(loopvar);
|
||||
e.array_load(componentType);
|
||||
callback.processElement(componentType);
|
||||
e.iinc(loopvar, 1);
|
||||
|
||||
|
||||
e.mark(checkloop);
|
||||
e.load_local(loopvar);
|
||||
e.load_local(array);
|
||||
e.arraylength();
|
||||
e.if_icmp(e.LT, loopbody);
|
||||
e.if_icmp(CodeEmitter.LT, loopbody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process two arrays on the stack in parallel. Assumes the top two items on the stack
|
||||
* are arrays of the specified class. The arrays must be the same length. For each pair
|
||||
|
|
@ -145,7 +154,7 @@ public class EmitUtils {
|
|||
e.push(0);
|
||||
e.store_local(loopvar);
|
||||
e.goTo(checkloop);
|
||||
|
||||
|
||||
e.mark(loopbody);
|
||||
e.load_local(array1);
|
||||
e.load_local(loopvar);
|
||||
|
|
@ -155,14 +164,14 @@ public class EmitUtils {
|
|||
e.array_load(componentType);
|
||||
callback.processElement(componentType);
|
||||
e.iinc(loopvar, 1);
|
||||
|
||||
|
||||
e.mark(checkloop);
|
||||
e.load_local(loopvar);
|
||||
e.load_local(array1);
|
||||
e.arraylength();
|
||||
e.if_icmp(e.LT, loopbody);
|
||||
e.if_icmp(CodeEmitter.LT, loopbody);
|
||||
}
|
||||
|
||||
|
||||
public static void string_switch(CodeEmitter e, String[] strings, int switchStyle, ObjectSwitchCallback callback) {
|
||||
try {
|
||||
switch (switchStyle) {
|
||||
|
|
@ -193,6 +202,7 @@ public class EmitUtils {
|
|||
final Label def = e.make_label();
|
||||
final Label end = e.make_label();
|
||||
final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() {
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return ((String)value).length();
|
||||
}
|
||||
|
|
@ -200,10 +210,12 @@ public class EmitUtils {
|
|||
e.dup();
|
||||
e.invoke_virtual(Constants.TYPE_STRING, STRING_LENGTH);
|
||||
e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(int key, Label ignore_end) throws Exception {
|
||||
List bucket = (List)buckets.get(key);
|
||||
stringSwitchHelper(e, bucket, callback, def, end, 0);
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.goTo(def);
|
||||
}
|
||||
|
|
@ -222,6 +234,7 @@ public class EmitUtils {
|
|||
final int index) throws Exception {
|
||||
final int len = ((String)strings.get(0)).length();
|
||||
final Map buckets = CollectionUtils.bucket(strings, new Transformer() {
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return ((String)value).charAt(index);
|
||||
}
|
||||
|
|
@ -230,6 +243,7 @@ public class EmitUtils {
|
|||
e.push(index);
|
||||
e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT);
|
||||
e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(int key, Label ignore_end) throws Exception {
|
||||
List bucket = (List)buckets.get(key);
|
||||
if (index + 1 == len) {
|
||||
|
|
@ -239,11 +253,12 @@ public class EmitUtils {
|
|||
stringSwitchHelper(e, bucket, callback, def, end, index + 1);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.goTo(def);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static int[] getSwitchKeys(Map buckets) {
|
||||
int[] keys = new int[buckets.size()];
|
||||
|
|
@ -260,6 +275,7 @@ public class EmitUtils {
|
|||
final ObjectSwitchCallback callback,
|
||||
final boolean skipEquals) throws Exception {
|
||||
final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() {
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return value.hashCode();
|
||||
}
|
||||
|
|
@ -269,13 +285,14 @@ public class EmitUtils {
|
|||
e.dup();
|
||||
e.invoke_virtual(Constants.TYPE_OBJECT, HASH_CODE);
|
||||
e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(int key, Label ignore_end) throws Exception {
|
||||
List bucket = (List)buckets.get(key);
|
||||
Label next = null;
|
||||
if (skipEquals && bucket.size() == 1) {
|
||||
if (skipEquals)
|
||||
e.pop();
|
||||
callback.processCase((String)bucket.get(0), end);
|
||||
callback.processCase(bucket.get(0), end);
|
||||
} else {
|
||||
for (Iterator it = bucket.iterator(); it.hasNext();) {
|
||||
String string = (String)it.next();
|
||||
|
|
@ -288,15 +305,16 @@ public class EmitUtils {
|
|||
e.push(string);
|
||||
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
|
||||
if (it.hasNext()) {
|
||||
e.if_jump(e.EQ, next = e.make_label());
|
||||
e.if_jump(CodeEmitter.EQ, next = e.make_label());
|
||||
e.pop();
|
||||
} else {
|
||||
e.if_jump(e.EQ, def);
|
||||
e.if_jump(CodeEmitter.EQ, def);
|
||||
}
|
||||
callback.processCase(string, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.pop();
|
||||
}
|
||||
|
|
@ -309,7 +327,7 @@ public class EmitUtils {
|
|||
public static void load_class_this(CodeEmitter e) {
|
||||
load_class_helper(e, e.getClassEmitter().getClassType());
|
||||
}
|
||||
|
||||
|
||||
public static void load_class(CodeEmitter e, Type type) {
|
||||
if (TypeUtils.isPrimitive(type)) {
|
||||
if (type == Type.VOID_TYPE) {
|
||||
|
|
@ -359,7 +377,7 @@ public class EmitUtils {
|
|||
return Class.class;
|
||||
return componentType;
|
||||
}
|
||||
|
||||
|
||||
public static void push_object(CodeEmitter e, Object obj) {
|
||||
if (obj == null) {
|
||||
e.aconst_null();
|
||||
|
|
@ -394,23 +412,23 @@ public class EmitUtils {
|
|||
*/
|
||||
@Deprecated
|
||||
public static void hash_code(CodeEmitter e, Type type, int multiplier, final Customizer customizer) {
|
||||
hash_code(e, type, multiplier, CustomizerRegistry.singleton(customizer));
|
||||
hash_code(e, type, multiplier, CustomizerRegistry.singleton(customizer));
|
||||
}
|
||||
|
||||
|
||||
public static void hash_code(CodeEmitter e, Type type, int multiplier, final CustomizerRegistry registry) {
|
||||
if (TypeUtils.isArray(type)) {
|
||||
hash_array(e, type, multiplier, registry);
|
||||
} else {
|
||||
e.swap(Type.INT_TYPE, type);
|
||||
e.push(multiplier);
|
||||
e.math(e.MUL, Type.INT_TYPE);
|
||||
e.math(CodeEmitter.MUL, Type.INT_TYPE);
|
||||
e.swap(type, Type.INT_TYPE);
|
||||
if (TypeUtils.isPrimitive(type)) {
|
||||
hash_primitive(e, type);
|
||||
} else {
|
||||
hash_object(e, type, registry);
|
||||
}
|
||||
e.math(e.ADD, Type.INT_TYPE);
|
||||
e.math(CodeEmitter.ADD, Type.INT_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -420,6 +438,7 @@ public class EmitUtils {
|
|||
e.dup();
|
||||
e.ifnull(skip);
|
||||
EmitUtils.process_array(e, type, new ProcessArrayCallback() {
|
||||
@Override
|
||||
public void processElement(Type type) {
|
||||
hash_code(e, type, multiplier, registry);
|
||||
}
|
||||
|
|
@ -461,7 +480,7 @@ public class EmitUtils {
|
|||
case Type.BOOLEAN:
|
||||
// f ? 0 : 1
|
||||
e.push(1);
|
||||
e.math(e.XOR, Type.INT_TYPE);
|
||||
e.math(CodeEmitter.XOR, Type.INT_TYPE);
|
||||
break;
|
||||
case Type.FLOAT:
|
||||
// Float.floatToIntBits(f)
|
||||
|
|
@ -480,23 +499,23 @@ public class EmitUtils {
|
|||
// (int)(f ^ (f >>> 32))
|
||||
e.dup2();
|
||||
e.push(32);
|
||||
e.math(e.USHR, Type.LONG_TYPE);
|
||||
e.math(e.XOR, Type.LONG_TYPE);
|
||||
e.math(CodeEmitter.USHR, Type.LONG_TYPE);
|
||||
e.math(CodeEmitter.XOR, Type.LONG_TYPE);
|
||||
e.cast_numeric(Type.LONG_TYPE, Type.INT_TYPE);
|
||||
}
|
||||
|
||||
// public static void not_equals(CodeEmitter e, Type type, Label notEquals) {
|
||||
// not_equals(e, type, notEquals, null);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #not_equals(CodeEmitter, Type, Label, CustomizerRegistry)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static void not_equals(CodeEmitter e, Type type, final Label notEquals, final Customizer customizer) {
|
||||
not_equals(e, type, notEquals, CustomizerRegistry.singleton(customizer));
|
||||
not_equals(e, type, notEquals, CustomizerRegistry.singleton(customizer));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Branches to the specified label if the top two items on the stack
|
||||
* are not equal. The items must both be of the specified
|
||||
|
|
@ -506,19 +525,20 @@ public class EmitUtils {
|
|||
*/
|
||||
public static void not_equals(final CodeEmitter e, Type type, final Label notEquals, final CustomizerRegistry registry) {
|
||||
(new ProcessArrayCallback() {
|
||||
@Override
|
||||
public void processElement(Type type) {
|
||||
not_equals_helper(e, type, notEquals, registry, this);
|
||||
}
|
||||
}).processElement(type);
|
||||
}
|
||||
|
||||
|
||||
private static void not_equals_helper(CodeEmitter e,
|
||||
Type type,
|
||||
Label notEquals,
|
||||
CustomizerRegistry registry,
|
||||
ProcessArrayCallback callback) {
|
||||
if (TypeUtils.isPrimitive(type)) {
|
||||
e.if_cmp(type, e.NE, notEquals);
|
||||
e.if_cmp(type, CodeEmitter.NE, notEquals);
|
||||
} else {
|
||||
Label end = e.make_label();
|
||||
nullcmp(e, notEquals, end);
|
||||
|
|
@ -528,7 +548,7 @@ public class EmitUtils {
|
|||
e.arraylength();
|
||||
e.swap();
|
||||
e.arraylength();
|
||||
e.if_icmp(e.EQ, checkContents);
|
||||
e.if_icmp(CodeEmitter.EQ, checkContents);
|
||||
e.pop2();
|
||||
e.goTo(notEquals);
|
||||
e.mark(checkContents);
|
||||
|
|
@ -545,7 +565,7 @@ public class EmitUtils {
|
|||
}
|
||||
}
|
||||
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
|
||||
e.if_jump(e.EQ, notEquals);
|
||||
e.if_jump(CodeEmitter.EQ, notEquals);
|
||||
}
|
||||
e.mark(end);
|
||||
}
|
||||
|
|
@ -567,15 +587,15 @@ public class EmitUtils {
|
|||
e.ifnonnull(oneNullHelper);
|
||||
e.pop2();
|
||||
e.goTo(bothNull);
|
||||
|
||||
|
||||
e.mark(nonNull);
|
||||
e.ifnull(oneNullHelper);
|
||||
e.goTo(end);
|
||||
|
||||
|
||||
e.mark(oneNullHelper);
|
||||
e.pop2();
|
||||
e.goTo(oneNull);
|
||||
|
||||
|
||||
e.mark(end);
|
||||
}
|
||||
|
||||
|
|
@ -610,6 +630,7 @@ public class EmitUtils {
|
|||
final CustomizerRegistry registry) {
|
||||
final ArrayDelimiters d = (delims != null) ? delims : DEFAULT_DELIMITERS;
|
||||
ProcessArrayCallback callback = new ProcessArrayCallback() {
|
||||
@Override
|
||||
public void processElement(Type type) {
|
||||
append_string_helper(e, type, d, registry, this);
|
||||
e.push(d.inside);
|
||||
|
|
@ -686,7 +707,7 @@ public class EmitUtils {
|
|||
e.dup();
|
||||
e.invoke_virtual(Constants.TYPE_STRING_BUFFER, LENGTH);
|
||||
e.push(amt);
|
||||
e.math(e.SUB, Type.INT_TYPE);
|
||||
e.math(CodeEmitter.SUB, Type.INT_TYPE);
|
||||
e.invoke_virtual(Constants.TYPE_STRING_BUFFER, SET_LENGTH);
|
||||
}
|
||||
|
||||
|
|
@ -694,7 +715,7 @@ public class EmitUtils {
|
|||
private String before;
|
||||
private String inside;
|
||||
private String after;
|
||||
|
||||
|
||||
public ArrayDelimiters(String before, String inside, String after) {
|
||||
this.before = before;
|
||||
this.inside = inside;
|
||||
|
|
@ -732,6 +753,7 @@ public class EmitUtils {
|
|||
try {
|
||||
final Map cache = new HashMap();
|
||||
final ParameterTyper cached = new ParameterTyper() {
|
||||
@Override
|
||||
public Type[] getParameterTypes(MethodInfo member) {
|
||||
Type[] types = (Type[])cache.get(member);
|
||||
if (types == null) {
|
||||
|
|
@ -745,15 +767,18 @@ public class EmitUtils {
|
|||
if (useName) {
|
||||
e.swap();
|
||||
final Map buckets = CollectionUtils.bucket(members, new Transformer() {
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return ((MethodInfo)value).getSignature().getName();
|
||||
}
|
||||
});
|
||||
String[] names = (String[])buckets.keySet().toArray(new String[buckets.size()]);
|
||||
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(Object key, Label dontUseEnd) throws Exception {
|
||||
member_helper_size(e, (List)buckets.get(key), callback, cached, def, end);
|
||||
}
|
||||
@Override
|
||||
public void processDefault() throws Exception {
|
||||
e.goTo(def);
|
||||
}
|
||||
|
|
@ -781,6 +806,7 @@ public class EmitUtils {
|
|||
final Label def,
|
||||
final Label end) throws Exception {
|
||||
final Map buckets = CollectionUtils.bucket(members, new Transformer() {
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return typer.getParameterTypes((MethodInfo)value).length;
|
||||
}
|
||||
|
|
@ -788,10 +814,12 @@ public class EmitUtils {
|
|||
e.dup();
|
||||
e.arraylength();
|
||||
e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(int key, Label dontUseEnd) throws Exception {
|
||||
List bucket = (List)buckets.get(key);
|
||||
member_helper_type(e, bucket, callback, typer, def, end, new BitSet());
|
||||
}
|
||||
@Override
|
||||
public void processDefault() throws Exception {
|
||||
e.goTo(def);
|
||||
}
|
||||
|
|
@ -816,7 +844,7 @@ public class EmitUtils {
|
|||
e.invoke_virtual(Constants.TYPE_CLASS, GET_NAME);
|
||||
e.push(TypeUtils.emulateClassGetName(types[i]));
|
||||
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
|
||||
e.if_jump(e.EQ, def);
|
||||
e.if_jump(CodeEmitter.EQ, def);
|
||||
}
|
||||
}
|
||||
e.pop();
|
||||
|
|
@ -829,6 +857,7 @@ public class EmitUtils {
|
|||
for (int i = 0; i < example.length; i++) {
|
||||
final int j = i;
|
||||
Map test = CollectionUtils.bucket(members, new Transformer() {
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return TypeUtils.emulateClassGetName(typer.getParameterTypes((MethodInfo)value)[j]);
|
||||
}
|
||||
|
|
@ -852,9 +881,11 @@ public class EmitUtils {
|
|||
final Map fbuckets = buckets;
|
||||
String[] names = (String[])buckets.keySet().toArray(new String[buckets.size()]);
|
||||
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(Object key, Label dontUseEnd) throws Exception {
|
||||
member_helper_type(e, (List)fbuckets.get(key), callback, typer, def, end, checked);
|
||||
}
|
||||
@Override
|
||||
public void processDefault() throws Exception {
|
||||
e.goTo(def);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,21 +13,22 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import org.springframework.asm.Attribute;
|
||||
import org.springframework.asm.Type;
|
||||
|
||||
abstract public class MethodInfo {
|
||||
|
||||
protected MethodInfo() {
|
||||
}
|
||||
|
||||
|
||||
abstract public ClassInfo getClassInfo();
|
||||
abstract public int getModifiers();
|
||||
abstract public Signature getSignature();
|
||||
abstract public Type[] getExceptionTypes();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null)
|
||||
return false;
|
||||
|
|
@ -36,10 +37,12 @@ abstract public class MethodInfo {
|
|||
return getSignature().equals(((MethodInfo)o).getSignature());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getSignature().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: include modifiers, exceptions
|
||||
return getSignature().toString();
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MethodInfoTransformer implements Transformer
|
||||
{
|
||||
|
|
@ -24,12 +26,13 @@ public class MethodInfoTransformer implements Transformer
|
|||
public static MethodInfoTransformer getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
if (value instanceof Method) {
|
||||
return ReflectUtils.getMethodInfo((Method)value);
|
||||
} else if (value instanceof Constructor) {
|
||||
return ReflectUtils.getMethodInfo((Constructor)value);
|
||||
if (value instanceof Method method) {
|
||||
return ReflectUtils.getMethodInfo(method);
|
||||
} else if (value instanceof Constructor<?> constructor) {
|
||||
return ReflectUtils.getMethodInfo(constructor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot get method info for " + value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.util.Set;
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
/**
|
||||
* Customize the generated class name for {@link AbstractClassGenerator}-based utilities.
|
||||
|
|
@ -39,5 +38,6 @@ public interface NamingPolicy {
|
|||
* correctly implement <code>equals</code> and <code>hashCode</code>
|
||||
* to avoid generating too many classes.
|
||||
*/
|
||||
@Override
|
||||
boolean equals(Object o);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ public class WeakCacheKey<T> extends WeakReference<T> {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof WeakCacheKey)) {
|
||||
if (!(obj instanceof WeakCacheKey<?> weakCacheKey)) {
|
||||
return false;
|
||||
}
|
||||
Object ours = get();
|
||||
Object theirs = ((WeakCacheKey) obj).get();
|
||||
Object theirs = weakCacheKey.get();
|
||||
return ours != null && theirs != null && ours.equals(theirs);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package org.springframework.cglib.core.internal;
|
||||
|
||||
import org.springframework.cglib.core.Customizer;
|
||||
import org.springframework.cglib.core.FieldTypeCustomizer;
|
||||
import org.springframework.cglib.core.KeyFactoryCustomizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.Customizer;
|
||||
import org.springframework.cglib.core.KeyFactoryCustomizer;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class CustomizerRegistry {
|
||||
|
|
@ -35,7 +38,7 @@ public class CustomizerRegistry {
|
|||
}
|
||||
return (List<T>) list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Only to keep backward compatibility.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -13,12 +13,28 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.proxy;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.asm.Label;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.ClassEmitter;
|
||||
import org.springframework.cglib.core.ClassInfo;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.CollectionUtils;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.Local;
|
||||
import org.springframework.cglib.core.MethodInfo;
|
||||
import org.springframework.cglib.core.ObjectSwitchCallback;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.Transformer;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked", "deprecation"})
|
||||
class MethodInterceptorGenerator
|
||||
|
|
@ -42,8 +58,6 @@ implements CallbackGenerator
|
|||
TypeUtils.parseType("org.springframework.cglib.proxy.MethodInterceptor");
|
||||
private static final Signature GET_DECLARED_METHODS =
|
||||
TypeUtils.parseSignature("java.lang.reflect.Method[] getDeclaredMethods()");
|
||||
private static final Signature GET_DECLARING_CLASS =
|
||||
TypeUtils.parseSignature("Class getDeclaringClass()");
|
||||
private static final Signature FIND_METHODS =
|
||||
TypeUtils.parseSignature("java.lang.reflect.Method[] findMethods(String[], java.lang.reflect.Method[])");
|
||||
private static final Signature MAKE_PROXY =
|
||||
|
|
@ -66,12 +80,11 @@ implements CallbackGenerator
|
|||
private static final Signature TO_STRING =
|
||||
TypeUtils.parseSignature("String toString()");
|
||||
private static final Transformer METHOD_TO_CLASS = new Transformer(){
|
||||
@Override
|
||||
public Object transform(Object value) {
|
||||
return ((MethodInfo)value).getClassInfo();
|
||||
}
|
||||
};
|
||||
private static final Signature CSTRUCT_SIGNATURE =
|
||||
TypeUtils.parseConstructor("String, String");
|
||||
|
||||
private String getMethodField(Signature impl) {
|
||||
return impl.getName() + "$Method";
|
||||
|
|
@ -80,6 +93,7 @@ implements CallbackGenerator
|
|||
return impl.getName() + "$Proxy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(ClassEmitter ce, Context context, List methods) {
|
||||
Map sigMap = new HashMap();
|
||||
for (Iterator it = methods.iterator(); it.hasNext();) {
|
||||
|
|
@ -113,13 +127,13 @@ implements CallbackGenerator
|
|||
|
||||
e.load_this();
|
||||
e.getfield(methodField);
|
||||
|
||||
|
||||
if (sig.getArgumentTypes().length == 0) {
|
||||
e.getfield(EMPTY_ARGS_NAME);
|
||||
} else {
|
||||
e.create_arg_array();
|
||||
}
|
||||
|
||||
|
||||
e.getfield(methodProxyField);
|
||||
e.invoke_interface(METHOD_INTERCEPTOR, INTERCEPT);
|
||||
e.unbox_or_zero(sig.getReturnType());
|
||||
|
|
@ -143,6 +157,7 @@ implements CallbackGenerator
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateStatic(CodeEmitter e, Context context, List methods) throws Exception {
|
||||
/* generates:
|
||||
static {
|
||||
|
|
@ -165,7 +180,7 @@ implements CallbackGenerator
|
|||
Local declaringclass = e.make_local();
|
||||
EmitUtils.load_class_this(e);
|
||||
e.store_local(thisclass);
|
||||
|
||||
|
||||
Map methodsByClass = CollectionUtils.bucket(methods, METHOD_TO_CLASS);
|
||||
for (Iterator i = methodsByClass.keySet().iterator(); i.hasNext();) {
|
||||
ClassInfo classInfo = (ClassInfo)i.next();
|
||||
|
|
@ -185,7 +200,7 @@ implements CallbackGenerator
|
|||
e.push(sig.getDescriptor());
|
||||
e.aastore();
|
||||
}
|
||||
|
||||
|
||||
EmitUtils.load_class(e, classInfo.getType());
|
||||
e.dup();
|
||||
e.store_local(declaringclass);
|
||||
|
|
@ -220,10 +235,12 @@ implements CallbackGenerator
|
|||
e.load_arg(0);
|
||||
e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
|
||||
ObjectSwitchCallback callback = new ObjectSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(Object key, Label end) {
|
||||
e.getfield((String)sigMap.get(key));
|
||||
e.return_value();
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.aconst_null();
|
||||
e.return_value();
|
||||
|
|
|
|||
|
|
@ -13,16 +13,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.proxy;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
|
||||
|
||||
import org.springframework.cglib.core.AbstractClassGenerator;
|
||||
import org.springframework.cglib.core.ClassesKey;
|
||||
import org.springframework.cglib.core.KeyFactory;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
|
||||
/**
|
||||
* <code>Mixin</code> allows
|
||||
|
|
@ -73,11 +78,11 @@ abstract public class Mixin {
|
|||
return gen.create();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Mixin createBean(Object[] beans) {
|
||||
|
||||
|
||||
return createBean(null, beans);
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Helper method to create a bean mixin. For finer control over the
|
||||
|
|
@ -92,26 +97,28 @@ abstract public class Mixin {
|
|||
gen.setClassLoader(loader);
|
||||
return gen.create();
|
||||
}
|
||||
|
||||
|
||||
public static class Generator extends AbstractClassGenerator {
|
||||
private static final Source SOURCE = new Source(Mixin.class.getName());
|
||||
|
||||
private Class[] classes;
|
||||
private Object[] delegates;
|
||||
private int style = STYLE_INTERFACES;
|
||||
|
||||
|
||||
private int[] route;
|
||||
|
||||
public Generator() {
|
||||
super(SOURCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassLoader getDefaultClassLoader() {
|
||||
return classes[0].getClassLoader(); // is this right?
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProtectionDomain getProtectionDomain() {
|
||||
return ReflectUtils.getProtectionDomain(classes[0]);
|
||||
return ReflectUtils.getProtectionDomain(classes[0]);
|
||||
}
|
||||
|
||||
public void setStyle(int style) {
|
||||
|
|
@ -166,10 +173,11 @@ abstract public class Mixin {
|
|||
}
|
||||
}
|
||||
setNamePrefix(classes[ReflectUtils.findPackageProtected(classes)].getName());
|
||||
|
||||
|
||||
return (Mixin)super.create(KEY_FACTORY.newInstance(style, ReflectUtils.getNames( classes ), route));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateClass(ClassVisitor v) {
|
||||
switch (style) {
|
||||
case STYLE_INTERFACES:
|
||||
|
|
@ -184,10 +192,12 @@ abstract public class Mixin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object firstInstance(Class type) {
|
||||
return ((Mixin)ReflectUtils.newInstance(type)).newInstance(delegates);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object nextInstance(Object instance) {
|
||||
return ((Mixin)instance).newInstance(delegates);
|
||||
}
|
||||
|
|
@ -200,7 +210,7 @@ abstract public class Mixin {
|
|||
// public static int[] getRoute(Object[] delegates) {
|
||||
// return (int[])route(delegates).route.clone();
|
||||
// }
|
||||
|
||||
|
||||
private static Route route(Object[] delegates) {
|
||||
Object key = ClassesKey.create(delegates);
|
||||
Route route = (Route)ROUTE_CACHE.get(key);
|
||||
|
|
|
|||
|
|
@ -13,11 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.proxy;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Member;
|
||||
|
||||
import org.springframework.cglib.core.CodeGenerationException;
|
||||
|
||||
/**
|
||||
|
|
@ -40,6 +41,7 @@ public class Proxy implements Serializable {
|
|||
protected InvocationHandler h;
|
||||
|
||||
private static final CallbackFilter BAD_OBJECT_METHOD_FILTER = new CallbackFilter() {
|
||||
@Override
|
||||
public int accept(Method method) {
|
||||
if (method.getDeclaringClass().getName().equals("java.lang.Object")) {
|
||||
String name = method.getName();
|
||||
|
|
|
|||
|
|
@ -13,14 +13,24 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.reflect;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.ProtectionDomain;
|
||||
import org.springframework.cglib.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.AbstractClassGenerator;
|
||||
import org.springframework.cglib.core.ClassEmitter;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.KeyFactory;
|
||||
import org.springframework.cglib.core.MethodInfo;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
|
||||
// TODO: don't require exact match for return type
|
||||
|
||||
|
|
@ -133,11 +143,13 @@ abstract public class MethodDelegate {
|
|||
return gen.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
MethodDelegate other = (MethodDelegate)obj;
|
||||
return (other != null && target == other.target) && eqMethod.equals(other.eqMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return target.hashCode() ^ eqMethod.hashCode();
|
||||
}
|
||||
|
|
@ -181,12 +193,14 @@ abstract public class MethodDelegate {
|
|||
this.iface = iface;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassLoader getDefaultClassLoader() {
|
||||
return targetClass.getClassLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProtectionDomain getProtectionDomain() {
|
||||
return ReflectUtils.getProtectionDomain(targetClass);
|
||||
return ReflectUtils.getProtectionDomain(targetClass);
|
||||
}
|
||||
|
||||
public MethodDelegate create() {
|
||||
|
|
@ -195,14 +209,17 @@ abstract public class MethodDelegate {
|
|||
return (MethodDelegate)super.create(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object firstInstance(Class type) {
|
||||
return ((MethodDelegate)ReflectUtils.newInstance(type)).newInstance(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object nextInstance(Object instance) {
|
||||
return ((MethodDelegate)instance).newInstance(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateClass(ClassVisitor v) throws NoSuchMethodException {
|
||||
Method proxy = ReflectUtils.findInterfaceMethod(iface);
|
||||
final Method method = targetClass.getMethod(methodName, proxy.getParameterTypes());
|
||||
|
|
|
|||
|
|
@ -13,15 +13,27 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.reflect;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.AbstractClassGenerator;
|
||||
import org.springframework.cglib.core.ClassEmitter;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.Local;
|
||||
import org.springframework.cglib.core.MethodInfo;
|
||||
import org.springframework.cglib.core.ProcessArrayCallback;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
abstract public class MulticastDelegate implements Cloneable {
|
||||
|
|
@ -82,12 +94,14 @@ abstract public class MulticastDelegate implements Cloneable {
|
|||
super(SOURCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassLoader getDefaultClassLoader() {
|
||||
return iface.getClassLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProtectionDomain getProtectionDomain() {
|
||||
return ReflectUtils.getProtectionDomain(iface);
|
||||
return ReflectUtils.getProtectionDomain(iface);
|
||||
}
|
||||
|
||||
public void setInterface(Class iface) {
|
||||
|
|
@ -99,6 +113,7 @@ abstract public class MulticastDelegate implements Cloneable {
|
|||
return (MulticastDelegate)super.create(iface.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateClass(ClassVisitor cv) {
|
||||
final MethodInfo method = ReflectUtils.getMethodInfo(ReflectUtils.findInterfaceMethod(iface));
|
||||
|
||||
|
|
@ -152,6 +167,7 @@ abstract public class MulticastDelegate implements Cloneable {
|
|||
e.super_getfield("targets", Constants.TYPE_OBJECT_ARRAY);
|
||||
final Local result2 = result;
|
||||
EmitUtils.process_array(e, Constants.TYPE_OBJECT_ARRAY, new ProcessArrayCallback() {
|
||||
@Override
|
||||
public void processElement(Type type) {
|
||||
e.checkcast(Type.getType(iface));
|
||||
e.load_args();
|
||||
|
|
@ -168,11 +184,13 @@ abstract public class MulticastDelegate implements Cloneable {
|
|||
e.end_method();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object firstInstance(Class type) {
|
||||
// make a new instance in case first object is used with a long list of targets
|
||||
return ((MulticastDelegate)ReflectUtils.newInstance(type)).newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object nextInstance(Object instance) {
|
||||
return ((MulticastDelegate)instance).newInstance();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cglib.transform;
|
||||
|
||||
import org.springframework.asm.*;
|
||||
package org.springframework.cglib.transform;
|
||||
|
||||
public class ClassFilterTransformer extends AbstractClassFilterTransformer {
|
||||
private ClassFilter filter;
|
||||
|
|
@ -25,6 +24,7 @@ public class ClassFilterTransformer extends AbstractClassFilterTransformer {
|
|||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean accept(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
return filter.accept(name.replace('/', '.'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cglib.transform;
|
||||
|
||||
import org.springframework.asm.Attribute;
|
||||
package org.springframework.cglib.transform;
|
||||
|
||||
public interface MethodFilter {
|
||||
// TODO: pass class name too?
|
||||
|
|
|
|||
|
|
@ -13,21 +13,22 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform;
|
||||
|
||||
import org.springframework.cglib.core.ClassGenerator;
|
||||
import org.springframework.cglib.core.Transformer;
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.cglib.core.ClassGenerator;
|
||||
|
||||
public class TransformingClassGenerator implements ClassGenerator {
|
||||
private ClassGenerator gen;
|
||||
private ClassTransformer t;
|
||||
|
||||
private final ClassGenerator gen;
|
||||
private final ClassTransformer t;
|
||||
|
||||
public TransformingClassGenerator(ClassGenerator gen, ClassTransformer t) {
|
||||
this.gen = gen;
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateClass(ClassVisitor v) throws Exception {
|
||||
t.setTarget(v);
|
||||
gen.generateClass(t);
|
||||
|
|
|
|||
|
|
@ -13,20 +13,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.asm.ClassReader;
|
||||
import org.springframework.cglib.core.ClassGenerator;
|
||||
import org.springframework.asm.*;
|
||||
|
||||
public class TransformingClassLoader extends AbstractClassLoader {
|
||||
private ClassTransformerFactory t;
|
||||
|
||||
private final ClassTransformerFactory t;
|
||||
|
||||
public TransformingClassLoader(ClassLoader parent, ClassFilter filter, ClassTransformerFactory t) {
|
||||
super(parent, parent, filter);
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassGenerator getGenerator(ClassReader r) {
|
||||
ClassTransformer t2 = t.newInstance();
|
||||
return new TransformingClassGenerator(super.getGenerator(r), t2);
|
||||
|
|
|
|||
|
|
@ -13,14 +13,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform.impl;
|
||||
|
||||
import org.springframework.cglib.transform.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Attribute;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
import org.springframework.cglib.transform.ClassEmitterTransformer;
|
||||
|
||||
public class AccessFieldTransformer extends ClassEmitterTransformer {
|
||||
private Callback callback;
|
||||
|
|
@ -33,6 +34,7 @@ public class AccessFieldTransformer extends ClassEmitterTransformer {
|
|||
String getPropertyName(Type owner, String fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declare_field(int access, final String name, Type type, Object value) {
|
||||
super.declare_field(access, name, type, value);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,14 +13,20 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform.impl;
|
||||
|
||||
import org.springframework.cglib.transform.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import org.springframework.asm.Attribute;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.CodeGenerationException;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
import org.springframework.cglib.transform.ClassEmitterTransformer;
|
||||
|
||||
/**
|
||||
* @author Juozas Baliuka
|
||||
|
|
@ -30,11 +36,11 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
|
|||
private static final String DELEGATE = "$CGLIB_DELEGATE";
|
||||
private static final Signature CSTRUCT_OBJECT =
|
||||
TypeUtils.parseSignature("void <init>(Object)");
|
||||
|
||||
|
||||
private Class[] delegateIf;
|
||||
private Class delegateImpl;
|
||||
private Type delegateType;
|
||||
|
||||
|
||||
/** Creates a new instance of AddDelegateTransformer */
|
||||
public AddDelegateTransformer(Class delegateIf[], Class delegateImpl) {
|
||||
try {
|
||||
|
|
@ -46,14 +52,15 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
|
|||
throw new CodeGenerationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) {
|
||||
|
||||
|
||||
if(!TypeUtils.isInterface(access)){
|
||||
|
||||
|
||||
Type[] all = TypeUtils.add(interfaces, TypeUtils.getTypes(delegateIf));
|
||||
super.begin_class(version, access, className, superType, all, sourceFile);
|
||||
|
||||
|
||||
declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT,
|
||||
DELEGATE,
|
||||
delegateType,
|
||||
|
|
@ -71,11 +78,13 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
|
||||
final CodeEmitter e = super.begin_method(access, sig, exceptions);
|
||||
if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
|
||||
return new CodeEmitter(e) {
|
||||
private boolean transformInit = true;
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
if (transformInit && opcode == Constants.INVOKESPECIAL) {
|
||||
|
|
@ -115,6 +124,3 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
|
|||
e.end_method();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform.impl;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.MethodInfo;
|
||||
|
|
@ -24,18 +26,15 @@ import org.springframework.cglib.core.ReflectUtils;
|
|||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.transform.ClassEmitterTransformer;
|
||||
|
||||
import org.springframework.asm.Attribute;
|
||||
import org.springframework.asm.Type;
|
||||
|
||||
/**
|
||||
* @author Mark Hobson
|
||||
* @author Mark Hobson
|
||||
*/
|
||||
public class AddInitTransformer extends ClassEmitterTransformer {
|
||||
private MethodInfo info;
|
||||
|
||||
|
||||
public AddInitTransformer(Method method) {
|
||||
info = ReflectUtils.getMethodInfo(method);
|
||||
|
||||
|
||||
Type[] types = info.getSignature().getArgumentTypes();
|
||||
if (types.length != 1 ||
|
||||
!types[0].equals(Constants.TYPE_OBJECT) ||
|
||||
|
|
@ -43,11 +42,13 @@ public class AddInitTransformer extends ClassEmitterTransformer {
|
|||
throw new IllegalArgumentException(method + " illegal signature");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
|
||||
final CodeEmitter emitter = super.begin_method(access, sig, exceptions);
|
||||
if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
|
||||
return new CodeEmitter(emitter) {
|
||||
@Override
|
||||
public void visitInsn(int opcode) {
|
||||
if (opcode == Constants.RETURN) {
|
||||
load_this();
|
||||
|
|
@ -60,4 +61,3 @@ public class AddInitTransformer extends ClassEmitterTransformer {
|
|||
return emitter;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,21 +13,30 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform.impl;
|
||||
|
||||
import org.springframework.cglib.transform.*;
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import org.springframework.asm.Attribute;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.asm.Label;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.CodeGenerationException;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.ObjectSwitchCallback;
|
||||
import org.springframework.cglib.core.ProcessSwitchCallback;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
import org.springframework.cglib.transform.ClassEmitterTransformer;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class FieldProviderTransformer extends ClassEmitterTransformer {
|
||||
|
||||
|
||||
private static final String FIELD_NAMES = "CGLIB$FIELD_NAMES";
|
||||
private static final String FIELD_TYPES = "CGLIB$FIELD_TYPES";
|
||||
|
||||
|
||||
private static final Type FIELD_PROVIDER =
|
||||
TypeUtils.parseType("org.springframework.cglib.transform.impl.FieldProvider");
|
||||
private static final Type ILLEGAL_ARGUMENT_EXCEPTION =
|
||||
|
|
@ -44,10 +53,11 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
TypeUtils.parseSignature("Class[] getFieldTypes()");
|
||||
private static final Signature PROVIDER_GET_NAMES =
|
||||
TypeUtils.parseSignature("String[] getFieldNames()");
|
||||
|
||||
|
||||
private int access;
|
||||
private Map fields;
|
||||
|
||||
|
||||
@Override
|
||||
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) {
|
||||
if (!TypeUtils.isAbstract(access)) {
|
||||
interfaces = TypeUtils.add(interfaces, FIELD_PROVIDER);
|
||||
|
|
@ -57,16 +67,18 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
super.begin_class(version, access, className, superType, interfaces, sourceFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declare_field(int access, String name, Type type, Object value) {
|
||||
super.declare_field(access, name, type, value);
|
||||
|
||||
|
||||
if (!TypeUtils.isStatic(access)) {
|
||||
fields.put(name, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end_class() {
|
||||
if (!TypeUtils.isInterface(access)) {
|
||||
if (!TypeUtils.isInterface(access)) {
|
||||
try {
|
||||
generate();
|
||||
} catch (RuntimeException e) {
|
||||
|
|
@ -85,7 +97,7 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
for (int i = 0; i < indexes.length; i++) {
|
||||
indexes[i] = i;
|
||||
}
|
||||
|
||||
|
||||
super.declare_field(Constants.PRIVATE_FINAL_STATIC, FIELD_NAMES, Constants.TYPE_STRING_ARRAY, null);
|
||||
super.declare_field(Constants.PRIVATE_FINAL_STATIC, FIELD_TYPES, Constants.TYPE_CLASS_ARRAY, null);
|
||||
|
||||
|
|
@ -103,11 +115,11 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
CodeEmitter e = getStaticHook();
|
||||
EmitUtils.push_object(e, names);
|
||||
e.putstatic(getClassType(), FIELD_NAMES, Constants.TYPE_STRING_ARRAY);
|
||||
|
||||
|
||||
e.push(names.length);
|
||||
e.newarray(Constants.TYPE_CLASS);
|
||||
e.dup();
|
||||
for(int i = 0; i < names.length; i++ ){
|
||||
for(int i = 0; i < names.length; i++ ){
|
||||
e.dup();
|
||||
e.push(i);
|
||||
Type type = (Type)fields.get(names[i]);
|
||||
|
|
@ -137,14 +149,16 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
e.load_arg(1);
|
||||
e.load_arg(0);
|
||||
e.process_switch(indexes, new ProcessSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(int key, Label end) throws Exception {
|
||||
Type type = (Type)fields.get(names[key]);
|
||||
e.unbox(type);
|
||||
e.putfield(names[key]);
|
||||
e.return_value();
|
||||
}
|
||||
@Override
|
||||
public void processDefault() throws Exception {
|
||||
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
|
||||
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
|
||||
}
|
||||
});
|
||||
e.end_method();
|
||||
|
|
@ -155,14 +169,16 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
e.load_this();
|
||||
e.load_arg(0);
|
||||
e.process_switch(indexes, new ProcessSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(int key, Label end) throws Exception {
|
||||
Type type = (Type)fields.get(names[key]);
|
||||
e.getfield(names[key]);
|
||||
e.box(type);
|
||||
e.return_value();
|
||||
}
|
||||
@Override
|
||||
public void processDefault() throws Exception {
|
||||
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
|
||||
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
|
||||
}
|
||||
});
|
||||
e.end_method();
|
||||
|
|
@ -175,12 +191,14 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
e.load_this();
|
||||
e.load_arg(0);
|
||||
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(Object key, Label end) {
|
||||
Type type = (Type)fields.get(key);
|
||||
e.getfield((String)key);
|
||||
e.box(type);
|
||||
e.return_value();
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
|
||||
}
|
||||
|
|
@ -194,12 +212,14 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
|
|||
e.load_arg(1);
|
||||
e.load_arg(0);
|
||||
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(Object key, Label end) {
|
||||
Type type = (Type)fields.get(key);
|
||||
e.unbox(type);
|
||||
e.putfield((String)key);
|
||||
e.return_value();
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,18 +13,24 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.transform.impl;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import org.springframework.cglib.core.*;
|
||||
import org.springframework.cglib.transform.*;
|
||||
import org.springframework.asm.Attribute;
|
||||
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.cglib.core.Block;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
import org.springframework.cglib.transform.ClassEmitterTransformer;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
|
||||
private Type wrapper;
|
||||
|
||||
private final Type wrapper;
|
||||
|
||||
public UndeclaredThrowableTransformer(Class wrapper) {
|
||||
this.wrapper = Type.getType(wrapper);
|
||||
|
|
@ -41,6 +47,7 @@ public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
|
|||
throw new IllegalArgumentException(wrapper + " does not have a single-arg constructor that takes a Throwable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeEmitter begin_method(int access, final Signature sig, final Type[] exceptions) {
|
||||
CodeEmitter e = super.begin_method(access, sig, exceptions);
|
||||
if (TypeUtils.isAbstract(access) || sig.equals(Constants.SIG_STATIC)) {
|
||||
|
|
@ -51,6 +58,7 @@ public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
|
|||
/* init */ {
|
||||
handler = begin_block();
|
||||
}
|
||||
@Override
|
||||
public void visitMaxs(int maxStack, int maxLocals) {
|
||||
handler.end();
|
||||
EmitUtils.wrap_undeclared_throwable(this, handler, exceptions, wrapper);
|
||||
|
|
|
|||
|
|
@ -13,12 +13,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.util;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Comparator;
|
||||
import org.springframework.cglib.core.*;
|
||||
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.cglib.core.AbstractClassGenerator;
|
||||
import org.springframework.cglib.core.ClassesKey;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
|
||||
/**
|
||||
* For the efficient sorting of multiple arrays in parallel.
|
||||
|
|
@ -49,7 +52,7 @@ import org.springframework.asm.ClassVisitor;
|
|||
abstract public class ParallelSorter extends SorterTemplate {
|
||||
protected Object[] a;
|
||||
private Comparer comparer;
|
||||
|
||||
|
||||
protected ParallelSorter() {
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +153,7 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
chooseComparer(index, cmp);
|
||||
super.mergeSort(lo, hi - 1);
|
||||
}
|
||||
|
||||
|
||||
private void chooseComparer(int index, Comparator cmp) {
|
||||
Object array = a[index];
|
||||
Class type = array.getClass().getComponentType();
|
||||
|
|
@ -170,9 +173,10 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
comparer = new ComparatorComparer((Object[])array, cmp);
|
||||
} else {
|
||||
comparer = new ObjectComparer((Object[])array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int compare(int i, int j) {
|
||||
return comparer.compare(i, j);
|
||||
}
|
||||
|
|
@ -190,14 +194,16 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
this.cmp = cmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(int i, int j) {
|
||||
return cmp.compare(a[i], a[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class ObjectComparer implements Comparer {
|
||||
private Object[] a;
|
||||
public ObjectComparer(Object[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) {
|
||||
return ((Comparable)a[i]).compareTo(a[j]);
|
||||
}
|
||||
|
|
@ -206,12 +212,14 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
static class IntComparer implements Comparer {
|
||||
private int[] a;
|
||||
public IntComparer(int[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) { return a[i] - a[j]; }
|
||||
}
|
||||
|
||||
static class LongComparer implements Comparer {
|
||||
private long[] a;
|
||||
public LongComparer(long[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) {
|
||||
long vi = a[i];
|
||||
long vj = a[j];
|
||||
|
|
@ -222,16 +230,18 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
static class FloatComparer implements Comparer {
|
||||
private float[] a;
|
||||
public FloatComparer(float[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) {
|
||||
float vi = a[i];
|
||||
float vj = a[j];
|
||||
return (vi == vj) ? 0 : (vi > vj) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class DoubleComparer implements Comparer {
|
||||
private double[] a;
|
||||
public DoubleComparer(double[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) {
|
||||
double vi = a[i];
|
||||
double vj = a[j];
|
||||
|
|
@ -242,12 +252,14 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
static class ShortComparer implements Comparer {
|
||||
private short[] a;
|
||||
public ShortComparer(short[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) { return a[i] - a[j]; }
|
||||
}
|
||||
|
||||
static class ByteComparer implements Comparer {
|
||||
private byte[] a;
|
||||
public ByteComparer(byte[] a) { this.a = a; }
|
||||
@Override
|
||||
public int compare(int i, int j) { return a[i] - a[j]; }
|
||||
}
|
||||
|
||||
|
|
@ -260,6 +272,7 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
super(SOURCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassLoader getDefaultClassLoader() {
|
||||
return null; // TODO
|
||||
}
|
||||
|
|
@ -272,6 +285,7 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
return (ParallelSorter)super.create(ClassesKey.create(arrays));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateClass(ClassVisitor v) throws Exception {
|
||||
if (arrays.length == 0) {
|
||||
throw new IllegalArgumentException("No arrays specified to sort");
|
||||
|
|
@ -283,11 +297,13 @@ abstract public class ParallelSorter extends SorterTemplate {
|
|||
}
|
||||
new ParallelSorterEmitter(v, getClassName(), arrays);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object firstInstance(Class type) {
|
||||
return ((ParallelSorter)ReflectUtils.newInstance(type)).newInstance(arrays);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object nextInstance(Object instance) {
|
||||
return ((ParallelSorter)instance).newInstance(arrays);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,18 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import org.springframework.cglib.core.*;
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.ClassEmitter;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.Local;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
|
||||
class ParallelSorterEmitter extends ClassEmitter {
|
||||
private static final Type PARALLEL_SORTER =
|
||||
|
|
@ -83,7 +88,7 @@ class ParallelSorterEmitter extends ClassEmitter {
|
|||
e.load_local(T);
|
||||
e.load_arg(1);
|
||||
e.array_load(component);
|
||||
|
||||
|
||||
e.load_local(T);
|
||||
e.load_arg(1);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cglib.util;
|
||||
|
||||
import java.util.*;
|
||||
package org.springframework.cglib.util;
|
||||
|
||||
abstract class SorterTemplate {
|
||||
private static final int MERGESORT_THRESHOLD = 12;
|
||||
|
|
@ -71,7 +70,7 @@ abstract class SorterTemplate {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void insertionSort(int lo, int hi) {
|
||||
for (int i = lo + 1 ; i <= hi; i++) {
|
||||
for (int j = i; j > lo; j--) {
|
||||
|
|
|
|||
|
|
@ -13,16 +13,28 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cglib.util;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.cglib.core.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.Label;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.AbstractClassGenerator;
|
||||
import org.springframework.cglib.core.ClassEmitter;
|
||||
import org.springframework.cglib.core.CodeEmitter;
|
||||
import org.springframework.cglib.core.Constants;
|
||||
import org.springframework.cglib.core.EmitUtils;
|
||||
import org.springframework.cglib.core.KeyFactory;
|
||||
import org.springframework.cglib.core.ObjectSwitchCallback;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
|
||||
/**
|
||||
* This class implements a simple String->int mapping for a fixed set of keys.
|
||||
* This class implements a simple String → int mapping for a fixed set of keys.
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
abstract public class StringSwitcher {
|
||||
|
|
@ -72,7 +84,7 @@ abstract public class StringSwitcher {
|
|||
private String[] strings;
|
||||
private int[] ints;
|
||||
private boolean fixedInput;
|
||||
|
||||
|
||||
public Generator() {
|
||||
super(SOURCE);
|
||||
}
|
||||
|
|
@ -104,6 +116,7 @@ abstract public class StringSwitcher {
|
|||
this.fixedInput = fixedInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassLoader getDefaultClassLoader() {
|
||||
return getClass().getClassLoader();
|
||||
}
|
||||
|
|
@ -117,6 +130,7 @@ abstract public class StringSwitcher {
|
|||
return (StringSwitcher)super.create(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateClass(ClassVisitor v) throws Exception {
|
||||
ClassEmitter ce = new ClassEmitter(v);
|
||||
ce.begin_class(Constants.V1_8,
|
||||
|
|
@ -131,10 +145,12 @@ abstract public class StringSwitcher {
|
|||
final List stringList = Arrays.asList(strings);
|
||||
int style = fixedInput ? Constants.SWITCH_STYLE_HASHONLY : Constants.SWITCH_STYLE_HASH;
|
||||
EmitUtils.string_switch(e, strings, style, new ObjectSwitchCallback() {
|
||||
@Override
|
||||
public void processCase(Object key, Label end) {
|
||||
e.push(ints[stringList.indexOf(key)]);
|
||||
e.return_value();
|
||||
}
|
||||
@Override
|
||||
public void processDefault() {
|
||||
e.push(-1);
|
||||
e.return_value();
|
||||
|
|
@ -144,10 +160,12 @@ abstract public class StringSwitcher {
|
|||
ce.end_class();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object firstInstance(Class type) {
|
||||
return (StringSwitcher)ReflectUtils.newInstance(type);
|
||||
return ReflectUtils.newInstance(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object nextInstance(Object instance) {
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue