/*
 * Copyright (C) 2016 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
 *
 * http://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 com.github.sormuras.listing.unit;

import com.github.sormuras.listing.Annotatable.AbstractAnnotatable;
import com.github.sormuras.listing.Listable;
import com.github.sormuras.listing.Listing;
import com.github.sormuras.listing.type.JavaType;
import java.lang.annotation.ElementType;

/**
 * The body of an annotation type declaration may contain method declarations, each of which defines
 * an <b>element</b> of the annotation type. An annotation type has no elements other than those
 * defined by the methods it explicitly declares.
 *
 * @see https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.1
 */
public class AnnotationElement extends AbstractAnnotatable implements Listable {

  private Listable defaultValue;
  private String name;
  private JavaType returnType;

  public AnnotationElement() {
    this("value");
  }

  public AnnotationElement(String name) {
    setName(name);
  }

  @Override
  public Listing apply(Listing listing) {
    listing.newline();
    listing.add(toAnnotationsListable());
    listing.add(getReturnType()).add(' ').add(getName()).add("()");
    if (defaultValue != null) {
      listing.add(' ').add("default").add(' ').add(getDefaultValue());
    }
    listing.add(';').newline();
    return listing;
  }

  public Listable getDefaultValue() {
    return defaultValue;
  }

  public String getName() {
    return name;
  }

  public JavaType getReturnType() {
    return returnType;
  }

  public AnnotationElement setDefaultValue(Listable defaultValue) {
    this.defaultValue = defaultValue;
    return this;
  }

  public AnnotationElement setName(String name) {
    this.name = name;
    return this;
  }

  public AnnotationElement setReturnType(JavaType type) {
    this.returnType = type;
    return this;
  }

  @Override
  public ElementType getAnnotationTarget() {
    return ElementType.METHOD;
  }
}

@@ -1391,129 +1391,8 @@
 e;%0A%0A
-  public AnnotationElement() %7B%0A    this(%22value%22);%0A  %7D%0A%0A  public AnnotationElement(String name) %7B%0A    setName(name);%0A  %7D%0A%0A
   @O
@@ -1391,32 +1391,32 @@
 e;%0A%0A  @Override%0A
+
   public Listing
@@ -1736,24 +1736,117 @@
 sting;%0A  %7D%0A%0A
+  @Override%0A  public ElementType getAnnotationTarget() %7B%0A    return ElementType.METHOD;%0A  %7D%0A%0A
   public Lis
@@ -2323,16 +2323,16 @@
 = type;%0A
+
     retu
@@ -2347,100 +2347,7 @@
 %0A  %7D
-%0A%0A  @Override%0A  public ElementType getAnnotationTarget() %7B%0A    return ElementType.METHOD;%0A  %7D
 %0A%7D%0A

Clean up.