Bug 458804 - [content assist] Contribute non-local templates to JDT (aka postfix code completion)
Summary: [content assist] Contribute non-local templates to JDT (aka postfix code comp...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 enhancement with 3 votes (vote)
Target Milestone: 4.14 M1   Edit
Assignee: Roland Grunberg CLA
QA Contact: Roland Grunberg CLA
URL:
Whiteboard:
Keywords: noteworthy
: 487030 507929 (view as bug list)
Depends on:
Blocks: 552146 560305
  Show dependency tree
 
Reported: 2015-01-30 06:00 EST by Lars Vogel CLA
Modified: 2020-02-25 07:54 EST (History)
21 users (show)

See Also:


Attachments
Current behavior in latest integration build. (81.58 KB, image/gif)
2019-10-01 14:41 EDT, Nicolaj Hoess CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2015-01-30 06:00:51 EST
In Eclipse 4.5 the JDT API was modified via Bug 433500 to support an implementation of postfix code completion. 

See https://github.com/trylimits/Eclipse-Postfix-Code-Completion for a demo.

Nico the main developer indicated that he would be interested to contribute that to JDT and Dani indicated that we should create a Gerrit review for that. This bug is to track this effort.
Comment 1 Nicolaj Hoess CLA 2015-02-01 18:18:34 EST
Pushed to gerrit (for a first review): https://git.eclipse.org/r/#/c/40855/

This commit covers all changes which would be needed to integrate Postfix Code Completion templates into JDT.

As this commit is for review purposes and not supposed to be merged into master I did not include copyright notice and extended javadoc.

In my opinion the actual integration should be split into more atomic parts, i.e.

- Fixing the access restriction to ASTNode (compile error atm)

- Adding/Extending VariableResolvers (newType, newActualType, newField) to the Java context (these are pretty helpful for conventional templates too) and extend JavaContext accordingly (addField(..), addImportGeneric(..), ...)

- Postfix functionality (ProposalComputer, TemplateEngine, PostfixContext, ...)

Ofc I would be willing to invest further work for the integration.
Comment 2 Eclipse Genie CLA 2015-02-15 10:21:07 EST
WARNING: this patchset contains 1322 new lines of code and may require a Contribution Questionnaire (CQ) if the author is not a committer on the project. Please see:https://wiki.eclipse.org/Project_Management_Infrastructure/Creating_A_Contribution_Questionnaire
Comment 3 Eclipse Genie CLA 2015-02-17 14:16:24 EST
WARNING: this patchset contains 1321 new lines of code and may require a Contribution Questionnaire (CQ) if the author is not a committer on the project. Please see:https://wiki.eclipse.org/Project_Management_Infrastructure/Creating_A_Contribution_Questionnaire
Comment 4 Eclipse Genie CLA 2015-04-09 08:14:56 EDT
WARNING: this patchset contains 1321 new lines of code and may require a Contribution Questionnaire (CQ) if the author is not a committer on the project. Please see:https://wiki.eclipse.org/Project_Management_Infrastructure/Creating_A_Contribution_Questionnaire
Comment 5 Noopur Gupta CLA 2015-04-09 08:34:50 EDT
(In reply to Nicolaj Hoess from comment #1)
> Pushed to gerrit (for a first review): https://git.eclipse.org/r/#/c/40855/

To begin with the review, this part has to be fixed first:
> - Fixing the access restriction to ASTNode (compile error atm)

Currently applying the patch on jdt.ui results in 96 compile errors, all related to accessing multiple internal classes from jdt.core:
Discouraged access: xxx is not API (restriction on required project 'org.eclipse.jdt.core')

You should check if the existing APIs can be used for the above or request for new APIs in jdt.core if required.
Comment 6 Dani Megert CLA 2016-02-04 06:42:32 EST
*** Bug 487030 has been marked as a duplicate of this bug. ***
Comment 7 Noopur Gupta CLA 2016-03-16 06:29:42 EDT
(In reply to Noopur Gupta from comment #5)
> You should check if the existing APIs can be used for the above or request
> for new APIs in jdt.core if required.

Moving to 4.7 as it may need new APIs in jdt.core.
Comment 8 Lars Vogel CLA 2016-11-22 04:58:15 EST
*** Bug 507929 has been marked as a duplicate of this bug. ***
Comment 9 Marco Descher CLA 2018-02-02 01:44:31 EST
Sad, that this is still not being part of the default Eclipse JDT installation ...

https://github.com/trylimits/Eclipse-Postfix-Code-Completion/issues/20

https://blog.novatec-gmbh.de/working-postfix-code-completion/
Comment 10 Noopur Gupta CLA 2018-02-02 03:29:14 EST
(In reply to Marco Descher from comment #9)
> Sad, that this is still not being part of the default Eclipse JDT
> installation ...
> 
> https://github.com/trylimits/Eclipse-Postfix-Code-Completion/issues/20
> 
> https://blog.novatec-gmbh.de/working-postfix-code-completion/

A high-quality patch to integrate it in JDT will be welcome.
Comment 11 Gayan Perera CLA 2019-04-17 12:59:38 EDT
@Lars you had a fork of the tryLimits postfix implementation right ? Can't we polish it and bring that to JDT. i wonder how the licensing will effect on the original work of the author.
Comment 12 Lars Vogel CLA 2019-04-17 13:43:07 EDT
(In reply to Gayan Perera from comment #11)
> @Lars you had a fork of the tryLimits postfix implementation right ? Can't
> we polish it and bring that to JDT. i wonder how the licensing will effect
> on the original work of the author.

No worked happened in the fork. I think a good starting point is the Gerrit from Nicolaj
Comment 13 Nicolaj Hoess CLA 2019-04-18 05:25:49 EDT
(In reply to Gayan Perera from comment #11)
> @Lars you had a fork of the tryLimits postfix implementation right ? Can't
> we polish it and bring that to JDT. i wonder how the licensing will effect
> on the original work of the author.

Don't mind the licensing.
Unfortunately, I don't have enough knowledge to choose an adequate license type, but if I would have such knowledge, I would choose one which basically says: "I'm looking forward to see this feature integrated into Eclipse. I'm glad to grant any permission on the source code to anybody who is pursuing this goal."
Comment 14 Lars Vogel CLA 2019-04-18 05:32:35 EDT
(In reply to Nicolaj Hoess from comment #13

Great to hear that you are still around. :-)
Comment 15 Roland Grunberg CLA 2019-06-05 09:34:09 EDT
I was thinking of taking this but I see the original author is still active. I'd be interested in reviewing this but just need to solidify an existing feature, then I could have a look.
Comment 16 Lars Vogel CLA 2019-06-05 09:46:01 EDT
(In reply to Roland Grunberg from comment #15)
> I was thinking of taking this but I see the original author is still active.
> I'd be interested in reviewing this but just need to solidify an existing
> feature, then I could have a look.

Nicolaj is not active anymore so it would be great if you can take this.
Comment 17 Eclipse Genie CLA 2019-08-07 13:36:43 EDT
New Gerrit change created: https://git.eclipse.org/r/40855
Comment 18 Eclipse Genie CLA 2019-08-15 16:34:59 EDT Comment hidden (obsolete)
Comment 19 Roland Grunberg CLA 2019-09-10 11:37:23 EDT
(In reply to Nicolaj Hoess from comment #13)
> (In reply to Gayan Perera from comment #11)
> > @Lars you had a fork of the tryLimits postfix implementation right ? Can't
> > we polish it and bring that to JDT. i wonder how the licensing will effect
> > on the original work of the author.
> 
> Don't mind the licensing.
> Unfortunately, I don't have enough knowledge to choose an adequate license
> type, but if I would have such knowledge, I would choose one which basically
> says: "I'm looking forward to see this feature integrated into Eclipse. I'm
> glad to grant any permission on the source code to anybody who is pursuing
> this goal."

Hi Nicolaj, I know you're not active on the change but would it be possible for you to add license headers to the top of ActualTypeResolver.java, InnerExpressionResolver.java, JavaPostfixContext.java, JavaPostfixContextType.java, NewFieldResolver.java, and default-postfixtemplates.xml .

Something like :

/*******************************************************************************
 * Copyright (c) 2019 Nicolaj Hoess
 * 
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Nicolaj Hoess - Initial Contribution
 *******************************************************************************/

for the java files and using <!-- --> for the xml file. Most contributions are made under EPL-2.0 and that would be ideal for Eclipse, but, if you would strongly prefer to use another license, let me know so we can determine if it would be compatible.
Comment 20 Nicolaj Hoess CLA 2019-09-10 17:04:38 EDT
(In reply to Roland Grunberg from comment #19)
> (In reply to Nicolaj Hoess from comment #13)
> > (In reply to Gayan Perera from comment #11)
> > > @Lars you had a fork of the tryLimits postfix implementation right ? Can't
> > > we polish it and bring that to JDT. i wonder how the licensing will effect
> > > on the original work of the author.
> > 
> > Don't mind the licensing.
> > Unfortunately, I don't have enough knowledge to choose an adequate license
> > type, but if I would have such knowledge, I would choose one which basically
> > says: "I'm looking forward to see this feature integrated into Eclipse. I'm
> > glad to grant any permission on the source code to anybody who is pursuing
> > this goal."
> 
> Hi Nicolaj, I know you're not active on the change but would it be possible
> for you to add license headers to the top of ActualTypeResolver.java,
> InnerExpressionResolver.java, JavaPostfixContext.java,
> JavaPostfixContextType.java, NewFieldResolver.java, and
> default-postfixtemplates.xml .
> 
> Something like :
> 
> /
> *****************************************************************************
> **
>  * Copyright (c) 2019 Nicolaj Hoess
>  * 
>  * This program and the accompanying materials are made
>  * available under the terms of the Eclipse Public License 2.0
>  * which is available at https://www.eclipse.org/legal/epl-2.0/
>  *
>  * SPDX-License-Identifier: EPL-2.0
>  *
>  * Contributors:
>  *     Nicolaj Hoess - Initial Contribution
>  ****************************************************************************
> ***/
> 
> for the java files and using <!-- --> for the xml file. Most contributions
> are made under EPL-2.0 and that would be ideal for Eclipse, but, if you
> would strongly prefer to use another license, let me know so we can
> determine if it would be compatible.

Sure, I'll do that asap (probably tomorrow evening).
And btw. I really appreciate your help and contributions :-)
Comment 21 Roland Grunberg CLA 2019-09-17 12:15:00 EDT
(In reply to Nicolaj Hoess from comment #20)
> Sure, I'll do that asap (probably tomorrow evening).
> And btw. I really appreciate your help and contributions :-)

@Nicolaj,

Thanks again for doing this. It seems I completely missed to ask for PostfixCompletionProposalComputer.java, PostfixTemplateEngine.java, PostfixTemplateProposal.java . They'll need headers the same as the previous ones.

Thanks again.
Comment 22 Roland Grunberg CLA 2019-09-24 15:54:36 EDT
Filed https://dev.eclipse.org/ipzilla/show_bug.cgi?id=20875 .
Comment 24 Lars Vogel CLA 2019-10-01 08:01:28 EDT
Thanks Roland and Nicolaj for working on this. 

Should be report issues with postfix completion in this bug, or is it better to close this one and open new dependent bugs for it?
Comment 25 Eclipse Genie CLA 2019-10-01 13:49:12 EDT
New Gerrit change created: https://git.eclipse.org/r/150450
Comment 26 Roland Grunberg CLA 2019-10-01 13:51:49 EDT
(In reply to Lars Vogel from comment #24)
> Thanks Roland and Nicolaj for working on this. 
> 
> Should be report issues with postfix completion in this bug, or is it better
> to close this one and open new dependent bugs for it?

I would open separate bugs. The only changes that will be associated with this are the N&N and possible formatting changes.

Also, please note that PostFixCompletionTest seems to have many failures now, but this is due to Bug 549989 . The commit for that refactoring seems to have changed how certain template variables get resolved.
Comment 27 Nicolaj Hoess CLA 2019-10-01 14:41:25 EDT
Created attachment 280128 [details]
Current behavior in latest integration build.

(In reply to Roland Grunberg from comment #26)
> (In reply to Lars Vogel from comment #24)
> > Thanks Roland and Nicolaj for working on this. 
> > 
> > Should be report issues with postfix completion in this bug, or is it better
> > to close this one and open new dependent bugs for it?
> 
> I would open separate bugs. The only changes that will be associated with
> this are the N&N and possible formatting changes.
> 
> Also, please note that PostFixCompletionTest seems to have many failures
> now, but this is due to Bug 549989 . The commit for that refactoring seems
> to have changed how certain template variables get resolved.

I just tested the latest build and it seems that the current state is not usable at all, e.g. if I apply false.var$ it ends up in a text selection /false.|var - if I then apply the template again it resolves correctly (see attached gif for examples).

I would appreciate if these integration issues are solved, before this ticket is closed.
Comment 29 Sebastian Ratz CLA 2019-10-04 10:12:26 EDT
(In reply to Nicolaj Hoess from comment #27)
> I just tested the latest build and it seems that the current state is not
> usable at all, e.g. if I apply false.var$ it ends up in a text selection
> /false.|var - if I then apply the template again it resolves correctly (see
> attached gif for examples).
> 
> I would appreciate if these integration issues are solved, before this
> ticket is closed.

Those issues were also caused by bug 549989, but should now be solved.

Latest I-Build works correctly for me again, so I guess it's just the N&N that is needed now.
Comment 30 Eclipse Genie CLA 2019-10-04 15:46:48 EDT
New Gerrit change created: https://git.eclipse.org/r/150616
Comment 32 Eclipse Genie CLA 2019-10-05 09:06:26 EDT
New Gerrit change created: https://git.eclipse.org/r/150630
Comment 33 Eclipse Genie CLA 2019-10-05 09:09:07 EDT
New Gerrit change created: https://git.eclipse.org/r/150631
Comment 34 Eclipse Genie CLA 2019-10-05 09:12:21 EDT
New Gerrit change created: https://git.eclipse.org/r/150632
Comment 37 Noopur Gupta CLA 2019-10-09 01:46:24 EDT
Thanks, Roland. Closing this for M1. Please add N&N for this and release new fixes in separate bug reports.
Comment 38 Roland Grunberg CLA 2019-10-09 16:42:57 EDT
Verified for 4.14 M1 using I20191009-0600 build.
Comment 39 Eclipse Genie CLA 2019-10-11 16:19:41 EDT
New Gerrit change created: https://git.eclipse.org/r/150965
Comment 41 Pierre-Yves Bigourdan CLA 2019-11-20 10:58:31 EST
I've using the latest JDT nightly build, I just got the exception with postfix completion enabled:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.ui.text.java.PostfixCompletionProposalComputer.updateTemplateEngine(PostfixCompletionProposalComputer.java:157)
	at org.eclipse.jdt.internal.ui.text.java.PostfixCompletionProposalComputer.analyzeCoreContext(PostfixCompletionProposalComputer.java:114)
	at org.eclipse.jdt.internal.ui.text.java.PostfixCompletionProposalComputer.computeCompletionEngine(PostfixCompletionProposalComputer.java:103)
	at org.eclipse.jdt.internal.ui.text.java.AbstractTemplateCompletionProposalComputer.computeCompletionProposals(AbstractTemplateCompletionProposalComputer.java:71)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:345)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:340)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:334)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:291)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2.lambda$0(ContentAssistant.java:2015)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2$$Lambda$1118.0000000019CFD820.accept(Unknown Source)
	at java.base/java.util.Collections$SingletonSet.forEach(Collections.java:4797)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2.run(ContentAssistant.java:2014)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:2011)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:575)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.lambda$0(CompletionProposalPopup.java:505)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$$Lambda$1117.0000000019B7D620.run(Unknown Source)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:72)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:500)
	at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener.lambda$0(ContentAssistant.java:380)
	at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener$$Lambda$1115.0000000019CB7420.run(Unknown Source)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3812)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1160)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1049)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:660)
	at org.eclipse.ui.internal.Workbench$$Lambda$107.0000000000000000.run(Unknown Source)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:559)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
Comment 42 Dani Megert CLA 2019-11-20 11:04:12 EST
(In reply to Pierre-Yves B. from comment #41)
> I've using the latest JDT nightly build, I just got the exception with
> postfix completion enabled:
Please file a new bug report with steps to reproduce if possible.
Comment 43 Pierre-Yves Bigourdan CLA 2019-11-20 11:52:44 EST
(In reply to Dani Megert from comment #42)
> (In reply to Pierre-Yves B. from comment #41)
> > I've using the latest JDT nightly build, I just got the exception with
> > postfix completion enabled:
> Please file a new bug report with steps to reproduce if possible.

Done, see Bug 553279.
Comment 44 Andrey Loskutov CLA 2019-12-18 11:20:28 EST
Please check bug 558434, that seem to be caused by the new proposal code added here.
Comment 45 Andrey Loskutov CLA 2019-12-18 11:56:30 EST
(In reply to Andrey Loskutov from comment #44)
> Please check bug 558434, that seem to be caused by the new proposal code
> added here.

See also bug 558436 and bug 558435.