Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JVMField with primitive type
JVMField with primitive type [message #894994] Wed, 11 July 2012 11:10 Go to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Hi,

i am trying to create a JVMField with a JVMTypeReference to a primitive boolean type.

Did many approaches, but all ended in exceptions due to not resolvable types.

I tried the following with different types of JVMTypeReference:
		JvmPrimitiveType primitiveType = typesFactory.createJvmPrimitiveType();
		primitiveType.setSimpleName("boolean");
		JvmParameterizedTypeReference primitiveReference = typesFactory
				.createJvmParameterizedTypeReference();
		primitiveReference.setType(primitiveType);


		JvmField field = typesFactory.createJvmField();
		field.setSimpleName(name);
		field.setVisibility(JvmVisibility.PRIVATE);
		field.setType(primitiveReference);


I also inspected the created type reference from domainModel-example. But got no results.

Can anybody point me to an example or something else that i could browser deeper in that topic?
Btw. creating fields with Object-Types is really easy and straight forward.

Thanks a lot,
Florian
Re: JVMField with primitive type [message #894996 is a reply to message #894994] Wed, 11 July 2012 11:18 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Exactly in that moment i found org.eclipse.xtext.common.types.util.Primitives

It offers a method asPrimitiveIfWrapperType()

I try to use that class and post the results.

Thanks,
Florian
Re: JVMField with primitive type [message #895002 is a reply to message #894996] Wed, 11 July 2012 11:32 Go to previous messageGo to next message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

org.eclipse.xtext.common.types.util.Primitives solves the Problem:

		JvmTypeReference typeRef = newTypeRef(sourceElement, primitiveType,
				(JvmTypeReference[]) null);

		JvmField result = typesFactory.createJvmField();
		result.setSimpleName(name);
		result.setVisibility(JvmVisibility.PRIVATE);
		result.setType(cloneWithProxies(primitives
				.asPrimitiveIfWrapperType(typeRef)));
Re: JVMField with primitive type [message #895005 is a reply to message #894994] Wed, 11 July 2012 11:31 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Florian,

you should always use TypeReferences#getTypeForName(Class, Context)
findDeclaredType(Boolean.TYPE, some context) to obtain a valid instance
of JvmType.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 11.07.12 13:10, schrieb Florian Pirchner:
> Hi,
>
> i am trying to create a JVMField with a JVMTypeReference to a primitive
> boolean type.
>
> Did many approaches, but all ended in exceptions due to not resolvable
> types.
>
> I tried the following with different types of JVMTypeReference:
>
> JvmPrimitiveType primitiveType = typesFactory.createJvmPrimitiveType();
> primitiveType.setSimpleName("boolean");
> JvmParameterizedTypeReference primitiveReference = typesFactory
> .createJvmParameterizedTypeReference();
> primitiveReference.setType(primitiveType);
>
>
> JvmField field = typesFactory.createJvmField();
> field.setSimpleName(name);
> field.setVisibility(JvmVisibility.PRIVATE);
> field.setType(primitiveReference);
>
>
> I also inspected the created type reference from domainModel-example.
> But got no results.
>
> Can anybody point me to an example or something else that i could
> browser deeper in that topic?
> Btw. creating fields with Object-Types is really easy and straight forward.
>
> Thanks a lot,
> Florian
Re: JVMField with primitive type [message #895009 is a reply to message #895002] Wed, 11 July 2012 11:49 Go to previous message
Florian Pirchner is currently offline Florian PirchnerFriend
Messages: 94
Registered: July 2009
Member

Hi Sebastian,

thanks.

Now my result looks like this and works fine:

                Class<?> primitiveType = Boolean.TYPE;

		JvmTypeReference typeRef = newTypeRef(sourceElement, primitiveType,
				(JvmTypeReference[]) null);
		JvmField result = typesFactory.createJvmField();
		result.setSimpleName(name);
		result.setVisibility(JvmVisibility.PRIVATE);
		result.setType(cloneWithProxies(typeRef));
		associate(sourceElement, result);
		return initializeSafely(result, initializer);


The class Primitives is not required anymore.

Thanks,
Florian
Previous Topic:Xcore - magic content assist for XBlockExpression
Next Topic:Cross References are working only in a specific parts of the model - why?
Goto Forum:
  


Current Time: Sat Apr 27 05:07:54 GMT 2024

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

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

Back to the top