As far as possible these conventions are checked by the checkstyle plugin.
- If not explicitely otherwise specified apply the Java coding conventions (http://www.oracle.com/technetwork/java/codeconventions-150003.pdf).
- The line length mentioned in section 4.1 is limited to 120 characters.
- When chaining commands every command is in its own line like:
someObject.commandA() .commandB() .commandC() .commandD();
- When looking at a JavaFX property x the order of methods should be:
xProperty()getXProperty()setXProperty(...)
- If the property should be readonly omit
setXProperty(...)and make surexProperty()returns a readonly property. - Define all properties of classes serving as instance variables where you declared them and make them final.
- When accessing a property prefer calling
getXProperty()instead of directly accessing it. - When accessing a property within a constructor prefer direct access.
- An actual controller should not have any subclasses unless related to a wizardable window. If so it should have one subclass which has no subclasses itself.
- Declare controller without subclasses as final.
- Associate controller within FXML files.
- A utility class has to be in a package under
bayern.steinbrecher.green2.utility - It has to have a name like
SomeUtility. - It has to be a
final class. - It has to define a
privateconstructor like:private SomeUtility(){ throw new UnsupportedOperationException("Construction of an object is prohibited."); }
- Each class needing a logger has to define it as
private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName());. - This is the only logger to be used by that class.
- If it is an enum use
Logger.getLogger(MyClass.class.getName()).
- Every package name has to start with
bayern.steinbrecher.green2 - All packages have to define a
package-info.java- If a certain package is part of projects
package-info.javahas to be identical.
- If a certain package is part of projects
- There have to be two fxml files:
SomeClassWizard.fxmlwhich contains the actual content and data of the dialog such that it can be used in a wizard.SomeClassParent.fxmlwhich usesfx:includeto includeSomeClassWizard.fxmland adds controls like finish or cancel to control the dialog without using it with a wizard.
- There have to be two controller:
SomeClassControllerextendingWizardableControllerand providing all functions and properties needed bySomeClassWizard.fxml. This controller also contains methods for requesting the actual results of the window.- Package private class
SomeClassControllerParentextendingSomeClassControllerand adding the functions needed for the controls ofSomeClassParent.fxml.
- There has to be at most one view which references
SomeClassControllerfor requesting results and loads eitherSomeClassParent.fxmlorSomeClassWizard.fxml. - It may be neccessary for
SomeClassControllerParentto add a listener to some property ofSomeClassControllere.g. to add submit-on-enter functionality. Realize by defining a protected method calledaddListenerToSomeProperty(ChangeListener<...>). Call this method the default constructor of the subclass.
- Prefer to bind properties of elements defined in FXML files using FXML instead of binding them within its controller.
- If a CSS file to include is in the same package include it within FXML.
Place CSS files containing rules for specific classes or dialogs in the same package as the class they are refered to.
- Add the license to every file before the package declaration.
- Do not add a license to
package-info.javafiles.
- Avoid the var keyword in general
varis allowed in direct definitions of variables likevar someObject = new SomeObject()- If the type is generic and
varis used on the left side the right side should not use the diamond operator<>but specify the generic type explitely.
Avoid default methods as much as possible.
An allowed usecase could be one-line setter or getter.
Default methods may not play well with FXML. (See SO Thread)
- When overriding initializable(...) of any class call
super.initializable(...).
- Prefer
Stream#forEach(...)overIterable#forEach(...).
- Avoid
!important. - Omit any unit when specifying lengths or sizes of zero.
- Document every non-
privateclass, method, field,... - When referencing any method, interface, class, etc. use
{@link ...}. - When a class or interface is solely referenced within JavaDocs use full qualified name instead of an import to avoid "unused" imports.
- Document packages using a
package-info.java. When multiple modules contain the same package add only one package description. If they depend on each other prefer the module they depend on.