1 20 21 package net.innig.macker.rule.filter; 22 23 import net.innig.macker.rule.*; 24 import net.innig.macker.structure.ClassInfo; 25 import java.util.*; 26 27 public class SubtypeFilter 28 implements Filter 29 { 30 public Pattern createPattern( 31 RuleSet ruleSet, 32 List params, 33 Map options) 34 throws RulesException 35 { 36 if(params.size() != 1) 37 throw new FilterSyntaxException( 38 this, 39 "Filter \"" + options.get("filter") + "\" expects one parameter, but has " + params.size()); 40 final Pattern supertypePat = (Pattern) params.get(0); 41 return new Pattern() 42 { 43 public boolean matches(EvaluationContext context, ClassInfo classInfo) 44 throws RulesException 45 { 46 for(Iterator superI = classInfo.getSupertypes().iterator(); superI.hasNext(); ) 47 { 48 ClassInfo supertype = (ClassInfo) superI.next(); 49 if(supertypePat.matches(context, supertype)) 50 return true; 51 } 52 return false; 53 } 54 }; 55 } 56 } 57 | Popular Tags |