package retrofit.http;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Contains the desired HttpMethodType and relative path specified by a
 * service method.  See also the factory method {@link #fromMethod(Method)}.
 * @author Patrick Forhan (patrick@squareup.com)
 */
final class RequestLine {
  private final String relativePath;
  private final HttpMethodType httpMethod;

  private RequestLine(HttpMethodType methodType,
      Annotation methodAnnotation) {
    relativePath = getValue(methodAnnotation);
    httpMethod = methodType;
  }

  String getRelativePath() {
    return relativePath;
  }

  HttpMethodType getHttpMethod() {
    return httpMethod;
  }

  /** Using reflection, get the value field of the specified annotation. */
  private static String getValue(Annotation annotation) {
    try {
      final Method valueMethod = annotation.annotationType()
          .getMethod("value");
      return (String) valueMethod.invoke(annotation);

    } catch (Exception ex) {
      throw new IllegalStateException("Failed to extract URI path", ex);
    }
  }

  /**
   * Looks for exactly one annotation of type {@link DELETE}, {@link GET},
   * {@link POST}, or {@link PUT} and extracts its path data.  Throws an
   * {@link IllegalStateException} if none or multiple are found.
   */
  static RequestLine fromMethod(Method method) {
    Annotation[] annotations = method.getAnnotations();
    RequestLine found = null;
    for (Annotation annotation : annotations) {
      // look for an HttpMethod annotation describing the type:
      final retrofit.http.HttpMethod typeAnnotation = annotation.annotationType()
          .getAnnotation(retrofit.http.HttpMethod.class);
      if (typeAnnotation != null) {
        if (found != null) {
          throw new IllegalStateException(
              "Method annotated with multiple HTTP method annotations: "
                + method.toString());
        }
        found = new RequestLine(typeAnnotation.value(), annotation);
      }
    }

    if (found == null) {
      throw new IllegalStateException(
          "Method not annotated with GET, POST, PUT, or DELETE: "
            + method.toString());
    }
    return found;
  }
}
@@ -166,19 +166,16 @@
 ied by a
-%0A *
  service
@@ -182,17 +182,16 @@
  method.
- 
  See als
@@ -195,16 +195,19 @@
 also the
+%0A *
  factory
@@ -243,16 +243,19 @@
 thod)%7D.%0A
+ *%0A
  * @auth
@@ -454,22 +454,16 @@
 hodType,
-%0A     
  Annotat
@@ -889,35 +889,24 @@
 tationType()
-%0A          
 .getMethod(%22
@@ -968,17 +968,16 @@
 ation);%0A
-%0A
     %7D ca
@@ -1607,16 +1607,26 @@
 tation =
+%0A         
  annotat
@@ -1645,27 +1645,16 @@
 onType()
-%0A          
 .getAnno
@@ -1877,24 +1877,8 @@
 s: %22
-%0A               
  + m
@@ -2119,28 +2119,16 @@
 ELETE: %22
-%0A           
  + metho

Convert to 100-char lines.