@Override public void validateFigures(final ValidationContext context, final IntegerOrVariableRefAttribute attribute) { final IntegerOrVariableRef integerOrVariableRef = attribute.getValue(); if (integerOrVariableRef.isConstantInteger()) { final int intValue = integerOrVariableRef.getConstantIntegerValue().intValue(); if (intValue < 0) { context.fireAttributeValidationError(attribute, "Figures count (" + intValue + ") must be 0 or more."); } } }
@Override public void validateFigures(final ValidationContext context, final IntegerOrVariableRefAttribute attribute) { final IntegerOrVariableRef integerOrVariableRef = attribute.getValue(); if (integerOrVariableRef.isConstantInteger()) { final int intValue = integerOrVariableRef.getConstantIntegerValue().intValue(); if (intValue < 1) { context.fireAttributeValidationError(attribute, "Figures count (" + intValue + ") must be 1 or more."); } } }
/** * Evaluates this holder. If this holds an explicit integer then its value is returned as-is. * Otherwise, the given {@link ProcessingContext} is used to look up the value of the variable * that this type refers to. The result will either be an {@link IntegerValue} or {@link NullValue} * <p> * If the variable cannot be successfully resolved or is of the wrong type then a runtime error * is recorded and a {@link NullValue} will be returned. */ public Value evaluate(final Expression owner, final ProcessingContext context) { if (isConstantInteger()) { return constantIntegerValue; } else { final Value result = context.evaluateVariableValue(variableReferenceValue, VariableType.TEMPLATE, VariableType.OUTCOME); if (result.hasSignature(Signature.SINGLE_INTEGER)) { return result; } else { context.fireRuntimeError(owner, "Variable referenced by " + variableReferenceValue + " was expected to be a single integer - returning NULL"); return NullValue.INSTANCE; } } }
@Override protected void validateThis(final ValidationContext context) { super.validateThis(context); final IntegerOrVariableRef indexComputer = getIndex(); if (indexComputer.isConstantInteger()) { final int index = indexComputer.getConstantIntegerValue().intValue(); if (index < 1) { context.fireAttributeValidationError(getAttributes().get(ATTR_INDEX_NAME), "Attribute " + ATTR_INDEX_NAME + " (" + index + ") must be positive"); } if (getChildren().size() != 0 && getChildren().get(0) instanceof Ordered) { final Ordered ordered = (Ordered) getChildren().get(0); if (ordered.getChildren().size() > 0 && index > ordered.getChildren().size()) { context.fireAttributeValidationWarning(getAttributes().get(ATTR_INDEX_NAME), "Attribute " + ATTR_INDEX_NAME + " is too big. Expected at most: " + ordered.getChildren().size() + ", but found: " + index); } } } }
@Override protected void validateThis(final ValidationContext context) { super.validateThis(context); final IntegerOrVariableRef minComputer = getMin(); final IntegerOrVariableRef maxComputer = getMax(); if (minComputer.isConstantInteger()) { final int min = minComputer.getConstantIntegerValue().intValue(); if (min < 0) { context.fireValidationWarning(this, "Attribute " + ATTR_MINIMUM_NAME + " (" + min + ") should be positive."); } if (maxComputer.isConstantInteger()) { final int max = maxComputer.getConstantIntegerValue().intValue(); if (max < min) { context.fireValidationWarning(this, "Attribute " + ATTR_MAXIMUM_NAME + " (" + max + ") should be greater than " + ATTR_MINIMUM_NAME + " (" + min + ")."); } } } }
@Override protected void validateThis(final ValidationContext context) { super.validateThis(context); final IntegerOrVariableRef numberRepeatsTemplate = getNumberRepeats(); if (numberRepeatsTemplate.isConstantInteger()) { final int numberRepeats = numberRepeatsTemplate.getConstantIntegerValue().intValue(); if (numberRepeats < 1) { context.fireAttributeValidationError(getAttributes().get(ATTR_NUMBER_REPEATS_NAME), "Attribute " + ATTR_NUMBER_REPEATS_NAME + " (" + numberRepeats + ") must be at least 1"); } } }
@Override protected void validateThis(final ValidationContext context) { super.validateThis(context); final IntegerOrVariableRef maxComputer = getMax(); final IntegerOrVariableRef minComputer = getMin(); final IntegerOrVariableRef stepComputer = getStep(); if (maxComputer.isConstantInteger() && minComputer.isConstantInteger()) { final int max = maxComputer.getConstantIntegerValue().intValue(); final int min = minComputer.getConstantIntegerValue().intValue(); if (max < min) { context.fireAttributeValidationError(getAttributes().get(ATTR_MAX_NAME), "Attribute " + ATTR_MAX_NAME + " (" + max + ") cannot be lower than " + ATTR_MIN_NAME + " (" + min + ")"); } } if (stepComputer!=null && stepComputer.isConstantInteger()) { final int step = stepComputer.getConstantIntegerValue().intValue(); if (step < 1) { context.fireAttributeValidationError(getAttributes().get(ATTR_STEP_NAME), "Attribute " + ATTR_STEP_NAME + " (" + step + ") must be positive."); } } }