/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003, University of Maryland
 * 
 * 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 edu.umd.cs.findbugs;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class DetectorFactory {
	private Class detectorClass;
	// Other meta-information about the detector?

	public DetectorFactory(Class detectorClass) {
		this.detectorClass = detectorClass;
	}

	private static final Class[] constructorArgTypes = new Class[]{BugReporter.class};

	public Detector create(BugReporter bugReporter)
		throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
		Constructor constructor = detectorClass.getConstructor(constructorArgTypes);
		return (Detector) constructor.newInstance(new Object[] {bugReporter});
	}
}

// vim:ts=4

@@ -1286,117 +1286,20 @@
 ter)
+ %7B
 %0A%09%09t
-hrows NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
+ry
  %7B%0A
+%09
 %09%09Co
@@ -1373,16 +1373,17 @@
 Types);%0A
+%09
 %09%09return
@@ -1447,16 +1447,332 @@
 rter%7D);%0A
+%09%09%7D catch (Exception e) %7B%0A%09%09%09throw new RuntimeException(%22Could not instantiate Detector%22, e);%0A%09%09%7D%0A%09%7D%0A%0A%09public String getShortName() %7B%0A%09%09String className = detectorClass.getName();%0A%09%09int endOfPkg = className.lastIndexOf('.');%0A%09%09if (endOfPkg %3E= 0)%0A%09%09%09className = className.substring(endOfPkg + 1);%0A%09%09return className;%0A
 %09%7D%0A%7D%0A%0A//

Throw a RuntimeException if class can't be instantiated.