View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.vm.util;
5   
6   import java.util.HashMap;
7   import java.util.HashSet;
8   import java.util.Map;
9   import java.util.Set;
10  
11  import net.sourceforge.pmd.lang.vm.directive.Break;
12  import net.sourceforge.pmd.lang.vm.directive.Define;
13  import net.sourceforge.pmd.lang.vm.directive.Directive;
14  import net.sourceforge.pmd.lang.vm.directive.Evaluate;
15  import net.sourceforge.pmd.lang.vm.directive.Foreach;
16  import net.sourceforge.pmd.lang.vm.directive.Include;
17  import net.sourceforge.pmd.lang.vm.directive.Literal;
18  import net.sourceforge.pmd.lang.vm.directive.Macro;
19  import net.sourceforge.pmd.lang.vm.directive.Parse;
20  import net.sourceforge.pmd.lang.vm.directive.Stop;
21  
22  public class DirectiveMapper {
23  
24  	private static final Map<String, Directive> DIRECTIVE_MAP = new HashMap<>();
25  	
26  	private static final Set<String> DIRECTIVE_NAMES = new HashSet<>();
27  	
28  	static {
29  		DIRECTIVE_MAP.put("foreach", new Foreach());
30  		DIRECTIVE_MAP.put("include", new Include());
31  		DIRECTIVE_MAP.put("parse", new Parse());
32  		DIRECTIVE_MAP.put("macro", new Macro());
33  		DIRECTIVE_MAP.put("literal", new Literal());
34  		DIRECTIVE_MAP.put("evaluate", new Evaluate());
35  		DIRECTIVE_MAP.put("break", new Break());
36  		DIRECTIVE_MAP.put("define", new Define());
37  		DIRECTIVE_MAP.put("stop", new Stop());
38  		
39  		for (Directive d : DIRECTIVE_MAP.values()) {
40  			DIRECTIVE_NAMES.add(d.getName());
41  		}
42  	}
43  	
44  	public static Directive getDirective(String directiveName) {
45  		return DIRECTIVE_MAP.get(directiveName);
46  	}
47  	
48  	public static boolean isDirective(String name) {
49  		return DIRECTIVE_NAMES.contains(name);
50  	}
51  	
52  }