[Fb-contrib-commit] SF.net SVN: fb-contrib: [626] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/u
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-09-04 03:08:51
|
Revision: 626 http://svn.sourceforge.net/fb-contrib/?rev=626&view=rev Author: dbrosius Date: 2006-09-03 20:08:46 -0700 (Sun, 03 Sep 2006) Log Message: ----------- collection of methods to help with method signatures. Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2006-09-04 03:08:46 UTC (rev 626) @@ -0,0 +1,57 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.utils; + +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; + +public class SignatureUtils { + + public static boolean isInheritedMethod(JavaClass cls, String methodName, String signature) throws ClassNotFoundException { + JavaClass[] infs = cls.getAllInterfaces(); + if (findInheritedMethod(infs, methodName, signature) != null) { + return true; + } + + JavaClass[] supers = cls.getSuperClasses(); + for (int i = 0; i < supers.length; i++) { + if (supers[i].getClassName().equals("java/lang/Object")) { + supers[i] = null; + } + } + return findInheritedMethod(supers, methodName, signature) != null; + } + + private static JavaClass findInheritedMethod(JavaClass[] classes, String methodName, String signature) { + for (JavaClass cls : classes) { + if (cls != null) { + Method[] methods = cls.getMethods(); + for (Method m : methods) { + if (!m.isPrivate()) { + if (m.getName().equals(methodName)) { + if (m.getSignature().equals(signature)) + return cls; + } + } + } + } + } + return null; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |