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

Consolidate Signature and Member content generation code #5419

Merged
merged 6 commits into from
Mar 24, 2020

Conversation

BZngr
Copy link
Contributor

@BZngr BZngr commented Mar 8, 2020

Refactorings that generate code (e.g., ImplementInterface, EncapsulateField, and others) have a common interest in creating blocks of code for Properties and Methods based on, or using, existing Member and Variable declarations. This common interest has resulted in similar (if not identical) code showing up in multiple refactorings and in UI elements as well (e.g., just to display the signature). So, as I was pondering how to avoid duplicating the code in a fourth location (MoveMemberRefactoring), it seemed that it was time to attempt a PR that would consolidate this functionality in a central location.

In its current state, the PR introduces this functionality through DeclarationExtension and ModuleBodyElementDeclarationExtension methods in the Rubberduck.Refactorings.Common folder. This approach/location can certainly be changed. The primary goal was to corral this capability into a single place where it could be easily reused by the refactorings. And, I figured it would be easier for all to evaluate where this code belongs if there was a working version from which to start.

Notes:

  1. The PR primarily affects the EncapsulateFieldRefactoring and AddInterfaceImplementationsRefactoringAction refactorings.

  2. There is a UI converter class DeclarationToMemberSignatureConverter which also duplicates the code to build a full member signature from the Declaration. It seems that the UI project does not have access to the Rubberduck.Refactorings.Common namespace(?) - so for now, it is left as-is.
    Update: I am unable to find any references to DeclarationToMemberSignatureConverter in the xaml files (or anywhere else). I think the file/class can be deleted.

  3. The functions in DeclarationExtensions.cs for this PR begin with FieldToPropertyBlock near the end of the file. There are other functions starting at the top of the file that were moved there from EncapulateFieldRefactoring. A few are relevant to support this PR. I've moved the others there in preparation for the MoveMemberRefactoring.

Adds method and property generation code to extension classes.   Allows
removal two files/classes and duplicate function/content in
EncapsulateField refactoring and ImplementInterface refactoring.  Moves
Encapsulate Field Declaration Extensions to RefactoringCommon folder to
share content with ImplementInterface.
@codecov
Copy link

codecov bot commented Mar 8, 2020

Codecov Report

Merging #5419 into next will decrease coverage by 0.02%.
The diff coverage is 81.05%.

@@            Coverage Diff             @@
##             next    #5419      +/-   ##
==========================================
- Coverage   61.52%   61.49%   -0.02%     
==========================================
  Files        1195     1194       -1     
  Lines       40572    40595      +23     
  Branches     8643     8666      +23     
==========================================
+ Hits        24958    24963       +5     
- Misses      13788    13789       +1     
- Partials     1826     1843      +17
Impacted Files Coverage Δ
.../Validations/EncapsulateFieldConflictFinderBase.cs 90.59% <ø> (ø) ⬆️
...eField/EncapsulationStrategies/UseBackingFields.cs 100% <ø> (ø) ⬆️
...ulateField/Extensions/IModuleRewriterExtensions.cs 45.83% <ø> (ø) ⬆️
...Field/FieldCandidates/EncapsulateFieldCandidate.cs 87.1% <100%> (+0.14%) ⬆️
...eField/FieldCandidates/UserDefinedTypeCandidate.cs 86.15% <100%> (+0.22%) ⬆️
.../FieldCandidates/UserDefinedTypeMemberCandidate.cs 79.8% <100%> (+0.21%) ⬆️
...rduck.Refactorings/Common/DeclarationExtensions.cs 58.06% <58.06%> (ø)
...k.Refactorings/ExtractInterface/InterfaceMember.cs 73.33% <75%> (-14.47%) ⬇️
...capsulationStrategies/ConvertFieldsToUDTMembers.cs 90% <76.92%> (-5%) ⬇️
...s/Common/ModuleBodyElementDeclarationExtensions.cs 82.35% <82.35%> (ø)
... and 5 more

@BZngr BZngr added the PR-Status: Conflicting PR can't be merged as it stands, conflicts must be resolved by the author. label Mar 9, 2020
@BZngr
Copy link
Contributor Author

BZngr commented Mar 9, 2020

Merging this PR should wait for the same reason(s) as given for #5420

@BZngr BZngr added Status: Blocked by other issue and removed PR-Status: Conflicting PR can't be merged as it stands, conflicts must be resolved by the author. labels Mar 9, 2020
@retailcoder
Copy link
Member

It's been 14 days, I'm not going to hold up merging this PR - I'll just deal with any conflicts on my side =)

/// <param name="content"></param>
/// <param name="parameterIdentifier"></param>
/// <returns></returns>
public static string FieldToPropertyBlock(this Declaration variable, DeclarationType letSetGetType, string propertyIdentifier, string accessibility = null, string content = null, string parameterIdentifier = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this type of work really belongs here as an extension method to Declaration... would the target object not always be a VariableDeclaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - should have been VariableDeclaration. Once the dust settles surrounding EncapsulateField - I'll put together a PR for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this does not belong into an extension at all. Instead, I thing there should be some ICodeBulder to build the standard code for declarations. That would make the standard easily testable and would also allow to specify different versions of the code by injecting another implementation.
The same applies to the extensions for module body elements, even more, actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MDoerner I was certain using an extension was a debatable location for this functionality - and I was hoping for either confirmation or some guidance to move it elsewhere - thanks. As I understand your comment, the ICodeBuilder instance would be delivered by CW?

As per my earlier comment, I was planning to wait for the coming EncapsulateField PR before introducing anything further changes.

@retailcoder retailcoder merged commit e56bb88 into rubberduck-vba:next Mar 24, 2020
@@ -1779,4 +1779,7 @@ Import aborted.</value>
<data name="EncapsulateField_WrapFieldsInPrivateType" xml:space="preserve">
<value>Wrap Fields in Private Type</value>
</data>
<data name="ImplementInterface_TODO" xml:space="preserve">
<value>'TODO implement interface member</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong here; it is not related to the UI.

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.

None yet

3 participants