File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes Default code formatter in eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Default code formatter in eclipse" Watch "Default code formatter in eclipse" New topic
Author

Default code formatter in eclipse

Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Hi All,
I wanted to to set my own code formatter xml file as default code formatter in my eclipse platform without manually configuring ( Need to set by program itself, already i've installed some plugins. so through one of the plugin or by someway). Not the way which we usually do to configure by windows=>preferences=>code style.

Since my plugins are added with the eclipse I don't my clients to configure this for every release which releases aften. Really I'm in needed the solution.

Kindly any one of you can help me on this? Thanks in advance.


No pain, No gain.
OCJP 1.6
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

you can use code format files in eclipse, I know you can use one saved from another version of eclipse.
under the code formatter import button, maybe your xml file will work
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

I think what you are asking is that you want to put together an Eclipse package for your users, such that when they install that Eclipse package, your source formatting rules are the defaults. You do not want your users to have to first import your formatting xml file and then set it up as the formatting rule.

Well, you would think that because you can import and export formatting as an XML that the Eclipse developers would use XML files to define the formatting rules. Wrong! The "Java Conventions [built-in]" and "Eclipse [built-in]" formatting options are embedded in the org.eclipse.jdt.internal.formatter.DefaultFormatterOptions class, and the "Eclipse 2.1 [built-in]" options are in org.eclipse.jdt.internal.formatter.old.CodeFormatter class within the org.eclipse.jdt.core_*.jar file (exact file name depends on your Eclipse version).

Usually what I would do in a case like this is grab the source for the DefaultFormatterOptions class, modify it so that the defaults are the ones I want, compile just that class, and rebuild the JAR file with that class. But in this case it is a little harder because the SHA-1 checksums are kept for the class files in the MANIFEST.MF and ECLIPSEF.SF files (both in META-INF), so I would have to update those with the new checksum.


JBoss In Action
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Hi Peter,

Actually your guess is my problem. Thanks to explain the problem and I've taken one example in net which will just override the default code formatting options of eclipse. Currently I'm working on it, once its done I shall let you know about this. (But facing some problem ) Thanks folks.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Hi,
I've overwritten the JavaCore options by my custom code formatter value pair items and it runs without any problem. But I'm not able to see the new changes. And my another doubt is how do I know it works fine, without writing a program and apply my new changes( manually)? Basically when we change in window->preferences dialog window shows the preview and name of the code formatter, to change those what I needs to be done? I've gone through some eclipse base classes, but no luck. Please provide your valuable thoughts on this.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

I had no luck in finding where the names of the built-in formatting schemes are declared, so unless you can find it, you will be stuck with the existing names.

The best way I can think of to verify that your formatting options are working is to get to write some code (grab the source for some open-source project where the formatting is very different from your formatting specs), open it in the editor, and hit CTRL-SHIFT-F and see if the code reformats to your specs.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Hi Peter,

I've checked and it's working fine. The problem is by code I do my own formatting but user doesn't know until the preferences code formatter profile is pointing to mine. Even checked the default code formatter core eclipse and all, not able to understand the things really.

Also can you tell me in which class I need to do all pre-configurations of my customization when eclipse starts? Thanks in advance.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Hi,

At the end of big struggle got a solution to my problem. I've provided the sample codes here (may be it will useful for others like me ). I've tested this and working fine as we expected. But whenever I use classes of jdt.internal.* warning says security constraints may create problem, but no impact on runtime.



Really it was very hard to find these easy methods to work it out.Thanks Peter and Gibbons for your support on this.

[edited to add code tags]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default code formatter in eclipse
 
Similar Threads
Eclipse plug-in for JBOSS
Checkstyle
Which IDE: netbeans or eclipse?
Eclipse JavaScript formatter?
eclipse settings