public static ImplementInterfaceCodeAction CreateImplementRemainingExplicitlyCodeAction(
     AbstractImplementInterfaceService service,
     Document document,
     ImplementTypeGenerationOptions options,
     State state)
 {
     return(new ImplementInterfaceCodeAction(service, document, options, state, explicitly: true, abstractly: false, onlyRemaining: true, throughMember: null));
 }
 internal ImplementInterfaceCodeAction(
     AbstractImplementInterfaceService service,
     Document document,
     ImplementTypeGenerationOptions options,
     State state,
     bool explicitly,
     bool abstractly,
     bool onlyRemaining,
     ISymbol throughMember)
 {
     Service         = service;
     Document        = document;
     State           = state;
     Options         = options;
     Abstractly      = abstractly;
     _onlyRemaining  = onlyRemaining;
     Explicitly      = explicitly;
     ThroughMember   = throughMember;
     _equivalenceKey = ComputeEquivalenceKey(state, explicitly, abstractly, onlyRemaining, throughMember, GetType().FullName);
 }
Пример #3
0
        public async Task <Document> ImplementInterfaceAsync(Document document, ImplementTypeGenerationOptions options, SyntaxNode node, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.Refactoring_ImplementInterface, cancellationToken))
            {
                var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

                var state = State.Generate(this, document, model, node, cancellationToken);
                if (state == null)
                {
                    return(document);
                }

                // While implementing just one default action, like in the case of pressing enter after interface name in VB,
                // choose to implement with the dispose pattern as that's the Dev12 behavior.
                var action = ShouldImplementDisposePattern(state, explicitly: false)
                    ? ImplementInterfaceWithDisposePatternCodeAction.CreateImplementWithDisposePatternCodeAction(this, document, options, state)
                    : ImplementInterfaceCodeAction.CreateImplementCodeAction(this, document, options, state);

                return(await action.GetUpdatedDocumentAsync(cancellationToken).ConfigureAwait(false));
            }
        }
Пример #4
0
        private IEnumerable <CodeAction> GetActions(Document document, ImplementTypeGenerationOptions options, State state)
        {
            if (state == null)
            {
                yield break;
            }

            if (state.MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented.Length > 0)
            {
                var totalMemberCount        = 0;
                var inaccessibleMemberCount = 0;

                foreach (var(_, members) in state.MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented)
                {
                    foreach (var member in members)
                    {
                        totalMemberCount++;

                        if (AccessibilityHelper.IsLessAccessibleThan(member, state.ClassOrStructType))
                        {
                            inaccessibleMemberCount++;
                        }
                    }
                }

                // If all members to implement are inaccessible, then "Implement interface" codeaction
                // will be the same as "Implement interface explicitly", so there is no point in having both of them
                if (totalMemberCount != inaccessibleMemberCount)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementCodeAction(this, document, options, state));
                }

                if (ShouldImplementDisposePattern(state, explicitly: false))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementWithDisposePatternCodeAction(this, document, options, state));
                }

                var delegatableMembers = GetDelegatableMembers(state);
                foreach (var member in delegatableMembers)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementThroughMemberCodeAction(this, document, options, state, member));
                }

                if (state.ClassOrStructType.IsAbstract)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementAbstractlyCodeAction(this, document, options, state));
                }
            }

            if (state.MembersWithoutExplicitImplementation.Length > 0)
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementExplicitlyCodeAction(this, document, options, state));

                if (ShouldImplementDisposePattern(state, explicitly: true))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementExplicitlyWithDisposePatternCodeAction(this, document, options, state));
                }
            }

            if (AnyImplementedImplicitly(state))
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementRemainingExplicitlyCodeAction(this, document, options, state));
            }
        }
Пример #5
0
        public ImmutableArray <CodeAction> GetCodeActions(Document document, ImplementTypeGenerationOptions options, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken)
        {
            var state = State.Generate(this, document, model, node, cancellationToken);

            return(GetActions(document, options, state).ToImmutableArray());
        }