[Fb-contrib-commit] SF.net SVN: fb-contrib: [717] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-10 07:16:14
|
Revision: 717 http://svn.sourceforge.net/fb-contrib/?rev=717&view=rev Author: dbrosius Date: 2006-12-09 23:16:06 -0800 (Sat, 09 Dec 2006) Log Message: ----------- initial checkin - new SCII detector Added Paths: ----------- trunk/fb-contrib/samples/SCII_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java Added: trunk/fb-contrib/samples/SCII_Sample.java =================================================================== --- trunk/fb-contrib/samples/SCII_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SCII_Sample.java 2006-12-10 07:16:06 UTC (rev 717) @@ -0,0 +1,33 @@ +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +public class SCII_Sample extends OverEndulgentParent implements MouseListener +{ + public void mouseClicked(MouseEvent arg0) { + // TODO Auto-generated method stub + + } +} + +class OverEndulgentParent +{ + public void mousePressed(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseReleased(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseEntered(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseExited(MouseEvent arg0) { + // TODO Auto-generated method stub + + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2006-12-10 07:16:06 UTC (rev 717) @@ -0,0 +1,120 @@ +/* + * 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.detect; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.Detector; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for classes that implement interfaces by relying on methods being + * implemented in superclasses, even tho the superclass knows nothing about + * the interface being implemented by the child. + */ +public class SpoiledChildInterfaceImplementor implements Detector { + + private BugReporter bugReporter; + + /** + * constructs a SCII detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public SpoiledChildInterfaceImplementor(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** looks for classes that implement interfaces but don't provide those methods + * + * @param classContext the context object of the currently parsed class + */ + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + + if (cls.isAbstract() || cls.isInterface()) + return; + + if ("java.lang.Object".equals(cls.getSuperclassName())) + return; + + JavaClass[] infs = cls.getInterfaces(); + if (infs.length > 0) { + Set<String> clsMethods = buildMethodSet(cls); + for (JavaClass inf : cls.getInterfaces()) { + Set<String> infMethods = buildMethodSet(inf); + if (infMethods.size() > 0) { + infMethods.removeAll(clsMethods); + if (infMethods.size() > 0) { + if (!cls.getSuperClass().implementationOf(inf)) { + BugInstance bi = new BugInstance(this, "SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR", NORMAL_PRIORITY) + .addClass(cls) + .addString("Implementing interface: " + inf.getClassName()) + .addString("Methods:"); + for (String nameSig : infMethods) + bi.addString("\t" + nameSig); + + bugReporter.reportBug(bi); + return; + } + } + } + } + } + + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + } + + /** + * required for implementing the interface + */ + public void report() { + } + + /** + * builds a set of all non constructor or static initializer method/signatures + * + * @param cls the class to build the method set from + * @return a set of method names/signatures + */ + public Set<String> buildMethodSet(JavaClass cls) { + Set<String> methods = new HashSet<String>(); + + for (Method m : cls.getMethods()) { + String methodName = m.getName(); + if (!"<init>".equals(methodName) && !"<clinit>".equals(methodName)) { + methods.add(methodName + ":" + m.getSignature()); + } + } + + return methods; + } + + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |