[Fb-contrib-commit] SF.net SVN: fb-contrib:[1233] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/u
Brought to you by:
dbrosius
From: <dbr...@us...> - 2009-07-30 04:06:08
|
Revision: 1233 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1233&view=rev Author: dbrosius Date: 2009-07-30 04:05:50 +0000 (Thu, 30 Jul 2009) Log Message: ----------- move getPackageName to SignatureUtils Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-07-30 04:02:28 UTC (rev 1232) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-07-30 04:05:50 UTC (rev 1233) @@ -22,13 +22,13 @@ 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 ("java.lang.Object".equals(supers[i].getClassName())) { @@ -37,8 +37,23 @@ } return findInheritedMethod(supers, methodName, signature) != null; } - + /** + * parses the package name from a fully qualified class name + * + * @param className the class in question + * + * @return the package of the class + */ + public static String getPackageName(final String className) { + int dotPos = className.lastIndexOf('.'); + if (dotPos < 0) { + return ""; + } + return className.substring(0, dotPos); + } + + /** * returns whether or not the two packages have the same first 'depth' parts, if they exist * * @param packName1 the first package to check @@ -48,29 +63,32 @@ * @return if they are similar */ public static boolean similarPackages(String packName1, String packName2, int depth) { - if (depth == 0) + if (depth == 0) { return true; - + } + packName1 = packName1.replace('/', '.'); packName2 = packName2.replace('/', '.'); - + int dot1 = packName1.indexOf('.'); int dot2 = packName2.indexOf('.'); - if (dot1 < 0) + if (dot1 < 0) { return (dot2 < 0); - else if (dot2 < 0) + } else if (dot2 < 0) { return false; - + } + String s1 = packName1.substring(0, dot1); String s2 = packName2.substring(0, dot2); - - if (!s1.equals(s2)) + + if (!s1.equals(s2)) { return false; - + } + return similarPackages(packName1.substring(dot1+1), packName2.substring(dot2+1), depth-1); } - + private static JavaClass findInheritedMethod(JavaClass[] classes, String methodName, String signature) { for (JavaClass cls : classes) { if (cls != null) { @@ -78,8 +96,9 @@ for (Method m : methods) { if (!m.isPrivate()) { if (m.getName().equals(methodName)) { - if (m.getSignature().equals(signature)) + if (m.getSignature().equals(signature)) { return cls; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |