Coding style is very much personal, and using your favorite style improves the coding productivity.
Say, for example, someone (many Java programmer, apparently) likes the following style.
class test(){
public main(args[]){
if(a == b){
System.out.println("Hello World!");
}
}
}
I personally never liked putting curly braces in the same line. I always like the following style.
class test()
{
public main(args[])
{
if(a == b)
{
System.out.println("Hello World!");
}
}
}
Sometimes, you want to change the coding style in your favorite way, like the above. If you are writing code from scratch, Eclipse has the feature called Formatter in Preferences, Java --> Code Style --> Formatter. There, you can set up your own format (i.e. coding style).
But what if you want change existing file?
There's a way to convert existing Java source code at once.
http://wiyoo.blogspot.com/2007/05/batch-formatting-java-source-code-with... ![]()
In case the page's gone, here's the excerpt of the linked page.
1. In Eclipse, open the properties of a Java project.
2. In Code Style > Formatter, check Enable project specific settings.
3. Select and edit a formatter configuration.
4. Click on OK.
5. The code formatter configuration file will then be in your Eclipse workspace in workspace/YourJavaProject/.settings/org.eclipse.jdt.core.prefs.
Then, run the following.
eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -config D:/formatter.prefs D:/tmp/src
This will convert all the .java files under D:/temp/src to your format.


新しいコメントの投稿