Skip to content

Conversation

@jonathanpeppers
Copy link
Member

In the same fashion that 7a96efe refactored fields, this commit aims at
refactoring methods. I also added various unit tests to add coverage
around the new TestMethod support type.

Refactoring in generator:

  • Dropped the method "support" classes in favor of extension methods
    from ManagedExtensions and XmlExtensions. These existed due to C#
    single-inheritance getting in the way of the relationship between
    methods, properties, constructors, etc.
  • Moved methods from Method and MethodBase to CodeGenerator and
    renamed them from Generate* to WriteMethod*. I tried to not modify
    the code in these methods other than to add a parameter for the incoming
    method.
  • Output of generator should remain the same.
  • *Method classes are now alot closer to POCOs

Other changes:

  • Dropped usage of ContextTypes stack in XamarinAndroidCodeGenerator
  • Added a base test class for JavaInteropCodeGeneratorTests and
    XamarinAndroidCodeGeneratorTests because there were several tests that
    were completely identical (due to CodeGenerator base class)
  • Changed StreamWriter to TextWriter as needed
  • Now up to 88 tests! Most new ones are ~1ms

Future plans (trying to keep this commit of reasonable size):

In the same fashion that 7a96efe refactored fields, this commit aims at
refactoring methods. I also added various unit tests to add coverage
around the new `TestMethod` support type.

Refactoring in generator:
- Dropped the method "support" classes in favor of extension methods
from `ManagedExtensions` and `XmlExtensions`. These existed due to C#
single-inheritance getting in the way of the relationship between
methods, properties, constructors, etc.
- Moved methods from `Method` and `MethodBase` to `CodeGenerator` and
renamed them from `Generate*` to `WriteMethod*`. I tried to not modify
the code in these methods other than to add a parameter for the incoming
method.
- Output of generator *should* remain the same.
- `*Method` classes are now alot closer to POCOs

Other changes:
- Dropped usage of `ContextTypes` stack in `XamarinAndroidCodeGenerator`
- Added a base test class for `JavaInteropCodeGeneratorTests` and
`XamarinAndroidCodeGeneratorTests` because there were several tests that
were completely identical (due to `CodeGenerator` base class)
- Changed `StreamWriter` to `TextWriter` as needed
- Now up to 88 tests! Most new ones are ~1ms

Future plans (trying to keep this commit of reasonable size):
- The `CodeGenerator` base class is starting to get large. As
refactoring continues, I would like to make a class for
`FieldGenerator`, `MethodGenerator`, etc. and `CodeGenerator` would get
properties named `Fields` and `Methods` that would return these child
generator classes
- This is exactly what grendel did with his prototype, so we should
adopt this improvement:
https://github.com/grendello/JavaBindingGenerator/blob/fb8864d1842bdf0b8d45eb04b89ef2bd57de0014/src/Java.Interop.Bindings/Compiler/MethodCodeGenerator.cs
@jonathanpeppers jonathanpeppers force-pushed the generator-methods-refactor branch from cfa862d to fa7078e Compare April 16, 2018 16:20
@jonpryor jonpryor merged commit c084a83 into dotnet:master Apr 17, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants