-
Notifications
You must be signed in to change notification settings - Fork 8
Coding Conventions
The Aura code style is based on the Java style from the google-styleguide project.
In order to improve readability, we introduce the following set of amendments on top of google-styleguide.
The maximum line with is increased to 150 characters. This fits well in modern widescreens even if the sidepanel of your IDE is visible.
The default indent is set to 4 spaces. This increases readability in of branched code typical for system programming.
Parameter lists on constructor and method declarations are aligned to the opening brace if they don't fit on the line.
Example:
public class Foo {
public void bar(String someArgument,
Integer anotherArgument,
Float yetAnotherArgument) {
...
}
}
Type lists after throws, extends and implements clauses are wrapped if necessary (all but the first element), and indented by 8 spaces.
Example:
public class Foo extends SomeOtherClass implements
InterfaceOne,
InterfaceTwo {
public void bar(String someArgument) throws
IllegalArgumentException,
IndexOutOfBoundsException,
IOException,
FileNotFoundException {
...
}
}
Enum constants are always indented by 4 spaces.
Example:
public class Foo {
public Enum Bar {
SOME_VALUE(1, 2),
SOME_THER_VALUE(3, 4),
YET_ANOTHER_VALUE(5, 6)
}
}
Arguments in method and constructor invocations are wrapped if necessary and indented on the column of the first argument.
Example:
public class Foo {
public void Foo() {
super("Some Value",
"Some Other Value",
"Yet Another Value");
}
public String bar(Some a, String someArgument, someOtherArgument) {
return a.someMethod(someArgument,
someOtherArgument);
}
}
Chained method invocations, typical for fluent APIs are wrapped if necessary and indented on the column of the first method call.
Example:
public class Foo {
public String bar() {
return a.someMethod()
.someOtherMethod()
.yetAnotherMethod();
}
}
Classes must implement the following section of five basic sections. Each section starts with a block comment. Empty sections can be omitted. Declaration of elements inside a section should be ordered on modifier: public, protected, private.
public class Baz {
// ---------------------------------------------------
// Constants.
// ---------------------------------------------------
...
// ---------------------------------------------------
// Fields.
// ---------------------------------------------------
...
// ---------------------------------------------------
// Constructors.
// ---------------------------------------------------
...
// ---------------------------------------------------
// Methods.
// ---------------------------------------------------
...
// ---------------------------------------------------
// Inner Classes.
// ---------------------------------------------------
...
}
A code block between the special comments @formatter:off
and @formatter:on
is not formatted.
Example:
public class Foo {
public String bar() {
// @formatter:off
return custom
.formatted()
.code();
// @formatter:on
}
}
An code style profile for Еclipse following the above guidelines can be found in the aura-build-tools
package.
The format is configured with the maven-java-formatter-plugin to be applied automatically on each maven build. You can also apply the format manually from the console using the dedicated Maven goal:
mvn java-formatter:format
In order to use the Aura code format from your IDE, follow the instructions below.
- Go to Eclise | Windows | Preferences | Java | Code Style | Formatter.
- Import the
formatter.xml
profile and configure it for theAura
project.
Tested with Eclipse 4.2 (Juno).
- Install the Eclipse Code Formatter plugin.
- Go to Settings | Eclipse Code Formatter and poin to the
formatter.xml
in the Eclipse Java Formatter config file field.
Tested with IntelliJ 13.0.2.
- Home
-
System Design
- System Configuration
- [Feature Ideas](Future Features)
- [Distributed Environment](Distributed Environment)
- Development
-
Testing
- [Wally-cluster Usage](Wally Cluster)
- Remote Monitoring
- Remote Debugging