Changes between Version 32 and Version 33 of DevelopersGuide/StyleGuide
- Timestamp:
- 2017-05-11T10:48:19+02:00 (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DevelopersGuide/StyleGuide
v32 v33 5 5 6 6 * make sure the code is Java 8 compatible 7 * '''Document''' your code using inline comments and javadoc. Many people will thank you :) 8 * Try to avoid public fields 9 * JOSM has a lot of helper methods in the `Utils`, `GuiUtils`, `Geometry` ... classes. Use them if you need 10 * Check parameters. You can use `Objects.requireNonNull`. 11 * Don't write for performance - write for readability. Use `Stream`s, `Function`s and other Java 8 features if they make the code more readable. 12 13 === Threading / Locking === 14 15 * JOSM uses various locking mechanisms, depending on the object. 16 * The data sets are protected by a RW lock. Some methods do not automatically lock for performance reasons. Make sure to acquire the locks required for your changes. 17 * GUI components should only be modified in the EDT thread 18 * Prefer to use `SwingUtils.invokeLater` if you need to run anything on the UI thread 19 * Many listeners already run in the EDT thread (layer changes) or have a central manager that allows you to register listeners that run in EDT (dataset changes, selection changes). 20 21 == How your formatting should look like == 22 7 23 * make sure there is no trailing white space 8 24 * don't use multiple consecutive empty lines 9 25 * 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"). 10 * Document your code '''thoroughly'''. Many people will thank you :)11 26 * add curly brackets for each {{{if}}}, unless it is followed by {{{return}}} (or maybe {{{throw}}}) 12 * check your changes before patch/commit: `ant checkstyle` and check `checkstyle-josm.xml`; if you find running checkstyle slow for all files, run for changed files only: 13 27 * You should use '''checkstyle''' before patch/commit: `ant checkstyle` and check `checkstyle-josm.xml`; if you find running checkstyle slow for all files, run for changed files only: 14 28 {{{ 15 29 svn diff --summarize | awk '{ print $2 }' | xargs java -jar tools/checkstyle/checkstyle-7.1-all.jar -c tools/checkstyle/josm_checks.xml … … 21 35 * The [http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#styleguide Oracle Javadoc style guide] is used as the base guide 22 36 * {{{@since}}} is used for public classes and methods (visible to plugin developers) with the JOSM revision that introduced the element. Example: {{{@since 5408}}} 23 * {{{@since}}} is updated when a public method signature changes or if a class is renamed 37 * {{{@since}}} is updated / added when a public method signature changes or if a class is renamed. 24 38 * {{{@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. 39 * There can be multiple {{{@since}}} tags, e.g. for adding interfaces to a class. The reason for those tags should be added Example: {{{@since 12345 @FunctionalIterface was added}}} 40 * If you submit a patch and don't know the revision, add {{{@since xxx}}} any way. It can then be replaced when merging your patch. 25 41 * {{{@throws}}} is preferred to {{{@exception}}} 26 42 * 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: