Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Switch-statement with OclIsTypeOf()-function(Is it possible to use OclIsTypeOf()-function as boolean-condition for a switch-statement?)
[QVTo] Switch-statement with OclIsTypeOf()-function [message #527224] Wed, 14 April 2010 14:16 Go to next message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Hi everybody, I just have a short question.

I would like to use the oclIsTypeOf()-fuunction as the condition for a switch-statement, just as follows:

query getNameOfPrimitiveType(in type:DataType) : String {
	var resultString:String;
	resultString := type.oclIsTypeOf().switch {
		case (OpaqueType) "Bitstring";
		case (BooleanType) "Boolean";
		case (IntegerType) "Integer";
		case (RealType) "Float";
		case (StringType) "Charstring";
		else "not found";
	};
	return resultString;
}


Anyway this does not work, I expect because of the fact that oclIsTypeOf() is a function and not a Collection itself. I also tried using the '->' operator and some kind of "casting" the function to a collection, without honorable results.

Probably anyone og you knows how to handle, this, better than using an if-else-cascade?


here are the compiler errors shown (i do not think this helps a lot further, but anyway:
at the line "resultString := type.oclIsTypeOf().switch {":
oclIsNew() expected instead of oclIsTypeOf()
:= expected instead of .
) misplaced construct(s) [i expect this is because a parameter for the oclIsTypeOf-function is missing]

at the line "return resultString;":
return misplaced construct(s)


well anyway it does not work due to several issues i expect, so does anybody have a nice idea? Cool
Re: [QVTo] Switch-statement with OclIsTypeOf()-function [message #527285 is a reply to message #527224] Wed, 14 April 2010 16:28 Go to previous messageGo to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Hi Chris,

Hmm, I'm not sure whether you can use the switch statement in this way. When I use it, I don't prefix it with a set or something, just the switch statement on itself.

Tip, when you press "Ctrl + Space" in Eclipse, a pop-up window with code with possibilities appears (use this combination again for the so-called "Template Proposals").

Furthermore, oclIsTypeOf() needs an argument and returns a Boolean value. Maybe you can use the function metaClassName() which returns a string. However, I think it doesn't work when you work with basic types like Integer.
Maybe the _localId() and _globalId() functions are useful, but they are not yet implemented Sad. There must be a function which can return the type of all types, because the oclIstypeOf() function compares this result with the argument.

Maybe there is some other OCL function available? I don't see it in the mentioned pop-up, but who knows Very Happy

Oh by the way, I finished my Bachelor Thesis, you can download it at my site. It discusses QVTo in a bit more detail than the tutorial on my site.
icon14.gif  Re: [QVTo] Switch-statement with OclIsTypeOf()-function [message #527491 is a reply to message #527285] Thu, 15 April 2010 12:55 Go to previous message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Hi P.,

first of all congratulations to your BSc! I hope it was as good as you expected it to be - well I am somewhat sure it was, right?

Quote:
Hmm, I'm not sure whether you can use the switch statement in this way.

me neither.
Quote:
When I use it, I don't prefix it with a set or something, just the switch statement on itself.

I also tested this, but anyway good that you mentioned it again, see below! Wink

Quote:
Furthermore, oclIsTypeOf() needs an argument and returns a Boolean value.

Yes, just as I expected.
Quote:
Maybe you can use the function metaClassName() which returns a string. However, I think it doesn't work when you work with basic types like Integer.

Well, QVTo/OCL basic types are not of interest in my purpose, but anyway: the way I used the switch statement does not work with metaClassName() as well.
Quote:
Maybe the _localId() and _globalId() functions are useful, but they are not yet implemented . There must be a function which can return the type of all types, because the oclIstypeOf() function compares this result with the argument. (...) Maybe there is some other OCL function available

This is just what I am looking for. Well I am still searching, if I find it I shall post it here.
Anyway, by now I found a solution which helps me along. Although it is not as nice as the one mentioned, it is easy read- and understandable:

query getNameOfPrimitiveType(in type:Datatype) : String {
	var resultString:String;
	var className:String := type.metaClassName();
	switch {
		case (type.oclIsTypeOf(OpaqueType)) resultString := "Bitstring";
		case (type.oclIsTypeOf(BooleanType)) resultString := "Boolean";
		case (type.oclIsTypeOf(IntegerType)) resultString := "Integer";
		case (type.oclIsTypeOf(RealType)) resultString := "Float";
		case (type.oclIsTypeOf(StringType)) resultString := "Charstring";
		else resultString := "not found";
	};
	return resultString;
}


I got the idea, as I combined the options from "Ctrl + Space" and your word saying "I don't prefix it" and "oclIsTypeOf() needs an argument and returns a Boolean value".

Thanks!

btw: I am curious about having a look upon your bachelor thesis. So I got something to read at the weekend. Cool


Cheers,

Chris
Previous Topic:[ATL] Creating multiple output files dynamically.
Next Topic:'writeTo' issue with atl standalone transformation
Goto Forum:
  


Current Time: Tue Apr 23 17:18:47 GMT 2024

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

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

Back to the top