Version 32 (modified by 7 years ago) ( diff ) | ,
---|
Languages:
- English
- français
- 日本語
- Nederlands
Development Guidelines
How your code should look like
- make sure the code is Java 8 compatible
- make sure there is no trailing white space
- don't use multiple consecutive empty lines
- JOSM uses 4 characters indentation and no tab stops. If you use Notepad++ you can change the default indentation in the "Preferences" -> "Language" -> "Tab Settings" -> check "Replace by spaces" (this is permanent) or with the "change indentation settings" button in the toolbar (this is a temopary setting and requires the plugin "Customize Toolbar").
- Document your code thoroughly. Many people will thank you :)
- add curly brackets for each
if
, unless it is followed byreturn
(or maybethrow
) - check your changes before patch/commit:
ant checkstyle
and checkcheckstyle-josm.xml
; if you find running checkstyle slow for all files, run for changed files only:
svn diff --summarize | awk '{ print $2 }' | xargs java -jar tools/checkstyle/checkstyle-7.1-all.jar -c tools/checkstyle/josm_checks.xml # or git diff --name-only | xargs java -jar tools/checkstyle/checkstyle-7.1-all.jar -c tools/checkstyle/josm_checks.xml
How your javadoc should look like
- The Oracle Javadoc style guide is used as the base guide
@since
is used for public classes and methods (visible to plugin developers) with the JOSM revision that introduced the element. Example:@since 5408
@since
is updated when a public method signature changes or if a class is renamed@since
can be omitted for public methods and fields introduced at the same time as the class, provided they do not have changed and the class is correctly documented.
@throws
is preferred to@exception
- check your changes before patch/commit by generating javadoc:
ant javadoc
, browse output messages; if you find running javadoc slow for all files, run for changed files only:
svn diff --summarize | awk '{ print $2 }' | xargs javadoc -d javadoc # or git diff --name-only | xargs javadoc -d javadoc
Configuring Eclipse
Internationalization
- make sure you use
tr(...)
for all localized stringsimport import static org.openstreetmap.josm.tools.I18n.tr; // use tr(...) for exception messages // throw new Exception(tr("error message always in tr()")); // use tr(...) for labels, title, tooltip texts and the like // new JLabel(tr("Label always in tr()")); // etc.
- never assemble localized messages with
+
. Use format placeholders instead.
DONT
new JLabel(tr("My Label " + labelId));
DO
new JLabel(tr("My Label {0}",labelId));
Only exception:
+
can be used to break long lines of non-variable texts.
- When using apostrophe, the following rules apply:
For all
tr
the apostrophe is special. (Like backslash in C)
It needs to be escaped by another apostrophe:
new JButton(tr("Don''t press me more than {0} times!", n))
Back to Developers Guide
Attachments (4)
- ss1.png (142.2 KB ) - added by 15 years ago.
- ss2.png (55.2 KB ) - added by 15 years ago.
- ss3.png (68.2 KB ) - added by 15 years ago.
- styleguide_compiler_16.png (55.0 KB ) - added by 12 years ago.
Download all attachments as: .zip
Note:
See TracWiki
for help on using the wiki.