Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Bounds mismatch error using generic extension
Bounds mismatch error using generic extension [message #1713389] Tue, 03 November 2015 18:26 Go to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
Hi,

I've extended the domainmodel like explained below and get a strange error:
"Bounds mismatch: The type argument <Class<Entity>> is not a valid substitute for the bounded type parameter <T extends IEntity> of the method createAndInit(T)"

1. Created an interface:
package org.eclipse.xtext.example.domainmodel.ext;

public interface IEntity {
}


2. Added the interface to the DomainmodelJvmModelInferrer Entity part:
	def dispatch infer(Entity entity, extension IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) {
		accept(entity.toClass( entity.fullyQualifiedName )) [
			documentation = entity.documentation
			superTypes += typeRef(IEntity)
...


3. Added an extension class:
package org.eclipse.xtext.example.domainmodel.ext;

public class EntityFunctionsExtension {
	public static final <T extends IEntity> T createAndInit(
			final T complexType )
	{
		throw new UnsupportedOperationException( "This method should have been replaced by Xtext compiler!" );
	}
}


4. Implicitly import the the extension class via newly created DomainmodelImplicitlyImportedFeatures:
package org.eclipse.xtext.example.domainmodel.jvmmodel;

import java.util.List;

import org.eclipse.xtext.example.domainmodel.ext.EntityFunctionsExtension;
import org.eclipse.xtext.xbase.lib.ArrayExtensions;
import org.eclipse.xtext.xbase.lib.BigDecimalExtensions;
import org.eclipse.xtext.xbase.lib.BigIntegerExtensions;
import org.eclipse.xtext.xbase.lib.BooleanExtensions;
import org.eclipse.xtext.xbase.lib.ByteExtensions;
import org.eclipse.xtext.xbase.lib.CharacterExtensions;
import org.eclipse.xtext.xbase.lib.CollectionExtensions;
import org.eclipse.xtext.xbase.lib.ComparableExtensions;
import org.eclipse.xtext.xbase.lib.DoubleExtensions;
import org.eclipse.xtext.xbase.lib.FloatExtensions;
import org.eclipse.xtext.xbase.lib.FunctionExtensions;
import org.eclipse.xtext.xbase.lib.IntegerExtensions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.LongExtensions;
import org.eclipse.xtext.xbase.lib.MapExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.ProcedureExtensions;
import org.eclipse.xtext.xbase.lib.ShortExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedFeatures;

import com.google.common.collect.Lists;

public class DomainmodelImplicitlyImportedFeatures extends ImplicitlyImportedFeatures {
	@Override
	protected List<Class<?>> getExtensionClasses() {
		return Lists.<Class<?>> newArrayList(
			EntityFunctionsExtension.class,
			ArrayExtensions.class,
			BigDecimalExtensions.class,
			BigIntegerExtensions.class,
			BooleanExtensions.class,
			ByteExtensions.class,
			CharacterExtensions.class,
			CollectionExtensions.class,
			ComparableExtensions.class,
			DoubleExtensions.class,
			FloatExtensions.class,
			FunctionExtensions.class,
			IntegerExtensions.class,
			IterableExtensions.class,
			IteratorExtensions.class,
			ListExtensions.class,
			LongExtensions.class,
			MapExtensions.class,
			ObjectExtensions.class,
			ProcedureExtensions.class,
			ShortExtensions.class,
			StringExtensions.class);
	}
}


5. Register DomainmodelImplicitlyImportedFeatures in DomainmodelRuntimeModule:
	public Class<? extends ImplicitlyImportedFeatures> bindImplicitlyImportedFeatures() {
		return DomainmodelImplicitlyImportedFeatures.class;
	}


Run the editor and use the test .dmodel:
package test {
	entity Entity
	{
		attr1 : String
		attr2 : Integer
		
		op doCreate () {
			Entity.createAndInit // <== here comes the error
		}
	}
}


In my very old Xtext 2.4 environment the same thing will work.
I'm using 2.9 now.

Any ideas?
A bug?

Thanks a lot,
~Ingo
Re: Bounds mismatch error using generic extension [message #1713395 is a reply to message #1713389] Tue, 03 November 2015 18:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Sure that worked? Guess that was abug. You call a method that expects an ientity instance with a instance of javva.lang.Class

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Bounds mismatch error using generic extension [message #1713457 is a reply to message #1713395] Wed, 04 November 2015 09:29 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Your method definition is wrong, it should be

public static final <T extends IEntity> T createAndInit(final Class<T> complexType )

and then you can call Entity.crateAndInit.
Re: Bounds mismatch error using generic extension [message #1713644 is a reply to message #1713457] Thu, 05 November 2015 16:44 Go to previous message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
Thanks Stefan, that will work.

But I investigated a little bit further what was in 2.4 and what is know in 2.9. In the old version an expression "EntityName" would have been linked to the JvmGenericType of that entity directly, now it is linked as a Class<Entity> reference somehow.
For my DSL this is not wanted at specific places, i.e. I want to call an operation of an entity via "EntityName.operationName" (The XMFC should be JvmGenericType.JvmOperation). This is working in the old version when providing an own scoping.
Where is the starting point to achive that in 2.9?
Previous Topic:expandall icon
Next Topic:Serialisation time grows exponentially when adding new elements to model instance
Goto Forum:
  


Current Time: Tue Apr 23 09:06:54 GMT 2024

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

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

Back to the top