Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365257 - Extension point "org.eclipse.cdt.core.CodeFormatter" fails to engage with custom code formatter
Summary: Extension point "org.eclipse.cdt.core.CodeFormatter" fails to engage with cus...
Status: RESOLVED WORKSFORME
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-30 19:15 EST by Haroogan CLA
Modified: 2011-12-19 04:42 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Haroogan CLA 2011-11-30 19:15:52 EST
Build Identifier: 3.7.1

I've created Eclipse plug-in, which provides custom code formatter.

When I switch from [built-in] to custom code formatter in "Code Style" option - my custom formatter is called and it can successfully format the "Preview Code".

However, when I start using "CTRL + SHIFT + F" or "Source -> Format" to format any real source file in workspace, the [built-in] formatter is obviously called instead of mine. This was confirmed by debugging - my custom code formatter is never called on real source code files.

Reproducible: Always

Steps to Reproduce:
1. Create plug-in with "org.eclipse.cdt.core.CodeFormatter" extension;
2. Select your custom code formatter in "Code Style" option;
3. Try to format any real source code file.
Comment 1 Anton Leherbauer CLA 2011-12-01 08:41:59 EST
This works for me. Just tried with the Astyle Eclipse plugin from http://astyleclipse.sourceforge.net/

Can you provide your custom formatter plugin?
Comment 2 Haroogan CLA 2011-12-01 12:56:55 EST
(In reply to comment #1)
> This works for me. Just tried with the Astyle Eclipse plugin from
> http://astyleclipse.sourceforge.net/
> 
> Can you provide your custom formatter plugin?

No problem, here you go: [http://dl.dropbox.com/u/43869765/ru.haroogan.astyle.rar]

NOTE: ***Windows x86 only for now***

Instructions:
1. Open "Window -> Preferences -> AStyle Preference Page" and select "Options.txt" as "Options File";
2. Go to "Window -> Preferences -> C/C++ -> Code Style" and switch to "AStyle Code Formatter";
3. Test.

I'm keen to learn what causes the issue! ;)

P. S.

One more thing to consider: [https://bugs.eclipse.org/bugs/show_bug.cgi?id=309787]
Maybe CDT's CodeFormatter has the same fate?
Comment 3 Anton Leherbauer CLA 2011-12-02 08:34:17 EST
(In reply to comment #2)
> One more thing to consider:
> [https://bugs.eclipse.org/bugs/show_bug.cgi?id=309787]
> Maybe CDT's CodeFormatter has the same fate?

There are no plans to deprecate this extension point.

I tried your plugin, but there is a problem loading the DLL. It cannot find a few dependent libraries. Still I could verify that your formatter gets called both for the preview and also using Ctrl+Shift+F, because it throws this exception (which is a consequence of the DLL loading issue).

java.lang.NoClassDefFoundError: Could not initialize class ru.haroogan.astyle.AStyleInterface
	at ru.haroogan.astyle.AStyleCodeFormatter.format(AStyleCodeFormatter.java:27)
	at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:129)
	at org.eclipse.cdt.internal.ui.text.CFormattingStrategy.format(CFormattingStrategy.java:62)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:193)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:142)
	at org.eclipse.cdt.internal.ui.preferences.formatter.TranslationUnitPreview.doFormatPreview(TranslationUnitPreview.java:68)
	at org.eclipse.cdt.internal.ui.preferences.formatter.CPreview.update(CPreview.java:161)
	at org.eclipse.cdt.internal.ui.preferences.formatter.CodeFormatterConfigurationBlock$PreviewController.update(CodeFormatterConfigurationBlock.java:52)
Comment 4 Haroogan CLA 2011-12-02 08:50:10 EST
Sorry for that, here you go, the dependencies: [http://dl.dropbox.com/u/43869765/Dependency.rar]
Comment 5 Haroogan CLA 2011-12-02 09:26:29 EST
Sorry for that, please re-download: [http://dl.dropbox.com/u/43869765/ru.haroogan.astyle.rar]

I have rebuilt DLL to mitigate dependencies. Hope this works now!
Comment 6 Haroogan CLA 2011-12-02 12:06:54 EST
Update: I've noticed that it works, but only when I switch from [built-in] to custom formatter SPECIFICALLY in some project's "Code Style" settings.

Therefore, now I have a reasonable question: why having custom formatter in global "Code Style" settings has no effect? - Actually, it looks like a bug.
Comment 7 Anton Leherbauer CLA 2011-12-05 03:00:01 EST
(In reply to comment #6)
> Update: I've noticed that it works, but only when I switch from [built-in] to
> custom formatter SPECIFICALLY in some project's "Code Style" settings.
> 
> Therefore, now I have a reasonable question: why having custom formatter in
> global "Code Style" settings has no effect? - Actually, it looks like a bug.

As soon as you specify project specific settings in your project properties, the workspace settings have no effect for that project.  I think that's reasonable.
Comment 8 Anton Leherbauer CLA 2011-12-19 04:42:45 EST
Works as designed.