Skip to content

Finish #123 - Fix sealed & visibility issues part2#125

Open
udlose wants to merge 8 commits intodanipen:masterfrom
udlose:fix/gethashcode-sealed-visibility-issues-part2
Open

Finish #123 - Fix sealed & visibility issues part2#125
udlose wants to merge 8 commits intodanipen:masterfrom
udlose:fix/gethashcode-sealed-visibility-issues-part2

Conversation

@udlose
Copy link
Contributor

@udlose udlose commented Mar 8, 2026

Finishes #123

This pull request introduces several improvements to encapsulation and immutability for internal classes, adds a custom benchmark configuration for memory measurement, and refactors code for clarity and correctness. The most important changes are grouped below by theme.

Benchmark enhancements

  • Added a custom benchmark configuration (CustomBenchmarksConfig) and a new memory allocation column (AllocatedBytesColumn) in BigFileTokenizationBenchmark.cs to provide more detailed memory usage reporting during benchmarks. [1] [2]

Encapsulation and immutability improvements

  • Changed multiple internal classes (AttributedScopeStack, BalancedBracketSelectors, BasicScopeAttributes, BasicScopeAttributesProvider, BeginEndRule, BeginWhileRule, CaptureRule, NameMatcher, and CompilePatternsResult) from public to internal or sealed, and made fields readonly where appropriate to improve encapsulation and immutability. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Refactoring for clarity and correctness

  • Refactored parsing logic in PList.cs to use local variable t instead of text, improved error handling for integer and float parsing, and simplified exception handling. [1] [2]
  • Fixed a bug in BasicScopeAttributesProvider where the wrong variable was used in a regex string join, now correctly joining reversedScopes.
  • Renamed method getWhileWithResolvedBackReferences to GetWhileWithResolvedBackReferences for consistency in BeginWhileRule. [1] [2]

Internal visibility for testing

  • Added InternalsVisibleTo for DynamicProxyGenAssembly2 in AssemblyInfo.cs to enable mocking and testing of internal members.

Minor improvements

  • Changed GrammarNames to a static class and its array to readonly for improved safety and clarity.

udlose added 8 commits March 8, 2026 18:07
Refactored TMModel.cs to implement the recommended Dispose pattern:
- Replaced original Dispose with public Dispose and protected virtual Dispose(bool).
- Added detailed XML documentation for disposal methods.
- Ensured managed resources are disposed only once via Interlocked.CompareExchange inside the isDisposing branch.
- Moved resource cleanup logic to managed disposal section.
- Suppressed finalization and enabled safe extension for derived classes.
- Structure allows for future unmanaged resource handling.
Strengthen encapsulation and immutability

Several classes changed from public to internal and sealed, with fields and methods updated to internal and readonly where appropriate. GrammarNames made static; SupportedGrammars is now readonly. These changes improve code safety and clarify usage boundaries.
Introduced CustomBenchmarksConfig to display memory usage in kilobytes for more precise measurement in benchmark summaries. Applied this config to BigFileTokenizationBenchmark via attribute. Cleaned up using statements and improved formatting.
Introduced AllocatedBytesColumn for detailed memory usage reporting in benchmark results. Updated CustomBenchmarksConfig to include this column and set summary style to kilobytes and current culture. Minor formatting and console message improvements.
Refactored variable naming for clarity. Replaced exception-based parsing with TryParse for integers and floats, providing more accurate error messages. Corrected grammar in integer error message.
Added InternalsVisibleTo for DynamicProxyGenAssembly2 in AssemblyInfo.cs, allowing internal members to be accessed by mocking frameworks such as Moq during unit testing. Existing access for TextMateSharp.Tests remains unchanged.
Apply signature parity with tm4e upstream per https://github.com/eclipse-tm4e/tm4e/tree/main/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/rule

Restrict visibility and improve encapsulation

Refactored multiple classes to be internal and/or sealed, limiting access to within the assembly. Updated constructors, properties, and methods for better encapsulation and immutability. Renamed methods to follow C# conventions. Made static fields in RuleId readonly. Converted ThemeReader to a static class. Removed ICompilePatternsResult.cs and merged its contents. These changes clarify API boundaries and enhance maintainability.
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.

1 participant