Java handlers are mere factories - made their broker a static function

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4726 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Brian Remedios
2006-10-21 14:29:16 +00:00
parent 47655a29c8
commit 42c4e0e336
2 changed files with 13 additions and 24 deletions

View File

@ -35,7 +35,6 @@ public class PMD {
private String excludeMarker = EXCLUDE_MARKER;
private SourceTypeDiscoverer sourceTypeDiscoverer = new SourceTypeDiscoverer();
private SourceTypeHandlerBroker sourceTypeHandlerBroker = new SourceTypeHandlerBroker();
public PMD() {}
@ -68,7 +67,7 @@ public class PMD {
public void processFile(Reader reader, RuleSets ruleSets, RuleContext ctx,
SourceType sourceType) throws PMDException {
try {
SourceTypeHandler sourceTypeHandler = sourceTypeHandlerBroker.getVisitorsFactoryForSourceType(sourceType);
SourceTypeHandler sourceTypeHandler = SourceTypeHandlerBroker.getVisitorsFactoryForSourceType(sourceType);
ctx.setSourceType(sourceType);
Parser parser = sourceTypeHandler.getParser();
parser.setExcludeMarker(excludeMarker);

View File

@ -1,10 +1,10 @@
package net.sourceforge.pmd.sourcetypehandlers;
import net.sourceforge.pmd.SourceType;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.pmd.SourceType;
import net.sourceforge.pmd.util.CollectionUtil;
/**
* Broker for SourceTypeHandler instances for specific SourceTypes.
*
@ -12,30 +12,20 @@ import java.util.Map;
*/
public class SourceTypeHandlerBroker {
/**
* Map of SourceType on SourceTypeHandler.
*/
private Map mapSourceTypeOnSourceTypeHandler = new HashMap();
private static final Map mapSourceTypeOnSourceTypeHandler = CollectionUtil.mapFrom( new Object[][] {
{ SourceType.JAVA_13, new Java13Handler()},
{ SourceType.JAVA_14, new Java14Handler()},
{ SourceType.JAVA_15, new Java15Handler()},
{ SourceType.JAVA_16, new Java16Handler()},
{ SourceType.JSP, new JspTypeHandler()},
});
/**
* Public constructor.
*/
public SourceTypeHandlerBroker() {
initialize();
}
private SourceTypeHandlerBroker() { }
/**
* Initialize the mapSourceTypeOnVisitorsFactory.
*/
private void initialize() {
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_13, new Java13Handler());
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_14, new Java14Handler());
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_15, new Java15Handler());
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_16, new Java16Handler());
mapSourceTypeOnSourceTypeHandler.put(SourceType.JSP, new JspTypeHandler());
}
public SourceTypeHandler getVisitorsFactoryForSourceType(SourceType sourceType) {
public static SourceTypeHandler getVisitorsFactoryForSourceType(SourceType sourceType) {
SourceTypeHandler handler = (SourceTypeHandler) mapSourceTypeOnSourceTypeHandler.get(sourceType);
if (handler == null) {