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 thepropertyKey
toi18n.properties
. Also, all of theshow*()
methods in MapTool, such asshowError()
andshowWarning()
, takepropertyKeys
as well as strings -- only usepropertyKeys
!) - Use
static final String
when 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.
InterruptedException
while 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 apropertyKey
and theThrowable
object representing the exception. Note that the various "show" methods already provide logging to the.maptool/log.txt
file. - Use the language-defined static variables instead of hard-coded strings when possible. Examples include
File.separator
instead of "/" andAppActions.menuShortcut
instead of "ctrl".
There are surely others that you (the contributors) may want added and that we (the dev team) determine to be acceptable. Please speak up. :)
Most IDEs include some Source Formatting functionality and using that functionality can make following the guidelines easier. You will need to ensure that using any such functionality does follow the guidelines.
Example for Eclipse:
- Source -> Format
- Source -> Reorganize Imports
An exported set of Eclipse Preferences can be found in the GitHub repo under build-resources/eclipse
. Other IDEs/editors may be able to import those preference files. If you create one for your preferred environment, you can always create a Pull Request to submit it to the MapTool repo.
The gradle build file for MapTool includes the Spotless targets: spotlessCheck and spotlessApply. Make use of them by doing a gradlew spotlessCheck
and/or spotlessApply
prior to committing or pushing your changes. Spotless will enforce the majority of the rules but not all.