Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » automatic imports insert
automatic imports insert [message #692189] Sun, 03 July 2011 21:14 Go to next message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Hi,


Please hint me, how to insert import statement automatically after user have choosed qualified name from content assist or show ambiguity resolve dialog if two entities with same name (in others packages ) exists?

I just want to make code more clear, not messed with qualified names

Thanks

[Updated on: Mon, 04 July 2011 08:26]

Report message to a moderator

Re: automatic imports insert [message #692381 is a reply to message #692189] Mon, 04 July 2011 10:34 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

Xtend2 (i.e. the editor for .xtend files) offers this functionality and it seems to be implemented in ImportingTypesProposalProvider in the /Users/ani/Desktop/indigo/plugins/org.eclipse.xtext.xtend2.ui plugin. So have a look there for inspiration.

Alex
Re: automatic imports insert [message #693112 is a reply to message #692381] Tue, 05 July 2011 20:02 Go to previous messageGo to next message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Hi Alexander,

ImportingTypesProposalProvider extends JdtTypesProposalProvider
public class JdtTypesProposalProvider extends AbstractTypesProposalProvider

and
public abstract class AbstractTypesProposalProvider implements ITypesProposalProvider




so I create own
public class MyDslTypesProposalProvider  extends AbstractTypesProposalProvider 

and bind it to ITypesProposalProvider
public Class<? extends ITypesProposalProvider> bindITypesProposalProvider() {
		return MyDslTypesProposalProvider.class;
}

then I add break point to any of its methods and launch eclipse in debug mode

then I tried to use content assist and no breakpoint works for me. What I'm doing wrong?

Thanks

[Updated on: Tue, 05 July 2011 20:06]

Report message to a moderator

Re: automatic imports insert [message #693152 is a reply to message #693112] Tue, 05 July 2011 22:27 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi,

the XtendProposalProvider contains a lot of distracting details. Since
I assume that you don't use JvmTypeReferences in your language, I'd
recommend to look into the
org.eclipse.xtext.ui.editor.contentassist.ReplacementTextApplier. Each
completion proposal that is created by the generated proposal provider
can be casted to a ConfigurableCompletionProposal which in turn can take
a ReplacementTextApplier. The ReplacementTextApplier is a powerful hook
to perform complex changes in the document as soon as a proposal is
selected (see #apply(IDocument, ConfigurableCompletionProposal) ). You
have to compute the location for the import and add it to the document.

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

On 05.07.11 22:02, amazuzu wrote:
> Hi Alexander,
>
>
> ImportingTypesProposalProvider extends JdtTypesProposalProvider
> and
> public abstract class AbstractTypesProposalProvider implements
> ITypesProposalProvider
>
>
> so I create own
>
> public class MyDslTypesProposalProvider extends
> AbstractTypesProposalProvider and bind it to ITypesProposalProvider
> public Class<? extends ITypesProposalProvider>
> bindITypesProposalProvider() {
> return MyDslTypesProposalProvider.class;
> }
> then I add break point to any of its methods and launch eclipse in debug
> mode
>
> then I tried to use content assist and no breakpoint works for me. What
> I'm doing wrong?
>
> Thanks
>
Re: automatic imports insert [message #693486 is a reply to message #693152] Wed, 06 July 2011 14:51 Go to previous messageGo to next message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Thank you,

I moved further but not so much.
Also I know your blog post http://zarnekow.blogspot.com/2011/06/customizing-content-assist-with-xtext.html

I tried to get instance of ICompletionProposal in method below but without success
public void complete_QualifiedName(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
//I unable to retrieve instance of ICompletionProposal
}


here I don't want to create my own proposals, I wan't to use default ones.


Is there a way to set textApplier to already accepted proposals (e.g those I see in content assist)? I unable get them from acceptor.

[Updated on: Wed, 06 July 2011 14:52]

Report message to a moderator

Re: automatic imports insert [message #693528 is a reply to message #693486] Wed, 06 July 2011 16:46 Go to previous messageGo to next message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Oh sorry, I understand

	public ICompletionProposal createCompletionProposal(String proposal, StyledString displayString, Image image, ContentAssistContext contentAssistContext) {
		ICompletionProposal completionProposal = createCompletionProposal(proposal, displayString, image, getPriorityHelper().getDefaultPriority(), contentAssistContext.getPrefix(), contentAssistContext);
		ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal)completionProposal;

//set my text applier
		configurableCompletionProposal.setTextApplier(null);

		return completionProposal;
}


Thanks
Re: automatic imports insert [message #693588 is a reply to message #693528] Wed, 06 July 2011 19:30 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi,

that's one option. If you want to change the behavior of a specific set
of proposals, you could try something like this:

super.complete_QualifiedName(model, ruleCall, context, new
ICompletionProposalAcceptor.Delegate(acceptor) {
public void accept(ICompletionProposal proposal) {
if (proposal != null) {
proposal.setTextApplier(..)
getDelegate().accept(proposal);
}

}
}

Hope that help,s
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 06.07.11 18:46, amazuzu wrote:
> Oh sorry, I understand
> public ICompletionProposal createCompletionProposal(String proposal,
> StyledString displayString, Image image, ContentAssistContext
> contentAssistContext) {
> ICompletionProposal completionProposal =
> createCompletionProposal(proposal, displayString, image,
> getPriorityHelper().getDefaultPriority(),
> contentAssistContext.getPrefix(), contentAssistContext);
> ConfigurableCompletionProposal configurableCompletionProposal =
> (ConfigurableCompletionProposal)completionProposal;
>
> //set my text applier
> configurableCompletionProposal.setTextApplier(null);
>
> return completionProposal;
> }
>
> Thanks
Re: automatic imports insert [message #693631 is a reply to message #693588] Wed, 06 July 2011 23:04 Go to previous message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Hi Sebastian,

your solution works! Thank you.

but I succeded only by overriding lookupCrossReference(arg0, arg1, arg2)

if I override some other method then in contentassist I see e.g 10 proposals in debug mode but 10*2 instantiations (not 10) of ConfigurableCompletionProposal (10 with textApplier and 10 without i.e textApplier=null)

@Override
protected void lookupCrossReference(CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
		
super.lookupCrossReference(crossReference, contentAssistContext, new EntityClassProposalAcceptorDelegate(acceptor, contentAssistContext));
}


private class EntityClassProposalAcceptorDelegate extends           ICompletionProposalAcceptor.Delegate {
private ContentAssistContext context;

public EntityClassProposalAcceptorDelegate(ICompletionProposalAcceptor delegate, ContentAssistContext context) {
     super(delegate);
     this.context = context;
}

public void accept(ICompletionProposal proposal) {
    if (proposal != null) {
          ((ConfigurableCompletionProposal) proposal).setTextApplier(new ImportReplacementTextApplier(context.getResource(), context.getViewer(), qualifiedNameValueConverter, qualifiedNameConverter));

     super.accept(proposal);

     }
}
}
Previous Topic:IFoldingRegion
Next Topic:two file extenstions with slightly different grammar
Goto Forum:
  


Current Time: Thu Mar 28 11:27:10 GMT 2024

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

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

Back to the top