/** * 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; }
/** * 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; }
/** * 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; }
/** * 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 MethodSource<O> createMutator() { Assert.isTrue(getMutator() == null, "Mutator method already exists"); final String mutatorName = methodName("set", name); final String parameters = String.format("%s %s", typeName(), getName()); final MethodSource<O> result = getOrigin().addMethod().setReturnTypeVoid().setName(mutatorName) .setParameters(parameters); if (!getOrigin().isInterface()) { result.setVisibility(Visibility.PUBLIC); if (hasField()) { final String body = String.format("this.%1$s = %1$s;", getName()); result.setBody(body); } } return result; }
@Override public MethodSource<O> createMutator() { Assert.isTrue(getMutator() == null, "Mutator method already exists"); final String mutatorName = methodName("set", name); final String parameters = String.format("%s %s", typeName(), getName()); final MethodSource<O> result = getOrigin().addMethod().setReturnTypeVoid().setName(mutatorName) .setParameters(parameters); if (!getOrigin().isInterface()) { result.setVisibility(Visibility.PUBLIC); if (hasField()) { final String body = String.format("this.%1$s = %1$s;", getName()); result.setBody(body); } } return result; }
@Override public MethodSource<O> createMutator() { Assert.isTrue(getMutator() == null, "Mutator method already exists"); final String mutatorName = methodName("set", name); final String parameters = String.format("%s %s", typeName(), getName()); final MethodSource<O> result = getOrigin().addMethod().setReturnTypeVoid().setName(mutatorName) .setParameters(parameters); if (!getOrigin().isInterface()) { result.setVisibility(Visibility.PUBLIC); if (hasField()) { final String body = String.format("this.%1$s = %1$s;", getName()); result.setBody(body); } } return result; }
final MethodSource<?> method = methodHolder.addMethod() .setName(o.name()) .setAbstract(o.isAbstract())
private MethodSource<O> createAccessor() { Assert.isTrue(getAccessor() == null, "Accessor method already exists"); final Type<O> type = getType(); final String accessorName = methodName(type.isType(boolean.class) ? "is" : "get", name); final MethodSource<O> result = getOrigin().addMethod().setReturnType(typeName()) .setName(accessorName); if (!getOrigin().isInterface()) { result.setVisibility(Visibility.PUBLIC); if (hasField()) { final String body = String.format("return %s;", getName()); result.setBody(body); } } return result; }
@Override public MethodSource<O> createAccessor() { Assert.isTrue(getAccessor() == null, "Accessor method already exists"); final Type<O> type = getType(); final String accessorName = methodName(type.isType(boolean.class) ? "is" : "get", name); final MethodSource<O> result = getOrigin().addMethod().setReturnType(typeName()) .setName(accessorName); if (!getOrigin().isInterface()) { result.setVisibility(Visibility.PUBLIC); if (hasField()) { final String body = String.format("return %s;", getName()); result.setBody(body); } } return result; }
@Override public MethodSource<O> createAccessor() { Assert.isTrue(getAccessor() == null, "Accessor method already exists"); final Type<O> type = getType(); final String accessorName = methodName(type.isType(boolean.class) ? "is" : "get", name); final MethodSource<O> result = getOrigin().addMethod().setReturnType(typeName()) .setName(accessorName); if (!getOrigin().isInterface()) { result.setVisibility(Visibility.PUBLIC); if (hasField()) { final String body = String.format("return %s;", getName()); result.setBody(body); } } return result; }