Code Style and Guidelines
February 26, 2025 ยท View on GitHub
Please observe the following rules when working on MapTool. Failure to do so will typically result in your pull request being rejected.
- The Google Java Style Guide is incorporated by reference. Submitted code shall follow those guidelines unless modified by one or more of the following rules.
- Use parameter names different from member field names so that disambiguation using this is not necessary. This rule is relaxed for simple short methods (e.g. setters).
- Avoid hard-coded strings in code when a property from an external file can be used. In MapTool's
case, this means calling
I18N.getText(propertyKey)and adding a definition for thepropertyKeytoi18n.properties. Also, all of theshow*()methods in MapTool, such asshowError()andshowWarning(), takepropertyKeysas well as strings -- only usepropertyKeys!) - Use
static final Stringwhen hard-coded strings are appropriate. Examples include resources that are embedded inside the MapTool JAR, such as unknown.png -- the question mark image. - Report to the user all exceptions that are true errors.
InterruptedExceptionwhile waiting for a timer can be ignored, for example. But all other errors should be handled by callingMapTool.showError(propertyKey)or similar and passing both apropertyKeyand theThrowableobject representing the exception. Note that the various "show" methods already provide logging to the.maptool/log.txtfile. - Use the language-defined static variables instead of hard-coded strings when possible. Examples
include
File.separatorinstead of "/" andAppActions.menuShortcutinstead of "ctrl".
Formatting Source Files
Formatting with Spotless
The gradle build file for MapTool includes the Spotless targets: spotlessCheck and spotlessApply.
Make use of them by doing a gradlew spotlessCheck and/or gradlew spotlessApply prior to
committing or pushing your changes. Spotless will enforce the majority of the rules but not all.