Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to Implement OCL Check #76

Open
ghost opened this issue Nov 8, 2016 · 0 comments
Open

Need to Implement OCL Check #76

ghost opened this issue Nov 8, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 8, 2016

Hello,

I have a metamodel and OCL constraints are defined inside this metamodel using OCLinECore. An example entity from this metamodel is as follows:

/*
 * OCL Constraint: NoNullName
 * The name attribute can't be null.
 * 
 */
abstract class Nameable { interface }
{
	attribute name : String[1];
	attribute description : String[?];
	invariant NoNullName: 
		self.name <> null and self.name.size() > 0;
}
  • I have generated genmodel of this metamodel and enabled "Operation Reflection" option of the genmodel to enable generation OCL validation code. After that, I have generated the model code (Java EClasses) of this metamodel. The generated code also includes a class that extends EObjectValidator that extends methods for validation like the following:
/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean validateNameable(Nameable nameable, DiagnosticChain diagnostics, Map<Object, Object> context) {
		if (!validate_NoCircularContainment(nameable, diagnostics, context)) return false;
		boolean result = validate_EveryMultiplicityConforms(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryDataValueConforms(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryReferenceIsContained(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryBidirectionalReferenceIsPaired(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryProxyResolves(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_UniqueID(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryKeyUnique(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryMapEntryUnique(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validateNameable_NoNullName(nameable, diagnostics, context);
		return result;
	} 
  • Following this, I have defined a grammar for this metamodel using EMFText.

Now, I have two tasks that I want to achieve:

(1) I want to have OCL constraints applied in the editor of the parser. If there are any violations of the OCL constraints, I want them to be reported in the same way that the grammar parsing problems raise error in the editor.

(2) I want to use the parser's generated code in another Java application I wrote (I won't use the generated editor). What I have in my mind is, writing a Java application which gives a String (which is an instance of the grammar) to the parser and printing the errors (parsing errors, OCL violations, etc) in the console with the same messages that are shown in the visual editor of the language.

I looked at the generated code and try to understand, but it was not so trivial to me how to achieve these two tasks. I need some help, some suggestions from you.

Thanks a lot.

Note 1: I have looked at all the example grammars in the zoo and also looked at the mailing list archieve, but could not really find a solution for my case. Only one example uses OCL checker and it does not integrate with the parser.
Note 2: General suggestion is NOT to use validation as a post processing step. So, that is why I want to integrate OCL-based validation with the parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants