[Fb-contrib-commit] SF.net SVN: fb-contrib: [851] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-02-13 23:19:13
|
Revision: 851 http://svn.sourceforge.net/fb-contrib/?rev=851&view=rev Author: dbrosius Date: 2007-02-13 15:19:12 -0800 (Tue, 13 Feb 2007) Log Message: ----------- Fix [ 1655778 ] SPOILED_CHILD_INTERFACE_IMPLEMENTOR: wrong analysis If a superclass implements a super interface of the interface that the child implements, and the super interface has the same methods as the child, then don't report -- even if hinky. Modified Paths: -------------- trunk/fb-contrib/samples/SCII_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java Modified: trunk/fb-contrib/samples/SCII_Sample.java =================================================================== --- trunk/fb-contrib/samples/SCII_Sample.java 2007-02-13 04:34:14 UTC (rev 850) +++ trunk/fb-contrib/samples/SCII_Sample.java 2007-02-13 23:19:12 UTC (rev 851) @@ -34,6 +34,10 @@ interface A { public void a(); + + public void b(); + + public void c(); } interface B extends A @@ -41,15 +45,27 @@ public void b(); } + interface C extends B + { + public void c(); + } + class AA implements A { public void a() {} public void b() {} + + public void c() {} } class BB extends AA implements B { } + + class CC extends BB implements C + { + + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2007-02-13 04:34:14 UTC (rev 850) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2007-02-13 23:19:12 UTC (rev 851) @@ -71,18 +71,21 @@ infMethods.removeAll(clsMethods); if (infMethods.size() > 0) { JavaClass superCls = cls.getSuperClass(); - if (!superCls.implementationOf(inf)) { - int priority = AnalysisContext.currentAnalysisContext().getSubtypes().isApplicationClass(superCls) ? NORMAL_PRIORITY : LOW_PRIORITY; - BugInstance bi = new BugInstance(this, "SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR", priority) - .addClass(cls) - .addString("Implementing interface: " + inf.getClassName()) - .addString("Methods:"); - for (String nameSig : infMethods) - bi.addString("\t" + nameSig); - - bugReporter.reportBug(bi); - return; - } + filterSuperInterfaceMethods(inf, infMethods, superCls); + if (infMethods.size() > 0) { + if (!superCls.implementationOf(inf)) { + int priority = AnalysisContext.currentAnalysisContext().getSubtypes().isApplicationClass(superCls) ? NORMAL_PRIORITY : LOW_PRIORITY; + BugInstance bi = new BugInstance(this, "SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR", priority) + .addClass(cls) + .addString("Implementing interface: " + inf.getClassName()) + .addString("Methods:"); + for (String nameSig : infMethods) + bi.addString("\t" + nameSig); + + bugReporter.reportBug(bi); + return; + } + } } } } @@ -105,7 +108,7 @@ * @param cls the class to build the method set from * @return a set of method names/signatures */ - public Set<String> buildMethodSet(JavaClass cls) { + private Set<String> buildMethodSet(JavaClass cls) { Set<String> methods = new HashSet<String>(); for (Method m : cls.getMethods()) { @@ -117,6 +120,35 @@ return methods; } + + /** + * removes methods found in an interface when a superinterface having the same methods + * is implemented in a parent. While this is somewhat hinky, we'll allow it. + * + * @param inf the interface to look for super interfaces for + * @param infMethods the remaining methods that are needed to be found + * @param cls the super class to look for these methods in + */ + private void filterSuperInterfaceMethods(JavaClass inf, Set<String> infMethods, JavaClass cls) { + try { + if (infMethods.size() == 0) + return; + + JavaClass[] superInfs = inf.getInterfaces(); + for (JavaClass superInf : superInfs) { + if (cls.implementationOf(superInf)) { + Set<String> superInfMethods = buildMethodSet(superInf); + infMethods.removeAll(superInfMethods); + if (infMethods.size() == 0) + return; + } + filterSuperInterfaceMethods(superInf, infMethods, cls); + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + infMethods.clear(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |