Skip to content

Commit

Permalink
[v1] Refactor AstNode getChildren() method
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Dec 9, 2024
1 parent 7b818d6 commit c1db6ff
Show file tree
Hide file tree
Showing 99 changed files with 284 additions and 355 deletions.
257 changes: 128 additions & 129 deletions partiql-ast/api/partiql-ast.api

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/AstNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.List;
import java.util.Random;

/**
Expand All @@ -14,7 +14,7 @@ public abstract class AstNode {
public String tag = "Ast-" + String.format("%06x", new Random().nextInt());

@NotNull
public abstract Collection<AstNode> children();
public abstract List<AstNode> getChildren();

public abstract <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx);
}
2 changes: 1 addition & 1 deletion partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
// Also include docs on how a library user could create a new variant for sum types and which methods to override
public abstract class AstVisitor<R, C> {
public R defaultVisit(AstNode node, C ctx) {
for (AstNode child : node.children()) {
for (AstNode child : node.getChildren()) {
child.accept(this, ctx);
}
return defaultReturn(node, ctx);
Expand Down
5 changes: 2 additions & 3 deletions partiql-ast/src/main/java/org/partiql/ast/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.partiql.ast.ddl.AttributeConstraint;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@EqualsAndHashCode(callSuper = false)
Expand Down Expand Up @@ -56,7 +55,7 @@ public StructField(

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
ArrayList<AstNode> kids = new ArrayList<>();
kids.add(name);
kids.add(type);
Expand Down Expand Up @@ -722,7 +721,7 @@ public List<StructField> getFields() {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
if (name != null) {
kids.add(name);
Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/DatetimeField.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
* TODO docs, equals, hashcode
Expand Down Expand Up @@ -118,7 +118,7 @@ public static int[] codes() {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return Collections.emptyList();
}

Expand Down
3 changes: 1 addition & 2 deletions partiql-ast/src/main/java/org/partiql/ast/Exclude.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -23,7 +22,7 @@ public Exclude(@NotNull List<ExcludePath> excludePaths) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>(excludePaths);
}

Expand Down
3 changes: 1 addition & 2 deletions partiql-ast/src/main/java/org/partiql/ast/ExcludePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.partiql.ast.expr.ExprVarRef;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -28,7 +27,7 @@ public ExcludePath(@NotNull ExprVarRef root, @NotNull List<ExcludeStep> excludeS

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(root);
kids.addAll(excludeSteps);
Expand Down
9 changes: 4 additions & 5 deletions partiql-ast/src/main/java/org/partiql/ast/ExcludeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -27,7 +26,7 @@ public StructField(@NotNull Identifier symbol) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(symbol);
return kids;
Expand All @@ -53,7 +52,7 @@ public CollIndex(int index) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>();
}

Expand All @@ -73,7 +72,7 @@ public StructWildcard() {}

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>();
}

Expand All @@ -93,7 +92,7 @@ public CollWildcard() {}

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>();
}

Expand Down
3 changes: 1 addition & 2 deletions partiql-ast/src/main/java/org/partiql/ast/Explain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand All @@ -28,7 +27,7 @@ public Explain(@NotNull Map<String, Literal> options, @NotNull Statement stateme

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(statement);
return kids;
Expand Down
3 changes: 1 addition & 2 deletions partiql-ast/src/main/java/org/partiql/ast/From.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -23,7 +22,7 @@ public From(@NotNull List<FromTableRef> tableRefs) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>(tableRefs);
}

Expand Down
3 changes: 1 addition & 2 deletions partiql-ast/src/main/java/org/partiql/ast/FromExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.partiql.ast.expr.Expr;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -38,7 +37,7 @@ public FromExpr(@NotNull Expr expr, @NotNull FromType fromType, @Nullable Identi

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(expr);
if (asAlias != null) kids.add(asAlias);
Expand Down
3 changes: 1 addition & 2 deletions partiql-ast/src/main/java/org/partiql/ast/FromJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.partiql.ast.expr.Expr;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -37,7 +36,7 @@ public FromJoin(@NotNull FromTableRef lhs, @NotNull FromTableRef rhs, @Nullable

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(lhs);
kids.add(rhs);
Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/FromType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
* TODO docs, equals, hashcode
Expand Down Expand Up @@ -70,7 +70,7 @@ public static int[] codes() {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return Collections.emptyList();
}

Expand Down
5 changes: 2 additions & 3 deletions partiql-ast/src/main/java/org/partiql/ast/GroupBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.partiql.ast.expr.Expr;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -33,7 +32,7 @@ public GroupBy(@NotNull GroupByStrategy strategy, @NotNull List<Key> keys, @Null

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>(keys);
if (asAlias != null) {
kids.add(asAlias);
Expand Down Expand Up @@ -64,7 +63,7 @@ public Key(@NotNull Expr expr, @Nullable Identifier asAlias) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(expr);
if (asAlias != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
* TODO docs, equals, hashcode
Expand Down Expand Up @@ -70,7 +70,7 @@ public static int[] codes() {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return Collections.emptyList();
}

Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/Identifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* TODO docs, equals, hashcode
Expand All @@ -25,7 +25,7 @@ public Identifier(@NotNull String symbol, boolean isDelimited) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -28,7 +27,7 @@ public IdentifierChain(@NotNull Identifier root, @Nullable IdentifierChain next)

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(root);
if (next != null) {
Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/JoinType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
* TODO docs, equals, hashcode
Expand Down Expand Up @@ -126,7 +126,7 @@ public static int[] codes() {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return Collections.emptyList();
}

Expand Down
5 changes: 2 additions & 3 deletions partiql-ast/src/main/java/org/partiql/ast/Let.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.partiql.ast.expr.Expr;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -24,7 +23,7 @@ public Let(@NotNull List<Binding> bindings) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return new ArrayList<>(bindings);
}

Expand All @@ -51,7 +50,7 @@ public Binding(@NotNull Expr expr, @NotNull Identifier asAlias) {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
List<AstNode> kids = new ArrayList<>();
kids.add(expr);
kids.add(asAlias);
Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/Literal.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -103,7 +103,7 @@ public String name() {

@Override
@NotNull
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return Collections.emptyList();
}

Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/Nulls.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
* TODO docs, equals, hashcode
Expand Down Expand Up @@ -71,7 +71,7 @@ public static int[] codes() {

@NotNull
@Override
public Collection<AstNode> children() {
public List<AstNode> getChildren() {
return Collections.emptyList();
}

Expand Down
Loading

0 comments on commit c1db6ff

Please sign in to comment.