@Test public void testModuloByOne() throws Exception { final Set<Violation> violations = new ModuloFunctionRules(toDocument("modulo-by-one.xml")).doMeasuredAnalysis(); assertThat(violations).hasSize(3); assertThat(violations).contains(new ModuloByOneViolation(13)); assertThat(violations).contains(new ModuloByOneViolation(15)); assertThat(violations).contains(new ModuloByOneViolation(17)); }
@Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); for (final Element call : selectNodesByName("CALL.")) { if (!getCclName(call).equalsIgnoreCase("MOD")) continue; if (call.getChildren().size() != 3) throw new JDOMException("Unhandled number of child elements to call mod() statement at line [" + getLineNumber(call) + "]"); final Element param1 = call.getChildren().get(1); final Element param2 = call.getChildren().get(2); if (param1.getName().equalsIgnoreCase("INT")) { violations.add(new ReversedModuloParametersViolation(getLineNumber(param1))); } if (param2.getName().equalsIgnoreCase("INT") && param2.getAttributeValue("text").equalsIgnoreCase("1")) { violations.add(new ModuloByOneViolation(getLineNumber(param2))); } } return violations; }
ModuloFunctionRules extends TimedDelegate { @Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); for (final Element call : selectNodesByName("CALL.")) { if (!getCclName(call).equalsIgnoreCase("MOD")) continue; if (call.getChildren().size() != 3) throw new JDOMException("Unhandled number of child elements to call mod() statement at line [" + getLineNumber(call) + "]"); final Element param1 = call.getChildren().get(1); final Element param2 = call.getChildren().get(2); if (param1.getName().equalsIgnoreCase("INT")) { violations.add(new ReversedModuloParametersViolation(getLineNumber(param1))); } if (param2.getName().equalsIgnoreCase("INT") && param2.getAttributeValue("text").equalsIgnoreCase("1")) { violations.add(new ModuloByOneViolation(getLineNumber(param2))); } } return violations; } }
ModuloFunctionRules extends TimedDelegate { @Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); for (final Element call : selectNodesByName("CALL.")) { if (!getCclName(call).equalsIgnoreCase("MOD")) continue; if (call.getChildren().size() != 3) throw new JDOMException("Unhandled number of child elements to call mod() statement at line [" + getLineNumber(call) + "]"); final Element param1 = call.getChildren().get(1); final Element param2 = call.getChildren().get(2); if (param1.getName().equalsIgnoreCase("INT")) { violations.add(new ReversedModuloParametersViolation(getLineNumber(param1))); } if (param2.getName().equalsIgnoreCase("INT") && param2.getAttributeValue("text").equalsIgnoreCase("1")) { violations.add(new ModuloByOneViolation(getLineNumber(param2))); } } return violations; } ModuloFunctionRules(final Document document); }
ModuloFunctionRules extends TimedDelegate { @Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); for (final Element call : selectNodesByName("CALL.")) { if (!getCclName(call).equalsIgnoreCase("MOD")) continue; if (call.getChildren().size() != 3) throw new JDOMException("Unhandled number of child elements to call mod() statement at line [" + getLineNumber(call) + "]"); final Element param1 = call.getChildren().get(1); final Element param2 = call.getChildren().get(2); if (param1.getName().equalsIgnoreCase("INT")) { violations.add(new ReversedModuloParametersViolation(getLineNumber(param1))); } if (param2.getName().equalsIgnoreCase("INT") && param2.getAttributeValue("text").equalsIgnoreCase("1")) { violations.add(new ModuloByOneViolation(getLineNumber(param2))); } } return violations; } ModuloFunctionRules(final Document document); @Override Set<Violation> getCheckedViolations(); }
ModuloFunctionRules extends TimedDelegate { @Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); for (final Element call : selectNodesByName("CALL.")) { if (!getCclName(call).equalsIgnoreCase("MOD")) continue; if (call.getChildren().size() != 3) throw new JDOMException("Unhandled number of child elements to call mod() statement at line [" + getLineNumber(call) + "]"); final Element param1 = call.getChildren().get(1); final Element param2 = call.getChildren().get(2); if (param1.getName().equalsIgnoreCase("INT")) { violations.add(new ReversedModuloParametersViolation(getLineNumber(param1))); } if (param2.getName().equalsIgnoreCase("INT") && param2.getAttributeValue("text").equalsIgnoreCase("1")) { violations.add(new ModuloByOneViolation(getLineNumber(param2))); } } return violations; } ModuloFunctionRules(final Document document); @Override Set<Violation> getCheckedViolations();  }