inferred / FreeBuilder

Automatic generation of the Builder pattern for Java
Apache License 2.0
838 stars 101 forks source link

Automatically detect method parameter names #371

Closed alicederyn closed 5 years ago

alicederyn commented 5 years ago

Block.methodBody creates a temporary MethodScope containing the method's parameter names, allowing code to create temporary variables and reference fields without risking a clash. However, nothing checks the passed in parameter list, leaving it vulnerable to refactoring and copy/paste errors.

Instead, enhance SourceParser to pull out parameters from method declarations directly, calling back into CompilationUnitBuilder to create the MethodScope.

Block is now redundant and has been deleted, leaving the Property classes a little tidier. SourceBuilder.subScope is similarly gone.

Note: As part of this work, I used the two different ways of obtaining the same information (source parsing and methodBlock calls) as a consistency check, and discovered a copy/paste error in SortedSetProperty, so I feel rather vindicated.