Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JavaCorrectionProcessor.collectCorrections does not collect any available correction
icon5.gif  JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1027320] Tue, 26 March 2013 21:15 Go to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi all,

For the following code:
public class QFSDemo {
	private string name_;
}


I am running
JavaCorrectionProcessor.collectCorrections(..)
with the context and location of the compilation error for 'string' to get the quick fixes offered for that location. My plug-in runs on top of a headless application (e.g., IApplication) that dynamically loads Eclipse UI libraries (e.g., org.eclipse.ui and org.eclipse.jdt.ui).

For some reason, JavaCorrectionProcessor.collectCorrections(..) does not collect any proposal (e.g., the array list I pass to that method returns empty). However, if I load the same file in Eclipse and invoke quick fix, I get 12 Quick Fix Proposals.

Any idea why I am not getting any proposals in my headless application? Is there any way to get all proposals offered for a specific compilation error in a headless application (other than I currently use)?

For reference, I use the following code to get the proposals offered for a specific compilation error:
        ArrayList <IJavaCompletionProposal> proposals = new ArrayList <>();
        IProblemLocation location = // Location for the compilation error.
        IInvocationContext context = // Context for the compilation error.
        IProblemLocation [] locations = new IProblemLocation [1];
        locations[0] = location;
        JavaCorrectionProcessor.collectCorrections(context, locations, proposals);
        return proposals;


Let me know if I am doing a mistake in my logic. Thanks in advance, best regards,

[Updated on: Tue, 26 March 2013 21:18]

Report message to a moderator

Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1027354 is a reply to message #1027320] Tue, 26 March 2013 22:12 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
A quick guess:
Quote:
a headless application (e.g., IApplication) that dynamically loads Eclipse UI libraries (e.g., org.eclipse.ui and org.eclipse.jdt.ui).


How exactly do you load jdt.ui? If you're bypassing equinox for that purpose, maybe the actual processor extensions are just not registered?

HTH
Stephan
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1027359 is a reply to message #1027354] Tue, 26 March 2013 22:17 Go to previous messageGo to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi Stephan,

