/* * Copyright 2014 mango.jfaster.org * * The Mango Project licenses this file to you 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 org.jfaster.mango.descriptor; import javax.annotation.Nullable; import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Collections; import java.util.List; /** * 方法描述 * * @author ash */ public class MethodDescriptor { private final String name; private final Class<?> daoClass; private final ReturnDescriptor returnDescriptor; private final List<ParameterDescriptor> parameterDescriptors; private MethodDescriptor( String name, Class<?> daoClass, ReturnDescriptor returnDescriptor, List<ParameterDescriptor> parameterDescriptors) { this.name = name; this.daoClass = daoClass; this.returnDescriptor = returnDescriptor; this.parameterDescriptors = Collections.unmodifiableList(parameterDescriptors); } public static MethodDescriptor create( String name, Class<?> daoClass, ReturnDescriptor returnDescriptor, List<ParameterDescriptor> parameterDescriptors) { return new MethodDescriptor(name, daoClass, returnDescriptor, parameterDescriptors); } public String getName() { return name; } public Class<?> getDaoClass() { return daoClass; } public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) { return getAnnotation(annotationType) != null; } @Nullable public <A extends Annotation> A getAnnotation(Class<A> annotationType) { return returnDescriptor.getAnnotation(annotationType); } public Type getReturnType() { return returnDescriptor.getType(); } public Class<?> getReturnRawType() { return returnDescriptor.getRawType(); } public List<Annotation> getAnnotations() { return returnDescriptor.getAnnotations(); } public ReturnDescriptor getReturnDescriptor() { return returnDescriptor; } public List<ParameterDescriptor> getParameterDescriptors() { return parameterDescriptors; } }