001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.reflect; 019 020import com.esotericsoftware.reflectasm.MethodAccess; 021import net.tridentsdk.docs.InternalUseOnly; 022 023/** 024 * Wrapper for the provided ReflectASM method library 025 * 026 * @author The TridentSDK Team 027 * @since 0.3-alpha-DP 028 */ 029public class FastMethod { 030 private final MethodAccess access; 031 private final String name; 032 private final Object instance; 033 034 @InternalUseOnly 035 public FastMethod(Object instance, MethodAccess access, String name) { 036 this.access = access; 037 this.name = name; 038 this.instance = instance; 039 } 040 041 /** 042 * Invokes the method with parameters 043 * 044 * @param instance the instance of the class to use, to {@code null for static methods} 045 * @param args the parameter values for the method 046 * @return the return type of the method, or {@code null} for {@code void} methods 047 */ 048 public Object invoke(Object instance, Object... args) { 049 return this.access.invoke(instance, this.name, args); 050 } 051 052 /** 053 * Invokes the method without parameters (no-arg) 054 * 055 * @param instance the instance of the class to use, to {@code null for static methods} 056 * @return the return type of the method, or {@code null} for {@code void} methods 057 */ 058 public Object invoke(Object instance) { 059 return this.access.invoke(instance, this.name); 060 } 061 062 /** 063 * Gets the object instance used by this class 064 * 065 * @return the instance for method invocation 066 */ 067 public Object instance() { 068 return instance; 069 } 070}