I just use a quick hack to add the org.eclipse.jdt.ui jar to the class-path of the main thread. I am pretty sure that I am not doing a complete loading of the UI elements as I was actually trying not to create a Workbench (I don't want my plug-in to create another splash screen or any visible UI elements).

Would you suggest a more systematic way to load jdt.ui without actually running a Workbench?

Thanks,
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1027385 is a reply to message #1027359] Tue, 26 March 2013 23:07 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
It seems you're between a rock and a hard place:
You need to let Equinox load jdt.ui, because otherwise the extension mechanism doesn't work,
but then Equinox will find that some dependencies may not be present / loaded and perhaps just refuse to load it.

Would repackaging jdt.ui be an option for you? This way you could pick just the UI-independent parts you need, and have that loaded via Equinox. Make sure the plugin.xml is included (except for references to omitted stuff of course), and check which initialization from the activator should be relevant.
Otherwise you might need to manually trigger the registration of the extensions you need. Not sure which is less of a pain.

best,
Stephan
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1027400 is a reply to message #1027385] Tue, 26 March 2013 23:33 Go to previous messageGo to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi Stephan,

Thanks for the explanation.

I might be missing some terminology, but my understanding is:

I need to load jdt.ui through Equinox so that it loads the JavaCorrectionProcessors (which are extensions, which don't get loaded when I do the class-path hack). However, as I am running a headless IApplication, Equinox might fail while loading jdt.ui, is that the case?

Also, would JavaCorrectionProcessors get loaded correctly, if I were to also add them into the class-path of the main thread of my application, or do they need to be loaded differently (you mentioned registration of the extensions)?

I generally don't like repacking existing Eclipse core plug-ins. I did this once for my previous projects, however it increases the maintenance, distribution and installation of the end plug-in. However, if that is the only choice, I might consider it.

A side question: is there a reason Eclipse developers not separating the non-UI dependent parts of ui and jdt.ui into separate plug-ins and let us load them in headless applications? I am sure that this would be a lot of work, however it would help a lot to us as it even took around a month for me to be able to create an instance of ProblemLocation in my headless plug-in because it was complaining that it could not find ProblemLocation in the class-path Smile

Finally, could you point me some tutorial/API/document for both cases (e.g., loading jdt.ui through Equinox or loading registering extensions manually)?

Thanks, best regards,
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1028013 is a reply to message #1027400] Wed, 27 March 2013 18:13 Go to previous messageGo to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Just wanted to provide some extra information:

The implementation for JavaCorrectionProcessor.collectCorrections(..) is given as:
	public static IStatus collectCorrections(IInvocationContext context, IProblemLocation[] locations, Collection<IJavaCompletionProposal> proposals) {
		ContributedProcessorDescriptor[] processors= getCorrectionProcessors();
		SafeCorrectionCollector collector= new SafeCorrectionCollector(context, proposals);
		for (int i= 0; i < processors.length; i++) {
			ContributedProcessorDescriptor curr= processors[i];
			IProblemLocation[] handled= getHandledProblems(locations, curr);
			if (handled != null) {
				collector.setProblemLocations(handled);
				collector.process(curr);
			}
		}
		return collector.getStatus();
	}


Here, I debugged the result of getCorrectionProcessors(), just to make sure that I am getting some correction processor descriptions. In my IApplication it returns an array with 4 elements. Does this mean that the extension points get correctly loaded or completely something else?

Thanks,
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1030023 is a reply to message #1028013] Sat, 30 March 2013 15:02 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
If the answer from getCorrectionProcessors() contains the necessary processor you should be fine, and I might have been barking up the wrong tree in my previous posts, sorry.
To check this you may want to place a breakpoint in org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.SafeCorrectionCollector.safeRun(ContributedProcessorDescriptor)
where you'll see that actual processor obtained from the ContributedProcessorDescriptor. My guess is you'd be looking for org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor, right?

If then you see the correct processor and still no proposal, you're just a few steps from going into the processor to see why it proposes nothing.

If you don't see the expected processor, it may be an issue in processor.canHandleMarkerType() etc.pp.
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1030492 is a reply to message #1030023] Sun, 31 March 2013 08:02 Go to previous messageGo to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi Stephan,

Yes, I was looking for QuickFixProcessor. My system is difficult to debug because the main plug-in (which runs through Eclipse and completely debuggable), creates another Eclipse as a sub-process and runs my IApplication (which I am trying to debug) on top (which is very hard to debug) Smile.

Still, I confirmed that it finds QuickFixProcessor with success. I believe the problem is the following: QuickFixProcessor.process(..) eventually calls PlatformUI.getWorkbench(..), which throws an internal Eclipse exception as my headless IApplication has no workbench at all. JavaCorrectionProcessor.collectCorrections(..) runs the processors in 'safe' mode, so I guess the internal exception becomes silent and it just returns empty set as the result. Here is the complete stack trace I managed to get:
Workbench has not been created yet.
	at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.install(ASTProvider.java:245)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.<init>(ASTProvider.java:236)
	at org.eclipse.jdt.internal.ui.JavaPlugin.getASTProvider(JavaPlugin.java:710)
	at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:128)
	at org.eclipse.jdt.internal.ui.text.correction.AssistContext.getASTRoot(AssistContext.java:119)
	at org.eclipse.jdt.internal.ui.text.correction.UnresolvedElementsSubProcessor.getTypeProposals(UnresolvedElementsSubProcessor.java:587)
	at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.process(QuickFixProcessor.java:349)
	at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.getCorrections(QuickFixProcessor.java:290)

Do you see any workaround to fool the QuickFixProcessor as if the workbench was loaded? Alternatively, is it possible to create a workbench that is invisible?

Thanks for all the help, much appreciated. Best regards,
Re: JavaCorrectionProcessor.collectCorrections does not collect any available correction [message #1722907 is a reply to message #1030492] Wed, 10 February 2016 09:27 Go to previous message
Valentina Gatteschi is currently offline Valentina GatteschiFriend
Messages: 1
Registered: February 2016
Junior Member
Hi Stephan and Kivanc.

Sorry for digging up this old thread.
Did you find a solution?

I found that creating a workbench (PlatformUI.createAndRunWorkbench(...)) could overcome this error, but:
- the workbench has to be closed, in order to let the program continue its execution
- another exception is thrown: QuickFix could not be applied - "No active workbench page"

Thanks,
Valentina
Previous Topic:Installing of the eclipse programme.
Next Topic:Differences between Oracle and Eclipse compiler
Goto Forum:
  


Current Time: Tue Apr 16 04:37:20 GMT 2024

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

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

Back to the top