Skip to content

Latest commit

 

History

History
70 lines (44 loc) · 2.52 KB

File metadata and controls

70 lines (44 loc) · 2.52 KB

Java code style

We use Google Style conventions with 4 spaces (instead of 2) for indentation. Other extensions and changes are described below.

Table of contents

Javadocs

See Javadoc page for details.

Using var keyword

Use the var keyword everywhere it's possible. It makes the code more readable and concise.

Dealing with nulls

@ParametersAreNonnullByDefault

This annotation must be set in package-info.java of all the packages.

Use @Nullable when required

Everything which is not annotated with @Nullable is not null by default.

Using checkNotNull()

Non-nullity of parameters should be checked in public and protected methods to catch incorrect use of the API as early as possible.

If a method accepts two or more parameters that cannot be null, we call Preconditions.checkNotNull() in the order of parameters. checkNotNull() must be statically imported:

import static com.google.common.base.Preconditions.checkNotNull;

protected void dispatch(Message message, CommandContext context) {
    checkNotNull(message);
    checkNotNull(context);
    ...
}

Returning null

If a method returns a single object, it should never return null. Use Optional if the method can return nothing.

Returning collections

If a method returns a collection, it should never return null. Instead, it should return an empty immutable collection.

Suppressing unchecked warnings using annotation

Suppress unchecked warnings via standardized @SuppressWarnings annotation only instead of IntelliJ IDEA-specific //noinspection suppression style. We want to keep code compliant with any tool, not just with IntelliJ IDEA.

Always comment on why a specific suppression is valid

Please do. Framework users and developers need to know the reason why a warning was suppressed.