Skip to content

[4.35+] Refactor ConditionalExpression and SwitchExpression by making them implement INumericChoiceContext #3225

@srikanth-sankaran

Description

@srikanth-sankaran

JLS 5.6 classifies SwitchExpression and ConditionalExpression as constructs in numeric choice context (when all result expressions are numeric) The computation of result type, their polyness or not all are all similarly defined. Essentially a switch is multi-way-conditional.

As such there is enormous room for code sharing by hoisting contract and default behavior to a new interface type say INumericChoiceContext that both switch expressions and ternary operators implement.

Comparing org.eclipse.jdt.internal.compiler.ast.SwitchExpression.resolveType(BlockScope) and org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(BlockScope) it is possible for the latter to be as minimal as the former.

Metadata

Metadata

Labels

ModernizationHigh value non-critical path refactoring efforts

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions