private static void stringSwitchHelper(final CodeEmitter e, List strings, final ObjectSwitchCallback callback, final Label def, final Label end, final int index) throws Exception { final int len = ((String)strings.get(0)).length(); final Map buckets = CollectionUtils.bucket(strings, new Transformer() { public Object transform(Object value) { return new Integer(((String)value).charAt(index)); } }); e.dup(); e.push(index); e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT); e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() { public void processCase(int key, Label ignore_end) throws Exception { List bucket = (List)buckets.get(new Integer(key)); if (index + 1 == len) { e.pop(); callback.processCase(bucket.get(0), end); } else { stringSwitchHelper(e, bucket, callback, def, end, index + 1); } } public void processDefault() { e.goTo(def); } }); }
CollectionUtils.filter(methods, vp); CollectionUtils.filter(methods, new DuplicatesPredicate()); List constructors = new ArrayList(Arrays.asList(type.getDeclaredConstructors())); CollectionUtils.filter(constructors, vp); List info = CollectionUtils.transform(constructors, MethodInfoTransformer.getInstance()); EmitUtils.constructor_switch(e, info, new GetIndexCallback(e, info)); e.end_method();
final Map indexes = new HashMap(); final Map originalModifiers = new HashMap(); final Map positions = CollectionUtils.getIndexMap(methods);
private void emitIndexByClassArray(List methods) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, METHOD_GET_INDEX, null); if (methods.size() > TOO_MANY_METHODS) { // hack for big classes List signatures = CollectionUtils.transform(methods, new Transformer() { public Object transform(Object obj) { String s = ReflectUtils.getSignature((Method)obj).toString(); return s.substring(0, s.lastIndexOf(')') + 1); } }); e.load_args(); e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE); signatureSwitchHelper(e, signatures); } else { e.load_args(); List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance()); EmitUtils.method_switch(e, info, new GetIndexCallback(e, info)); } e.end_method(); }
protected Method[] getMethods(Class type) { List methods = new ArrayList(Arrays.asList(type.getMethods())); CollectionUtils.filter(methods, new RejectModifierPredicate(Modifier.FINAL | Modifier.STATIC)); return (Method[])methods.toArray(new Method[methods.size()]); } }
private void emitIndexBySignature(List methods) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SIGNATURE_GET_INDEX, null); List signatures = CollectionUtils.transform(methods, new Transformer() { public Object transform(Object obj) { return ReflectUtils.getSignature((Method)obj).toString(); } }); e.load_arg(0); e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING); signatureSwitchHelper(e, signatures); e.end_method(); }
/** * Filter the list of constructors from the superclass. The * constructors which remain will be included in the generated * class. The default implementation is to filter out all private * constructors, but subclasses may extend Enhancer to override this * behavior. * @param sc the superclass * @param constructors the list of all declared constructors from the superclass * @throws IllegalArgumentException if there are no non-private constructors */ protected void filterConstructors(Class sc, List constructors) { CollectionUtils.filter(constructors, new VisibilityPredicate(sc, true)); if (constructors.size() == 0) throw new IllegalArgumentException("No visible constructors in " + sc); }
private static void member_helper_size(final CodeEmitter e, List members, final ObjectSwitchCallback callback, final ParameterTyper typer, final Label def, final Label end) throws Exception { final Map buckets = CollectionUtils.bucket(members, new Transformer() { public Object transform(Object value) { return new Integer(typer.getParameterTypes((MethodInfo)value).length); } }); e.dup(); e.arraylength(); e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() { public void processCase(int key, Label dontUseEnd) throws Exception { List bucket = (List)buckets.get(new Integer(key)); member_helper_type(e, bucket, callback, typer, def, end, new BitSet()); } public void processDefault() throws Exception { e.goTo(def); } }); }
private static void invokeSwitchHelper(final CodeEmitter e, List members, final int arg, final Type base) { final List info = CollectionUtils.transform(members, MethodInfoTransformer.getInstance()); final Label illegalArg = e.make_label(); Block block = e.begin_block(); e.process_switch(getIntRange(info.size()), new ProcessSwitchCallback() { public void processCase(int key, Label end) { MethodInfo method = (MethodInfo)info.get(key); Type[] types = method.getSignature().getArgumentTypes(); for (int i = 0; i < types.length; i++) { e.load_arg(arg); e.aaload(i); e.unbox(types[i]); } // TODO: change method lookup process so MethodInfo will already reference base // instead of superclass when superclass method is inaccessible e.invoke(method, base); if (!TypeUtils.isConstructor(method)) { e.box(method.getSignature().getReturnType()); } e.return_value(); } public void processDefault() { e.goTo(illegalArg); } }); block.end(); EmitUtils.wrap_throwable(block, INVOCATION_TARGET_EXCEPTION); e.mark(illegalArg); e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Cannot find matching method/constructor"); }
CollectionUtils.filter(methods, vp); CollectionUtils.filter(methods, new DuplicatesPredicate()); List constructors = new ArrayList(Arrays.asList(type.getDeclaredConstructors())); CollectionUtils.filter(constructors, vp); List info = CollectionUtils.transform(constructors, MethodInfoTransformer.getInstance()); EmitUtils.constructor_switch(e, info, new GetIndexCallback(e, info)); e.end_method();
private static void getMethods(Class superclass, Class[] interfaces, List methods, List interfaceMethods, Set forcePublic) { ReflectUtils.addAllMethods(superclass, methods); List target = (interfaceMethods != null) ? interfaceMethods : methods; if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { if (interfaces[i] != Factory.class) { ReflectUtils.addAllMethods(interfaces[i], target); } } } if (interfaceMethods != null) { if (forcePublic != null) { forcePublic.addAll(MethodWrapper.createSet(interfaceMethods)); } methods.addAll(interfaceMethods); } CollectionUtils.filter(methods, new RejectModifierPredicate(Constants.ACC_STATIC)); CollectionUtils.filter(methods, new VisibilityPredicate(superclass, true)); CollectionUtils.filter(methods, new DuplicatesPredicate()); CollectionUtils.filter(methods, new RejectModifierPredicate(Constants.ACC_FINAL)); }
final Map indexes = new HashMap(); final Map originalModifiers = new HashMap(); final Map positions = CollectionUtils.getIndexMap(methods);
for (int i = 0; i < example.length; i++) { final int j = i; Map test = CollectionUtils.bucket(members, new Transformer() { public Object transform(Object value) { return TypeUtils.emulateClassGetName(typer.getParameterTypes((MethodInfo)value)[j]);
getMethods(sc, interfaces, actualMethods, interfaceMethods, forcePublic); List methods = CollectionUtils.transform(actualMethods, new Transformer() { public Object transform(Object value) { Method method = (Method)value; TypeUtils.getTypes(interfaces)), Constants.SOURCE_FILE); List constructorInfo = CollectionUtils.transform(constructors, MethodInfoTransformer.getInstance());
protected Method[] getMethods(Class type) { List methods = new ArrayList(Arrays.asList(type.getMethods())); CollectionUtils.filter(methods, new RejectModifierPredicate(Modifier.FINAL | Modifier.STATIC)); return (Method[])methods.toArray(new Method[methods.size()]); } }
if (useName) { e.swap(); final Map buckets = CollectionUtils.bucket(members, new Transformer() { public Object transform(Object value) { return ((MethodInfo)value).getSignature().getName();
private void emitIndexBySignature(List methods) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SIGNATURE_GET_INDEX, null); List signatures = CollectionUtils.transform(methods, new Transformer() { public Object transform(Object obj) { return ReflectUtils.getSignature((Method)obj).toString(); } }); e.load_arg(0); e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING); signatureSwitchHelper(e, signatures); e.end_method(); }
/** * Filter the list of constructors from the superclass. The * constructors which remain will be included in the generated * class. The default implementation is to filter out all private * constructors, but subclasses may extend Enhancer to override this * behavior. * @param sc the superclass * @param constructors the list of all declared constructors from the superclass * @throws IllegalArgumentException if there are no non-private constructors */ protected void filterConstructors(Class sc, List constructors) { CollectionUtils.filter(constructors, new VisibilityPredicate(sc, true)); if (constructors.size() == 0) throw new IllegalArgumentException("No visible constructors in " + sc); }
private static void string_switch_trie(final CodeEmitter e, String[] strings, final ObjectSwitchCallback callback) throws Exception { final Label def = e.make_label(); final Label end = e.make_label(); final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() { public Object transform(Object value) { return new Integer(((String)value).length()); } }); e.dup(); e.invoke_virtual(Constants.TYPE_STRING, STRING_LENGTH); e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() { public void processCase(int key, Label ignore_end) throws Exception { List bucket = (List)buckets.get(new Integer(key)); stringSwitchHelper(e, bucket, callback, def, end, 0); } public void processDefault() { e.goTo(def); } }); e.mark(def); e.pop(); callback.processDefault(); e.mark(end); }
private void emitIndexByClassArray(List methods) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, METHOD_GET_INDEX, null); if (methods.size() > TOO_MANY_METHODS) { // hack for big classes List signatures = CollectionUtils.transform(methods, new Transformer() { public Object transform(Object obj) { String s = ReflectUtils.getSignature((Method)obj).toString(); return s.substring(0, s.lastIndexOf(')') + 1); } }); e.load_args(); e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE); signatureSwitchHelper(e, signatures); } else { e.load_args(); List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance()); EmitUtils.method_switch(e, info, new GetIndexCallback(e, info)); } e.end_method(); }