Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[style](fe) code correct rules and name rules #9670

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-support/IntelliJ-code-format.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ under the License.
<option name="THROWS_KEYWORD_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
<option name="BINARY_OPERATION_WRAP" value="1" />
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
<option name="TERNARY_OPERATION_WRAP" value="1" />
<option name="FOR_STATEMENT_WRAP" value="1" />
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
Expand All @@ -92,4 +93,3 @@ under the License.
</arrangement>
</codeStyleSettings>
</code_scheme>

40 changes: 31 additions & 9 deletions fe/check/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ under the License.
<property name="file" value="fe/check/checkstyle/suppressions.xml"/>
<property name="optional" value="true"/>
</module>
<module name="SuppressWithPlainTextCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE OFF"/>
<property name="onCommentFormat" value="CHECKSTYLE ON"/>
</module>

<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
Expand Down Expand Up @@ -69,6 +73,10 @@ under the License.
</module>

<module name="TreeWalker">
<!-- filter -->
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="CHECKSTYLE IGNORE THIS LINE"/>
</module>
<!-- Annotations -->
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/>
Expand Down Expand Up @@ -100,6 +108,7 @@ under the License.
<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
<property name="severity" value="error"/>
</module>
<module name="LeftCurly">
<property name="tokens"
Expand Down Expand Up @@ -135,17 +144,23 @@ under the License.

<!-- Coding -->
<module name="DeclarationOrder"/>
<module name="FallThrough"/>
<module name="FallThrough">
<property name="severity" value="error"/>
</module>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="MissingSwitchDefault"/>
<module name="MissingSwitchDefault">
<property name="severity" value="error"/>
</module>
<module name="MultipleVariableDeclarations"/>
<module name="NoFinalizer"/>
<module name="NoFinalizer">
<property name="severity" value="error"/>
</module>
<module name="OneStatementPerLine"/>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="StringLiteralEquality"/>
Expand Down Expand Up @@ -249,20 +264,22 @@ under the License.
<!-- Naming Conventions -->
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="3"/>
<property name="allowedAbbreviationLength" value="4"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF,
RECORD_COMPONENT_DEF"/>
<property name="severity" value="error"/>
</module>
<module name="CatchParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="format" value="^([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*$)"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/>
</module>
Expand All @@ -273,22 +290,26 @@ under the License.
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LambdaParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="format" value="^([a-z][a-zA-Z0-9]*)?$"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="format" value="^([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="format" value="^([a-z][a-zA-Z0-9]*)?$"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
Expand All @@ -305,7 +326,8 @@ under the License.
value="Package name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="format" value="^([a-z0-9][a-zA-Z0-9]*)?$"/>
<property name="severity" value="error"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void add(int value) {
}

public void add(long value) {
switch (bitmapType) {
switch (bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
singleValue = value;
bitmapType = SINGLE_VALUE;
Expand Down Expand Up @@ -95,7 +95,7 @@ public boolean contains(long value) {
}

public long cardinality() {
switch (bitmapType) {
switch (bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
return 0;
case SINGLE_VALUE:
Expand All @@ -107,7 +107,7 @@ public long cardinality() {
}

public void serialize(DataOutput output) throws IOException {
switch (bitmapType) {
switch (bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
output.writeByte(EMPTY);
break;
Expand Down Expand Up @@ -155,12 +155,12 @@ public void deserialize(DataInput input) throws IOException {

// In-place bitwise AND (intersection) operation. The current bitmap is modified.
public void and(BitmapValue other) {
switch (other.bitmapType) {
switch (other.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
clear();
break;
case SINGLE_VALUE:
switch (this.bitmapType) {
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
Expand All @@ -180,7 +180,7 @@ public void and(BitmapValue other) {
}
break;
case BITMAP_VALUE:
switch (this.bitmapType) {
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
Expand All @@ -199,14 +199,14 @@ public void and(BitmapValue other) {

// In-place bitwise OR (union) operation. The current bitmap is modified.
public void or(BitmapValue other) {
switch (other.bitmapType) {
switch (other.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
add(other.singleValue);
break;
case BITMAP_VALUE:
switch (this.bitmapType) {
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
// deep copy the bitmap in case of multi-rollups update the bitmap repeatedly
this.bitmap = new Roaring64Map();
Expand All @@ -228,7 +228,7 @@ public void or(BitmapValue other) {
}

public void remove(long value){
switch (this.bitmapType){
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
Expand All @@ -245,14 +245,14 @@ public void remove(long value){

//In-place bitwise ANDNOT (difference) operation. The current bitmap is modified
public void not(BitmapValue other) {
switch (other.bitmapType) {
switch (other.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
remove(other.singleValue);
break;
case BITMAP_VALUE:
switch (this.bitmapType) {
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
Expand All @@ -271,11 +271,11 @@ public void not(BitmapValue other) {

//In-place bitwise XOR (symmetric difference) operation. The current bitmap is modified
public void xor(BitmapValue other) {
switch (other.bitmapType) {
switch (other.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
switch (this.bitmapType){
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
add(other.singleValue);
break;
Expand All @@ -297,7 +297,7 @@ public void xor(BitmapValue other) {
}
break;
case BITMAP_VALUE:
switch (this.bitmapType) {
switch (this.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
this.bitmap = other.bitmap;
this.bitmapType = BITMAP_VALUE;
Expand Down Expand Up @@ -325,7 +325,7 @@ public boolean equals(BitmapValue other) {
if (this.bitmapType != other.bitmapType) {
return false;
}
switch (other.bitmapType) {
switch (other.bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
ret = true;
break;
Expand All @@ -348,7 +348,7 @@ public boolean equals(BitmapValue other) {
// TODO(wb): keep getSizeInBytes consistent with be and refactor roaring
public long getSizeInBytes() {
long size = 0;
switch (bitmapType) {
switch (bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
size = 1;
break;
Expand All @@ -368,7 +368,7 @@ public long getSizeInBytes() {
@Override
public String toString() {
String toStringStr = "{}";
switch (bitmapType) {
switch (bitmapType) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case EMPTY:
break;
case SINGLE_VALUE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Codec {
// not support encode negative value now
public static void encodeVarint64(long source, DataOutput out) throws IOException {
assert source >= 0;
short B = 128;
short B = 128; // CHECKSTYLE IGNORE THIS LINE

while (source >= B) {
out.write((int) (source & (B - 1) | B));
Expand All @@ -39,7 +39,7 @@ public static void encodeVarint64(long source, DataOutput out) throws IOExceptio
public static long decodeVarint64(DataInput in) throws IOException {
long result = 0;
int shift = 0;
short B = 128;
short B = 128; // CHECKSTYLE IGNORE THIS LINE

while (true) {
int oneByte = in.readUnsignedByte();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public final int read() {
}

public final int read(byte[] b, int off, int len) {
if (pos >= count)
if (pos >= count) {
return -1;
}

if ((pos + len) > count) {
len = (count - pos);
Expand Down
28 changes: 14 additions & 14 deletions fe/fe-common/src/main/java/org/apache/doris/common/io/Hll.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void updateWithHash(Object value) {
}

public void update(long hashValue) {
switch (this.type) {
switch (this.type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case HLL_DATA_EMPTY:
hashSet.add(hashValue);
type = HLL_DATA_EXPLICIT;
Expand All @@ -128,7 +128,7 @@ public void update(long hashValue) {
}
convertExplicitToRegister();
type = HLL_DATA_FULL;
case HLL_DATA_SPARSE:
case HLL_DATA_SPARSE: // CHECKSTYLE IGNORE THIS LINE: fall through
case HLL_DATA_FULL:
updateRegisters(hashValue);
break;
Expand All @@ -139,10 +139,10 @@ public void merge(Hll other) {
if (other.type == HLL_DATA_EMPTY) {
return;
}
switch (this.type) {
switch (this.type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case HLL_DATA_EMPTY:
this.type = other.type;
switch (other.type) {
switch (other.type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case HLL_DATA_EXPLICIT:
this.hashSet.addAll(other.hashSet);
break;
Expand All @@ -154,7 +154,7 @@ public void merge(Hll other) {
}
break;
case HLL_DATA_EXPLICIT:
switch (other.type) {
switch (other.type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case HLL_DATA_EXPLICIT:
this.hashSet.addAll(other.hashSet);
if (this.hashSet.size() > HLL_EXPLICLIT_INT64_NUM) {
Expand All @@ -172,7 +172,7 @@ public void merge(Hll other) {
break;
case HLL_DATA_SPARSE:
case HLL_DATA_FULL:
switch (other.type) {
switch (other.type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case HLL_DATA_EXPLICIT:
for (long value : other.hashSet) {
update(value);
Expand All @@ -188,7 +188,7 @@ public void merge(Hll other) {
}

public void serialize(DataOutput output) throws IOException {
switch (type) {
switch (type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case HLL_DATA_EMPTY:
output.writeByte(type);
break;
Expand Down Expand Up @@ -363,20 +363,20 @@ public static long hash64(final byte[] data, final int length, final int seed) {
}

final int index = (nblocks << 3);
switch (length - index) {
switch (length - index) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
case 7:
h ^= ((long) data[index + 6] & 0xff) << 48;
case 6:
case 6: // CHECKSTYLE IGNORE THIS LINE: fall through
h ^= ((long) data[index + 5] & 0xff) << 40;
case 5:
case 5: // CHECKSTYLE IGNORE THIS LINE: fall through
h ^= ((long) data[index + 4] & 0xff) << 32;
case 4:
case 4: // CHECKSTYLE IGNORE THIS LINE: fall through
h ^= ((long) data[index + 3] & 0xff) << 24;
case 3:
case 3: // CHECKSTYLE IGNORE THIS LINE: fall through
h ^= ((long) data[index + 2] & 0xff) << 16;
case 2:
case 2: // CHECKSTYLE IGNORE THIS LINE: fall through
h ^= ((long) data[index + 1] & 0xff) << 8;
case 1:
case 1: // CHECKSTYLE IGNORE THIS LINE: fall through
h ^= ((long) data[index] & 0xff);
h *= M64;
}
Expand Down
Loading