Thread: [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. |
From: <dbr...@us...> - 2009-09-06 05:53:54
|
Revision: 1255 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1255&view=rev Author: dbrosius Date: 2009-09-06 05:53:44 +0000 (Sun, 06 Sep 2009) Log Message: ----------- add getTypeCodeSignature 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-09-06 04:03:39 UTC (rev 1254) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-09-06 05:53:44 UTC (rev 1255) @@ -18,6 +18,7 @@ */ package com.mebigfatguy.fbcontrib.utils; +import org.apache.bcel.Constants; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; @@ -87,6 +88,39 @@ return similarPackages(packName1.substring(dot1+1), packName2.substring(dot2+1), depth-1); } + + /** + * converts a primitive type code to a signature + */ + public static String getTypeCodeSignature(int typeCode) { + switch (typeCode) { + case Constants.T_BOOLEAN: + return "Z"; + + case Constants.T_CHAR: + return "C"; + + case Constants.T_FLOAT: + return "F"; + + case Constants.T_DOUBLE: + return "D"; + + case Constants.T_BYTE: + return "B"; + + case Constants.T_SHORT: + return "S"; + + case Constants.T_INT: + return "I"; + + case Constants.T_LONG: + return "L"; + } + + return "Ljava/lang/Object;"; + } private static JavaClass findInheritedMethod(JavaClass[] classes, String methodName, String signature) { @@ -106,4 +140,5 @@ } return null; } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-09-26 19:05:33
|
Revision: 1318 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1318&view=rev Author: dbrosius Date: 2009-09-26 19:05:22 +0000 (Sat, 26 Sep 2009) Log Message: ----------- add getParameterSignatures 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-09-26 18:48:14 UTC (rev 1317) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-09-26 19:05:22 UTC (rev 1318) @@ -18,9 +18,13 @@ */ package com.mebigfatguy.fbcontrib.utils; +import java.util.ArrayList; +import java.util.List; + import org.apache.bcel.Constants; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import org.apache.bcel.generic.Type; public class SignatureUtils { @@ -141,4 +145,27 @@ return null; } + /** + * returns a List that represents the type of the parameter in slot x + * + * @param m the method for which you want the parameters + * @return a list of parameter types (expect empty slots when doubles/longs are used + */ + public List<String> getParameterSignatures(Method m) { + Type[] parms = m.getArgumentTypes(); + + List<String> parmSigs = new ArrayList<String>(); + + int slot = m.isStatic() ? 0 : 1; + for (Type t : parms) { + String signature = t.getSignature(); + while (parmSigs.size() <= slot) + parmSigs.add(null); + parmSigs.set(slot, signature); + slot += ("L".equals(signature) || "D".equals(signature)) ? 2 : 1; + } + + return parmSigs; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-09-26 19:07:35
|
Revision: 1319 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1319&view=rev Author: dbrosius Date: 2009-09-26 19:07:24 +0000 (Sat, 26 Sep 2009) Log Message: ----------- switch getParameterSignatures to return a map 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-09-26 19:05:22 UTC (rev 1318) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-09-26 19:07:24 UTC (rev 1319) @@ -18,8 +18,8 @@ */ package com.mebigfatguy.fbcontrib.utils; -import java.util.ArrayList; -import java.util.List; +import java.util.LinkedHashMap; +import java.util.Map; import org.apache.bcel.Constants; import org.apache.bcel.classfile.JavaClass; @@ -146,22 +146,20 @@ } /** - * returns a List that represents the type of the parameter in slot x + * returns a Map that represents the type of the parameter in slot x * * @param m the method for which you want the parameters - * @return a list of parameter types (expect empty slots when doubles/longs are used + * @return a map of parameter types (expect empty slots when doubles/longs are used */ - public List<String> getParameterSignatures(Method m) { + public Map<Integer, String> getParameterSignatures(Method m) { Type[] parms = m.getArgumentTypes(); - List<String> parmSigs = new ArrayList<String>(); + Map<Integer, String> parmSigs = new LinkedHashMap<Integer, String>(); int slot = m.isStatic() ? 0 : 1; for (Type t : parms) { String signature = t.getSignature(); - while (parmSigs.size() <= slot) - parmSigs.add(null); - parmSigs.set(slot, signature); + parmSigs.put(Integer14.valueOf(slot), signature); slot += ("L".equals(signature) || "D".equals(signature)) ? 2 : 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-09-26 19:09:42
|
Revision: 1320 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1320&view=rev Author: dbrosius Date: 2009-09-26 19:09:28 +0000 (Sat, 26 Sep 2009) Log Message: ----------- make it static 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-09-26 19:07:24 UTC (rev 1319) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-09-26 19:09:28 UTC (rev 1320) @@ -151,7 +151,7 @@ * @param m the method for which you want the parameters * @return a map of parameter types (expect empty slots when doubles/longs are used */ - public Map<Integer, String> getParameterSignatures(Method m) { + public static Map<Integer, String> getParameterSignatures(Method m) { Type[] parms = m.getArgumentTypes(); Map<Integer, String> parmSigs = new LinkedHashMap<Integer, String>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-09-26 20:07:44
|
Revision: 1329 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1329&view=rev Author: dbrosius Date: 2009-09-26 20:07:36 +0000 (Sat, 26 Sep 2009) Log Message: ----------- add PDP Detector 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-09-26 20:07:17 UTC (rev 1328) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2009-09-26 20:07:36 UTC (rev 1329) @@ -160,7 +160,7 @@ for (Type t : parms) { String signature = t.getSignature(); parmSigs.put(Integer14.valueOf(slot), signature); - slot += ("L".equals(signature) || "D".equals(signature)) ? 2 : 1; + slot += ("J".equals(signature) || "D".equals(signature)) ? 2 : 1; } return parmSigs; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |