/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach.internal;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** A factory method creates a new instance of the class that encloses the annotated element. */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Factory {

  /** A description of the input sources the factory method. */
  enum Kind {

    /** A static factory method that creates a new instance using any parameters. */
    STATIC,

    /** An instance factory method that replaces a single component of the instance. */
    COMPONENT,

    /** An instance factory method that augments one or more components with the given arguments. */
    GENERATOR
  }

  /**
   * Return the factory kind.
   *
   * @return a kind constant.
   */
  Kind value() default Kind.STATIC;
}

@@ -1100,16 +1100,23 @@
 %0A    /**
+%0A     *
  A stati
@@ -1181,16 +1181,366 @@
 ameters.
+%0A     *%0A     * %3Cpre%3E%7B@code%0A     * record Foo(Bar bar, String text) %7B%0A     *%0A     *   @Factory%0A     *   static Foo of() %7B%0A     *     return new Foo(Bar.of(), %22Lorem%22);%0A     *   %7D%0A     *%0A     *   @Factory(Kind.STATIC)%0A     *   static Foo ofSystem() %7B%0A     *     return new Foo(Bar.of(), System.getProperty(...));%0A     *   %7D%0A     * %7D%0A     * %7D%3C/pre%3E%0A    
  */%0A    
@@ -1547,32 +1547,39 @@
 STATIC,%0A%0A    /**
+%0A     *
  An instance fac
@@ -1643,25 +1643,364 @@
 nce.
- */%0A    COMPONENT
+%0A     *%0A     * %3Cpre%3E%7B@code%0A     * record Foo(Bar bar, String text) %7B%0A     *%0A     *   @Factory(Kind.SETTER)%0A     *   Foo bar(Bar bar) %7B%0A     *     return new Foo(bar, this.text);%0A     *   %7D%0A     *%0A     *   @Factory(Kind.SETTER)%0A     *   Foo text(String text) %7B%0A     *     return new Foo(this.bar, text);%0A     *   %7D%0A     * %7D%0A     * %7D%3C/pre%3E%0A     */%0A    SETTER
 ,%0A%0A 
@@ -2005,16 +2005,23 @@
 %0A    /**
+%0A     *
  An inst
@@ -2049,15 +2049,15 @@
 hat 
-augment
+modifie
 s on
@@ -2106,19 +2106,254 @@
 nts.
- */%0A    GEN
+%0A     *%0A     * %3Cpre%3E%7B@code%0A     * record Foo(Bar bar, String text) %7B%0A     *%0A     *   @Factory(Kind.OPERATOR)%0A     *   Foo withSuffix(String suffix) %7B%0A     *     return new Foo(bar, text + suffix);%0A     *   %7D%0A     * %7D%0A     * %7D%3C/pre%3E%0A     */%0A    OP
 ERAT

Document factory annotation with examples