/** * Implement the abstract methods present in a {@link Class} to the specified {@link MethodHolderSource} * * @param source the {@link Class} where the methods will be imported from * @param target the {@link MethodHolderSource} where the methods will be exported to * @return a {@link List} of the implemented methods added to the provided {@link MethodHolderSource} */ public static List<MethodSource<?>> implementAbstractMethods(final Class<?> source, final MethodHolderSource<?> target) { List<MethodSource<?>> methods = new ArrayList<MethodSource<?>>(); for (java.lang.reflect.Method m : source.getMethods()) { if (m.getDeclaringClass() == Object.class) continue; if (Modifier.isAbstract(m.getModifiers()) && target.getMethod(m.getName(), m.getParameterTypes()) == null) { MethodSource<?> newMethod = target.addMethod(m); implementMethod(newMethod); removeAllAnnotations(newMethod); methods.add(newMethod); } } return methods; }
@Override public JavaClassSource extendSuperType(final Class<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
/** * @return the parameter names of a given {@link Method} */ public static String[] generateParameterNames(Class<?>[] parameterTypes) { List<String> parameterNames = new ArrayList<String>(); for (Class<?> paramType : parameterTypes) { // Check if we haven't already used it. String name = toParamName(paramType.getSimpleName()); String paramName = name; int idx = 1; while (parameterNames.contains(paramName)) { paramName = name + idx++; } parameterNames.add(paramName); } return parameterNames.toArray(new String[parameterNames.size()]); }
String[] paramNames = Methods.generateParameterNames(paramTypes); for (int i = 0; i < paramTypes.length; i++) Methods.implementMethod(this);
String[] paramNames = Methods.generateParameterNames(paramTypes); for (int i = 0; i < paramTypes.length; i++) Methods.implementMethod(this);
/** * Implement the abstract methods present in a {@link Class} to the specified {@link MethodHolderSource} * * @param source the {@link Class} where the methods will be imported from * @param target the {@link MethodHolderSource} where the methods will be exported to * @return a {@link List} of the implemented methods added to the provided {@link MethodHolderSource} */ public static List<MethodSource<?>> implementAbstractMethods(final Class<?> source, final MethodHolderSource<?> target) { List<MethodSource<?>> methods = new ArrayList<MethodSource<?>>(); for (java.lang.reflect.Method m : source.getMethods()) { if (m.getDeclaringClass() == Object.class) continue; if (Modifier.isAbstract(m.getModifiers()) && target.getMethod(m.getName(), m.getParameterTypes()) == null) { MethodSource<?> newMethod = target.addMethod(m); implementMethod(newMethod); removeAllAnnotations(newMethod); methods.add(newMethod); } } return methods; }
@Override public JavaClassSource extendSuperType(final Class<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
/** * @return the parameter names of a given {@link Method} */ public static String[] generateParameterNames(Class<?>[] parameterTypes) { List<String> parameterNames = new ArrayList<String>(); for (Class<?> paramType : parameterTypes) { // Check if we haven't already used it. String name = toParamName(paramType.getSimpleName()); String paramName = name; int idx = 1; while (parameterNames.contains(paramName)) { paramName = name + idx++; } parameterNames.add(paramName); } return parameterNames.toArray(new String[parameterNames.size()]); }
/** * Implement the abstract methods present in a {@link MethodHolder} to the specified {@link MethodHolderSource} * * @param source the {@link MethodHolder} where the methods will be imported from * @param target the {@link MethodHolderSource} where the methods will be exported to * @return a {@link List} of the implemented methods added to the provided {@link MethodHolderSource} */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static List<MethodSource<?>> implementAbstractMethods(final MethodHolder<?> source, final MethodHolderSource<?> target) { List<MethodSource<?>> methods = new ArrayList<MethodSource<?>>(); for (Method method : source.getMethods()) { if (method.isAbstract() && !target.hasMethod(method)) { MethodSource<?> newMethod = target.addMethod(method); implementMethod(newMethod); removeAllAnnotations(newMethod); methods.add(newMethod); } } return methods; }
@Override public JavaClassSource extendSuperType(JavaClass<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
/** * Implement the abstract methods present in a {@link MethodHolder} to the specified {@link MethodHolderSource} * * @param source the {@link MethodHolder} where the methods will be imported from * @param target the {@link MethodHolderSource} where the methods will be exported to * @return a {@link List} of the implemented methods added to the provided {@link MethodHolderSource} */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static List<MethodSource<?>> implementAbstractMethods(final MethodHolder<?> source, final MethodHolderSource<?> target) { List<MethodSource<?>> methods = new ArrayList<MethodSource<?>>(); for (Method method : source.getMethods()) { if (method.isAbstract() && !target.hasMethod(method)) { MethodSource<?> newMethod = target.addMethod(method); implementMethod(newMethod); removeAllAnnotations(newMethod); methods.add(newMethod); } } return methods; }
@Override public JavaClassSource extendSuperType(JavaClass<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
@Override public O implementInterface(Class<?> type) { O obj = addInterface(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.setPublic().addAnnotation(Override.class); } return obj; }
@Override public O implementInterface(Class<?> type) { O obj = addInterface(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.setPublic().addAnnotation(Override.class); } return obj; }
for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this))
for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this))