Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [791] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-01-28 20:14:53
|
Revision: 791 http://svn.sourceforge.net/fb-contrib/?rev=791&view=rev Author: dbrosius Date: 2007-01-28 12:14:52 -0800 (Sun, 28 Jan 2007) Log Message: ----------- javadoc Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 16:31:35 UTC (rev 790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 20:14:52 UTC (rev 791) @@ -262,6 +262,12 @@ } } + /** + * builds a map of method information for each method of each interface that each parameter implements of this method + * @return a map by parameter id of all the method signatures that interfaces of that parameter implements + * + * @throws ClassNotFoundException if the class can't be loaded + */ private boolean buildParameterDefiners() throws ClassNotFoundException { @@ -293,6 +299,13 @@ return hasPossiblyOverlyConcreteParm; } + /** + * returns a map of method information for each public method for each interface this class implements + * @param cls the class whose interfaces to record + * + * @return a map of (method name)(method sig) by interface + * @throws ClassNotFoundException if unable to load the class + */ private Map<JavaClass, List<String>> getClassDefiners(final JavaClass cls) throws ClassNotFoundException { Map<JavaClass, List<String>> definers = new HashMap<JavaClass, List<String>>(); @@ -308,6 +321,12 @@ return definers; } + /** + * returns a lost of method information of all public or protected methods in this class + * + * @param cls the class to look for methods + * @return a map of (method name)(method signature) + */ private List<String> getPublicMethodInfos(final JavaClass cls) { List<String> methodInfos = new ArrayList<String>(); Method[] methods = cls.getMethods(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:37:48
|
Revision: 792 http://svn.sourceforge.net/fb-contrib/?rev=792&view=rev Author: dbrosius Date: 2007-01-28 12:37:48 -0800 (Sun, 28 Jan 2007) Log Message: ----------- move to first class MethodInfo, to start pulling in exception stuff Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 20:14:52 UTC (rev 791) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 20:37:48 UTC (rev 792) @@ -29,6 +29,7 @@ import org.apache.bcel.Constants; import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.ExceptionTable; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.LocalVariable; import org.apache.bcel.classfile.LocalVariableTable; @@ -52,7 +53,7 @@ { private BugReporter bugReporter; private JavaClass[] interfaces; - private Map<Integer, Map<JavaClass, List<String>>> parameterDefiners; + private Map<Integer, Map<JavaClass, List<MethodInfo>>> parameterDefiners; private Set<Integer> usedParameters; private JavaClass objectClass; private OpcodeStack stack; @@ -78,7 +79,7 @@ public void visitClassContext(ClassContext classContext) { try { interfaces = classContext.getJavaClass().getAllInterfaces(); - parameterDefiners = new HashMap<Integer, Map<JavaClass, List<String>>>(); + parameterDefiners = new HashMap<Integer, Map<JavaClass, List<MethodInfo>>>(); usedParameters = new HashSet<Integer>(); stack = new OpcodeStack(); super.visitClassContext(classContext); @@ -228,16 +229,16 @@ } private void reportBugs() { - Iterator<Map.Entry<Integer, Map<JavaClass, List<String>>>> it = parameterDefiners.entrySet().iterator(); + Iterator<Map.Entry<Integer, Map<JavaClass, List<MethodInfo>>>> it = parameterDefiners.entrySet().iterator(); while (it.hasNext()) { - Map.Entry<Integer, Map<JavaClass, List<String>>> entry = it.next(); + Map.Entry<Integer, Map<JavaClass, List<MethodInfo>>> entry = it.next(); Integer reg = entry.getKey(); if (!usedParameters.contains(reg)) { it.remove(); continue; } - Map<JavaClass, List<String>> definers = entry.getValue(); + Map<JavaClass, List<MethodInfo>> definers = entry.getValue(); definers.remove(objectClass); if (definers.size() > 0) { String name = ""; @@ -286,7 +287,7 @@ JavaClass cls = Repository.lookupClass(clsName); if (cls.isClass()) { - Map<JavaClass, List<String>> definers = getClassDefiners(cls); + Map<JavaClass, List<MethodInfo>> definers = getClassDefiners(cls); if (definers.size() > 0) { parameterDefiners.put( Integer14.valueOf(i + (methodIsStatic ? 0 : 1)), definers ); @@ -306,14 +307,14 @@ * @return a map of (method name)(method sig) by interface * @throws ClassNotFoundException if unable to load the class */ - private Map<JavaClass, List<String>> getClassDefiners(final JavaClass cls) + private Map<JavaClass, List<MethodInfo>> getClassDefiners(final JavaClass cls) throws ClassNotFoundException { - Map<JavaClass, List<String>> definers = new HashMap<JavaClass, List<String>>(); + Map<JavaClass, List<MethodInfo>> definers = new HashMap<JavaClass, List<MethodInfo>>(); for (JavaClass ci : cls.getAllInterfaces()) { if ("java.lang.Comparable".equals(ci.getClassName())) continue; - List<String> methodInfos = getPublicMethodInfos(ci); + List<MethodInfo> methodInfos = getPublicMethodInfos(ci); if (methodInfos.size() > 0) { definers.put(ci, methodInfos); } @@ -327,13 +328,13 @@ * @param cls the class to look for methods * @return a map of (method name)(method signature) */ - private List<String> getPublicMethodInfos(final JavaClass cls) { - List<String> methodInfos = new ArrayList<String>(); + private List<MethodInfo> getPublicMethodInfos(final JavaClass cls) { + List<MethodInfo> methodInfos = new ArrayList<MethodInfo>(); Method[] methods = cls.getMethods(); for (Method m : methods) { if ((m.getAccessFlags() & (Constants.ACC_PUBLIC|Constants.ACC_PROTECTED)) != 0) { - String methodInfo = m.getName() + m.getSignature(); - methodInfos.add(methodInfo); + ExceptionTable et = m.getExceptionTable(); + methodInfos.add(new MethodInfo(m.getName(), m.getSignature(), et == null ? null : et.getExceptionNames())); } } return methodInfos; @@ -341,18 +342,18 @@ private void removeUselessDefiners(final int reg) { - Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); + Map<JavaClass, List<MethodInfo>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { String methodSig = getSigConstantOperand(); String methodName = getNameConstantOperand(); - String methodInfo = methodName + methodSig; + MethodInfo methodInfo = new MethodInfo(methodName, methodSig, null); - Iterator<List<String>> it = definers.values().iterator(); + Iterator<List<MethodInfo>> it = definers.values().iterator(); while (it.hasNext()) { boolean methodDefined = false; - List<String> methodSigs = it.next(); + List<MethodInfo> methodSigs = it.next(); - for (String mi : methodSigs) { + for (MethodInfo mi : methodSigs) { if (methodInfo.equals(mi)) { methodDefined = true; break; @@ -375,7 +376,7 @@ return; } - Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); + Map<JavaClass, List<MethodInfo>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { Iterator<JavaClass> it = definers.keySet().iterator(); while (it.hasNext()) { @@ -389,4 +390,49 @@ } } } + + public static class MethodInfo + { + private String methodName; + private String methodSig; + private String[] methodExceptions; + + public MethodInfo(String name, String sig, String[] excs) { + methodName = name; + methodSig = sig; + methodExceptions = excs; + } + + public String getMethodName() { + return methodName; + } + + public String getMethodSignature() { + return methodSig; + } + + public String[] getMethodExceptions() { + return methodExceptions; + } + + @Override + public int hashCode() { + return methodName.hashCode() ^ methodSig.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof MethodInfo)) + return false; + + MethodInfo that = (MethodInfo)o; + + if (!methodName.equals(that.methodName)) + return false; + if (!methodSig.equals(that.methodSig)) + return false; + + return true; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 21:08:05
|
Revision: 801 http://svn.sourceforge.net/fb-contrib/?rev=801&view=rev Author: dbrosius Date: 2007-01-28 13:08:03 -0800 (Sun, 28 Jan 2007) Log Message: ----------- add toString Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:01:52 UTC (rev 800) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:08:03 UTC (rev 801) @@ -434,5 +434,10 @@ return true; } + + @Override + public String toString() { + return methodName + methodSig; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-03-11 05:04:50
|
Revision: 874 http://svn.sourceforge.net/fb-contrib/?rev=874&view=rev Author: dbrosius Date: 2007-03-10 21:04:49 -0800 (Sat, 10 Mar 2007) Log Message: ----------- Fix for 1676812 OCP flags overriding methods - while at it, short-circuit methods that have no object parameters Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-03-11 04:43:41 UTC (rev 873) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-03-11 05:04:49 UTC (rev 874) @@ -54,13 +54,13 @@ public class OverlyConcreteParameter extends BytecodeScanningDetector { private BugReporter bugReporter; - private JavaClass[] interfaces; + private JavaClass[] constrainingClasses; private Map<Integer, Map<JavaClass, List<MethodInfo>>> parameterDefiners; private Set<Integer> usedParameters; private JavaClass objectClass; private OpcodeStack stack; private int parmCount; - private boolean methodImplementsInterface; + private boolean methodSignatureIsConstrained; private boolean methodIsStatic; /** @@ -80,7 +80,11 @@ @Override public void visitClassContext(ClassContext classContext) { try { - interfaces = classContext.getJavaClass().getAllInterfaces(); + JavaClass[] infs = classContext.getJavaClass().getAllInterfaces(); + JavaClass[] sups = classContext.getJavaClass().getSuperClasses(); + constrainingClasses = new JavaClass[infs.length + sups.length]; + System.arraycopy(infs, 0, constrainingClasses, 0, infs.length); + System.arraycopy(sups, 0, constrainingClasses, infs.length, sups.length); parameterDefiners = new HashMap<Integer, Map<JavaClass, List<MethodInfo>>>(); usedParameters = new HashSet<Integer>(); stack = new OpcodeStack(); @@ -88,7 +92,7 @@ } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } finally { - interfaces = null; + constrainingClasses = null; parameterDefiners = null; usedParameters = null; stack = null; @@ -97,33 +101,34 @@ @Override public void visitMethod(Method obj) { - methodImplementsInterface = false; + methodSignatureIsConstrained = false; String methodName = obj.getName(); if (!"<init>".equals(methodName) && !"<clinit>".equals(methodName)) { String methodSig = obj.getSignature(); + String parms = methodSig.split("\\(|\\)")[1]; + if (parms.indexOf(";") >= 0) { - outer:for (JavaClass inf : interfaces) { - Method[] methods = inf.getMethods(); - for (Method m : methods) { - if (methodName.equals(m.getName())) { - if (methodSig.equals(m.getSignature())) { - methodImplementsInterface = true; - break outer; + outer:for (JavaClass cls : constrainingClasses) { + Method[] methods = cls.getMethods(); + for (Method m : methods) { + if (methodName.equals(m.getName())) { + if (methodSig.equals(m.getSignature())) { + methodSignatureIsConstrained = true; + break outer; + } } } } } } - - super.visitMethod(obj); } @Override public void visitCode(final Code obj) { try { - if (methodImplementsInterface) + if (methodSignatureIsConstrained) return; parameterDefiners.clear(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-08 04:16:07
|
Revision: 1046 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1046&view=rev Author: dbrosius Date: 2008-06-07 21:16:12 -0700 (Sat, 07 Jun 2008) Log Message: ----------- use slashes for lookupClass Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2008-06-07 22:43:52 UTC (rev 1045) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2008-06-08 04:16:12 UTC (rev 1046) @@ -70,7 +70,7 @@ public OverlyConcreteParameter(final BugReporter bugReporter) { this.bugReporter = bugReporter; try { - objectClass = Repository.lookupClass("java.lang.Object"); + objectClass = Repository.lookupClass("java/lang/Object"); } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); objectClass = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-03-11 15:08:46
|
Revision: 879 http://svn.sourceforge.net/fb-contrib/?rev=879&view=rev Author: dbrosius Date: 2007-03-11 08:08:46 -0700 (Sun, 11 Mar 2007) Log Message: ----------- UCPM fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-03-11 15:06:35 UTC (rev 878) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-03-11 15:08:46 UTC (rev 879) @@ -108,7 +108,7 @@ && !"<clinit>".equals(methodName)) { String methodSig = obj.getSignature(); String parms = methodSig.split("\\(|\\)")[1]; - if (parms.indexOf(";") >= 0) { + if (parms.indexOf(';') >= 0) { outer:for (JavaClass cls : constrainingClasses) { Method[] methods = cls.getMethods(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |