private async Task <bool> TryInitializeAsync( TService service, SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken) { if (service.IsIdentifierNameGeneration(node)) { if (!TryInitializeIdentifierName(service, document, (TSimpleNameSyntax)node, cancellationToken)) { return(false); } } else { return(false); } // Ok. It either didn't bind to any symbols, or it bound to a symbol but with // errors. In the former case we definitely want to offer to generate a field. In // the latter case, we want to generate a field *unless* there's an existing member // with the same name. Note: it's ok if there's an existing field with the same // name. var existingMembers = TypeToGenerateIn.GetMembers(IdentifierToken.ValueText); if (existingMembers.Any()) { // TODO: Code coverage There was an existing member that the new member would // clash with. return(false); } cancellationToken.ThrowIfCancellationRequested(); TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; if (!service.ValidateTypeToGenerateIn( document.Project.Solution, TypeToGenerateIn, true, EnumType)) { return(false); } return(CodeGenerator.CanAdd(document.Project.Solution, TypeToGenerateIn, cancellationToken)); }
protected async Task <bool> TryFinishInitializingStateAsync(TService service, SemanticDocument document, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; if (TypeToGenerateIn.IsErrorType()) { return(false); } if (!service.ValidateTypeToGenerateIn(document.Project.Solution, TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) { return(false); } if (!CodeGenerator.CanAdd(document.Project.Solution, TypeToGenerateIn, cancellationToken)) { return(false); } // Ok. It either didn't bind to any symbols, or it bound to a symbol but with // errors. In the former case we definitely want to offer to generate a method. In // the latter case, we want to generate a method *unless* there's an existing method // with the same signature. var existingMethods = TypeToGenerateIn.GetMembers(IdentifierToken.ValueText) .OfType <IMethodSymbol>(); var destinationProvider = document.Project.Solution.Workspace.Services.GetLanguageServices(TypeToGenerateIn.Language); var syntaxFacts = destinationProvider.GetService <ISyntaxFactsService>(); var syntaxFactory = destinationProvider.GetService <SyntaxGenerator>(); IsContainedInUnsafeType = service.ContainingTypesOrSelfHasUnsafeKeyword(TypeToGenerateIn); var generatedMethod = SignatureInfo.GenerateMethod(syntaxFactory, false, cancellationToken); return(!existingMethods.Any(m => SignatureComparer.Instance.HaveSameSignature(m, generatedMethod, caseSensitive: syntaxFacts.IsCaseSensitive, compareParameterName: true, isParameterCaseSensitive: syntaxFacts.IsCaseSensitive))); }
private async Task <bool> TryInitializeAsync( TService service, SemanticDocument document, SyntaxNode node, CancellationToken cancellationToken) { if (service.IsIdentifierNameGeneration(node)) { // Cases that we deal with currently: // // 1) expr.Goo // 2) expr->Goo // 3) Goo if (!TryInitializeSimpleName(service, document, (TSimpleNameSyntax)node, cancellationToken)) { return(false); } } else if (service.IsExplicitInterfaceGeneration(node)) { // 4) bool IGoo.NewProp if (!TryInitializeExplicitInterface(service, document, node, cancellationToken)) { return(false); } } else { return(false); } // Ok. It either didn't bind to any symbols, or it bound to a symbol but with // errors. In the former case we definitely want to offer to generate a field. In // the latter case, we want to generate a field *unless* there's an existing member // with the same name. Note: it's ok if there's a method with the same name. var existingMembers = TypeToGenerateIn.GetMembers(IdentifierToken.ValueText) .Where(m => m.Kind != SymbolKind.Method); if (existingMembers.Any()) { // TODO: Code coverage // There was an existing method that the new method would clash with. return(false); } if (cancellationToken.IsCancellationRequested) { return(false); } TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; if (!service.ValidateTypeToGenerateIn( document.Project.Solution, TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) { return(false); } IsContainedInUnsafeType = service.ContainingTypesOrSelfHasUnsafeKeyword(TypeToGenerateIn); return(CanGenerateLocal() || CodeGenerator.CanAdd(document.Project.Solution, TypeToGenerateIn, cancellationToken)); }