ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

[Refactoring] Make inner classes static

Open f-schnabel opened this issue 1 year ago • 1 comments

Purpose

A non-static inner class has a reference to its outer class, and access to the outer class' fields and methods. That class reference makes the inner class larger and could cause the outer class instance to live in memory longer than necessary.

If the reference to the outer class isn’t used, it is more efficient to make the inner class static (also called nested). If the reference is used only in the class constructor, then explicitly pass a class reference to the constructor. If the inner class is anonymous, it will also be necessary to name it.

However, while a nested/static class would be more efficient, it’s worth noting that there are semantic differences between an inner class and a nested one:

  • an inner class can only be instantiated within the context of an instance of the outer class.
  • a nested (static) class can be instantiated independently of the outer class.

https://sonarcloud.io/organizations/ballerina-platform/rules?open=java%3AS2694&q=inner+class&tab=why

Check List

  • [x] Read the Contributing Guide
  • [ ] Updated Change Log
  • [ ] Checked Tooling Support (#<Issue Number>)
  • [ ] 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

f-schnabel avatar Jun 12 '24 21:06 f-schnabel

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.30%. Comparing base (4e71d28) to head (2f331d4). Report is 396 commits behind head on master.

Files with missing lines Patch % Lines
...rinalang/codegen/BallerinaAnnotationProcessor.java 0.00% 1 Missing :warning:
...lang/repository/fs/GeneralFSPackageRepository.java 0.00% 1 Missing :warning:
...alang/compiler/semantics/analyzer/SymbolEnter.java 0.00% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #42915      +/-   ##
============================================
- Coverage     77.34%   77.30%   -0.04%     
- Complexity    58244    58532     +288     
============================================
  Files          3450     3460      +10     
  Lines        218950   220074    +1124     
  Branches      28736    28911     +175     
============================================
+ Hits         169337   170125     +788     
- Misses        40288    40544     +256     
- Partials       9325     9405      +80     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 14 '24 06:06 codecov[bot]

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[bot] avatar Jul 20 '24 19:07 github-actions[bot]

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[bot] avatar Aug 08 '24 19:08 github-actions[bot]

Remove state status

f-schnabel avatar Aug 08 '24 22:08 f-schnabel

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[bot] avatar Sep 07 '24 19:09 github-actions[bot]