Clone

Applied to a method creates new method with name from methodName attribute and list of parameters same as original method. Generated method calls the original method, passes the result to an instance of transformer specified with transformer attribute and returns transformed value. If methodName is not specified, clone with default name is created. Default name is: originalName + "Clone". Return type of generated method is extracted from declaration of the transformer class.

Vanilla Java


      class SomeClass {

          class CsvTransformer {
              String transform(List<Object> inputCollection) {
                  return "imagine here is the original collection serialized to csv";
              }
          }

          List<Object> method1(int oneParam, String anotherParam) {
              List<Object> result = new ArrayList();
              // some logic
              return result;
          }

          List<Object> method2(int oneParam, String anotherParam) {
              List<Object> result = new ArrayList();
              // some logic
              return result;
          }

          String method1Csv(int oneParam, String anotherParam) {
              return new CsvTransformer().transform(method1(oneParam, anotherParam));
          }

          String method2Csv(int oneParam, String anotherParam) {
              return new CsvTransformer().transform(method2(oneParam, anotherParam));
          }

      }
  

Kendal


      class SomeClass {

          class CsvTransformer implements Clone.Transformer<List<Object>, String> {
              @Override
              public String transform(List<Object> inputCollection) {
                  return "imagine here is the original collection serialized to csv";
              }
          }

          @Clone(transformer = CsvTransformer.class, methodName="method1Csv")
          List<Object> method1(int oneParam, String anotherParam) {
              List<Object> result = new ArrayList();
              // some logic
              return result;
          }

          @Clone(transformer = CsvTransformer.class, methodName="method2Csv")
          List<Object> method2(int oneParam, String anotherParam) {
              List<Object> result = new ArrayList();
              // some logic
              return result;
          }

      }