Java Code Standards
This section defines the Java coding standards for FanRuan plugin development. All plugins involving Java development must comply with these rules.
The standards are organized into the following categories:
| Category | Summary |
|---|---|
| Format Standards | Spacing, indentation, braces, method length, JSON output, string utilities |
| Logging Standards | Logging method selection, format placeholders, exception naming |
| Naming Standards | Naming conventions for classes, methods, variables, constants, and packages |
| Output Standards | Standard methods for sending data to the frontend |
| Other Standards | Constructors, collection operations, switch, access control, @Override |
| Business Code Standards | equals/hashCode, @Identifier, singletons, cross-package reference restrictions |
Maximum Parameters in Public Methods
No more than 4 parameters. Too many parameters make a method harder to understand and use (an exception applies to HTTP handler methods that include Request/Response parameters).
Control Flow Statements Must Use Braces
if, if-else, for, while, do, and switch statements must always be followed by braces {}:
// Wrong
if (statement) return;
// Correct
if (statement) {
return;
}
Class Variable Ordering
Static variables before instance variables; public โ protected โ private:
// Correct
public class Test {
public static final String AAA = "aaa";
public String myData = "data";
protected String myProtectedData = "Protected";
private String myPrivate = "Private";
}
Simplify Boolean Returns
// Wrong
if (booleanExpression) {
return true;
} else {
return false;
}
// Correct
return booleanExpression;
Wrap Binary Expressions Before Ternary Operators in Parentheses
// Wrong
return a + b > 0 ? "student" : "teacher";
// Correct
return (a + b > 0) ? "student" : "teacher";
Do Not Override a Method with Only a super Call
// Wrong (no extra logic โ equivalent to not overriding at all)
@Override
public void doSomething() {
super.doSomething();
}
Exception: classes implementing the FClone interface must override clone(). When this conflicts with the rule above, the interface requirement takes precedence.