View Javadoc

    1   package net.sourceforge.pmd.sourcetypehandlers;
    2
    3   import java.util.Map;
    4
    5   import net.sourceforge.pmd.SourceType;
    6   import net.sourceforge.pmd.util.CollectionUtil;
    7
    8   /**
    9    * Broker for SourceTypeHandler instances for specific SourceTypes.
    10   *
    11   * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
    12   */
    13  public class SourceTypeHandlerBroker {
    14
    15      private static final Map<SourceType, SourceTypeHandler> mapSourceTypeOnSourceTypeHandler = CollectionUtil
    16              .mapFrom(new SourceType[] { SourceType.JAVA_13, SourceType.JAVA_14,
    17                      SourceType.JAVA_15, SourceType.JAVA_16, SourceType.JAVA_17, SourceType.JSP, },
    18
    19              new SourceTypeHandler[] { new Java13Handler(), new Java14Handler(),
    20                      new Java15Handler(), new Java16Handler(),
    21                      new Java17Handler(), new JspTypeHandler(), });
    22
    23      /**
    24       * Never create one
    25       */
    26      private SourceTypeHandlerBroker() {  }
    27
    28      public static SourceTypeHandler getVisitorsFactoryForSourceType(SourceType sourceType) {
    29          SourceTypeHandler handler = mapSourceTypeOnSourceTypeHandler.get(sourceType);
    30
    31          if (handler == null) {
    32              throw new IllegalArgumentException("No VisitorsFactory is registered for SourceType [" + sourceType + "].");
    33          }
    34          return handler;
    35      }
    36
    37  }