[OCLInEcore] Defining Helper Operations in Java [message #659393] |
Sun, 13 March 2011 15:21 |
Ralph Gerbig Messages: 702 Registered: November 2009 |
Senior Member |
|
|
Hello all,
I would like to develop helper operations in java on type like string. I found the topic "Customizing the Environment" in the OCL Help. Is there a way to use this with OCLInEcore? If I understand right I would need to find the place where the template generates this line of code
OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl;
ocl = OCL.newInstance(new EnvironmentFactory());
and replace it with my EnvironmentFactory. Is this right? Is there a way to replace the used EnvironmentFactory by using an Annotation etc? Is there an completely alternative way to do this?
Thanks
Ralph
|
|
|
|
Re: [OCLInEcore] Defining Helper Operations in Java [message #659404 is a reply to message #659393] |
Sun, 13 March 2011 16:17 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi Ralph
Customizing the MDT/OCL 1.x, 3.0 releases is hard and one of the
motivations for the introduction of a true library model in the MDT/OCL
3.1 examples. Here you will find the Xtext concrete syntax of the
library model in OCLstdlib-2.4.oclstdlib is:
type String : PrimitiveType conformsTo OclAny {
operation "="(object2 : OclAny) : Boolean precedence=EQUALITY =>
'org.eclipse.ocl.examples.library.oclany.OclAnyEqualOperatio n';
operation "<>"(object2 : OclAny) : Boolean precedence=EQUALITY =>
'org.eclipse.ocl.examples.library.oclany.OclAnyNotEqualOpera tion';
operation "+"(s : String) : String precedence=ADDITIVE =>
'org.eclipse.ocl.examples.library.string.StringConcatOperati on';
operation at(i : Integer) : String =>
'org.eclipse.ocl.examples.library.string.StringAtOperation';
operation characters() : Sequence(String) =>
'org.eclipse.ocl.examples.library.string.StringCharactersOpe ration';
operation concat(s : String) : String =>
'org.eclipse.ocl.examples.library.string.StringConcatOperati on';
operation equalsIgnoreCase(s : String) : Boolean =>
'org.eclipse.ocl.examples.library.string.StringEqualsIgnoreC aseOperation';
operation indexOf(s : String) : Integer =>
'org.eclipse.ocl.examples.library.string.StringIndexOfOperat ion';
operation size() : Integer =>
'org.eclipse.ocl.examples.library.string.StringSizeOperation ';
operation substring(lower : Integer, upper : Integer) : String =>
'org.eclipse.ocl.examples.library.string.StringSubstringOper ation';
operation toBoolean() : Boolean =>
'org.eclipse.ocl.examples.library.string.StringToBooleanOper ation';
operation toInteger() : Integer =>
'org.eclipse.ocl.examples.library.string.StringToIntegerOper ation';
operation toLower() : String =>
'org.eclipse.ocl.examples.library.string.StringToLowerCaseOp eration';
operation toLowerCase() : String =>
'org.eclipse.ocl.examples.library.string.StringToLowerCaseOp eration';
operation toReal() : Real =>
'org.eclipse.ocl.examples.library.string.StringToRealOperati on';
operation toString() : String =>
'org.eclipse.ocl.examples.library.oclany.OclAnyToStringOpera tion';
operation toUpper() : String =>
'org.eclipse.ocl.examples.library.string.StringToUpperCaseOp eration';
operation toUpperCase() : String =>
'org.eclipse.ocl.examples.library.string.StringToUpperCaseOp eration';
operation ">"(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringGreaterThanOp eration';
operation "<"(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringLessThanOpera tion';
operation "<="(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringLessThanEqual Operation';
operation ">="(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringGreaterThanEq ualOperation';
}
and this is 100% of the definition. The =>
'org.eclipse.ocl.examples.library.string.StringToRealOperati on' is the
binding of the library signature to the Java class; one class per
feature. Custom libraries are supported, so you could just clone and add
a couple of lines for your extra functions. There is an import statement
but I've yet to activate it so that you can add your own code; might
happen for Indigo.
---
If you're imaginative enough you may manage to insert features in the
current code, but I dont' know how to and wouldn't recommend it; for
full addition you need to add functionality in perhaps 7 places.
Don't know if that helps.
Regards
Ed Willink
On 13/03/2011 15:21, ralph. wrote:
> Hello all,
>
> I would like to develop helper operations in java on type like string.
> I found the topic "Customizing the Environment" in the OCL Help. Is
> there a way to use this with OCLInEcore? If I understand right I would
> need to find the place where the template generates this line of code
>
>
> OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject>
> ocl;
> ocl = OCL.newInstance(new EnvironmentFactory());
>
>
> and replace it with my EnvironmentFactory. Is this right? Is there a
> way to replace the used EnvironmentFactory by using an Annotation etc?
> Is there an completely alternative way to do this?
>
> Thanks
>
> Ralph
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04460 seconds