Skip to content

Commit ec76720

Browse files
authored
style: move fields to top of class (#441)
* style: move fields to top of class Signed-off-by: Niels Pardon <[email protected]> * build: check PMD rule FieldDeclarationsShouldBeAtStartOfClass Signed-off-by: Niels Pardon <[email protected]> * style(examples): move fields to top of class Signed-off-by: Niels Pardon <[email protected]> --------- Signed-off-by: Niels Pardon <[email protected]>
1 parent 42bac29 commit ec76720

28 files changed

+191
-195
lines changed

buildSrc/src/main/resources/substrait-pmd.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<exclude-pattern>.*/build/generated/.*</exclude-pattern>
1212

1313
<rule ref="category/java/codestyle.xml/UnnecessaryModifier" />
14+
<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass" />
1415
<rule ref="category/java/bestpractices.xml/MissingOverride" />
1516
<rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes" />
1617
</ruleset>

core/src/main/java/io/substrait/expression/EnumArg.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
@Value.Immutable
1616
public interface EnumArg extends FunctionArg {
17+
EnumArg UNSPECIFIED_ENUM_ARG = builder().value(Optional.empty()).build();
18+
1719
Optional<String> value();
1820

1921
@Override
@@ -32,8 +34,6 @@ static EnumArg of(String value) {
3234
return builder().value(Optional.of(value)).build();
3335
}
3436

35-
EnumArg UNSPECIFIED_ENUM_ARG = builder().value(Optional.empty()).build();
36-
3737
static ImmutableEnumArg.Builder builder() {
3838
return ImmutableEnumArg.builder();
3939
}

core/src/main/java/io/substrait/expression/WindowBound.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@Value.Enclosing
66
public interface WindowBound {
77

8+
CurrentRow CURRENT_ROW = ImmutableWindowBound.CurrentRow.builder().build();
9+
Unbounded UNBOUNDED = ImmutableWindowBound.Unbounded.builder().build();
10+
811
interface WindowBoundVisitor<R, E extends Throwable> {
912
R visit(Preceding preceding);
1013

@@ -17,9 +20,6 @@ interface WindowBoundVisitor<R, E extends Throwable> {
1720

1821
<R, E extends Throwable> R accept(WindowBoundVisitor<R, E> visitor);
1922

20-
CurrentRow CURRENT_ROW = ImmutableWindowBound.CurrentRow.builder().build();
21-
Unbounded UNBOUNDED = ImmutableWindowBound.Unbounded.builder().build();
22-
2323
@Value.Immutable
2424
abstract class Preceding implements WindowBound {
2525
public abstract long offset();

core/src/main/java/io/substrait/expression/proto/ExpressionProtoConverter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,12 @@ public Expression visit(
643643

644644
public static class BoundConverter
645645
implements WindowBound.WindowBoundVisitor<Expression.WindowFunction.Bound, RuntimeException> {
646+
private static final BoundConverter TO_BOUND_VISITOR = new BoundConverter();
646647

647648
public static Expression.WindowFunction.Bound convert(WindowBound bound) {
648649
return bound.accept(TO_BOUND_VISITOR);
649650
}
650651

651-
private static final BoundConverter TO_BOUND_VISITOR = new BoundConverter();
652-
653652
private BoundConverter() {}
654653

655654
@Override

core/src/main/java/io/substrait/extendedexpression/ProtoExtendedExpressionConverter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
public class ProtoExtendedExpressionConverter {
1919
private final SimpleExtension.ExtensionCollection extensionCollection;
2020

21+
private final ProtoTypeConverter protoTypeConverter =
22+
new ProtoTypeConverter(
23+
new ExtensionCollector(), SimpleExtension.ExtensionCollection.builder().build());
24+
2125
public ProtoExtendedExpressionConverter() {
2226
this(SimpleExtension.loadDefaults());
2327
}
@@ -26,10 +30,6 @@ public ProtoExtendedExpressionConverter(SimpleExtension.ExtensionCollection exte
2630
this.extensionCollection = extensionCollection;
2731
}
2832

29-
private final ProtoTypeConverter protoTypeConverter =
30-
new ProtoTypeConverter(
31-
new ExtensionCollector(), SimpleExtension.ExtensionCollection.builder().build());
32-
3333
public ExtendedExpression from(io.substrait.proto.ExtendedExpression extendedExpression) {
3434
// fill in simple extension information through a discovery in the current proto-extended
3535
// expression

core/src/main/java/io/substrait/extension/SimpleExtension.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ default ParameterConsistency parameterConsistency() {
226226
}
227227

228228
public abstract static class Function {
229+
private final Supplier<FunctionAnchor> anchorSupplier =
230+
Util.memoize(() -> FunctionAnchor.of(uri(), key()));
231+
private final Supplier<String> keySupplier = Util.memoize(() -> constructKey(name(), args()));
232+
private final Supplier<List<Argument>> requiredArgsSupplier =
233+
Util.memoize(
234+
() -> {
235+
return args().stream().filter(Argument::required).collect(Collectors.toList());
236+
});
237+
229238
@Value.Default
230239
public String name() {
231240
// we can't use null detection here since we initially construct this with a parent name.
@@ -275,15 +284,6 @@ public FunctionAnchor getAnchor() {
275284
@JsonProperty(value = "return")
276285
public abstract TypeExpression returnType();
277286

278-
private final Supplier<FunctionAnchor> anchorSupplier =
279-
Util.memoize(() -> FunctionAnchor.of(uri(), key()));
280-
private final Supplier<String> keySupplier = Util.memoize(() -> constructKey(name(), args()));
281-
private final Supplier<List<Argument>> requiredArgsSupplier =
282-
Util.memoize(
283-
() -> {
284-
return args().stream().filter(Argument::required).collect(Collectors.toList());
285-
});
286-
287287
public static String constructKeyFromTypes(
288288
String name, List<io.substrait.type.Type> arguments) {
289289
try {
@@ -515,6 +515,9 @@ public static ImmutableSimpleExtension.WindowFunctionVariant.Builder builder() {
515515
@JsonSerialize(as = ImmutableSimpleExtension.Type.class)
516516
@Value.Immutable
517517
public abstract static class Type {
518+
private final Supplier<TypeAnchor> anchorSupplier =
519+
Util.memoize(() -> TypeAnchor.of(uri(), name()));
520+
518521
public abstract String name();
519522

520523
@JacksonInject(SimpleExtension.URI_LOCATOR_KEY)
@@ -526,9 +529,6 @@ public abstract static class Type {
526529
public TypeAnchor getAnchor() {
527530
return anchorSupplier.get();
528531
}
529-
530-
private final Supplier<TypeAnchor> anchorSupplier =
531-
Util.memoize(() -> TypeAnchor.of(uri(), name()));
532532
}
533533

534534
@JsonDeserialize(as = ImmutableSimpleExtension.ExtensionSignatures.class)
@@ -567,19 +567,6 @@ public Stream<SimpleExtension.Function> resolve(String uri) {
567567

568568
@Value.Immutable
569569
public abstract static class ExtensionCollection {
570-
571-
public abstract List<Type> types();
572-
573-
public abstract List<ScalarFunctionVariant> scalarFunctions();
574-
575-
public abstract List<AggregateFunctionVariant> aggregateFunctions();
576-
577-
public abstract List<WindowFunctionVariant> windowFunctions();
578-
579-
public static ImmutableSimpleExtension.ExtensionCollection.Builder builder() {
580-
return ImmutableSimpleExtension.ExtensionCollection.builder();
581-
}
582-
583570
private final Supplier<Set<String>> namespaceSupplier =
584571
Util.memoize(
585572
() -> {
@@ -624,6 +611,18 @@ public static ImmutableSimpleExtension.ExtensionCollection.Builder builder() {
624611
Function::getAnchor, java.util.function.Function.identity()));
625612
});
626613

614+
public abstract List<Type> types();
615+
616+
public abstract List<ScalarFunctionVariant> scalarFunctions();
617+
618+
public abstract List<AggregateFunctionVariant> aggregateFunctions();
619+
620+
public abstract List<WindowFunctionVariant> windowFunctions();
621+
622+
public static ImmutableSimpleExtension.ExtensionCollection.Builder builder() {
623+
return ImmutableSimpleExtension.ExtensionCollection.builder();
624+
}
625+
627626
public Type getType(TypeAnchor anchor) {
628627
Type type = typeLookup.get().get(anchor);
629628
if (type != null) {

core/src/main/java/io/substrait/function/TypeExpressionCreator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public TypeExpression mapE(TypeExpression key, TypeExpression value) {
8383
}
8484

8585
public static class Assign {
86+
String name;
87+
TypeExpression expr;
8688

8789
public Assign() {}
8890

@@ -91,9 +93,6 @@ public Assign(final String name, final TypeExpression expr) {
9193
this.expr = expr;
9294
}
9395

94-
String name;
95-
TypeExpression expr;
96-
9796
public String name() {
9897
return name;
9998
}

core/src/main/java/io/substrait/type/TypeCreator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public class TypeCreator {
2525
public final Type INTERVAL_YEAR;
2626
public final Type UUID;
2727

28+
private static NullableSettingTypeVisitor NULLABLE_TRUE_VISITOR =
29+
new NullableSettingTypeVisitor(true);
30+
private static NullableSettingTypeVisitor NULLABLE_FALSE_VISITOR =
31+
new NullableSettingTypeVisitor(false);
32+
2833
protected TypeCreator(boolean nullable) {
2934
this.nullable = nullable;
3035
BOOLEAN = Type.Bool.builder().nullable(nullable).build();
@@ -119,11 +124,6 @@ public static Type asNotNullable(Type type) {
119124
return type.nullable() ? type.accept(NULLABLE_FALSE_VISITOR) : type;
120125
}
121126

122-
private static NullableSettingTypeVisitor NULLABLE_TRUE_VISITOR =
123-
new NullableSettingTypeVisitor(true);
124-
private static NullableSettingTypeVisitor NULLABLE_FALSE_VISITOR =
125-
new NullableSettingTypeVisitor(false);
126-
127127
private static final class NullableSettingTypeVisitor
128128
implements TypeVisitor<Type, RuntimeException> {
129129

core/src/main/java/io/substrait/type/parser/ParseToPojo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public static TypeExpression typeExpression(
3737
}
3838

3939
public static class Visitor implements SubstraitTypeVisitor<TypeExpression> {
40+
private final VisitorType expressionType;
41+
private final String namespace;
4042

4143
public static Visitor simple(String namespace) {
4244
return new Visitor(VisitorType.SIMPLE, namespace);
@@ -50,9 +52,6 @@ public static Visitor expression(String namespace) {
5052
return new Visitor(VisitorType.EXPRESSION, namespace);
5153
}
5254

53-
private final VisitorType expressionType;
54-
private final String namespace;
55-
5655
private Visitor(VisitorType exprType, String namespace) {
5756
this.expressionType = exprType;
5857
this.namespace = namespace;

core/src/main/java/io/substrait/type/proto/ParameterizedProtoConverter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
public class ParameterizedProtoConverter
1010
extends BaseProtoConverter<ParameterizedType, ParameterizedType.IntegerOption> {
1111

12+
private static final BaseProtoTypes<ParameterizedType, ParameterizedType.IntegerOption>
13+
PARAMETERIZED_NULLABLE = new ParameterizedTypes(Type.Nullability.NULLABILITY_NULLABLE);
14+
private static final BaseProtoTypes<ParameterizedType, ParameterizedType.IntegerOption>
15+
PARAMETERIZED_REQUIRED = new ParameterizedTypes(Type.Nullability.NULLABILITY_REQUIRED);
16+
1217
public ParameterizedProtoConverter(ExtensionCollector extensionCollector) {
1318
super(extensionCollector, "Parameterized types cannot include return type expressions.");
1419
}
@@ -19,11 +24,6 @@ public BaseProtoTypes<ParameterizedType, ParameterizedType.IntegerOption> typeCo
1924
return nullable ? PARAMETERIZED_NULLABLE : PARAMETERIZED_REQUIRED;
2025
}
2126

22-
private static final BaseProtoTypes<ParameterizedType, ParameterizedType.IntegerOption>
23-
PARAMETERIZED_NULLABLE = new ParameterizedTypes(Type.Nullability.NULLABILITY_NULLABLE);
24-
private static final BaseProtoTypes<ParameterizedType, ParameterizedType.IntegerOption>
25-
PARAMETERIZED_REQUIRED = new ParameterizedTypes(Type.Nullability.NULLABILITY_REQUIRED);
26-
2727
public ParameterizedType.IntegerOption i(final TypeExpression num) {
2828
return num.accept(new IntegerVisitor());
2929
}

0 commit comments

Comments
 (0)