/** * 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> getAccessor() { for (MethodSource<O> method : getOrigin().getMethods()) { if (isAccessor(method)) { return method; } } return null; }
@Override public PropertySource<O> removeAccessor() { if (isAccessible()) { getOrigin().removeMethod(getAccessor()); } return 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 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; }
protected void writeOperation(MethodHolderSource<?> methodHolder, Operation o) { if (!methodHolder.hasMethodSignature(o.name(), o.parameters().stream().map(p -> p.getName()).collect(Collectors.toList()).toArray(new String[0]))) { final MethodSource<?> method = methodHolder.addMethod() .setName(o.name()) .setAbstract(o.isAbstract())
@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; }
/** * 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 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> getAccessor() { for (MethodSource<O> method : getOrigin().getMethods()) { if (isAccessor(method)) { return method; } } return null; }
/** * 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 PropertySource<O> removeMutator() { if (isMutable()) { getOrigin().removeMethod(getMutator()); } return this; }
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> getAccessor() { for (MethodSource<O> method : getOrigin().getMethods()) { if (isAccessor(method)) { return method; } } return null; }
@Override public PropertySource<O> removeAccessor() { if (isAccessible()) { getOrigin().removeMethod(getAccessor()); } return this; }
@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; }
.getMethods(); for (MethodSource method : methods)
private PropertySource<O> removeAccessor() { if (isAccessible()) { getOrigin().removeMethod(getAccessor()); } return this; }
@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; }
.getMethods(); for (MethodSource method : methods)