Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Filter JvmType content assist for inferred type from specific source type from the dsl
Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072794] Tue, 23 July 2013 14:03 Go to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

I would like to refer to elements from my grammar, but in order to get import organisation and type parameter checking for free, I would like to refer to the generated JvmType inferred from the element instead of the source element itself.

Is there anyway, in the proposal provider and the validator to get JvmType that correspond to a given type of element?

I see two ways of doing that:
1) filter in the proposal existing JvmType and only keep those that are related to a source element of the type that interests me (and do the same in validation)
2) make a scope (which should be a global one I guess) that gets the elements I'm interested in and map (in functional sense) them to their equivalent inferred JvmType.

The problem with both is that I don't know how to do it.
The problem with 1) is that I think I need to hook into the complexity of the filtering of JvmType of proposal provider which is very... complex and maybe won't be very efficient as there is a LOT of JvmType visible.
The problem with 2) is that I can't succeed to get the global scope easily and map it... I may be missing something Smile

Is there a 3rd way?
Do you have insight on how to do 2? (which seems the best one from both)

Thanks Smile
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072897 is a reply to message #1072794] Tue, 23 July 2013 18:32 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
Hi,

i dont know if i got your question but you can use org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations to query the linkage btw model and inferred jvm types.
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072900 is a reply to message #1072897] Tue, 23 July 2013 18:38 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

Yes, that I know and actually use regularly.

The question was more about: what is the best practice to have a reference in the grammer to a JvmType but to restrict the scope (via ScopeProvider or via ProposalProvider+Validation) of these references to the JvmType inferred from elements of the model which are instances of a specific rule of the grammar.

So if I take the Domain Entity example, how can I restrict the scope of a reference to a JvmType only to those that are inferred from Entity elements (instead of having a reference to an Entity and then have to handle imports and other stuffs by myself).

Is it more clear? :/
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072903 is a reply to message #1072900] Tue, 23 July 2013 18:43 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
Hi,

hmmm i dont think there is a best practice for that yet.

Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072905 is a reply to message #1072903] Tue, 23 July 2013 18:48 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
hehe, and what would you do?

Do you think doing the solution 2 is feasible?

I would like to:
1) get the (global) scope as if it was for a reference to an Entity
2) return a scope for the JvmType inferred for each of the entity of the previous scope.

Can I do that easily? I'm missing the way to get the first scope and if there is a best practice to build a scope from the first one...
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072908 is a reply to message #1072905] Tue, 23 July 2013 18:51 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
Hi,

i as a fast solution would give the inferred entities a marker interface and do something like

http://kthoms.wordpress.com/2012/03/14/how-to-limit-proposed-java-types-to-implementors-of-an-interface/
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072911 is a reply to message #1072908] Tue, 23 July 2013 18:57 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hm, yes, but I can't use marker interface with my problem (as it would imply using a third party library for people using the developed language).


Thanks for the tips thought, if you have another idea I'm open to it Smile
I will post back if I find something.
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072922 is a reply to message #1072911] Tue, 23 July 2013 19:26 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
maybe something like

@Inject
	private ReferenceProposalCreator crossReferenceProposalCreator;
	
	
	@Override
	public void completeJvmParameterizedTypeReference_Type(EObject model, Assignment assignment,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		System.out.println(model);
		if (model instanceof Entity) {
			System.out.println("lulu");
			EReference eref = EcoreFactory.eINSTANCE.createEReference();
			eref.setEType(DomainmodelPackage.Literals.ENTITY);
			
			crossReferenceProposalCreator.lookupCrossReference(model, eref, acceptor, Predicates.<IEObjectDescription> alwaysTrue(), getProposalFactory("QualifiedName", context));
		} else {			
			super.completeJvmParameterizedTypeReference_Type(model, assignment, context, acceptor);
		}
	}


can help
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072923 is a reply to message #1072922] Tue, 23 July 2013 19:28 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
(you want get auto imports, for thast you may have to mix code with one from

org.eclipse.xtext.common.types.xtext.ui.JdtTypesProposalProvider.searchAndCreateProposals(IJavaSearchScope, ICompletionProposalFactory, ContentAssistContext, EReference, Filter, IValueConverter<String>, ICompletionProposalAcceptor))
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072925 is a reply to message #1072922] Tue, 23 July 2013 19:33 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Really cool, I'm going to play with that, thank you!
Re: Filter JvmType content assist for inferred type from specific source type from the dsl [message #1072973 is a reply to message #1072925] Tue, 23 July 2013 21:23 Go to previous message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Ok, so, your solution works quite well actually, I thought I would need to do more changes to it, but since the qualified names of the source element and of the jvm element are the same, it works out of the box, I just need a validation rule.

Concerning imports, as you say, I don't get them automatically when completing, but organize import works as it should Smile

That's not so bad for now for me, thank you!
Previous Topic:Bug with XImportSectionNamespaceScopeProvider and JvmTypeParameter??
Next Topic:about adding a package
Goto Forum:
  


Current Time: Mon Nov 24 12:25:37 GMT 2014

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

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