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

[Refactoring] Replace normal switches with enhanced switch expressions #42955

Merged
merged 1 commit into from
Sep 14, 2024

Conversation

Shadow-Devil
Copy link
Contributor

Purpose

Many existing switch statements are essentially simulations of switch expressions, where each arm either assigns to a common target variable or returns a value. Expressing this as a statement is roundabout, repetitive, and error-prone.

Java 14 added support for switch expressions, which provide more succinct and less error-prone version of switch.
See also: https://sonarcloud.io/organizations/ballerina-platform/rules?languages=java&open=java%3AS5194&q=switch+expression
Partly also fixes: https://sonarcloud.io/organizations/ballerina-platform/rules?open=java%3AS6208&rule_key=java%3AS6208

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

Copy link

codecov bot commented Jun 19, 2024

Codecov Report

Attention: Patch coverage is 70.18662% with 655 lines in your changes missing coverage. Please review.

Project coverage is 77.36%. Comparing base (39c7a3d) to head (1ca947f).
Report is 64 commits behind head on master.

Files with missing lines Patch % Lines
...a/io/ballerina/runtime/internal/TypeConverter.java 32.69% 28 Missing and 7 partials ⚠️
...llerinalang/compiler/semantics/analyzer/Types.java 67.67% 14 Missing and 18 partials ⚠️
...lerina/compiler/api/impl/symbols/TypesFactory.java 31.81% 27 Missing and 3 partials ⚠️
...mpiler/semantics/analyzer/ConstantTypeChecker.java 37.20% 21 Missing and 6 partials ⚠️
...va/org/ballerinalang/formatter/core/Formatter.java 18.18% 26 Missing and 1 partial ⚠️
...ava/io/ballerina/runtime/internal/TypeChecker.java 82.06% 7 Missing and 19 partials ⚠️
...java/io/ballerina/runtime/api/utils/TypeUtils.java 8.00% 22 Missing and 1 partial ⚠️
...rinalang/compiler/semantics/model/SymbolTable.java 52.38% 18 Missing and 2 partials ⚠️
...llerina/compiler/internal/parser/SyntaxErrors.java 89.41% 13 Missing and 5 partials ⚠️
...g/wso2/ballerinalang/compiler/desugar/Desugar.java 60.46% 13 Missing and 4 partials ⚠️
... and 85 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #42955      +/-   ##
============================================
+ Coverage     77.34%   77.36%   +0.02%     
- Complexity    58589    58594       +5     
============================================
  Files          3460     3460              
  Lines        219867   219650     -217     
  Branches      28917    28918       +1     
============================================
- Hits         170050   169937     -113     
+ Misses        40399    40300      -99     
+ Partials       9418     9413       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shadow-Devil Shadow-Devil changed the title Replace normal switches with enhanced switch expressions [Refactoring] Replace normal switches with enhanced switch expressions Jul 3, 2024
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added Stale and removed Stale labels Jul 19, 2024
Copy link

github-actions bot commented Aug 7, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Aug 7, 2024
@Shadow-Devil
Copy link
Contributor Author

Remove stale status

@github-actions github-actions bot removed the Stale label Aug 10, 2024
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@Shadow-Devil
Copy link
Contributor Author

Shadow-Devil commented Sep 13, 2024

Failing testcase in Ballerina Distribution:

Output Verification 'time-formatting-and-parsing'
Failed due to output did not match. Line 3: Civil string representation: 2021-04-12T23:20:50.520+05:30
WARNING: This command is deprecated and will be removed in a future release. Use `bal new .` instead
Created new package 'test'.
Building example 'time-formatting-and-parsing'
Compiling source
	runner/test:0.1.0

Running Tests

	test

	testFunc: has failed.
error: there are test failures


		[fail] testFunc:

		    error {ballerina/test:0}TestError ("Assertion Failed!
			 
			expected: 'Civil string representation: 2021-04-12T17:50:50.520Z'
			actual	: 'Civil string representation: 2021-04-12T23:20:50.520+05:30'
			 
			Diff	:
			
			--- actual
			+++ expected 
			 
			 @@ -1,1 +1,1 @@ 
			 
			 -Civil string representation: 2021-04-12T23:20:50.520+05:30
			+Civil string representation: 2021-04-12T17:50:50.520Z
			")
				callableName: createBallerinaError moduleName: ballerina.test.0 fileName: assert.bal lineNumber: 41
				callableName: assertEquals moduleName: ballerina.test.0 fileName: assert.bal lineNumber: 109
				callableName: testFunc moduleName: runner.test$test.0.tests.time_formatting_and_parsing_test fileName: tests/time_formatting_and_parsing_test.bal lineNumber: 79
				callableName: testFunc$lambda0$ moduleName: runner.test$test.0.tests.test_execute-generated_1 fileName: tests/test_execute-generated_1.bal lineNumber: 4
			


		0 passing
		1 failing
		0 skipped

		Test execution time : 0.147s

I dont think this is related to this PR

@gimantha gimantha merged commit f270bdf into ballerina-platform:master Sep 14, 2024
17 of 18 checks passed
@Shadow-Devil Shadow-Devil deleted the enhanced-switch branch September 14, 2024 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants