Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Unicode support
Unicode support [message #1733581] Mon, 30 May 2016 09:47 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Hi!

Does OCL support unicode?

Here is a simple test project:
https://github.com/AresEkb/ocl_unicode_test

It parses the following constraint contained in an UML model:
fullName.matches('[А-Яа-я]+')

After parsing unicode symbols become broken:
self.fullName.matches('[Рђ-РЇР°-СЏ]+')

Is there a workaround?
Re: Unicode support [message #1733584 is a reply to message #1733581] Mon, 30 May 2016 10:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks. Excellent repro.

It should work. It clearly doesn't. Fix might be trivial. Might
conceivably fix it for RC3 today.

Workaround. Using \uxxxx might work, but it might share the same problem.

Regards

Ed Willink


On 30/05/2016 10:47, Denis Nikiforov wrote:
> Hi!
>
> Does OCL support unicode?
>
> Here is a simple test project:
> https://github.com/AresEkb/ocl_unicode_test
>
> It parses the following constraint contained in an UML model:
> fullName.matches('[А-Яа-я]+')
>
> After parsing unicode symbols become broken:
> self.fullName.matches('[Рђ-РЇР°-СЏ]+')
>
> Is there a workaround?
Re: Unicode support [message #1733588 is a reply to message #1733584] Mon, 30 May 2016 10:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The problem is that you have not declared your project "Text file
encoding". On my machine it therefore inherits Cp1252. If I set the
project to UTF-8 your example works much better.

If there is a problem, it is an Xtext issue, but I suspect it is
entirely your problem in accidentally developing a file with one
encoding then processing it with another. AFAIK Xtext (and so OCL)
should respect whatever consistent encoding you choose.

Regards

Ed Willink


On 30/05/2016 11:01, Ed Willink wrote:
> Hi
>
> Thanks. Excellent repro.
>
> It should work. It clearly doesn't. Fix might be trivial. Might
> conceivably fix it for RC3 today.
>
> Workaround. Using \uxxxx might work, but it might share the same problem.
>
> Regards
>
> Ed Willink
>
>
> On 30/05/2016 10:47, Denis Nikiforov wrote:
>> Hi!
>>
>> Does OCL support unicode?
>>
>> Here is a simple test project:
>> https://github.com/AresEkb/ocl_unicode_test
>>
>> It parses the following constraint contained in an UML model:
>> fullName.matches('[А-Яа-я]+')
>>
>> After parsing unicode symbols become broken:
>> self.fullName.matches('[Рђ-РЇР°-СЏ]+')
>>
>> Is there a workaround?
>
>
Re: Unicode support [message #1733593 is a reply to message #1733588] Mon, 30 May 2016 10:54 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Thanks! It works, but it's a little bit strange.

There are two test cases in this file:
https://github.com/AresEkb/ocl_unicode_test/blob/master/src/ocl_unicode_test/Main.java

Test case 1:
            ExpressionInOCL expr = ocl.createInvariant(personAS, "fullName.matches('[А-Яа-я]+')");
            System.out.println("Expression: " + expr);

Test case 2:
            for (Constraint rule : person.getOwnedRules()) {
                ExpressionInOCL expr2 = getExpressionInOCL(ocl, rule);
                System.out.println("Expression: " + expr2);
            }

    public static ExpressionInOCL getExpressionInOCL(OCL ocl, Constraint constraint) throws ParserException
    {
        org.eclipse.ocl.pivot.Constraint asConstraint = ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Constraint.class, constraint);
        return ocl.getSpecification(asConstraint);
    }


I understand why test case 1 starts working after I've changed default text encoding in the project settings. It was my fault.

But why project encoding affects test case 2? The OCL is read from the external file (model/My.uml), it's not hard-coded in Main.java... I guess that test case 2 must not depend on project settings...
Re: Unicode support [message #1733605 is a reply to message #1733593] Mon, 30 May 2016 11:56 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

On a good day, the embedded encoding within an XML file ensures that
it's characters are read correctly.

<?xml version="1.0" encoding="UTF-8"?>

Regards

Ed Willink

On 30/05/2016 11:54, Denis Nikiforov wrote:
> Thanks! It works, but it's a little bit strange.
>
> There are two test cases in this file:
> https://github.com/AresEkb/ocl_unicode_test/blob/master/src/ocl_unicode_test/Main.java
>
>
> Test case 1:
>
> ExpressionInOCL expr = ocl.createInvariant(personAS,
> "fullName.matches('[А-Яа-я]+')");
> System.out.println("Expression: " + expr);
>
> Test case 2:
>
> for (Constraint rule : person.getOwnedRules()) {
> ExpressionInOCL expr2 = getExpressionInOCL(ocl, rule);
> System.out.println("Expression: " + expr2);
> }
>
> public static ExpressionInOCL getExpressionInOCL(OCL ocl,
> Constraint constraint) throws ParserException
> {
> org.eclipse.ocl.pivot.Constraint asConstraint =
> ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Constraint.class,
> constraint);
> return ocl.getSpecification(asConstraint);
> }
>
>
> I understand why test case 1 starts working after I've changed default
> text encoding in the project settings. It was my fault.
>
> But why project encoding affects test case 2? The OCL is read from the
> external file (model/My.uml), it's not hard-coded in Main.java... I
> guess that test case 2 must not depend on project settings...
Previous Topic:EMFtoCSP: Error in the ecl file
Next Topic:[oclinecore] import statement gets rewritten
Goto Forum:
  


Current Time: Thu Mar 28 10:15:13 GMT 2024

Powered by FUDForum. Page generated in 0.03917 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top