001/* 002 * Copyright 2013 Christopher Pheby 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.jadira.reflection.access.asm; 017 018import java.lang.reflect.Method; 019 020import org.jadira.reflection.access.api.MethodAccess; 021 022public class AsmMethodAccess<C> implements MethodAccess<C> { 023 024 private Method method; 025 private AsmClassAccess<C> classAccess; 026 private Class<C> declaringClass; 027 private Class<?> returnType; 028 029 @SuppressWarnings("unchecked") 030 private AsmMethodAccess(AsmClassAccess<C> classAccess, Method m) { 031 032 this.classAccess = classAccess; 033 this.method = m; 034 this.declaringClass = (Class<C>) m.getDeclaringClass(); 035 036 this.returnType = (Class<?>) m.getReturnType(); 037 } 038 039 public static final <C> AsmMethodAccess<C> get(AsmClassAccess<C> classAccess, Method m) { 040 return new AsmMethodAccess<C>(classAccess, m); 041 } 042 043 @Override 044 public Class<C> declaringClass() { 045 return declaringClass; 046 } 047 048 @Override 049 public Class<?> returnClass() { 050 return returnType; 051 } 052 053 @Override 054 public Method method() { 055 return method; 056 } 057 058 @Override 059 public Object invoke(Object target, Object... args) throws IllegalArgumentException { 060 return classAccess.invokeMethod(target, method, args); 061 } 062}