Improvements from feedback on case/when classes.

This commit is contained in:
Nick Rolfe
2021-01-07 17:48:51 +00:00
parent 36c7d3fe5b
commit 9a71bdc993
2 changed files with 12 additions and 8 deletions

View File

@@ -265,10 +265,10 @@ class CaseExpr extends ControlExpr, @case__ {
final Expr getABranch() { result = this.getBranch(_) }
/** Gets a `when` branch of this case expression. */
final WhenExpr getAWhenBranch() { result = range.getAWhenBranch() }
final WhenExpr getAWhenBranch() { result = getABranch() }
/** Gets the `else` branch of this case expression, if any. */
final ExprSequence getElseBranch() { result = range.getElseBranch() }
final ExprSequence getElseBranch() { result = getABranch() }
/**
* Gets the number of branches of this case expression.
@@ -280,7 +280,7 @@ class CaseExpr extends ControlExpr, @case__ {
* A `when` branch of a `case` expression.
* ```rb
* case
* when a>b then x
* when a > b then x
* end
* ```
*/
@@ -295,7 +295,15 @@ class WhenExpr extends Expr, @when {
final ExprSequence getBody() { result = range.getBody() }
/**
* Gets the `n`th pattern (or condition) in this case-when expression.
* Gets the `n`th pattern (or condition) in this case-when expression. In the
* following example, the 0th pattern is `x`, the 1st pattern is `y`, and the
* 2nd pattern is `z`.
* ```rb
* case foo
* when x, y, z
* puts 'x/y/z'
* end
* ```
*/
final Expr getPattern(int n) { result = range.getPattern(n) }

View File

@@ -126,10 +126,6 @@ module CaseExpr {
final Expr getValue() { result = generated.getValue() }
final Expr getBranch(int n) { result = generated.getChild(n) }
final WhenExpr getAWhenBranch() { result = this.getBranch(_) }
final ExprSequence getElseBranch() { result = this.getBranch(_) }
}
}