001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.bytecode; 021 022import java.lang.reflect.Method; 023import java.util.HashMap; 024 025public class MethodTable { 026 027 private HashMap nameToMethodMap; 028 private ChainedParamReader cpr; 029 030 public MethodTable(Class cls) throws Exception { 031 cpr = new ChainedParamReader(cls); 032 nameToMethodMap = new HashMap(); 033 loadMethods(cls); 034 } 035 036 /** 037 * To load all the methods in the given class by Java reflection 038 * 039 * @param cls 040 * @throws Exception 041 */ 042 private void loadMethods(Class cls) throws Exception { 043 Method [] methods = cls.getMethods(); 044 for (int i = 0; i < methods.length; i++) { 045 Method method = methods[i]; 046 if (method.isBridge()) { 047 continue; 048 } 049 nameToMethodMap.put(method.getName(), method); 050 } 051 } 052 053 public String [] getParameterNames(String methodName) { 054 Method method = (Method) nameToMethodMap.get(methodName); 055 if (method == null) { 056 return null; 057 } 058 return cpr.getParameterNames(method); 059 } 060 061 062}