Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Implicit conversion of string literals into instances of custom data types
Implicit conversion of string literals into instances of custom data types [message #1715587] Tue, 24 November 2015 13:52 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Hi

I have a custom DateType in my Ecore model. The values of this type can be converted to and from string.

In Java I can write something like this:

EcoreUtil.createFromString(CommonPackage.eINSTANCE.getDateType(), '2015-11-24')


Is it possible to let QVTo implicitly convert string literals of the form '2015-11-24' into instances of DateType? Or I have to use blackbox-library to create instances of my data type? Or I can use EcoreUtil from QVTo?
Re: Implicit conversion of string literals into instances of custom data types [message #1715606 is a reply to message #1715587] Tue, 24 November 2015 16:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

One might hope that new DateType(string) would use the Ecore

XXXFactoryImpl.createDateTypeFromString(EDataType eDataType, String
initialValue)

If it doesn't, please raise a bug.

The in-progress support for shadow object construction (side effect-free
type construction) in OCL should provide this too.

Regards

Ed Willink

On 24/11/2015 13:53, Denis Nikiforov wrote:
> Hi
>
> I have a custom DateType in my Ecore model. The values of this type
> can be converted to and from string.
>
> In Java I can write something like this:
>
> EcoreUtil.createFromString(CommonPackage.eINSTANCE.getDateType(),
> '2015-11-24')
>
> Is it possible to let QVTo implicitly convert string literals of the
> form '2015-11-24' into instances of DateType? Or I have to use
> blackbox-library to create instances of my data type? Or I can use
> EcoreUtil from QVTo?
Re: Implicit conversion of string literals into instances of custom data types [message #1715658 is a reply to message #1715606] Wed, 25 November 2015 06:21 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Thanks!

I didn't thought that it's so simple. The following code works fine for me:
    object SQL::_literal::DateLiteral {
    	value := new SQL::common::DateType('2011-01-01');
    };


I don't understand how to use shdow object creation, becase EDataTypes doesn't has attributes:
    object SQL::_literal::DateLiteral {
        value := SQL::common::DateType{ ??? = '2011-01-01' };
    };
Re: Implicit conversion of string literals into instances of custom data types [message #1715689 is a reply to message #1715658] Wed, 25 November 2015 09:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Shadow Datatype construction will allow a single String argument.

let value = SQL::common::DateType{ '2011-01-01' } in ...

Once this is in place, the 'new' in QVTo is redundant/confusing for
DataTypes.

Regards

Ed Willink

On 25/11/2015 06:21, Denis Nikiforov wrote:
> Thanks!
>
> I didn't thought that it's so simple. The following code works fine
> for me:
> object SQL::_literal::DateLiteral {
> value := new SQL::common::DateType('2011-01-01');
> };
>
> I don't understand how to use shdow object creation, becase EDataTypes
> doesn't has attributes:
> object SQL::_literal::DateLiteral {
> value := SQL::common::DateType{ ??? = '2011-01-01' };
> };
Re: Implicit conversion of string literals into instances of custom data types [message #1716834 is a reply to message #1715689] Tue, 08 December 2015 13:02 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Hi

It seems that new operator doesn't work:

modeltype ECORE uses 'http://www.eclipse.org/emf/2002/Ecore'; 

transformation NewTransformation();

main() {
    new ECORE::EString('test');
}


I get the following exception:

[QVTO Stack trace:]
	at NewTransformation::main(NewTransformation.qvto:6)
[Java cause:]
org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeException: Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl@6c430548 (name: EString) (instanceClassName: java.lang.String) (serializable: true)
	at org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEvaluationEnv.createInstance(QvtOperationalEvaluationEnv.java:568)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.createInstance(QvtOperationalEvaluationVisitorImpl.java:2514)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitInstantiationExp(QvtOperationalEvaluationVisitorImpl.java:975)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericEvaluationVisitor.visitInstantiationExp(QvtGenericEvaluationVisitor.java:387)
	at org.eclipse.m2m.qvt.oml.ecore.ImperativeOCL.impl.InstantiationExpImpl.accept(InstantiationExpImpl.java:291)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitExpression(QvtOperationalEvaluationVisitorImpl.java:419)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitOperationBody(QvtOperationalEvaluationVisitorImpl.java:1169)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitEntryOperation(QvtOperationalEvaluationVisitorImpl.java:496)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericEvaluationVisitor.visitEntryOperation(QvtGenericEvaluationVisitor.java:461)
	at org.eclipse.m2m.internal.qvt.oml.expressions.impl.EntryOperationImpl.accept(EntryOperationImpl.java:67)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.executeImperativeOperation(QvtOperationalEvaluationVisitorImpl.java:1968)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.runMainEntry(QvtOperationalEvaluationVisitorImpl.java:2569)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl$1.invoke(QvtOperationalEvaluationVisitorImpl.java:1070)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl$1.invoke(QvtOperationalEvaluationVisitorImpl.java:1)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.doVisitTransformation(QvtOperationalEvaluationVisitorImpl.java:1096)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitModule(QvtOperationalEvaluationVisitorImpl.java:878)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericEvaluationVisitor.visitModule(QvtGenericEvaluationVisitor.java:372)
	at org.eclipse.m2m.internal.qvt.oml.expressions.impl.ModuleImpl.accept(ModuleImpl.java:632)
	at org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.execute(QvtOperationalEvaluationVisitorImpl.java:866)
	at org.eclipse.m2m.qvt.oml.debug.core.vm.QVTODebugEvaluator$DebugInterceptor.execute(QVTODebugEvaluator.java:488)
	at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doExecute(InternalTransformationExecutor.java:236)
	at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:203)
	at org.eclipse.m2m.internal.qvt.oml.TransformationRunner.execute(TransformationRunner.java:189)
	at org.eclipse.m2m.qvt.oml.debug.core.app.DebugTransformationRunner$2.execute(DebugTransformationRunner.java:111)
	at org.eclipse.m2m.qvt.oml.debug.core.vm.QVTOVirtualMachine.execute(QVTOVirtualMachine.java:262)
	at org.eclipse.m2m.qvt.oml.debug.core.vm.QVTOVirtualMachine.access$11(QVTOVirtualMachine.java:259)
	at org.eclipse.m2m.qvt.oml.debug.core.vm.QVTOVirtualMachine$1.run(QVTOVirtualMachine.java:249)
	at java.lang.Thread.run(Unknown Source)
Diagnostic ERROR source=org.eclipse.m2m.qvt.oml.execution code=120: Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl@6c430548 (name: EString) (instanceClassName: java.lang.String) (serializable: true) data=[org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeException: Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl@6c430548 (name: EString) (instanceClassName: java.lang.String) (serializable: true)]
Re: Implicit conversion of string literals into instances of custom data types [message #1716841 is a reply to message #1716834] Tue, 08 December 2015 13:56 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You reported that your earlier example worked; it had an appropriate
target type.

This example has no target, so no clue that a non-class is acceptable.

Regards

Ed Willink


On 08/12/2015 05:02, Denis Nikiforov wrote:
> Hi
>
> It seems that new operator doesn't work:
>
> modeltype ECORE uses 'http://www.eclipse.org/emf/2002/Ecore';
> transformation NewTransformation();
>
> main() {
> new ECORE::EString('test');
> }
>
> I get the following exception:
>
> [QVTO Stack trace:]
> at NewTransformation::main(NewTransformation.qvto:6)
> [Java cause:]
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeException: Expected
> EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl@6c430548 (name:
> EString) (instanceClassName: java.lang.String) (serializable: true)
> at
> org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEvaluationEnv.createInstance(QvtOperationalEvaluationEnv.java:568)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.createInstance(QvtOperationalEvaluationVisitorImpl.java:2514)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitInstantiationExp(QvtOperationalEvaluationVisitorImpl.java:975)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericEvaluationVisitor.visitInstantiationExp(QvtGenericEvaluationVisitor.java:387)
>
> at
> org.eclipse.m2m.qvt.oml.ecore.ImperativeOCL.impl.InstantiationExpImpl.accept(InstantiationExpImpl.java:291)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitExpression(QvtOperationalEvaluationVisitorImpl.java:419)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitOperationBody(QvtOperationalEvaluationVisitorImpl.java:1169)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitEntryOperation(QvtOperationalEvaluationVisitorImpl.java:496)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericEvaluationVisitor.visitEntryOperation(QvtGenericEvaluationVisitor.java:461)
>
> at
> org.eclipse.m2m.internal.qvt.oml.expressions.impl.EntryOperationImpl.accept(EntryOperationImpl.java:67)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.executeImperativeOperation(QvtOperationalEvaluationVisitorImpl.java:1968)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.runMainEntry(QvtOperationalEvaluationVisitorImpl.java:2569)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl$1.invoke(QvtOperationalEvaluationVisitorImpl.java:1070)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl$1.invoke(QvtOperationalEvaluationVisitorImpl.java:1)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.doVisitTransformation(QvtOperationalEvaluationVisitorImpl.java:1096)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.visitModule(QvtOperationalEvaluationVisitorImpl.java:878)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericEvaluationVisitor.visitModule(QvtGenericEvaluationVisitor.java:372)
>
> at
> org.eclipse.m2m.internal.qvt.oml.expressions.impl.ModuleImpl.accept(ModuleImpl.java:632)
>
> at
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtOperationalEvaluationVisitorImpl.execute(QvtOperationalEvaluationVisitorImpl.java:866)
>
> at
> org.eclipse.m2m.qvt.oml.debug.core.vm.QVTODebugEvaluator$DebugInterceptor.execute(QVTODebugEvaluator.java:488)
>
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doExecute(InternalTransformationExecutor.java:236)
>
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:203)
>
> at
> org.eclipse.m2m.internal.qvt.oml.TransformationRunner.execute(TransformationRunner.java:189)
>
> at
> org.eclipse.m2m.qvt.oml.debug.core.app.DebugTransformationRunner$2.execute(DebugTransformationRunner.java:111)
>
> at
> org.eclipse.m2m.qvt.oml.debug.core.vm.QVTOVirtualMachine.execute(QVTOVirtualMachine.java:262)
>
> at
> org.eclipse.m2m.qvt.oml.debug.core.vm.QVTOVirtualMachine.access$11(QVTOVirtualMachine.java:259)
>
> at
> org.eclipse.m2m.qvt.oml.debug.core.vm.QVTOVirtualMachine$1.run(QVTOVirtualMachine.java:249)
>
> at java.lang.Thread.run(Unknown Source)
> Diagnostic ERROR source=org.eclipse.m2m.qvt.oml.execution code=120:
> Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl@6c430548
> (name: EString) (instanceClassName: java.lang.String) (serializable:
> true)
> data=[org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeException:
> Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl@6c430548
> (name: EString) (instanceClassName: java.lang.String) (serializable: true)]
>
Re: Implicit conversion of string literals into instances of custom data types [message #1716931 is a reply to message #1716841] Wed, 09 December 2015 06:34 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Hi

Two weeks ago I developed my metamodel. It was important for me whether to use Ecore primitive type or to create a custom one.

QVTo-transformation was syntactically valid, so I guessed that new operator works. I didn't run it Sad

But now, I've started to write real QVTo transformation.

Here is another example with 4 test cases:
modeltype ECORE uses 'http://www.eclipse.org/emf/2002/Ecore';

transformation NewTransformation();

main() {
    // Validation error: Can't instantiate type '<null>'
    var a := new ECORE::EString('test');

    // Validation error: Can't instantiate type '<null>'
    var b : ECORE::EString := new ECORE::EString('test');
    
    // Runtime exception: Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl
    var c : ECORE::EString;
    c := new ECORE::EString('test');

    // Runtime exception: Expected EClass, got org.eclipse.emf.ecore.impl.EDataTypeImpl
    object EClass {
    	name := new ECORE::EString('test');
    };
}


1 and 2 gives error at design time. 3 and 4 causes a runtime exception.
Re: Implicit conversion of string literals into instances of custom data types [message #1716999 is a reply to message #1716931] Wed, 09 December 2015 14:29 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks for the repro.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=484020

Regards

Ed Willink


On 08/12/2015 22:34, Denis Nikiforov wrote:
> Here is another example with 4 test cases:
> modeltype ECORE uses 'http://www.eclipse.org/emf/2002/Ecore';
>
> transformation NewTransformation();
>
> main() {
> // Validation error: Can't instantiate type '<null>'
> var a := new ECORE::EString('test');
>
> // Validation error: Can't instantiate type '<null>'
> var b : ECORE::EString := new ECORE::EString('test');
> // Runtime exception: Expected EClass, got
> org.eclipse.emf.ecore.impl.EDataTypeImpl
> var c : ECORE::EString;
> c := new ECORE::EString('test');
>
> // Runtime exception: Expected EClass, got
> org.eclipse.emf.ecore.impl.EDataTypeImpl
> object EClass {
> name := new ECORE::EString('test');
> };
> }
>
>
> 1 and 2 gives error at design time. 3 and 4 causes a runtime exception.
Previous Topic:bpmn2uml
Next Topic:QVTo Trace Editor doesn't show properties of elements
Goto Forum:
  


Current Time: Sat Apr 20 05:39:56 GMT 2024

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

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

Back to the top