automatic imports insert [message #692189] |
Sun, 03 July 2011 21:14 |
amazuzu 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 #693112 is a reply to message #692381] |
Tue, 05 July 2011 20:02 |
amazuzu 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 #693528 is a reply to message #693486] |
Wed, 06 July 2011 16:46 |
amazuzu 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 |
Sebastian Zarnekow 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 |
amazuzu 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);
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03854 seconds