• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default code formatter in eclipse

 
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic