Changes between Version 3 and Version 4 of Ja:DevelopersGuide/StyleGuide
- Timestamp:
- 2018-06-10T11:15:33+02:00 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ja:DevelopersGuide/StyleGuide
v3 v4 1 [[TranslatedPages(revision= 21,outdated=Translation incomplete)]]1 [[TranslatedPages(revision=34,outdated=Translation incomplete)]] 2 2 = 開発ガイドライン = 3 3 … … 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 * JOSM uses 4 characters indentation and no tab stops 10 * Document your code '''thoroughly'''. Many people will thank you :) 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"). 26 * add curly brackets for each {{{if}}}, unless it is followed by {{{return}}} (or maybe {{{throw}}}) 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: 28 {{{ 29 #!bash 30 # make sure build2 dir exists, if it does not run 'ant checkstyle-compile' before 31 32 svn diff --summarize | awk '{ print $2 }' | grep "^[a-z]" | xargs \ 33 java -classpath "build2:tools/checkstyle/checkstyle-all.jar" \ 34 com.puppycrawl.tools.checkstyle.Main -c tools/checkstyle/josm_checks.xml 35 # or 36 git diff --name-only | xargs \ 37 java -classpath "build2:tools/checkstyle/checkstyle-all.jar" \ 38 com.puppycrawl.tools.checkstyle.Main -c tools/checkstyle/josm_checks.xml 39 }}} 11 40 12 41 == How your javadoc should look like == 13 42 * The [http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#styleguide Oracle Javadoc style guide] is used as the base guide 14 43 * {{{@since}}} is used for public classes and methods (visible to plugin developers) with the JOSM revision that introduced the element. Example: {{{@since 5408}}} 15 * {{{@since}}} is updated when a public method signature changes or if a class is renamed 44 * {{{@since}}} is updated / added when a public method signature changes or if a class is renamed. 16 45 * {{{@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. 46 * 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}}} 47 * 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. 17 48 * {{{@throws}}} is preferred to {{{@exception}}} 49 * 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: 50 51 {{{ 52 svn diff --summarize | awk '{ print $2 }' | xargs javadoc -d javadoc 53 # or 54 git diff --name-only | xargs javadoc -d javadoc 55 }}} 18 56 19 57 === Eclipseの設定 === 20 [[Image(DevelopersGuide/StyleGuide:styleguide_compiler_16.png,700px)]] 58 [[Image(wiki:DevelopersGuide/StyleGuide:styleguide_compiler_16.png,700px)]] 21 59 22 [[Image(DevelopersGuide/StyleGuide:ss1.png,700px)]] 60 [[Image(wiki:DevelopersGuide/StyleGuide:ss1.png,700px)]] 23 61 24 [[Image(DevelopersGuide/StyleGuide:ss2.png,700px)]] 62 [[Image(wiki:DevelopersGuide/StyleGuide:ss2.png,700px)]] 25 63 26 [[Image(DevelopersGuide/StyleGuide:ss3.png,700px)]] 64 [[Image(wiki:DevelopersGuide/StyleGuide:ss3.png,700px)]] 27 65 28 66 29 67 == 国際化 == 30 68 31 * make sure you use {{{tr(...)}}} for all localized strings 32 {{{ 69 * make sure you use {{{tr(...)}}} for all localized strings 70 {{{ 33 71 import import static org.openstreetmap.josm.tools.I18n.tr; 34 72 … … 37 75 throw new Exception(tr("error message always in tr()")); 38 76 39 // use tr(...) for labels, title, tooltip texts and the like 77 // use tr(...) for labels, title, tooltip texts and the like 40 78 // 41 79 new JLabel(tr("Label always in tr()")); … … 54 92 '''DO''' 55 93 {{{new JLabel(tr("My Label {0}",labelId));}}} 56 94 57 95 Only exception: {{{+}}} can be used to break long lines of non-variable texts. 58 96 59 97 * When using apostrophe, the following rules apply: 60 98 61 99 For all {{{tr}}} the apostrophe is special. (Like backslash in C)[[BR]] 62 100 It needs to be escaped by another apostrophe: 63 101 64 102 {{{new JButton(tr("Don''t press me more than {0} times!", n))}}} 103 104 ---- 105 Back to [wiki:/DevelopersGuide Developers Guide]