/* * Copyright 2013 Netflix, Inc. * * 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 feign; import javax.inject.Named; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.List; import static feign.Util.checkState; import static feign.Util.emptyToNull; /** * Defines what annotations and values are valid on interfaces. */ public interface Contract { /** * Called to parse the methods in the class that are linked to HTTP requests. */ List parseAndValidatateMetadata(Class declaring); public static abstract class BaseContract implements Contract { @Override public List parseAndValidatateMetadata(Class declaring) { List metadata = new ArrayList(); for (Method method : declaring.getDeclaredMethods()) { if (method.getDeclaringClass() == Object.class) continue; metadata.add(parseAndValidatateMetadata(method)); } return metadata; } /** * Called indirectly by {@link #parseAndValidatateMetadata(Class)}. */ public MethodMetadata parseAndValidatateMetadata(Method method) { MethodMetadata data = new MethodMetadata(); data.returnType(method.getGenericReturnType()); data.configKey(Feign.configKey(method)); for (Annotation methodAnnotation : method.getAnnotations()) { processAnnotationOnMethod(data, methodAnnotation, method); } checkState(data.template().method() != null, "Method %s not annotated with HTTP method type (ex. GET, POST)", me