private void checkRules(final ICoverageNode node, final Collection<Rule> rules, final String typename, final String elementname) { for (final Rule rule : rules) { if (rule.matches(elementname)) { for (final Limit limit : rule.getLimits()) { checkLimit(node, typename, elementname, rule, limit); } } } }
/** * Sets allowed maximum value as decimal string or percent representation. * The given precision is also considered in error messages. Coverage ratios * are given in the range from 0.0 to 1.0. * * @param maximum * allowed maximum or <code>null</code>, if no maximum should be * checked */ public void setMaximum(final String maximum) { this.maximum = parseValue(maximum); }
public void visitBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException { bundleChecker.checkBundle(bundle); }
public void checkBundle(final IBundleCoverage bundleCoverage) { final String name = bundleCoverage.getName(); checkRules(bundleCoverage, bundleRules, "bundle", name); if (traversePackages) { for (final IPackageCoverage p : bundleCoverage.getPackages()) { check(p); } } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.List; import com.google.gson.Gson; public class GsonTest { public static void main(String[] args) throws FileNotFoundException { BufferedReader bufferedReader = new BufferedReader(new FileReader("C:/Users/JESNAMOL/Desktop/json.txt"));//i have kept your json string in a file for demonstration Gson gson = new Gson(); Data data = gson.fromJson(bufferedReader, Data.class); List<Rule> rules = data.getRules(); for (Rule rule : rules) { System.out.println("element: " + rule.getElement()); System.out.println("skip: " + rule.isSkip()); } } }
private void checkLimit(final ICoverageNode node, final String elementtype, final String typename, final Rule rule, final Limit limit) { final String message = limit.check(node); if (message != null) { output.onViolation(node, rule, limit, String.format( "Rule violated for %s %s: %s", elementtype, typename, message)); } }
/** * Creates a new Rule without limits. */ public Rule() { this.element = ElementType.BUNDLE; this.limits = new ArrayList<Limit>(); this.setIncludes("*"); this.setExcludes(""); }
this.methodRules = new ArrayList<Rule>(); for (final Rule rule : rules) { switch (rule.getElement()) { case BUNDLE: bundleRules.add(rule);
private void check(final ISourceFileCoverage sourceFile) { final String name = sourceFile.getPackageName() + "/" + sourceFile.getName(); checkRules(sourceFile, sourceFileRules, "source file", name); }
/** * Creates a new visitor to process the configured checks. * * @param output * call-back to report violations to * @return visitor to emit the report data to */ public IReportVisitor createVisitor(final IViolationsOutput output) { final BundleChecker bundleChecker = new BundleChecker(rules, languageNames, output); return new IReportVisitor() { public IReportGroupVisitor visitGroup(final String name) throws IOException { return this; } public void visitBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException { bundleChecker.checkBundle(bundle); } public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException { } public void visitEnd() throws IOException { } }; }
/** * Creates and adds a new {@link Limit}. * * @return creates {@link Limit} */ public Limit createLimit() { final Limit limit = new Limit(); this.limits.add(limit); return limit; }
/** * New formatter instance. */ public RulesChecker() { this.rules = new ArrayList<Rule>(); this.setLanguageNames(new JavaNames()); }
String check(final ICoverageNode node) { final double d = node.getCounter(entity).getValue(value); if (Double.isNaN(d)) { return null; } final BigDecimal bd = BigDecimal.valueOf(d); if (minimum != null && minimum.compareTo(bd) > 0) { return message("minimum", bd, minimum, RoundingMode.FLOOR); } if (maximum != null && maximum.compareTo(bd) < 0) { return message("maximum", bd, maximum, RoundingMode.CEILING); } return null; }
private void check(final IPackageCoverage packageCoverage) { final String name = names.getPackageName(packageCoverage.getName()); checkRules(packageCoverage, packageRules, "package", name); if (traverseClasses) { for (final IClassCoverage c : packageCoverage.getClasses()) { check(c); } } if (traverseSourceFiles) { for (final ISourceFileCoverage s : packageCoverage.getSourceFiles()) { check(s); } } }
/** * Sets allowed maximum value as decimal string or percent representation. * The given precision is also considered in error messages. Coverage ratios * are given in the range from 0.0 to 1.0. * * @param minimum * allowed minimum or <code>null</code>, if no minimum should be * checked */ public void setMinimum(final String minimum) { this.minimum = parseValue(minimum); }
private void check(final IMethodCoverage method, final String className) { final String name = names.getQualifiedMethodName(className, method.getName(), method.getDesc(), method.getSignature()); checkRules(method, methodRules, "method", name); }
private void check(final IClassCoverage classCoverage) { final String name = names .getQualifiedClassName(classCoverage.getName()); checkRules(classCoverage, classRules, "class", name); if (traverseMethods) { for (final IMethodCoverage m : classCoverage.getMethods()) { check(m, classCoverage.getName()); } } }