01 package net.sourceforge.pmd.lang.java;
02
03 import java.io.Writer;
04
05 import net.sf.saxon.sxpath.IndependentContext;
06 import net.sourceforge.pmd.lang.DataFlowHandler;
07 import net.sourceforge.pmd.lang.Language;
08 import net.sourceforge.pmd.lang.LanguageVersionHandler;
09 import net.sourceforge.pmd.lang.VisitorStarter;
10 import net.sourceforge.pmd.lang.XPathHandler;
11 import net.sourceforge.pmd.lang.ast.Node;
12 import net.sourceforge.pmd.lang.ast.xpath.AbstractASTXPathHandler;
13 import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
14 import net.sourceforge.pmd.lang.java.ast.DumpFacade;
15 import net.sourceforge.pmd.lang.java.ast.JavaNode;
16 import net.sourceforge.pmd.lang.java.dfa.DataFlowFacade;
17 import net.sourceforge.pmd.lang.java.rule.JavaRuleViolationFactory;
18 import net.sourceforge.pmd.lang.java.symboltable.SymbolFacade;
19 import net.sourceforge.pmd.lang.java.typeresolution.TypeResolutionFacade;
20 import net.sourceforge.pmd.lang.java.xpath.JavaFunctions;
21 import net.sourceforge.pmd.lang.java.xpath.TypeOfFunction;
22 import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
23
24 /**
25 * Implementation of LanguageVersionHandler for the Java AST. It uses anonymous classes
26 * as adapters of the visitors to the VisitorStarter interface.
27 *
28 * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
29 */
30 public abstract class AbstractJavaHandler implements LanguageVersionHandler {
31
32 public DataFlowHandler getDataFlowHandler() {
33 return new JavaDataFlowHandler();
34 }
35
36 public XPathHandler getXPathHandler() {
37 return new AbstractASTXPathHandler() {
38 public void initialize() {
39 TypeOfFunction.registerSelfInSimpleContext();
40 }
41
42 public void initialize(IndependentContext context) {
43 super.initialize(context, Language.JAVA, JavaFunctions.class);
44 }
45 };
46 }
47
48 public RuleViolationFactory getRuleViolationFactory() {
49 return JavaRuleViolationFactory.INSTANCE;
50 }
51
52 public VisitorStarter getDataFlowFacade() {
53 return new VisitorStarter() {
54 public void start(Node rootNode) {
55 new DataFlowFacade().initializeWith(getDataFlowHandler(), (ASTCompilationUnit) rootNode);
56 }
57 };
58 }
59
60 public VisitorStarter getSymbolFacade() {
61 return new VisitorStarter() {
62 public void start(Node rootNode) {
63 new SymbolFacade().initializeWith((ASTCompilationUnit) rootNode);
64 }
65 };
66 }
67
68 public VisitorStarter getTypeResolutionFacade(final ClassLoader classLoader) {
69 return new VisitorStarter() {
70 public void start(Node rootNode) {
71 new TypeResolutionFacade().initializeWith(classLoader, (ASTCompilationUnit) rootNode);
72 }
73 };
74 }
75
76 public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
77 return new VisitorStarter() {
78 public void start(Node rootNode) {
79 new DumpFacade().initializeWith(writer, prefix, recurse, (JavaNode) rootNode);
80 }
81 };
82 }
83 }
|