[OCLInEcore] Defining Helper Operations in Java [message #659393] |
Sun, 13 March 2011 11:21  |
Eclipse User |
|
|
|
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 12:17   |
Eclipse User |
|
|
|
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
|
|
|
|
Re: [OCLInEcore] Defining Helper Operations in Java [message #660058 is a reply to message #659968] |
Wed, 16 March 2011 12:54  |
Eclipse User |
|
|
|
Hi Ralph
The library is its own example, in particular all the implementations in
the library plugin.
Extension of the library by the user is in principle very easy, but not
yet fully developed.
I need to do it just for a clean release, so that the MDT/OCL typos of
toUpper() and toLower()
appear by default without polluting the standard library.
Regards
Ed Willink
On 16/03/2011 12:32, ralph. wrote:
> Hi,
>
> is there any example for the library model in OCL 3.1?
>
> Thanks,
>
> Ralph
|
|
|
Powered by
FUDForum. Page generated in 0.08887 seconds