Clean up warnings in CGLIB fork

This commit is contained in:
Sam Brannen 2022-08-13 16:03:28 +02:00
parent 6ba31acf35
commit d6d629a8eb
29 changed files with 431 additions and 231 deletions

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; package org.springframework.cglib.core;
import org.springframework.asm.Attribute;
import org.springframework.asm.Type; import org.springframework.asm.Type;
abstract public class ClassInfo { abstract public class ClassInfo {
@ -28,6 +28,7 @@ abstract public class ClassInfo {
abstract public Type[] getInterfaces(); abstract public Type[] getInterfaces();
abstract public int getModifiers(); abstract public int getModifiers();
@Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == null) if (o == null)
return false; return false;
@ -36,10 +37,12 @@ abstract public class ClassInfo {
return getType().equals(((ClassInfo)o).getType()); return getType().equals(((ClassInfo)o).getType());
} }
@Override
public int hashCode() { public int hashCode() {
return getType().hashCode(); return getType().hashCode();
} }
@Override
public String toString() { public String toString() {
// TODO: include modifiers, superType, interfaces // TODO: include modifiers, superType, interfaces
return getType().getClassName(); return getType().getClassName();

View File

@ -13,11 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; package org.springframework.cglib.core;
import java.io.*; import java.util.Arrays;
import java.util.*;
import org.springframework.asm.*; import org.springframework.asm.Label;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Type;
/** /**
* @author Juozas Baliuka, Chris Nokleberg * @author Juozas Baliuka, Chris Nokleberg
@ -81,26 +84,26 @@ public class CodeEmitter extends LocalVariablesSorter {
argumentTypes = sig.getArgumentTypes(); argumentTypes = sig.getArgumentTypes();
} }
@Override
public ClassInfo getClassInfo() { public ClassInfo getClassInfo() {
return classInfo; return classInfo;
} }
@Override
public int getModifiers() { public int getModifiers() {
return access; return access;
} }
@Override
public Signature getSignature() { public Signature getSignature() {
return sig; return sig;
} }
@Override
public Type[] getExceptionTypes() { public Type[] getExceptionTypes() {
return exceptionTypes; return exceptionTypes;
} }
public Attribute getAttribute() {
// TODO
return null;
}
} }
CodeEmitter(ClassEmitter ce, MethodVisitor mv, int access, Signature sig, Type[] exceptionTypes) { CodeEmitter(ClassEmitter ce, MethodVisitor mv, int access, Signature sig, Type[] exceptionTypes) {
@ -309,7 +312,7 @@ public class CodeEmitter extends LocalVariablesSorter {
mv.visitLdcInsn(i); mv.visitLdcInsn(i);
} }
} }
public void push(long value) { public void push(long value) {
if (value == 0L || value == 1L) { if (value == 0L || value == 1L) {
mv.visitInsn(TypeUtils.LCONST(value)); mv.visitInsn(TypeUtils.LCONST(value));
@ -317,7 +320,7 @@ public class CodeEmitter extends LocalVariablesSorter {
mv.visitLdcInsn(value); mv.visitLdcInsn(value);
} }
} }
public void push(float value) { public void push(float value) {
if (value == 0f || value == 1f || value == 2f) { if (value == 0f || value == 1f || value == 2f) {
mv.visitInsn(TypeUtils.FCONST(value)); mv.visitInsn(TypeUtils.FCONST(value));
@ -332,7 +335,7 @@ public class CodeEmitter extends LocalVariablesSorter {
mv.visitLdcInsn(value); mv.visitLdcInsn(value);
} }
} }
public void push(String value) { public void push(String value) {
mv.visitLdcInsn(value); mv.visitLdcInsn(value);
} }
@ -348,18 +351,18 @@ public class CodeEmitter extends LocalVariablesSorter {
emit_type(Constants.ANEWARRAY, type); emit_type(Constants.ANEWARRAY, type);
} }
} }
public void arraylength() { public void arraylength() {
mv.visitInsn(Constants.ARRAYLENGTH); mv.visitInsn(Constants.ARRAYLENGTH);
} }
public void load_this() { public void load_this() {
if (TypeUtils.isStatic(state.access)) { if (TypeUtils.isStatic(state.access)) {
throw new IllegalStateException("no 'this' pointer within static method"); throw new IllegalStateException("no 'this' pointer within static method");
} }
mv.visitVarInsn(Constants.ALOAD, 0); mv.visitVarInsn(Constants.ALOAD, 0);
} }
/** /**
* Pushes all of the arguments of the current method onto the stack. * Pushes all of the arguments of the current method onto the stack.
*/ */
@ -385,7 +388,7 @@ public class CodeEmitter extends LocalVariablesSorter {
pos += t.getSize(); pos += t.getSize();
} }
} }
private int skipArgs(int numArgs) { private int skipArgs(int numArgs) {
int amount = 0; int amount = 0;
for (int i = 0; i < numArgs; i++) { for (int i = 0; i < numArgs; i++) {
@ -403,15 +406,15 @@ public class CodeEmitter extends LocalVariablesSorter {
// TODO: make t == null ok? // TODO: make t == null ok?
mv.visitVarInsn(t.getOpcode(Constants.ISTORE), pos); mv.visitVarInsn(t.getOpcode(Constants.ISTORE), pos);
} }
public void iinc(Local local, int amount) { public void iinc(Local local, int amount) {
mv.visitIincInsn(local.getIndex(), amount); mv.visitIincInsn(local.getIndex(), amount);
} }
public void store_local(Local local) { public void store_local(Local local) {
store_local(local.getType(), local.getIndex()); store_local(local.getType(), local.getIndex());
} }
public void load_local(Local local) { public void load_local(Local local) {
load_local(local.getType(), local.getIndex()); 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; int opcode = TypeUtils.isStatic(info.access) ? Constants.GETSTATIC : Constants.GETFIELD;
emit_field(opcode, ce.getClassType(), name, info.type); emit_field(opcode, ce.getClassType(), name, info.type);
} }
public void putfield(String name) { public void putfield(String name) {
ClassEmitter.FieldInfo info = ce.getFieldInfo(name); ClassEmitter.FieldInfo info = ce.getFieldInfo(name);
int opcode = TypeUtils.isStatic(info.access) ? Constants.PUTSTATIC : Constants.PUTFIELD; 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) { public void super_getfield(String name, Type type) {
emit_field(Constants.GETFIELD, ce.getSuperType(), name, type); emit_field(Constants.GETFIELD, ce.getSuperType(), name, type);
} }
public void super_putfield(String name, Type type) { public void super_putfield(String name, Type type) {
emit_field(Constants.PUTFIELD, ce.getSuperType(), name, 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) { public void super_getstatic(String name, Type type) {
emit_field(Constants.GETSTATIC, ce.getSuperType(), name, type); emit_field(Constants.GETSTATIC, ce.getSuperType(), name, type);
} }
public void super_putstatic(String name, Type type) { public void super_putstatic(String name, Type type) {
emit_field(Constants.PUTSTATIC, ce.getSuperType(), name, 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) { public void getfield(Type owner, String name, Type type) {
emit_field(Constants.GETFIELD, owner, name, type); emit_field(Constants.GETFIELD, owner, name, type);
} }
public void putfield(Type owner, String name, Type type) { public void putfield(Type owner, String name, Type type) {
emit_field(Constants.PUTFIELD, owner, name, 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) { public void getstatic(Type owner, String name, Type type) {
emit_field(Constants.GETSTATIC, owner, name, type); emit_field(Constants.GETSTATIC, owner, name, type);
} }
public void putstatic(Type owner, String name, Type type) { public void putstatic(Type owner, String name, Type type) {
emit_field(Constants.PUTSTATIC, owner, name, type); emit_field(Constants.PUTSTATIC, owner, name, type);
} }
@ -487,7 +490,7 @@ public class CodeEmitter extends LocalVariablesSorter {
public void super_invoke_constructor() { public void super_invoke_constructor() {
invoke_constructor(ce.getSuperType()); invoke_constructor(ce.getSuperType());
} }
public void invoke_constructor_this() { public void invoke_constructor_this() {
invoke_constructor(ce.getClassType()); invoke_constructor(ce.getClassType());
} }
@ -504,7 +507,7 @@ public class CodeEmitter extends LocalVariablesSorter {
sig.getDescriptor(), sig.getDescriptor(),
isInterface); isInterface);
} }
public void invoke_interface(Type owner, Signature sig) { public void invoke_interface(Type owner, Signature sig) {
emit_invoke(Constants.INVOKEINTERFACE, owner, sig, true); emit_invoke(Constants.INVOKEINTERFACE, owner, sig, true);
} }
@ -541,7 +544,7 @@ public class CodeEmitter extends LocalVariablesSorter {
public void super_invoke_constructor(Signature sig) { public void super_invoke_constructor(Signature sig) {
invoke_constructor(ce.getSuperType(), sig); invoke_constructor(ce.getSuperType(), sig);
} }
public void new_instance_this() { public void new_instance_this() {
new_instance(ce.getClassType()); new_instance(ce.getClassType());
} }
@ -572,11 +575,11 @@ public class CodeEmitter extends LocalVariablesSorter {
public Label make_label() { public Label make_label() {
return new Label(); return new Label();
} }
public Local make_local() { public Local make_local() {
return make_local(Constants.TYPE_OBJECT); return make_local(Constants.TYPE_OBJECT);
} }
public Local make_local(Type type) { public Local make_local(Type type) {
return new Local(newLocal(type.getSize()), type); return new Local(newLocal(type.getSize()), type);
} }
@ -584,7 +587,7 @@ public class CodeEmitter extends LocalVariablesSorter {
public void checkcast_this() { public void checkcast_this() {
checkcast(ce.getClassType()); checkcast(ce.getClassType());
} }
public void checkcast(Type type) { public void checkcast(Type type) {
if (!type.equals(Constants.TYPE_OBJECT)) { if (!type.equals(Constants.TYPE_OBJECT)) {
emit_type(Constants.CHECKCAST, type); emit_type(Constants.CHECKCAST, type);
@ -594,7 +597,7 @@ public class CodeEmitter extends LocalVariablesSorter {
public void instance_of(Type type) { public void instance_of(Type type) {
emit_type(Constants.INSTANCEOF, type); emit_type(Constants.INSTANCEOF, type);
} }
public void instance_of_this() { public void instance_of_this() {
instance_of(ce.getClassType()); instance_of(ce.getClassType());
} }
@ -728,7 +731,7 @@ public class CodeEmitter extends LocalVariablesSorter {
} }
} }
} }
/** /**
* If the argument is a primitive class, replaces the object * If the argument is a primitive class, replaces the object
* on the top of the stack with the unwrapped (primitive) * 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) { public void visitMaxs(int maxStack, int maxLocals) {
if (!TypeUtils.isAbstract(state.access)) { if (!TypeUtils.isAbstract(state.access)) {
mv.visitMaxs(0, 0); mv.visitMaxs(0, 0);

View File

@ -13,10 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; package org.springframework.cglib.core;
import java.util.*; import java.util.ArrayList;
import java.lang.reflect.Array; 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 * @author Chris Nokleberg
@ -73,5 +79,4 @@ public class CollectionUtils {
} }
return indexes; return indexes;
} }
} }

View File

@ -13,27 +13,32 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; 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.ClassReader;
import org.springframework.asm.ClassVisitor; import org.springframework.asm.ClassVisitor;
import org.springframework.asm.Opcodes; import org.springframework.asm.ClassWriter;
import java.io.*;
import java.lang.reflect.Constructor;
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public class DebuggingClassWriter extends ClassVisitor { public class DebuggingClassWriter extends ClassVisitor {
public static final String DEBUG_LOCATION_PROPERTY = "cglib.debugLocation"; public static final String DEBUG_LOCATION_PROPERTY = "cglib.debugLocation";
private static String debugLocation; private static String debugLocation;
private static Constructor traceCtor; private static Constructor traceCtor;
private String className; private String className;
private String superName; private String superName;
static { static {
debugLocation = System.getProperty(DEBUG_LOCATION_PROPERTY); debugLocation = System.getProperty(DEBUG_LOCATION_PROPERTY);
if (debugLocation != null) { if (debugLocation != null) {
@ -45,11 +50,12 @@ public class DebuggingClassWriter extends ClassVisitor {
} }
} }
} }
public DebuggingClassWriter(int flags) { public DebuggingClassWriter(int flags) {
super(Constants.ASM_API, new ClassWriter(flags)); super(Constants.ASM_API, new ClassWriter(flags));
} }
@Override
public void visit(int version, public void visit(int version,
int access, int access,
String name, String name,
@ -60,17 +66,17 @@ public class DebuggingClassWriter extends ClassVisitor {
this.superName = superName.replace('/', '.'); this.superName = superName.replace('/', '.');
super.visit(version, access, name, signature, superName, interfaces); super.visit(version, access, name, signature, superName, interfaces);
} }
public String getClassName() { public String getClassName() {
return className; return className;
} }
public String getSuperName() { public String getSuperName() {
return superName; return superName;
} }
public byte[] toByteArray() { public byte[] toByteArray() {
byte[] b = ((ClassWriter) DebuggingClassWriter.super.cv).toByteArray(); byte[] b = ((ClassWriter) DebuggingClassWriter.super.cv).toByteArray();
if (debugLocation != null) { if (debugLocation != null) {
String dirs = className.replace('.', File.separatorChar); String dirs = className.replace('.', File.separatorChar);

View File

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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}. * 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()}. * This allows to test collisions of {@code key.hashCode()}.
*/ */
private final static boolean STRESS_HASH_CODE = Boolean.getBoolean("org.springframework.cglib.test.stressHashCodes"); 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) { public String getClassName(String prefix, String source, Object key, Predicate names) {
if (prefix == null) { if (prefix == null) {
prefix = "org.springframework.cglib.empty.Object"; prefix = "org.springframework.cglib.empty.Object";
@ -42,7 +42,7 @@ public class DefaultNamingPolicy implements NamingPolicy {
prefix = "$" + prefix; prefix = "$" + prefix;
} }
String base = String base =
prefix + "$$" + prefix + "$$" +
source.substring(source.lastIndexOf('.') + 1) + source.substring(source.lastIndexOf('.') + 1) +
getTag() + "$$" + getTag() + "$$" +
Integer.toHexString(STRESS_HASH_CODE ? 0 : key.hashCode()); Integer.toHexString(STRESS_HASH_CODE ? 0 : key.hashCode());
@ -61,11 +61,14 @@ public class DefaultNamingPolicy implements NamingPolicy {
return "ByCGLIB"; return "ByCGLIB";
} }
public int hashCode() { @Override
return getTag().hashCode(); public int hashCode() {
} return getTag().hashCode();
}
public boolean equals(Object o) { @Override
return (o instanceof DefaultNamingPolicy) && ((DefaultNamingPolicy) o).getTag().equals(getTag()); public boolean equals(Object o) {
} return (o instanceof DefaultNamingPolicy defaultNamingPolicy) &&
defaultNamingPolicy.getTag().equals(getTag());
}
} }

View File

@ -13,15 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; package org.springframework.cglib.core;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; 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.Label;
import org.springframework.asm.Type; import org.springframework.asm.Type;
import org.springframework.cglib.core.internal.CustomizerRegistry;
@SuppressWarnings({"rawtypes", "unchecked", "static", "fallthrough", "deprecation"}) @SuppressWarnings({"rawtypes", "unchecked", "static", "fallthrough", "deprecation"})
public class EmitUtils { public class EmitUtils {
@ -68,8 +77,8 @@ public class EmitUtils {
TypeUtils.parseSignature("void setLength(int)"); TypeUtils.parseSignature("void setLength(int)");
private static final Signature GET_DECLARED_METHOD = private static final Signature GET_DECLARED_METHOD =
TypeUtils.parseSignature("java.lang.reflect.Method getDeclaredMethod(String, Class[])"); TypeUtils.parseSignature("java.lang.reflect.Method getDeclaredMethod(String, Class[])");
public static final ArrayDelimiters DEFAULT_DELIMITERS = new ArrayDelimiters("{", ", ", "}"); public static final ArrayDelimiters DEFAULT_DELIMITERS = new ArrayDelimiters("{", ", ", "}");
@ -93,7 +102,7 @@ public class EmitUtils {
e.return_value(); e.return_value();
e.end_method(); e.end_method();
} }
/** /**
* Process an array on the stack. Assumes the top item on the stack * 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, * is an array of the specified type. For each element in the array,
@ -111,21 +120,21 @@ public class EmitUtils {
e.push(0); e.push(0);
e.store_local(loopvar); e.store_local(loopvar);
e.goTo(checkloop); e.goTo(checkloop);
e.mark(loopbody); e.mark(loopbody);
e.load_local(array); e.load_local(array);
e.load_local(loopvar); e.load_local(loopvar);
e.array_load(componentType); e.array_load(componentType);
callback.processElement(componentType); callback.processElement(componentType);
e.iinc(loopvar, 1); e.iinc(loopvar, 1);
e.mark(checkloop); e.mark(checkloop);
e.load_local(loopvar); e.load_local(loopvar);
e.load_local(array); e.load_local(array);
e.arraylength(); 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 * 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 * 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.push(0);
e.store_local(loopvar); e.store_local(loopvar);
e.goTo(checkloop); e.goTo(checkloop);
e.mark(loopbody); e.mark(loopbody);
e.load_local(array1); e.load_local(array1);
e.load_local(loopvar); e.load_local(loopvar);
@ -155,14 +164,14 @@ public class EmitUtils {
e.array_load(componentType); e.array_load(componentType);
callback.processElement(componentType); callback.processElement(componentType);
e.iinc(loopvar, 1); e.iinc(loopvar, 1);
e.mark(checkloop); e.mark(checkloop);
e.load_local(loopvar); e.load_local(loopvar);
e.load_local(array1); e.load_local(array1);
e.arraylength(); 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) { public static void string_switch(CodeEmitter e, String[] strings, int switchStyle, ObjectSwitchCallback callback) {
try { try {
switch (switchStyle) { switch (switchStyle) {
@ -193,6 +202,7 @@ public class EmitUtils {
final Label def = e.make_label(); final Label def = e.make_label();
final Label end = e.make_label(); final Label end = e.make_label();
final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() { final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() {
@Override
public Object transform(Object value) { public Object transform(Object value) {
return ((String)value).length(); return ((String)value).length();
} }
@ -200,10 +210,12 @@ public class EmitUtils {
e.dup(); e.dup();
e.invoke_virtual(Constants.TYPE_STRING, STRING_LENGTH); e.invoke_virtual(Constants.TYPE_STRING, STRING_LENGTH);
e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() { e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {
@Override
public void processCase(int key, Label ignore_end) throws Exception { public void processCase(int key, Label ignore_end) throws Exception {
List bucket = (List)buckets.get(key); List bucket = (List)buckets.get(key);
stringSwitchHelper(e, bucket, callback, def, end, 0); stringSwitchHelper(e, bucket, callback, def, end, 0);
} }
@Override
public void processDefault() { public void processDefault() {
e.goTo(def); e.goTo(def);
} }
@ -222,6 +234,7 @@ public class EmitUtils {
final int index) throws Exception { final int index) throws Exception {
final int len = ((String)strings.get(0)).length(); final int len = ((String)strings.get(0)).length();
final Map buckets = CollectionUtils.bucket(strings, new Transformer() { final Map buckets = CollectionUtils.bucket(strings, new Transformer() {
@Override
public Object transform(Object value) { public Object transform(Object value) {
return ((String)value).charAt(index); return ((String)value).charAt(index);
} }
@ -230,6 +243,7 @@ public class EmitUtils {
e.push(index); e.push(index);
e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT); e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT);
e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() { e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {
@Override
public void processCase(int key, Label ignore_end) throws Exception { public void processCase(int key, Label ignore_end) throws Exception {
List bucket = (List)buckets.get(key); List bucket = (List)buckets.get(key);
if (index + 1 == len) { if (index + 1 == len) {
@ -239,11 +253,12 @@ public class EmitUtils {
stringSwitchHelper(e, bucket, callback, def, end, index + 1); stringSwitchHelper(e, bucket, callback, def, end, index + 1);
} }
} }
@Override
public void processDefault() { public void processDefault() {
e.goTo(def); e.goTo(def);
} }
}); });
} }
static int[] getSwitchKeys(Map buckets) { static int[] getSwitchKeys(Map buckets) {
int[] keys = new int[buckets.size()]; int[] keys = new int[buckets.size()];
@ -260,6 +275,7 @@ public class EmitUtils {
final ObjectSwitchCallback callback, final ObjectSwitchCallback callback,
final boolean skipEquals) throws Exception { final boolean skipEquals) throws Exception {
final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() { final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() {
@Override
public Object transform(Object value) { public Object transform(Object value) {
return value.hashCode(); return value.hashCode();
} }
@ -269,13 +285,14 @@ public class EmitUtils {
e.dup(); e.dup();
e.invoke_virtual(Constants.TYPE_OBJECT, HASH_CODE); e.invoke_virtual(Constants.TYPE_OBJECT, HASH_CODE);
e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() { e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {
@Override
public void processCase(int key, Label ignore_end) throws Exception { public void processCase(int key, Label ignore_end) throws Exception {
List bucket = (List)buckets.get(key); List bucket = (List)buckets.get(key);
Label next = null; Label next = null;
if (skipEquals && bucket.size() == 1) { if (skipEquals && bucket.size() == 1) {
if (skipEquals) if (skipEquals)
e.pop(); e.pop();
callback.processCase((String)bucket.get(0), end); callback.processCase(bucket.get(0), end);
} else { } else {
for (Iterator it = bucket.iterator(); it.hasNext();) { for (Iterator it = bucket.iterator(); it.hasNext();) {
String string = (String)it.next(); String string = (String)it.next();
@ -288,15 +305,16 @@ public class EmitUtils {
e.push(string); e.push(string);
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS); e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
if (it.hasNext()) { if (it.hasNext()) {
e.if_jump(e.EQ, next = e.make_label()); e.if_jump(CodeEmitter.EQ, next = e.make_label());
e.pop(); e.pop();
} else { } else {
e.if_jump(e.EQ, def); e.if_jump(CodeEmitter.EQ, def);
} }
callback.processCase(string, end); callback.processCase(string, end);
} }
} }
} }
@Override
public void processDefault() { public void processDefault() {
e.pop(); e.pop();
} }
@ -309,7 +327,7 @@ public class EmitUtils {
public static void load_class_this(CodeEmitter e) { public static void load_class_this(CodeEmitter e) {
load_class_helper(e, e.getClassEmitter().getClassType()); load_class_helper(e, e.getClassEmitter().getClassType());
} }
public static void load_class(CodeEmitter e, Type type) { public static void load_class(CodeEmitter e, Type type) {
if (TypeUtils.isPrimitive(type)) { if (TypeUtils.isPrimitive(type)) {
if (type == Type.VOID_TYPE) { if (type == Type.VOID_TYPE) {
@ -359,7 +377,7 @@ public class EmitUtils {
return Class.class; return Class.class;
return componentType; return componentType;
} }
public static void push_object(CodeEmitter e, Object obj) { public static void push_object(CodeEmitter e, Object obj) {
if (obj == null) { if (obj == null) {
e.aconst_null(); e.aconst_null();
@ -394,23 +412,23 @@ public class EmitUtils {
*/ */
@Deprecated @Deprecated
public static void hash_code(CodeEmitter e, Type type, int multiplier, final Customizer customizer) { 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) { public static void hash_code(CodeEmitter e, Type type, int multiplier, final CustomizerRegistry registry) {
if (TypeUtils.isArray(type)) { if (TypeUtils.isArray(type)) {
hash_array(e, type, multiplier, registry); hash_array(e, type, multiplier, registry);
} else { } else {
e.swap(Type.INT_TYPE, type); e.swap(Type.INT_TYPE, type);
e.push(multiplier); e.push(multiplier);
e.math(e.MUL, Type.INT_TYPE); e.math(CodeEmitter.MUL, Type.INT_TYPE);
e.swap(type, Type.INT_TYPE); e.swap(type, Type.INT_TYPE);
if (TypeUtils.isPrimitive(type)) { if (TypeUtils.isPrimitive(type)) {
hash_primitive(e, type); hash_primitive(e, type);
} else { } else {
hash_object(e, type, registry); 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.dup();
e.ifnull(skip); e.ifnull(skip);
EmitUtils.process_array(e, type, new ProcessArrayCallback() { EmitUtils.process_array(e, type, new ProcessArrayCallback() {
@Override
public void processElement(Type type) { public void processElement(Type type) {
hash_code(e, type, multiplier, registry); hash_code(e, type, multiplier, registry);
} }
@ -461,7 +480,7 @@ public class EmitUtils {
case Type.BOOLEAN: case Type.BOOLEAN:
// f ? 0 : 1 // f ? 0 : 1
e.push(1); e.push(1);
e.math(e.XOR, Type.INT_TYPE); e.math(CodeEmitter.XOR, Type.INT_TYPE);
break; break;
case Type.FLOAT: case Type.FLOAT:
// Float.floatToIntBits(f) // Float.floatToIntBits(f)
@ -480,23 +499,23 @@ public class EmitUtils {
// (int)(f ^ (f >>> 32)) // (int)(f ^ (f >>> 32))
e.dup2(); e.dup2();
e.push(32); e.push(32);
e.math(e.USHR, Type.LONG_TYPE); e.math(CodeEmitter.USHR, Type.LONG_TYPE);
e.math(e.XOR, Type.LONG_TYPE); e.math(CodeEmitter.XOR, Type.LONG_TYPE);
e.cast_numeric(Type.LONG_TYPE, Type.INT_TYPE); e.cast_numeric(Type.LONG_TYPE, Type.INT_TYPE);
} }
// public static void not_equals(CodeEmitter e, Type type, Label notEquals) { // public static void not_equals(CodeEmitter e, Type type, Label notEquals) {
// not_equals(e, type, notEquals, null); // not_equals(e, type, notEquals, null);
// } // }
/** /**
* @deprecated use {@link #not_equals(CodeEmitter, Type, Label, CustomizerRegistry)} instead * @deprecated use {@link #not_equals(CodeEmitter, Type, Label, CustomizerRegistry)} instead
*/ */
@Deprecated @Deprecated
public static void not_equals(CodeEmitter e, Type type, final Label notEquals, final Customizer customizer) { 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 * Branches to the specified label if the top two items on the stack
* are not equal. The items must both be of the specified * 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) { public static void not_equals(final CodeEmitter e, Type type, final Label notEquals, final CustomizerRegistry registry) {
(new ProcessArrayCallback() { (new ProcessArrayCallback() {
@Override
public void processElement(Type type) { public void processElement(Type type) {
not_equals_helper(e, type, notEquals, registry, this); not_equals_helper(e, type, notEquals, registry, this);
} }
}).processElement(type); }).processElement(type);
} }
private static void not_equals_helper(CodeEmitter e, private static void not_equals_helper(CodeEmitter e,
Type type, Type type,
Label notEquals, Label notEquals,
CustomizerRegistry registry, CustomizerRegistry registry,
ProcessArrayCallback callback) { ProcessArrayCallback callback) {
if (TypeUtils.isPrimitive(type)) { if (TypeUtils.isPrimitive(type)) {
e.if_cmp(type, e.NE, notEquals); e.if_cmp(type, CodeEmitter.NE, notEquals);
} else { } else {
Label end = e.make_label(); Label end = e.make_label();
nullcmp(e, notEquals, end); nullcmp(e, notEquals, end);
@ -528,7 +548,7 @@ public class EmitUtils {
e.arraylength(); e.arraylength();
e.swap(); e.swap();
e.arraylength(); e.arraylength();
e.if_icmp(e.EQ, checkContents); e.if_icmp(CodeEmitter.EQ, checkContents);
e.pop2(); e.pop2();
e.goTo(notEquals); e.goTo(notEquals);
e.mark(checkContents); e.mark(checkContents);
@ -545,7 +565,7 @@ public class EmitUtils {
} }
} }
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS); e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
e.if_jump(e.EQ, notEquals); e.if_jump(CodeEmitter.EQ, notEquals);
} }
e.mark(end); e.mark(end);
} }
@ -567,15 +587,15 @@ public class EmitUtils {
e.ifnonnull(oneNullHelper); e.ifnonnull(oneNullHelper);
e.pop2(); e.pop2();
e.goTo(bothNull); e.goTo(bothNull);
e.mark(nonNull); e.mark(nonNull);
e.ifnull(oneNullHelper); e.ifnull(oneNullHelper);
e.goTo(end); e.goTo(end);
e.mark(oneNullHelper); e.mark(oneNullHelper);
e.pop2(); e.pop2();
e.goTo(oneNull); e.goTo(oneNull);
e.mark(end); e.mark(end);
} }
@ -610,6 +630,7 @@ public class EmitUtils {
final CustomizerRegistry registry) { final CustomizerRegistry registry) {
final ArrayDelimiters d = (delims != null) ? delims : DEFAULT_DELIMITERS; final ArrayDelimiters d = (delims != null) ? delims : DEFAULT_DELIMITERS;
ProcessArrayCallback callback = new ProcessArrayCallback() { ProcessArrayCallback callback = new ProcessArrayCallback() {
@Override
public void processElement(Type type) { public void processElement(Type type) {
append_string_helper(e, type, d, registry, this); append_string_helper(e, type, d, registry, this);
e.push(d.inside); e.push(d.inside);
@ -686,7 +707,7 @@ public class EmitUtils {
e.dup(); e.dup();
e.invoke_virtual(Constants.TYPE_STRING_BUFFER, LENGTH); e.invoke_virtual(Constants.TYPE_STRING_BUFFER, LENGTH);
e.push(amt); 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); e.invoke_virtual(Constants.TYPE_STRING_BUFFER, SET_LENGTH);
} }
@ -694,7 +715,7 @@ public class EmitUtils {
private String before; private String before;
private String inside; private String inside;
private String after; private String after;
public ArrayDelimiters(String before, String inside, String after) { public ArrayDelimiters(String before, String inside, String after) {
this.before = before; this.before = before;
this.inside = inside; this.inside = inside;
@ -732,6 +753,7 @@ public class EmitUtils {
try { try {
final Map cache = new HashMap(); final Map cache = new HashMap();
final ParameterTyper cached = new ParameterTyper() { final ParameterTyper cached = new ParameterTyper() {
@Override
public Type[] getParameterTypes(MethodInfo member) { public Type[] getParameterTypes(MethodInfo member) {
Type[] types = (Type[])cache.get(member); Type[] types = (Type[])cache.get(member);
if (types == null) { if (types == null) {
@ -745,15 +767,18 @@ public class EmitUtils {
if (useName) { if (useName) {
e.swap(); e.swap();
final Map buckets = CollectionUtils.bucket(members, new Transformer() { final Map buckets = CollectionUtils.bucket(members, new Transformer() {
@Override
public Object transform(Object value) { public Object transform(Object value) {
return ((MethodInfo)value).getSignature().getName(); return ((MethodInfo)value).getSignature().getName();
} }
}); });
String[] names = (String[])buckets.keySet().toArray(new String[buckets.size()]); String[] names = (String[])buckets.keySet().toArray(new String[buckets.size()]);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() { EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
@Override
public void processCase(Object key, Label dontUseEnd) throws Exception { public void processCase(Object key, Label dontUseEnd) throws Exception {
member_helper_size(e, (List)buckets.get(key), callback, cached, def, end); member_helper_size(e, (List)buckets.get(key), callback, cached, def, end);
} }
@Override
public void processDefault() throws Exception { public void processDefault() throws Exception {
e.goTo(def); e.goTo(def);
} }
@ -781,6 +806,7 @@ public class EmitUtils {
final Label def, final Label def,
final Label end) throws Exception { final Label end) throws Exception {
final Map buckets = CollectionUtils.bucket(members, new Transformer() { final Map buckets = CollectionUtils.bucket(members, new Transformer() {
@Override
public Object transform(Object value) { public Object transform(Object value) {
return typer.getParameterTypes((MethodInfo)value).length; return typer.getParameterTypes((MethodInfo)value).length;
} }
@ -788,10 +814,12 @@ public class EmitUtils {
e.dup(); e.dup();
e.arraylength(); e.arraylength();
e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() { e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() {
@Override
public void processCase(int key, Label dontUseEnd) throws Exception { public void processCase(int key, Label dontUseEnd) throws Exception {
List bucket = (List)buckets.get(key); List bucket = (List)buckets.get(key);
member_helper_type(e, bucket, callback, typer, def, end, new BitSet()); member_helper_type(e, bucket, callback, typer, def, end, new BitSet());
} }
@Override
public void processDefault() throws Exception { public void processDefault() throws Exception {
e.goTo(def); e.goTo(def);
} }
@ -816,7 +844,7 @@ public class EmitUtils {
e.invoke_virtual(Constants.TYPE_CLASS, GET_NAME); e.invoke_virtual(Constants.TYPE_CLASS, GET_NAME);
e.push(TypeUtils.emulateClassGetName(types[i])); e.push(TypeUtils.emulateClassGetName(types[i]));
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS); e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
e.if_jump(e.EQ, def); e.if_jump(CodeEmitter.EQ, def);
} }
} }
e.pop(); e.pop();
@ -829,6 +857,7 @@ public class EmitUtils {
for (int i = 0; i < example.length; i++) { for (int i = 0; i < example.length; i++) {
final int j = i; final int j = i;
Map test = CollectionUtils.bucket(members, new Transformer() { Map test = CollectionUtils.bucket(members, new Transformer() {
@Override
public Object transform(Object value) { public Object transform(Object value) {
return TypeUtils.emulateClassGetName(typer.getParameterTypes((MethodInfo)value)[j]); return TypeUtils.emulateClassGetName(typer.getParameterTypes((MethodInfo)value)[j]);
} }
@ -852,9 +881,11 @@ public class EmitUtils {
final Map fbuckets = buckets; final Map fbuckets = buckets;
String[] names = (String[])buckets.keySet().toArray(new String[buckets.size()]); String[] names = (String[])buckets.keySet().toArray(new String[buckets.size()]);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() { EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
@Override
public void processCase(Object key, Label dontUseEnd) throws Exception { public void processCase(Object key, Label dontUseEnd) throws Exception {
member_helper_type(e, (List)fbuckets.get(key), callback, typer, def, end, checked); member_helper_type(e, (List)fbuckets.get(key), callback, typer, def, end, checked);
} }
@Override
public void processDefault() throws Exception { public void processDefault() throws Exception {
e.goTo(def); e.goTo(def);
} }

View File

@ -13,21 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; package org.springframework.cglib.core;
import org.springframework.asm.Attribute;
import org.springframework.asm.Type; import org.springframework.asm.Type;
abstract public class MethodInfo { abstract public class MethodInfo {
protected MethodInfo() { protected MethodInfo() {
} }
abstract public ClassInfo getClassInfo(); abstract public ClassInfo getClassInfo();
abstract public int getModifiers(); abstract public int getModifiers();
abstract public Signature getSignature(); abstract public Signature getSignature();
abstract public Type[] getExceptionTypes(); abstract public Type[] getExceptionTypes();
@Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == null) if (o == null)
return false; return false;
@ -36,10 +37,12 @@ abstract public class MethodInfo {
return getSignature().equals(((MethodInfo)o).getSignature()); return getSignature().equals(((MethodInfo)o).getSignature());
} }
@Override
public int hashCode() { public int hashCode() {
return getSignature().hashCode(); return getSignature().hashCode();
} }
@Override
public String toString() { public String toString() {
// TODO: include modifiers, exceptions // TODO: include modifiers, exceptions
return getSignature().toString(); return getSignature().toString();

View File

@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.core; package org.springframework.cglib.core;
import java.lang.reflect.*; import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public class MethodInfoTransformer implements Transformer public class MethodInfoTransformer implements Transformer
{ {
@ -24,12 +26,13 @@ public class MethodInfoTransformer implements Transformer
public static MethodInfoTransformer getInstance() { public static MethodInfoTransformer getInstance() {
return INSTANCE; return INSTANCE;
} }
@Override
public Object transform(Object value) { public Object transform(Object value) {
if (value instanceof Method) { if (value instanceof Method method) {
return ReflectUtils.getMethodInfo((Method)value); return ReflectUtils.getMethodInfo(method);
} else if (value instanceof Constructor) { } else if (value instanceof Constructor<?> constructor) {
return ReflectUtils.getMethodInfo((Constructor)value); return ReflectUtils.getMethodInfo(constructor);
} else { } else {
throw new IllegalArgumentException("cannot get method info for " + value); throw new IllegalArgumentException("cannot get method info for " + value);
} }

View File

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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. * 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> * correctly implement <code>equals</code> and <code>hashCode</code>
* to avoid generating too many classes. * to avoid generating too many classes.
*/ */
@Override
boolean equals(Object o); boolean equals(Object o);
} }

View File

@ -21,11 +21,11 @@ public class WeakCacheKey<T> extends WeakReference<T> {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof WeakCacheKey)) { if (!(obj instanceof WeakCacheKey<?> weakCacheKey)) {
return false; return false;
} }
Object ours = get(); Object ours = get();
Object theirs = ((WeakCacheKey) obj).get(); Object theirs = weakCacheKey.get();
return ours != null && theirs != null && ours.equals(theirs); return ours != null && theirs != null && ours.equals(theirs);
} }

View File

@ -1,10 +1,13 @@
package org.springframework.cglib.core.internal; package org.springframework.cglib.core.internal;
import org.springframework.cglib.core.Customizer; import java.util.ArrayList;
import org.springframework.cglib.core.FieldTypeCustomizer; import java.util.Collections;
import org.springframework.cglib.core.KeyFactoryCustomizer; 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"}) @SuppressWarnings({"rawtypes", "unchecked"})
public class CustomizerRegistry { public class CustomizerRegistry {
@ -35,7 +38,7 @@ public class CustomizerRegistry {
} }
return (List<T>) list; return (List<T>) list;
} }
/** /**
* @deprecated Only to keep backward compatibility. * @deprecated Only to keep backward compatibility.
*/ */

View File

@ -13,12 +13,28 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.proxy; package org.springframework.cglib.proxy;
import java.util.*; import java.util.HashMap;
import org.springframework.cglib.core.*; import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.asm.Label; import org.springframework.asm.Label;
import org.springframework.asm.Type; 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"}) @SuppressWarnings({"rawtypes", "unchecked", "deprecation"})
class MethodInterceptorGenerator class MethodInterceptorGenerator
@ -42,8 +58,6 @@ implements CallbackGenerator
TypeUtils.parseType("org.springframework.cglib.proxy.MethodInterceptor"); TypeUtils.parseType("org.springframework.cglib.proxy.MethodInterceptor");
private static final Signature GET_DECLARED_METHODS = private static final Signature GET_DECLARED_METHODS =
TypeUtils.parseSignature("java.lang.reflect.Method[] getDeclaredMethods()"); TypeUtils.parseSignature("java.lang.reflect.Method[] getDeclaredMethods()");
private static final Signature GET_DECLARING_CLASS =
TypeUtils.parseSignature("Class getDeclaringClass()");
private static final Signature FIND_METHODS = private static final Signature FIND_METHODS =
TypeUtils.parseSignature("java.lang.reflect.Method[] findMethods(String[], java.lang.reflect.Method[])"); TypeUtils.parseSignature("java.lang.reflect.Method[] findMethods(String[], java.lang.reflect.Method[])");
private static final Signature MAKE_PROXY = private static final Signature MAKE_PROXY =
@ -66,12 +80,11 @@ implements CallbackGenerator
private static final Signature TO_STRING = private static final Signature TO_STRING =
TypeUtils.parseSignature("String toString()"); TypeUtils.parseSignature("String toString()");
private static final Transformer METHOD_TO_CLASS = new Transformer(){ private static final Transformer METHOD_TO_CLASS = new Transformer(){
@Override
public Object transform(Object value) { public Object transform(Object value) {
return ((MethodInfo)value).getClassInfo(); return ((MethodInfo)value).getClassInfo();
} }
}; };
private static final Signature CSTRUCT_SIGNATURE =
TypeUtils.parseConstructor("String, String");
private String getMethodField(Signature impl) { private String getMethodField(Signature impl) {
return impl.getName() + "$Method"; return impl.getName() + "$Method";
@ -80,6 +93,7 @@ implements CallbackGenerator
return impl.getName() + "$Proxy"; return impl.getName() + "$Proxy";
} }
@Override
public void generate(ClassEmitter ce, Context context, List methods) { public void generate(ClassEmitter ce, Context context, List methods) {
Map sigMap = new HashMap(); Map sigMap = new HashMap();
for (Iterator it = methods.iterator(); it.hasNext();) { for (Iterator it = methods.iterator(); it.hasNext();) {
@ -113,13 +127,13 @@ implements CallbackGenerator
e.load_this(); e.load_this();
e.getfield(methodField); e.getfield(methodField);
if (sig.getArgumentTypes().length == 0) { if (sig.getArgumentTypes().length == 0) {
e.getfield(EMPTY_ARGS_NAME); e.getfield(EMPTY_ARGS_NAME);
} else { } else {
e.create_arg_array(); e.create_arg_array();
} }
e.getfield(methodProxyField); e.getfield(methodProxyField);
e.invoke_interface(METHOD_INTERCEPTOR, INTERCEPT); e.invoke_interface(METHOD_INTERCEPTOR, INTERCEPT);
e.unbox_or_zero(sig.getReturnType()); e.unbox_or_zero(sig.getReturnType());
@ -143,6 +157,7 @@ implements CallbackGenerator
} }
} }
@Override
public void generateStatic(CodeEmitter e, Context context, List methods) throws Exception { public void generateStatic(CodeEmitter e, Context context, List methods) throws Exception {
/* generates: /* generates:
static { static {
@ -165,7 +180,7 @@ implements CallbackGenerator
Local declaringclass = e.make_local(); Local declaringclass = e.make_local();
EmitUtils.load_class_this(e); EmitUtils.load_class_this(e);
e.store_local(thisclass); e.store_local(thisclass);
Map methodsByClass = CollectionUtils.bucket(methods, METHOD_TO_CLASS); Map methodsByClass = CollectionUtils.bucket(methods, METHOD_TO_CLASS);
for (Iterator i = methodsByClass.keySet().iterator(); i.hasNext();) { for (Iterator i = methodsByClass.keySet().iterator(); i.hasNext();) {
ClassInfo classInfo = (ClassInfo)i.next(); ClassInfo classInfo = (ClassInfo)i.next();
@ -185,7 +200,7 @@ implements CallbackGenerator
e.push(sig.getDescriptor()); e.push(sig.getDescriptor());
e.aastore(); e.aastore();
} }
EmitUtils.load_class(e, classInfo.getType()); EmitUtils.load_class(e, classInfo.getType());
e.dup(); e.dup();
e.store_local(declaringclass); e.store_local(declaringclass);
@ -220,10 +235,12 @@ implements CallbackGenerator
e.load_arg(0); e.load_arg(0);
e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING); e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
ObjectSwitchCallback callback = new ObjectSwitchCallback() { ObjectSwitchCallback callback = new ObjectSwitchCallback() {
@Override
public void processCase(Object key, Label end) { public void processCase(Object key, Label end) {
e.getfield((String)sigMap.get(key)); e.getfield((String)sigMap.get(key));
e.return_value(); e.return_value();
} }
@Override
public void processDefault() { public void processDefault() {
e.aconst_null(); e.aconst_null();
e.return_value(); e.return_value();

View File

@ -13,16 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.proxy; package org.springframework.cglib.proxy;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.lang.reflect.Constructor; import java.util.ArrayList;
import java.lang.reflect.Modifier; import java.util.Collections;
import java.util.*; import java.util.HashMap;
import org.springframework.cglib.core.*; import java.util.Iterator;
import java.util.Map;
import org.springframework.asm.ClassVisitor; 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 * <code>Mixin</code> allows
@ -73,11 +78,11 @@ abstract public class Mixin {
return gen.create(); return gen.create();
} }
public static Mixin createBean(Object[] beans) { public static Mixin createBean(Object[] beans) {
return createBean(null, beans); return createBean(null, beans);
} }
/** /**
* Helper method to create a bean mixin. For finer control over the * Helper method to create a bean mixin. For finer control over the
@ -92,26 +97,28 @@ abstract public class Mixin {
gen.setClassLoader(loader); gen.setClassLoader(loader);
return gen.create(); return gen.create();
} }
public static class Generator extends AbstractClassGenerator { public static class Generator extends AbstractClassGenerator {
private static final Source SOURCE = new Source(Mixin.class.getName()); private static final Source SOURCE = new Source(Mixin.class.getName());
private Class[] classes; private Class[] classes;
private Object[] delegates; private Object[] delegates;
private int style = STYLE_INTERFACES; private int style = STYLE_INTERFACES;
private int[] route; private int[] route;
public Generator() { public Generator() {
super(SOURCE); super(SOURCE);
} }
@Override
protected ClassLoader getDefaultClassLoader() { protected ClassLoader getDefaultClassLoader() {
return classes[0].getClassLoader(); // is this right? return classes[0].getClassLoader(); // is this right?
} }
@Override
protected ProtectionDomain getProtectionDomain() { protected ProtectionDomain getProtectionDomain() {
return ReflectUtils.getProtectionDomain(classes[0]); return ReflectUtils.getProtectionDomain(classes[0]);
} }
public void setStyle(int style) { public void setStyle(int style) {
@ -166,10 +173,11 @@ abstract public class Mixin {
} }
} }
setNamePrefix(classes[ReflectUtils.findPackageProtected(classes)].getName()); setNamePrefix(classes[ReflectUtils.findPackageProtected(classes)].getName());
return (Mixin)super.create(KEY_FACTORY.newInstance(style, ReflectUtils.getNames( classes ), route)); return (Mixin)super.create(KEY_FACTORY.newInstance(style, ReflectUtils.getNames( classes ), route));
} }
@Override
public void generateClass(ClassVisitor v) { public void generateClass(ClassVisitor v) {
switch (style) { switch (style) {
case STYLE_INTERFACES: case STYLE_INTERFACES:
@ -184,10 +192,12 @@ abstract public class Mixin {
} }
} }
@Override
protected Object firstInstance(Class type) { protected Object firstInstance(Class type) {
return ((Mixin)ReflectUtils.newInstance(type)).newInstance(delegates); return ((Mixin)ReflectUtils.newInstance(type)).newInstance(delegates);
} }
@Override
protected Object nextInstance(Object instance) { protected Object nextInstance(Object instance) {
return ((Mixin)instance).newInstance(delegates); return ((Mixin)instance).newInstance(delegates);
} }
@ -200,7 +210,7 @@ abstract public class Mixin {
// public static int[] getRoute(Object[] delegates) { // public static int[] getRoute(Object[] delegates) {
// return (int[])route(delegates).route.clone(); // return (int[])route(delegates).route.clone();
// } // }
private static Route route(Object[] delegates) { private static Route route(Object[] delegates) {
Object key = ClassesKey.create(delegates); Object key = ClassesKey.create(delegates);
Route route = (Route)ROUTE_CACHE.get(key); Route route = (Route)ROUTE_CACHE.get(key);

View File

@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.proxy; package org.springframework.cglib.proxy;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Member;
import org.springframework.cglib.core.CodeGenerationException; import org.springframework.cglib.core.CodeGenerationException;
/** /**
@ -40,6 +41,7 @@ public class Proxy implements Serializable {
protected InvocationHandler h; protected InvocationHandler h;
private static final CallbackFilter BAD_OBJECT_METHOD_FILTER = new CallbackFilter() { private static final CallbackFilter BAD_OBJECT_METHOD_FILTER = new CallbackFilter() {
@Override
public int accept(Method method) { public int accept(Method method) {
if (method.getDeclaringClass().getName().equals("java.lang.Object")) { if (method.getDeclaringClass().getName().equals("java.lang.Object")) {
String name = method.getName(); String name = method.getName();

View File

@ -13,14 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.reflect; package org.springframework.cglib.reflect;
import java.lang.reflect.*; import java.lang.reflect.Method;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import org.springframework.cglib.*;
import org.springframework.cglib.core.*;
import org.springframework.asm.ClassVisitor; import org.springframework.asm.ClassVisitor;
import org.springframework.asm.Type; 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 // TODO: don't require exact match for return type
@ -133,11 +143,13 @@ abstract public class MethodDelegate {
return gen.create(); return gen.create();
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
MethodDelegate other = (MethodDelegate)obj; MethodDelegate other = (MethodDelegate)obj;
return (other != null && target == other.target) && eqMethod.equals(other.eqMethod); return (other != null && target == other.target) && eqMethod.equals(other.eqMethod);
} }
@Override
public int hashCode() { public int hashCode() {
return target.hashCode() ^ eqMethod.hashCode(); return target.hashCode() ^ eqMethod.hashCode();
} }
@ -181,12 +193,14 @@ abstract public class MethodDelegate {
this.iface = iface; this.iface = iface;
} }
@Override
protected ClassLoader getDefaultClassLoader() { protected ClassLoader getDefaultClassLoader() {
return targetClass.getClassLoader(); return targetClass.getClassLoader();
} }
@Override
protected ProtectionDomain getProtectionDomain() { protected ProtectionDomain getProtectionDomain() {
return ReflectUtils.getProtectionDomain(targetClass); return ReflectUtils.getProtectionDomain(targetClass);
} }
public MethodDelegate create() { public MethodDelegate create() {
@ -195,14 +209,17 @@ abstract public class MethodDelegate {
return (MethodDelegate)super.create(key); return (MethodDelegate)super.create(key);
} }
@Override
protected Object firstInstance(Class type) { protected Object firstInstance(Class type) {
return ((MethodDelegate)ReflectUtils.newInstance(type)).newInstance(target); return ((MethodDelegate)ReflectUtils.newInstance(type)).newInstance(target);
} }
@Override
protected Object nextInstance(Object instance) { protected Object nextInstance(Object instance) {
return ((MethodDelegate)instance).newInstance(target); return ((MethodDelegate)instance).newInstance(target);
} }
@Override
public void generateClass(ClassVisitor v) throws NoSuchMethodException { public void generateClass(ClassVisitor v) throws NoSuchMethodException {
Method proxy = ReflectUtils.findInterfaceMethod(iface); Method proxy = ReflectUtils.findInterfaceMethod(iface);
final Method method = targetClass.getMethod(methodName, proxy.getParameterTypes()); final Method method = targetClass.getMethod(methodName, proxy.getParameterTypes());

View File

@ -13,15 +13,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.reflect; package org.springframework.cglib.reflect;
import java.lang.reflect.*;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.*; import java.util.ArrayList;
import org.springframework.cglib.core.*; import java.util.Arrays;
import java.util.List;
import org.springframework.asm.ClassVisitor; import org.springframework.asm.ClassVisitor;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Type; 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"}) @SuppressWarnings({"rawtypes", "unchecked"})
abstract public class MulticastDelegate implements Cloneable { abstract public class MulticastDelegate implements Cloneable {
@ -82,12 +94,14 @@ abstract public class MulticastDelegate implements Cloneable {
super(SOURCE); super(SOURCE);
} }
@Override
protected ClassLoader getDefaultClassLoader() { protected ClassLoader getDefaultClassLoader() {
return iface.getClassLoader(); return iface.getClassLoader();
} }
@Override
protected ProtectionDomain getProtectionDomain() { protected ProtectionDomain getProtectionDomain() {
return ReflectUtils.getProtectionDomain(iface); return ReflectUtils.getProtectionDomain(iface);
} }
public void setInterface(Class iface) { public void setInterface(Class iface) {
@ -99,6 +113,7 @@ abstract public class MulticastDelegate implements Cloneable {
return (MulticastDelegate)super.create(iface.getName()); return (MulticastDelegate)super.create(iface.getName());
} }
@Override
public void generateClass(ClassVisitor cv) { public void generateClass(ClassVisitor cv) {
final MethodInfo method = ReflectUtils.getMethodInfo(ReflectUtils.findInterfaceMethod(iface)); 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); e.super_getfield("targets", Constants.TYPE_OBJECT_ARRAY);
final Local result2 = result; final Local result2 = result;
EmitUtils.process_array(e, Constants.TYPE_OBJECT_ARRAY, new ProcessArrayCallback() { EmitUtils.process_array(e, Constants.TYPE_OBJECT_ARRAY, new ProcessArrayCallback() {
@Override
public void processElement(Type type) { public void processElement(Type type) {
e.checkcast(Type.getType(iface)); e.checkcast(Type.getType(iface));
e.load_args(); e.load_args();
@ -168,11 +184,13 @@ abstract public class MulticastDelegate implements Cloneable {
e.end_method(); e.end_method();
} }
@Override
protected Object firstInstance(Class type) { protected Object firstInstance(Class type) {
// make a new instance in case first object is used with a long list of targets // make a new instance in case first object is used with a long list of targets
return ((MulticastDelegate)ReflectUtils.newInstance(type)).newInstance(); return ((MulticastDelegate)ReflectUtils.newInstance(type)).newInstance();
} }
@Override
protected Object nextInstance(Object instance) { protected Object nextInstance(Object instance) {
return ((MulticastDelegate)instance).newInstance(); return ((MulticastDelegate)instance).newInstance();
} }

View File

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform;
import org.springframework.asm.*; package org.springframework.cglib.transform;
public class ClassFilterTransformer extends AbstractClassFilterTransformer { public class ClassFilterTransformer extends AbstractClassFilterTransformer {
private ClassFilter filter; private ClassFilter filter;
@ -25,6 +24,7 @@ public class ClassFilterTransformer extends AbstractClassFilterTransformer {
this.filter = filter; this.filter = filter;
} }
@Override
protected boolean accept(int version, int access, String name, String signature, String superName, String[] interfaces) { protected boolean accept(int version, int access, String name, String signature, String superName, String[] interfaces) {
return filter.accept(name.replace('/', '.')); return filter.accept(name.replace('/', '.'));
} }

View File

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform;
import org.springframework.asm.Attribute; package org.springframework.cglib.transform;
public interface MethodFilter { public interface MethodFilter {
// TODO: pass class name too? // TODO: pass class name too?

View File

@ -13,21 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform; 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.asm.ClassVisitor;
import org.springframework.cglib.core.ClassGenerator;
public class TransformingClassGenerator implements ClassGenerator { public class TransformingClassGenerator implements ClassGenerator {
private ClassGenerator gen; private final ClassGenerator gen;
private ClassTransformer t; private final ClassTransformer t;
public TransformingClassGenerator(ClassGenerator gen, ClassTransformer t) { public TransformingClassGenerator(ClassGenerator gen, ClassTransformer t) {
this.gen = gen; this.gen = gen;
this.t = t; this.t = t;
} }
@Override
public void generateClass(ClassVisitor v) throws Exception { public void generateClass(ClassVisitor v) throws Exception {
t.setTarget(v); t.setTarget(v);
gen.generateClass(t); gen.generateClass(t);

View File

@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform; package org.springframework.cglib.transform;
import java.util.*; import org.springframework.asm.ClassReader;
import org.springframework.cglib.core.ClassGenerator; import org.springframework.cglib.core.ClassGenerator;
import org.springframework.asm.*;
public class TransformingClassLoader extends AbstractClassLoader { public class TransformingClassLoader extends AbstractClassLoader {
private ClassTransformerFactory t; private final ClassTransformerFactory t;
public TransformingClassLoader(ClassLoader parent, ClassFilter filter, ClassTransformerFactory t) { public TransformingClassLoader(ClassLoader parent, ClassFilter filter, ClassTransformerFactory t) {
super(parent, parent, filter); super(parent, parent, filter);
this.t = t; this.t = t;
} }
@Override
protected ClassGenerator getGenerator(ClassReader r) { protected ClassGenerator getGenerator(ClassReader r) {
ClassTransformer t2 = t.newInstance(); ClassTransformer t2 = t.newInstance();
return new TransformingClassGenerator(super.getGenerator(r), t2); return new TransformingClassGenerator(super.getGenerator(r), t2);

View File

@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform.impl; 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.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 { public class AccessFieldTransformer extends ClassEmitterTransformer {
private Callback callback; private Callback callback;
@ -33,6 +34,7 @@ public class AccessFieldTransformer extends ClassEmitterTransformer {
String getPropertyName(Type owner, String fieldName); String getPropertyName(Type owner, String fieldName);
} }
@Override
public void declare_field(int access, final String name, Type type, Object value) { public void declare_field(int access, final String name, Type type, Object value) {
super.declare_field(access, name, type, value); super.declare_field(access, name, type, value);

View File

@ -13,14 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform.impl; package org.springframework.cglib.transform.impl;
import org.springframework.cglib.transform.*; import java.lang.reflect.Method;
import java.lang.reflect.*; import java.lang.reflect.Modifier;
import java.util.*;
import org.springframework.cglib.core.*;
import org.springframework.asm.Attribute;
import org.springframework.asm.Type; 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 * @author Juozas Baliuka
@ -30,11 +36,11 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
private static final String DELEGATE = "$CGLIB_DELEGATE"; private static final String DELEGATE = "$CGLIB_DELEGATE";
private static final Signature CSTRUCT_OBJECT = private static final Signature CSTRUCT_OBJECT =
TypeUtils.parseSignature("void <init>(Object)"); TypeUtils.parseSignature("void <init>(Object)");
private Class[] delegateIf; private Class[] delegateIf;
private Class delegateImpl; private Class delegateImpl;
private Type delegateType; private Type delegateType;
/** Creates a new instance of AddDelegateTransformer */ /** Creates a new instance of AddDelegateTransformer */
public AddDelegateTransformer(Class delegateIf[], Class delegateImpl) { public AddDelegateTransformer(Class delegateIf[], Class delegateImpl) {
try { try {
@ -46,14 +52,15 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
throw new CodeGenerationException(e); throw new CodeGenerationException(e);
} }
} }
@Override
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) {
if(!TypeUtils.isInterface(access)){ if(!TypeUtils.isInterface(access)){
Type[] all = TypeUtils.add(interfaces, TypeUtils.getTypes(delegateIf)); Type[] all = TypeUtils.add(interfaces, TypeUtils.getTypes(delegateIf));
super.begin_class(version, access, className, superType, all, sourceFile); super.begin_class(version, access, className, superType, all, sourceFile);
declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT, declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT,
DELEGATE, DELEGATE,
delegateType, delegateType,
@ -71,11 +78,13 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
} }
} }
@Override
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) { public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
final CodeEmitter e = super.begin_method(access, sig, exceptions); final CodeEmitter e = super.begin_method(access, sig, exceptions);
if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) { if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
return new CodeEmitter(e) { return new CodeEmitter(e) {
private boolean transformInit = true; private boolean transformInit = true;
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
super.visitMethodInsn(opcode, owner, name, desc, itf); super.visitMethodInsn(opcode, owner, name, desc, itf);
if (transformInit && opcode == Constants.INVOKESPECIAL) { if (transformInit && opcode == Constants.INVOKESPECIAL) {
@ -115,6 +124,3 @@ public class AddDelegateTransformer extends ClassEmitterTransformer {
e.end_method(); e.end_method();
} }
} }

View File

@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform.impl; package org.springframework.cglib.transform.impl;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.springframework.asm.Type;
import org.springframework.cglib.core.CodeEmitter; import org.springframework.cglib.core.CodeEmitter;
import org.springframework.cglib.core.Constants; import org.springframework.cglib.core.Constants;
import org.springframework.cglib.core.MethodInfo; 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.core.Signature;
import org.springframework.cglib.transform.ClassEmitterTransformer; 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 { public class AddInitTransformer extends ClassEmitterTransformer {
private MethodInfo info; private MethodInfo info;
public AddInitTransformer(Method method) { public AddInitTransformer(Method method) {
info = ReflectUtils.getMethodInfo(method); info = ReflectUtils.getMethodInfo(method);
Type[] types = info.getSignature().getArgumentTypes(); Type[] types = info.getSignature().getArgumentTypes();
if (types.length != 1 || if (types.length != 1 ||
!types[0].equals(Constants.TYPE_OBJECT) || !types[0].equals(Constants.TYPE_OBJECT) ||
@ -43,11 +42,13 @@ public class AddInitTransformer extends ClassEmitterTransformer {
throw new IllegalArgumentException(method + " illegal signature"); throw new IllegalArgumentException(method + " illegal signature");
} }
} }
@Override
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) { public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
final CodeEmitter emitter = super.begin_method(access, sig, exceptions); final CodeEmitter emitter = super.begin_method(access, sig, exceptions);
if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) { if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
return new CodeEmitter(emitter) { return new CodeEmitter(emitter) {
@Override
public void visitInsn(int opcode) { public void visitInsn(int opcode) {
if (opcode == Constants.RETURN) { if (opcode == Constants.RETURN) {
load_this(); load_this();
@ -60,4 +61,3 @@ public class AddInitTransformer extends ClassEmitterTransformer {
return emitter; return emitter;
} }
} }

View File

@ -13,21 +13,30 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform.impl; package org.springframework.cglib.transform.impl;
import org.springframework.cglib.transform.*; import java.util.HashMap;
import java.util.*; import java.util.Map;
import org.springframework.cglib.core.*;
import org.springframework.asm.Attribute;
import org.springframework.asm.Label; import org.springframework.asm.Label;
import org.springframework.asm.Type; 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"}) @SuppressWarnings({"rawtypes", "unchecked"})
public class FieldProviderTransformer extends ClassEmitterTransformer { public class FieldProviderTransformer extends ClassEmitterTransformer {
private static final String FIELD_NAMES = "CGLIB$FIELD_NAMES"; private static final String FIELD_NAMES = "CGLIB$FIELD_NAMES";
private static final String FIELD_TYPES = "CGLIB$FIELD_TYPES"; private static final String FIELD_TYPES = "CGLIB$FIELD_TYPES";
private static final Type FIELD_PROVIDER = private static final Type FIELD_PROVIDER =
TypeUtils.parseType("org.springframework.cglib.transform.impl.FieldProvider"); TypeUtils.parseType("org.springframework.cglib.transform.impl.FieldProvider");
private static final Type ILLEGAL_ARGUMENT_EXCEPTION = private static final Type ILLEGAL_ARGUMENT_EXCEPTION =
@ -44,10 +53,11 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
TypeUtils.parseSignature("Class[] getFieldTypes()"); TypeUtils.parseSignature("Class[] getFieldTypes()");
private static final Signature PROVIDER_GET_NAMES = private static final Signature PROVIDER_GET_NAMES =
TypeUtils.parseSignature("String[] getFieldNames()"); TypeUtils.parseSignature("String[] getFieldNames()");
private int access; private int access;
private Map fields; private Map fields;
@Override
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) {
if (!TypeUtils.isAbstract(access)) { if (!TypeUtils.isAbstract(access)) {
interfaces = TypeUtils.add(interfaces, FIELD_PROVIDER); interfaces = TypeUtils.add(interfaces, FIELD_PROVIDER);
@ -57,16 +67,18 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
super.begin_class(version, access, className, superType, interfaces, sourceFile); super.begin_class(version, access, className, superType, interfaces, sourceFile);
} }
@Override
public void declare_field(int access, String name, Type type, Object value) { public void declare_field(int access, String name, Type type, Object value) {
super.declare_field(access, name, type, value); super.declare_field(access, name, type, value);
if (!TypeUtils.isStatic(access)) { if (!TypeUtils.isStatic(access)) {
fields.put(name, type); fields.put(name, type);
} }
} }
@Override
public void end_class() { public void end_class() {
if (!TypeUtils.isInterface(access)) { if (!TypeUtils.isInterface(access)) {
try { try {
generate(); generate();
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -85,7 +97,7 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
for (int i = 0; i < indexes.length; i++) { for (int i = 0; i < indexes.length; i++) {
indexes[i] = 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_NAMES, Constants.TYPE_STRING_ARRAY, null);
super.declare_field(Constants.PRIVATE_FINAL_STATIC, FIELD_TYPES, Constants.TYPE_CLASS_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(); CodeEmitter e = getStaticHook();
EmitUtils.push_object(e, names); EmitUtils.push_object(e, names);
e.putstatic(getClassType(), FIELD_NAMES, Constants.TYPE_STRING_ARRAY); e.putstatic(getClassType(), FIELD_NAMES, Constants.TYPE_STRING_ARRAY);
e.push(names.length); e.push(names.length);
e.newarray(Constants.TYPE_CLASS); e.newarray(Constants.TYPE_CLASS);
e.dup(); e.dup();
for(int i = 0; i < names.length; i++ ){ for(int i = 0; i < names.length; i++ ){
e.dup(); e.dup();
e.push(i); e.push(i);
Type type = (Type)fields.get(names[i]); Type type = (Type)fields.get(names[i]);
@ -137,14 +149,16 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
e.load_arg(1); e.load_arg(1);
e.load_arg(0); e.load_arg(0);
e.process_switch(indexes, new ProcessSwitchCallback() { e.process_switch(indexes, new ProcessSwitchCallback() {
@Override
public void processCase(int key, Label end) throws Exception { public void processCase(int key, Label end) throws Exception {
Type type = (Type)fields.get(names[key]); Type type = (Type)fields.get(names[key]);
e.unbox(type); e.unbox(type);
e.putfield(names[key]); e.putfield(names[key]);
e.return_value(); e.return_value();
} }
@Override
public void processDefault() throws Exception { 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(); e.end_method();
@ -155,14 +169,16 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
e.load_this(); e.load_this();
e.load_arg(0); e.load_arg(0);
e.process_switch(indexes, new ProcessSwitchCallback() { e.process_switch(indexes, new ProcessSwitchCallback() {
@Override
public void processCase(int key, Label end) throws Exception { public void processCase(int key, Label end) throws Exception {
Type type = (Type)fields.get(names[key]); Type type = (Type)fields.get(names[key]);
e.getfield(names[key]); e.getfield(names[key]);
e.box(type); e.box(type);
e.return_value(); e.return_value();
} }
@Override
public void processDefault() throws Exception { 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(); e.end_method();
@ -175,12 +191,14 @@ public class FieldProviderTransformer extends ClassEmitterTransformer {
e.load_this(); e.load_this();
e.load_arg(0); e.load_arg(0);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() { EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
@Override
public void processCase(Object key, Label end) { public void processCase(Object key, Label end) {
Type type = (Type)fields.get(key); Type type = (Type)fields.get(key);
e.getfield((String)key); e.getfield((String)key);
e.box(type); e.box(type);
e.return_value(); e.return_value();
} }
@Override
public void processDefault() { public void processDefault() {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name"); 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(1);
e.load_arg(0); e.load_arg(0);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() { EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
@Override
public void processCase(Object key, Label end) { public void processCase(Object key, Label end) {
Type type = (Type)fields.get(key); Type type = (Type)fields.get(key);
e.unbox(type); e.unbox(type);
e.putfield((String)key); e.putfield((String)key);
e.return_value(); e.return_value();
} }
@Override
public void processDefault() { public void processDefault() {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name"); e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
} }

View File

@ -13,18 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.transform.impl; package org.springframework.cglib.transform.impl;
import java.lang.reflect.Constructor; 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.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"}) @SuppressWarnings({"rawtypes", "unchecked"})
public class UndeclaredThrowableTransformer extends ClassEmitterTransformer { public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
private Type wrapper;
private final Type wrapper;
public UndeclaredThrowableTransformer(Class wrapper) { public UndeclaredThrowableTransformer(Class wrapper) {
this.wrapper = Type.getType(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"); 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) { public CodeEmitter begin_method(int access, final Signature sig, final Type[] exceptions) {
CodeEmitter e = super.begin_method(access, sig, exceptions); CodeEmitter e = super.begin_method(access, sig, exceptions);
if (TypeUtils.isAbstract(access) || sig.equals(Constants.SIG_STATIC)) { if (TypeUtils.isAbstract(access) || sig.equals(Constants.SIG_STATIC)) {
@ -51,6 +58,7 @@ public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
/* init */ { /* init */ {
handler = begin_block(); handler = begin_block();
} }
@Override
public void visitMaxs(int maxStack, int maxLocals) { public void visitMaxs(int maxStack, int maxLocals) {
handler.end(); handler.end();
EmitUtils.wrap_undeclared_throwable(this, handler, exceptions, wrapper); EmitUtils.wrap_undeclared_throwable(this, handler, exceptions, wrapper);

View File

@ -13,12 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.util; package org.springframework.cglib.util;
import java.lang.reflect.*;
import java.util.Comparator; import java.util.Comparator;
import org.springframework.cglib.core.*;
import org.springframework.asm.ClassVisitor; 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. * For the efficient sorting of multiple arrays in parallel.
@ -49,7 +52,7 @@ import org.springframework.asm.ClassVisitor;
abstract public class ParallelSorter extends SorterTemplate { abstract public class ParallelSorter extends SorterTemplate {
protected Object[] a; protected Object[] a;
private Comparer comparer; private Comparer comparer;
protected ParallelSorter() { protected ParallelSorter() {
} }
@ -150,7 +153,7 @@ abstract public class ParallelSorter extends SorterTemplate {
chooseComparer(index, cmp); chooseComparer(index, cmp);
super.mergeSort(lo, hi - 1); super.mergeSort(lo, hi - 1);
} }
private void chooseComparer(int index, Comparator cmp) { private void chooseComparer(int index, Comparator cmp) {
Object array = a[index]; Object array = a[index];
Class type = array.getClass().getComponentType(); Class type = array.getClass().getComponentType();
@ -170,9 +173,10 @@ abstract public class ParallelSorter extends SorterTemplate {
comparer = new ComparatorComparer((Object[])array, cmp); comparer = new ComparatorComparer((Object[])array, cmp);
} else { } else {
comparer = new ObjectComparer((Object[])array); comparer = new ObjectComparer((Object[])array);
} }
} }
@Override
protected int compare(int i, int j) { protected int compare(int i, int j) {
return comparer.compare(i, j); return comparer.compare(i, j);
} }
@ -190,14 +194,16 @@ abstract public class ParallelSorter extends SorterTemplate {
this.cmp = cmp; this.cmp = cmp;
} }
@Override
public int compare(int i, int j) { public int compare(int i, int j) {
return cmp.compare(a[i], a[j]); return cmp.compare(a[i], a[j]);
} }
} }
static class ObjectComparer implements Comparer { static class ObjectComparer implements Comparer {
private Object[] a; private Object[] a;
public ObjectComparer(Object[] a) { this.a = a; } public ObjectComparer(Object[] a) { this.a = a; }
@Override
public int compare(int i, int j) { public int compare(int i, int j) {
return ((Comparable)a[i]).compareTo(a[j]); return ((Comparable)a[i]).compareTo(a[j]);
} }
@ -206,12 +212,14 @@ abstract public class ParallelSorter extends SorterTemplate {
static class IntComparer implements Comparer { static class IntComparer implements Comparer {
private int[] a; private int[] a;
public IntComparer(int[] a) { this.a = a; } public IntComparer(int[] a) { this.a = a; }
@Override
public int compare(int i, int j) { return a[i] - a[j]; } public int compare(int i, int j) { return a[i] - a[j]; }
} }
static class LongComparer implements Comparer { static class LongComparer implements Comparer {
private long[] a; private long[] a;
public LongComparer(long[] a) { this.a = a; } public LongComparer(long[] a) { this.a = a; }
@Override
public int compare(int i, int j) { public int compare(int i, int j) {
long vi = a[i]; long vi = a[i];
long vj = a[j]; long vj = a[j];
@ -222,16 +230,18 @@ abstract public class ParallelSorter extends SorterTemplate {
static class FloatComparer implements Comparer { static class FloatComparer implements Comparer {
private float[] a; private float[] a;
public FloatComparer(float[] a) { this.a = a; } public FloatComparer(float[] a) { this.a = a; }
@Override
public int compare(int i, int j) { public int compare(int i, int j) {
float vi = a[i]; float vi = a[i];
float vj = a[j]; float vj = a[j];
return (vi == vj) ? 0 : (vi > vj) ? 1 : -1; return (vi == vj) ? 0 : (vi > vj) ? 1 : -1;
} }
} }
static class DoubleComparer implements Comparer { static class DoubleComparer implements Comparer {
private double[] a; private double[] a;
public DoubleComparer(double[] a) { this.a = a; } public DoubleComparer(double[] a) { this.a = a; }
@Override
public int compare(int i, int j) { public int compare(int i, int j) {
double vi = a[i]; double vi = a[i];
double vj = a[j]; double vj = a[j];
@ -242,12 +252,14 @@ abstract public class ParallelSorter extends SorterTemplate {
static class ShortComparer implements Comparer { static class ShortComparer implements Comparer {
private short[] a; private short[] a;
public ShortComparer(short[] a) { this.a = a; } public ShortComparer(short[] a) { this.a = a; }
@Override
public int compare(int i, int j) { return a[i] - a[j]; } public int compare(int i, int j) { return a[i] - a[j]; }
} }
static class ByteComparer implements Comparer { static class ByteComparer implements Comparer {
private byte[] a; private byte[] a;
public ByteComparer(byte[] a) { this.a = a; } public ByteComparer(byte[] a) { this.a = a; }
@Override
public int compare(int i, int j) { return a[i] - a[j]; } public int compare(int i, int j) { return a[i] - a[j]; }
} }
@ -260,6 +272,7 @@ abstract public class ParallelSorter extends SorterTemplate {
super(SOURCE); super(SOURCE);
} }
@Override
protected ClassLoader getDefaultClassLoader() { protected ClassLoader getDefaultClassLoader() {
return null; // TODO return null; // TODO
} }
@ -272,6 +285,7 @@ abstract public class ParallelSorter extends SorterTemplate {
return (ParallelSorter)super.create(ClassesKey.create(arrays)); return (ParallelSorter)super.create(ClassesKey.create(arrays));
} }
@Override
public void generateClass(ClassVisitor v) throws Exception { public void generateClass(ClassVisitor v) throws Exception {
if (arrays.length == 0) { if (arrays.length == 0) {
throw new IllegalArgumentException("No arrays specified to sort"); throw new IllegalArgumentException("No arrays specified to sort");
@ -283,11 +297,13 @@ abstract public class ParallelSorter extends SorterTemplate {
} }
new ParallelSorterEmitter(v, getClassName(), arrays); new ParallelSorterEmitter(v, getClassName(), arrays);
} }
@Override
protected Object firstInstance(Class type) { protected Object firstInstance(Class type) {
return ((ParallelSorter)ReflectUtils.newInstance(type)).newInstance(arrays); return ((ParallelSorter)ReflectUtils.newInstance(type)).newInstance(arrays);
} }
@Override
protected Object nextInstance(Object instance) { protected Object nextInstance(Object instance) {
return ((ParallelSorter)instance).newInstance(arrays); return ((ParallelSorter)instance).newInstance(arrays);
} }

View File

@ -13,13 +13,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.util; 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.ClassVisitor;
import org.springframework.asm.Type; 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 { class ParallelSorterEmitter extends ClassEmitter {
private static final Type PARALLEL_SORTER = private static final Type PARALLEL_SORTER =
@ -83,7 +88,7 @@ class ParallelSorterEmitter extends ClassEmitter {
e.load_local(T); e.load_local(T);
e.load_arg(1); e.load_arg(1);
e.array_load(component); e.array_load(component);
e.load_local(T); e.load_local(T);
e.load_arg(1); e.load_arg(1);

View File

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.util;
import java.util.*; package org.springframework.cglib.util;
abstract class SorterTemplate { abstract class SorterTemplate {
private static final int MERGESORT_THRESHOLD = 12; private static final int MERGESORT_THRESHOLD = 12;
@ -71,7 +70,7 @@ abstract class SorterTemplate {
} }
} }
} }
private void insertionSort(int lo, int hi) { private void insertionSort(int lo, int hi) {
for (int i = lo + 1 ; i <= hi; i++) { for (int i = lo + 1 ; i <= hi; i++) {
for (int j = i; j > lo; j--) { for (int j = i; j > lo; j--) {

View File

@ -13,16 +13,28 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cglib.util; package org.springframework.cglib.util;
import java.util.*; import java.util.Arrays;
import org.springframework.cglib.core.*; import java.util.List;
import org.springframework.asm.ClassVisitor; import org.springframework.asm.ClassVisitor;
import org.springframework.asm.Label; import org.springframework.asm.Label;
import org.springframework.asm.Type; 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 &rarr; int mapping for a fixed set of keys.
*/ */
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
abstract public class StringSwitcher { abstract public class StringSwitcher {
@ -72,7 +84,7 @@ abstract public class StringSwitcher {
private String[] strings; private String[] strings;
private int[] ints; private int[] ints;
private boolean fixedInput; private boolean fixedInput;
public Generator() { public Generator() {
super(SOURCE); super(SOURCE);
} }
@ -104,6 +116,7 @@ abstract public class StringSwitcher {
this.fixedInput = fixedInput; this.fixedInput = fixedInput;
} }
@Override
protected ClassLoader getDefaultClassLoader() { protected ClassLoader getDefaultClassLoader() {
return getClass().getClassLoader(); return getClass().getClassLoader();
} }
@ -117,6 +130,7 @@ abstract public class StringSwitcher {
return (StringSwitcher)super.create(key); return (StringSwitcher)super.create(key);
} }
@Override
public void generateClass(ClassVisitor v) throws Exception { public void generateClass(ClassVisitor v) throws Exception {
ClassEmitter ce = new ClassEmitter(v); ClassEmitter ce = new ClassEmitter(v);
ce.begin_class(Constants.V1_8, ce.begin_class(Constants.V1_8,
@ -131,10 +145,12 @@ abstract public class StringSwitcher {
final List stringList = Arrays.asList(strings); final List stringList = Arrays.asList(strings);
int style = fixedInput ? Constants.SWITCH_STYLE_HASHONLY : Constants.SWITCH_STYLE_HASH; int style = fixedInput ? Constants.SWITCH_STYLE_HASHONLY : Constants.SWITCH_STYLE_HASH;
EmitUtils.string_switch(e, strings, style, new ObjectSwitchCallback() { EmitUtils.string_switch(e, strings, style, new ObjectSwitchCallback() {
@Override
public void processCase(Object key, Label end) { public void processCase(Object key, Label end) {
e.push(ints[stringList.indexOf(key)]); e.push(ints[stringList.indexOf(key)]);
e.return_value(); e.return_value();
} }
@Override
public void processDefault() { public void processDefault() {
e.push(-1); e.push(-1);
e.return_value(); e.return_value();
@ -144,10 +160,12 @@ abstract public class StringSwitcher {
ce.end_class(); ce.end_class();
} }
@Override
protected Object firstInstance(Class type) { protected Object firstInstance(Class type) {
return (StringSwitcher)ReflectUtils.newInstance(type); return ReflectUtils.newInstance(type);
} }
@Override
protected Object nextInstance(Object instance) { protected Object nextInstance(Object instance) {
return instance; return instance;
} }