1 19 20 package org.netbeans.modules.j2ee.jpa.verification.common; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 import javax.lang.model.element.TypeElement; 26 import javax.lang.model.util.ElementFilter; 27 import javax.lang.model.util.ElementKindVisitor6; 28 import org.netbeans.spi.editor.hints.ErrorDescription; 29 30 34 public abstract class RulesEngine extends ElementKindVisitor6<Void , ProblemContext> { 35 private ProblemContext ctx; 36 private List <ErrorDescription> problemsFound = new ArrayList <ErrorDescription>(); 37 38 @Override public Void visitTypeAsClass(TypeElement javaClass, ProblemContext ctx){ 39 for (TypeElement enclosedClass : ElementFilter.typesIn(javaClass.getEnclosedElements())){ 41 visitTypeAsClass(enclosedClass, ctx); 42 } 43 44 for (Rule<TypeElement> rule : getClassRules()){ 46 if (ctx.isCancelled()){ 47 break; 48 } 49 50 ErrorDescription problems[] = rule.execute(javaClass, ctx); 51 52 if (problems != null){ 53 for (ErrorDescription problem : problems){ 54 if (problem != null){ 55 problemsFound.add(problem); 56 } 57 } 58 } 59 } 60 61 return null; 62 } 63 64 public List <ErrorDescription> getProblemsFound(){ 65 return problemsFound; 66 } 67 68 protected abstract Collection <Rule<TypeElement>> getClassRules(); 69 } 70 | Popular Tags |