Changes between Version 3 and Version 4 of Ja:DevelopersGuide/StyleGuide


Ignore:
Timestamp:
2018-06-10T11:15:33+02:00 (7 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Ja:DevelopersGuide/StyleGuide

    v3 v4  
    1 [[TranslatedPages(revision=21,outdated=Translation incomplete)]]
     1[[TranslatedPages(revision=34,outdated=Translation incomplete)]]
    22= 開発ガイドライン =
    33
     
    55
    66 * 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
    723 * make sure there is no trailing white space
    824 * 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}}}
    1140
    1241== How your javadoc should look like ==
    1342 * The [http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#styleguide Oracle Javadoc style guide] is used as the base guide
    1443 * {{{@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.
    1645   * {{{@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.
    1748 * {{{@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}}}
    1856
    1957=== Eclipseの設定 ===
    20 [[Image(DevelopersGuide/StyleGuide:styleguide_compiler_16.png,700px)]]
     58[[Image(wiki:DevelopersGuide/StyleGuide:styleguide_compiler_16.png,700px)]]
    2159
    22 [[Image(DevelopersGuide/StyleGuide:ss1.png,700px)]]
     60[[Image(wiki:DevelopersGuide/StyleGuide:ss1.png,700px)]]
    2361
    24 [[Image(DevelopersGuide/StyleGuide:ss2.png,700px)]]
     62[[Image(wiki:DevelopersGuide/StyleGuide:ss2.png,700px)]]
    2563
    26 [[Image(DevelopersGuide/StyleGuide:ss3.png,700px)]]
     64[[Image(wiki:DevelopersGuide/StyleGuide:ss3.png,700px)]]
    2765
    2866
    2967== 国際化 ==
    3068
    31  * make sure you use {{{tr(...)}}} for all localized strings 
    32    {{{ 
     69 * make sure you use {{{tr(...)}}} for all localized strings
     70   {{{
    3371   import import static org.openstreetmap.josm.tools.I18n.tr;
    3472
     
    3775   throw new Exception(tr("error message always in tr()"));
    3876
    39    // use tr(...) for labels, title, tooltip texts and the like 
     77   // use tr(...) for labels, title, tooltip texts and the like
    4078   //
    4179   new JLabel(tr("Label always in tr()"));
     
    5492   '''DO'''
    5593   {{{new JLabel(tr("My Label {0}",labelId));}}}
    56    
     94
    5795   Only exception: {{{+}}} can be used to break long lines of non-variable texts.
    5896
    5997 * When using apostrophe, the following rules apply:
    60    
     98
    6199   For all {{{tr}}} the apostrophe is special. (Like backslash in C)[[BR]]
    62100   It needs to be escaped by another apostrophe:
    63101
    64102   {{{new JButton(tr("Don''t press me more than {0} times!", n))}}}
     103
     104----
     105Back to [wiki:/DevelopersGuide Developers Guide]