Bug 520611 - Support for check validations that set constraint dynamically
Summary: Support for check validations that set constraint dynamically
Status: CLOSED WONTFIX
Alias: None
Product: Sphinx
Classification: Automotive
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-07 05:31 EDT by Andreas Graf CLA
Modified: 2024-05-07 00:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Graf CLA 2017-08-07 05:31:58 EDT
In some cases, it is effective to be able to set more than one validation/check issue from a method. Right now Sphinx only supports setting the issue from the annotation.

This code would go in AbstractCheckValidator and then it would be possible for the programmer to set any constraint issue. (This is e.g. advisable, if you have complex check that should better be written for the container than for the parameter values).

It is basically the same code, only with passing constraint as 1st argument.

    def void issue(String constraint, Object object, EStructuralFeature feature, Object... messageArguments) {
		if (object instanceof IWrapper<?>) {
			val eObject = ( object as IWrapper<?>).getTarget();
			issue(constraint, eObject, feature, -1, messageArguments);
		} else if (object instanceof EObject) {
			issue(constraint, object as EObject, feature, -1, messageArguments);
		} else {
			throw new UnsupportedOperationException("Could not recognize type of " + object.toString()); //$NON-NLS-1$
		}
	}
    def void issue(String constraint, EObject object, EStructuralFeature feature, int index, Object... messageArguments) {
	
		val checkCatalog = getCheckCatalog();
		if (checkCatalog == null) {
			return;
		}
		val message = MessageFormat.format(checkCatalog.getMessage(constraint), messageArguments);
		val severity = checkCatalog.getSeverity(constraint);
		switch (severity) {
		case ERROR:
			error(message, object, feature, index)
		case Severity.WARNING:
			warning(message, object, feature, index)
			
		case INFO:
			info(message, object, feature, index)
	
		default:
			throw new IllegalArgumentException("Unknow severity " + severity) //$NON-NLS-1$
		}
	}
Comment 1 Balazs Grill CLA 2024-05-07 00:14:37 EDT
Closed stale issue before migration