private SourceConstructorSymbol( SourceMemberContainerTypeSymbol containingType, Location location, ConstructorDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), syntax.Body.GetReferenceOrNull(), ImmutableArray.Create(location)) { bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, location, diagnostics, out modifierErrors); this.flags = MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExtensionMethod: false); var bodyOpt = syntax.Body; if (bodyOpt != null) { if (IsExtern) { diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); } } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (!modifierErrors) { this.CheckModifiers(methodKind, location, diagnostics); } }
public SignatureOnlyMethodSymbol( string name, TypeSymbol containingType, MethodKind methodKind, Cci.CallingConvention callingConvention, ImmutableArray<TypeParameterSymbol> typeParameters, ImmutableArray<ParameterSymbol> parameters, RefKind refKind, TypeSymbol returnType, ImmutableArray<CustomModifier> returnTypeCustomModifiers, ushort countOfCustomModifiersPrecedingByRef, ImmutableArray<MethodSymbol> explicitInterfaceImplementations) { _callingConvention = callingConvention; _typeParameters = typeParameters; _refKind = refKind; _returnType = returnType; _returnTypeCustomModifiers = returnTypeCustomModifiers; _countOfCustomModifiersPrecedingByRef = countOfCustomModifiersPrecedingByRef; _parameters = parameters; _explicitInterfaceImplementations = explicitInterfaceImplementations.NullToEmpty(); _containingType = containingType; _methodKind = methodKind; _name = name; }
public CodeGenerationMethodSymbol( INamedTypeSymbol containingType, IList<AttributeData> attributes, Accessibility declaredAccessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, bool returnsByRef, IMethodSymbol explicitInterfaceSymbolOpt, string name, IList<ITypeParameterSymbol> typeParameters, IList<IParameterSymbol> parameters, IList<AttributeData> returnTypeAttributes, MethodKind methodKind = MethodKind.Ordinary) : base(containingType, attributes, declaredAccessibility, modifiers, name, returnTypeAttributes) { _returnType = returnType; _returnsByRef = returnsByRef; _typeParameters = typeParameters.AsImmutableOrEmpty(); _parameters = parameters.AsImmutableOrEmpty(); _explicitInterfaceImplementations = explicitInterfaceSymbolOpt == null ? ImmutableArray.Create<IMethodSymbol>() : ImmutableArray.Create(explicitInterfaceSymbolOpt); this.OriginalDefinition = this; _methodKind = methodKind; }
private SourceMemberMethodSymbol( NamedTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, MethodDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), // Prefer a block body if both exist syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), location) { _name = name; _explicitInterfaceType = explicitInterfaceType; SyntaxTokenList modifiers = syntax.Modifiers; // The following two values are used to compute and store the initial value of the flags // However, these two components are placeholders; the correct value will be // computed lazily later and then the flags will be fixed up. const bool returnsVoid = false; var firstParam = syntax.ParameterList.Parameters.FirstOrDefault(); bool isExtensionMethod = firstParam != null && !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword); bool modifierErrors; var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors); var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers); _typeParameters = (syntax.Arity == 0) ? ImmutableArray<TypeParameterSymbol>.Empty : MakeTypeParameters(syntax, diagnostics); bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; if (hasBlockBody || _isExpressionBodied) { CheckModifiersForBody(location, diagnostics); } _refKind = syntax.RefKeyword.Kind().GetRefKind(); var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } }
protected SourceDelegateMethodSymbol( SourceMemberContainerTypeSymbol delegateType, TypeSymbol returnType, DelegateDeclarationSyntax syntax, MethodKind methodKind, DeclarationModifiers declarationModifiers) : base(delegateType, syntax.GetReference(), bodySyntaxReferenceOpt: null, location: syntax.Identifier.GetLocation()) { _returnType = returnType; this.MakeFlags(methodKind, declarationModifiers, _returnType.SpecialType == SpecialType.System_Void, isExtensionMethod: false); }
private CodeAccessorFunction(CodeModelState state, AbstractCodeMember parent, MethodKind kind) : base(state, parent.FileCodeModel) { Debug.Assert(kind == MethodKind.EventAdd || kind == MethodKind.EventRaise || kind == MethodKind.EventRemove || kind == MethodKind.PropertyGet || kind == MethodKind.PropertySet); _parentHandle = new ParentHandle<AbstractCodeMember>(parent); _kind = kind; }
internal static Match<SyntaxNode> GetMethodMatch(string src1, string src2, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { var m1 = MakeMethodBody(src1, options, kind); var m2 = MakeMethodBody(src2, options, kind); var diagnostics = new List<RudeEditDiagnostic>(); var match = Analyzer.ComputeBodyMatch(m1, m2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint); bool needsSyntaxMap = oldHasStateMachineSuspensionPoint && newHasStateMachineSuspensionPoint; Assert.Equal(kind != MethodKind.Regular && kind != MethodKind.ConstructorWithParameters, needsSyntaxMap); if (kind == MethodKind.Regular || kind == MethodKind.ConstructorWithParameters) { Assert.Empty(diagnostics); } return match; }
protected DelegateMethodSymbol( SourceNamedTypeSymbol containingType, DelegateDeclarationSyntax syntax, MethodKind methodKind, DeclarationModifiers declarationModifiers, Binder binder, DiagnosticBag diagnostics) : base(containingType, binder.GetSyntaxReference(syntax), blockSyntaxReference: null, location: binder.Location(syntax.Identifier)) { this.parameters = MakeParameters(binder, syntax, diagnostics); this.returnType = MakeReturnType(binder, syntax, diagnostics); this.flags = MakeFlags(methodKind, declarationModifiers, this.returnType.SpecialType == SpecialType.System_Void, isExtensionMethod: false); var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, this.locations[0]); } }
public SignatureOnlyMethodSymbol( string name, TypeSymbol containingType, MethodKind methodKind, Cci.CallingConvention callingConvention, ImmutableArray<TypeParameterSymbol> typeParameters, ImmutableArray<ParameterSymbol> parameters, TypeSymbol returnType, ImmutableArray<CustomModifier> returnTypeCustomModifiers, ImmutableArray<MethodSymbol> explicitInterfaceImplementations) { this.callingConvention = callingConvention; this.typeParameters = typeParameters; this.returnType = returnType; this.returnTypeCustomModifiers = returnTypeCustomModifiers; this.parameters = parameters; this.explicitInterfaceImplementations = explicitInterfaceImplementations.NullToEmpty(); this.containingType = containingType; this.methodKind = methodKind; this.name = name; }
private SourceConstructorSymbol( SourceMemberContainerTypeSymbol containingType, Location location, ConstructorDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), ImmutableArray.Create(location)) { bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, location, diagnostics, out modifierErrors); this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExtensionMethod: false); bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; if (IsExtern) { if (methodKind == MethodKind.Constructor && syntax.Initializer != null) { diagnostics.Add(ErrorCode.ERR_ExternHasConstructorInitializer, location, this); } if (hasBlockBody || _isExpressionBodied) { diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); } } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (!modifierErrors) { this.CheckModifiers(methodKind, location, diagnostics); } }
protected DelegateMethodSymbol( SourceNamedTypeSymbol containingType, string name, DelegateDeclarationSyntax syntax, MethodKind methodKind, DeclarationModifiers declarationModifiers, Binder binder, DiagnosticBag diagnostics, CancellationToken cancellationToken) : base(containingType, name, binder.GetSyntaxReference(syntax), blockSyntax: null, location: binder.Location(syntax.Identifier)) { var location = this.locations[0]; bool isExtensionMethod; this.parameters = MakeParameters(binder, syntax, out isExtensionMethod, out this.isVararg, diagnostics, cancellationToken); this.returnType = MakeReturnType(binder, syntax, diagnostics); this.flags = MakeFlags(methodKind, declarationModifiers, IsVoidType(this.returnType), isExtensionMethod: isExtensionMethod); var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } }
protected virtual bool IsMethodKindValid(MethodKind methodKind) { return(methodKind != MethodKind.PropertyGet && methodKind != MethodKind.PropertySet); }
internal static EnvDTE.CodeFunction Create(CodeModelState state, AbstractCodeMember parent, MethodKind kind) { var newElement = new CodeAccessorFunction(state, parent, kind); return (EnvDTE.CodeFunction)ComAggregate.CreateAggregatedObject(newElement); }
internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType, IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList<ITypeParameterSymbol> typeParameters, IList<IParameterSymbol> parameters, IList<SyntaxNode> statements = null, IList<SyntaxNode> handlesExpressions = null, IList<AttributeData> returnTypeAttributes = null, MethodKind methodKind = MethodKind.Ordinary, bool returnsByRef = false) { var result = new CodeGenerationMethodSymbol(containingType, attributes, accessibility, modifiers, returnType, returnsByRef, explicitInterfaceSymbol, name, typeParameters, parameters, returnTypeAttributes, methodKind); CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions); return result; }
public static bool IsPropertyAccessor(this MethodKind kind) { return(kind == MethodKind.PropertyGet || kind == MethodKind.PropertySet); }
protected static IEnumerable <IMethodSymbol> GetMethodsOrderedByLocation(INamedTypeSymbol type, string path, MethodKind kind = MethodKind.Ordinary) => type.GetMembers() .OfType <IMethodSymbol>() .Where(_ => _.MethodKind == kind) .Where(_ => _.Locations.First(__ => __.IsInSource).GetLineSpan().Path == path) .OrderBy(_ => _.Locations.First(__ => __.IsInSource).GetLineSpan().StartLinePosition);
protected virtual bool IsOnCodeBlockSupported(SymbolKind symbolKind, MethodKind methodKind, bool returnsVoid) { return(true); }
private (DeclarationModifiers mods, bool hasExplicitAccessMod) MakeModifiers(MethodKind methodKind, bool isPartial, bool hasBody, Location location, DiagnosticBag diagnostics) { bool isInterface = this.ContainingType.IsInterface; bool isExplicitInterfaceImplementation = methodKind == MethodKind.ExplicitInterfaceImplementation; var defaultAccess = isInterface && isPartial && !isExplicitInterfaceImplementation ? DeclarationModifiers.Public : DeclarationModifiers.Private; // Check that the set of modifiers is allowed var allowedModifiers = DeclarationModifiers.Partial | DeclarationModifiers.Unsafe; var defaultInterfaceImplementationModifiers = DeclarationModifiers.None; if (!isExplicitInterfaceImplementation) { allowedModifiers |= DeclarationModifiers.New | DeclarationModifiers.Sealed | DeclarationModifiers.Abstract | DeclarationModifiers.Static | DeclarationModifiers.Virtual | DeclarationModifiers.AccessibilityMask; if (!isInterface) { allowedModifiers |= DeclarationModifiers.Override; } else { // This is needed to make sure we can detect 'public' modifier specified explicitly and // check it against language version below. defaultAccess = DeclarationModifiers.None; defaultInterfaceImplementationModifiers |= DeclarationModifiers.Sealed | DeclarationModifiers.Abstract | DeclarationModifiers.Static | DeclarationModifiers.Virtual | DeclarationModifiers.Extern | DeclarationModifiers.Async | DeclarationModifiers.Partial | DeclarationModifiers.AccessibilityMask; } } else if (isInterface) { Debug.Assert(isExplicitInterfaceImplementation); allowedModifiers |= DeclarationModifiers.Abstract; } allowedModifiers |= DeclarationModifiers.Extern | DeclarationModifiers.Async; if (ContainingType.IsStructType()) { allowedModifiers |= DeclarationModifiers.ReadOnly; } // In order to detect whether explicit accessibility mods were provided, we pass the default value // for 'defaultAccess' and manually add in the 'defaultAccess' flags after the call. bool hasExplicitAccessMod; DeclarationModifiers mods = MakeDeclarationModifiers(allowedModifiers, diagnostics); if ((mods & DeclarationModifiers.AccessibilityMask) == 0) { hasExplicitAccessMod = false; mods |= defaultAccess; } else { hasExplicitAccessMod = true; } this.CheckUnsafeModifier(mods, diagnostics); ModifierUtils.ReportDefaultInterfaceImplementationModifiers(hasBody, mods, defaultInterfaceImplementationModifiers, location, diagnostics); mods = AddImpliedModifiers(mods, isInterface, methodKind, hasBody); return(mods, hasExplicitAccessMod); }
public SymbolKindViewModel(MethodKind methodKind, string name, SymbolSpecification specification) { _methodKind = methodKind; Name = name; IsChecked = specification.ApplicableSymbolKindList.Any(k => k.MethodKind == methodKind); }
private static DeclarationModifiers AddImpliedModifiers(DeclarationModifiers mods, bool containingTypeIsInterface, MethodKind methodKind) { // Let's overwrite modifiers for interface and explicit interface implementation methods with what they are supposed to be. // Proper errors must have been reported by now. if (containingTypeIsInterface) { mods = (mods & ~DeclarationModifiers.AccessibilityMask) | DeclarationModifiers.Public | DeclarationModifiers.Abstract; } else if (methodKind == MethodKind.ExplicitInterfaceImplementation) { mods = (mods & ~DeclarationModifiers.AccessibilityMask) | DeclarationModifiers.Private; } return(mods); }
protected SourceUserDefinedOperatorSymbolBase( MethodKind methodKind, string name, SourceMemberContainerTypeSymbol containingType, Location location, CSharpSyntaxNode syntax, DeclarationModifiers declarationModifiers, bool hasBody, bool isExpressionBodied, bool isIterator, bool isNullableAnalysisEnabled, BindingDiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), location, isIterator: isIterator) { _name = name; _isExpressionBodied = isExpressionBodied; this.CheckUnsafeModifier(declarationModifiers, diagnostics); // We will bind the formal parameters and the return type lazily. For now, // assume that the return type is non-void; when we do the lazy initialization // of the parameters and return type we will update the flag if necessary. this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (this.ContainingType.IsInterface && (methodKind == MethodKind.Conversion || name == WellKnownMemberNames.EqualityOperatorName || name == WellKnownMemberNames.InequalityOperatorName)) { // If we have a conversion or equality/inequality operator in an interface, we already have reported that fact as // an error. No need to cascade the error further. return; } if (this.ContainingType.IsStatic) { // Similarly if we're in a static class, though we have not reported it yet. // CS0715: '{0}': static classes cannot contain user-defined operators diagnostics.Add(ErrorCode.ERR_OperatorInStaticClass, location, this); return; } // SPEC: An operator declaration must include both a public and a // SPEC: static modifier if (this.DeclaredAccessibility != Accessibility.Public || !this.IsStatic) { // CS0558: User-defined operator '...' must be declared static and public diagnostics.Add(ErrorCode.ERR_OperatorsMustBeStatic, this.Locations[0], this); } // SPEC: Because an external operator provides no actual implementation, // SPEC: its operator body consists of a semicolon. For expression-bodied // SPEC: operators, the body is an expression. For all other operators, // SPEC: the operator body consists of a block... if (hasBody && IsExtern) { diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); } else if (!hasBody && !IsExtern && !IsAbstract && !IsPartial) { // Do not report that the body is missing if the operator is marked as // partial or abstract; we will already have given an error for that so // there's no need to "cascade" the error. diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } // SPEC: It is an error for the same modifier to appear multiple times in an // SPEC: operator declaration. var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers, this, isExplicitInterfaceImplementation: false); if (info != null) { diagnostics.Add(info, location); } }
private SourceOrdinaryMethodSymbol( NamedTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, MethodDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), // Prefer a block body if both exist syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), location) { _name = name; _explicitInterfaceType = explicitInterfaceType; SyntaxTokenList modifiers = syntax.Modifiers; // The following two values are used to compute and store the initial value of the flags // However, these two components are placeholders; the correct value will be // computed lazily later and then the flags will be fixed up. const bool returnsVoid = false; var firstParam = syntax.ParameterList.Parameters.FirstOrDefault(); bool isExtensionMethod = firstParam != null && !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword); bool modifierErrors; var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors); var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers); if (syntax.Arity == 0) { _typeParameters = ImmutableArray <TypeParameterSymbol> .Empty; ReportErrorIfHasConstraints(syntax.ConstraintClauses, diagnostics); } else { _typeParameters = MakeTypeParameters(syntax, diagnostics); } bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; syntax.ReturnType.SkipRef(out _refKind); if (hasBlockBody || _isExpressionBodied) { CheckModifiersForBody(location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } // When a generic method overrides a generic method declared in a base class, or is an // explicit interface member implementation of a method in a base interface, the method // shall not specify any type-parameter-constraints-clauses. In these cases, the type // parameters of the method inherit constraints from the method being overridden or // implemented if (syntax.ConstraintClauses.Count > 0) { if (syntax.ExplicitInterfaceSpecifier != null || syntax.Modifiers.Any(SyntaxKind.OverrideKeyword)) { diagnostics.Add( ErrorCode.ERR_OverrideWithConstraints, syntax.ConstraintClauses[0].WhereKeyword.GetLocation()); } } CheckForBlockAndExpressionBody( syntax.Body, syntax.ExpressionBody, syntax, diagnostics); }
internal static IEnumerable <KeyValuePair <SyntaxNode, SyntaxNode> > GetMethodMatches(string src1, string src2, MethodKind kind = MethodKind.Regular) { var methodMatch = GetMethodMatch(src1, src2, kind); return(EditAndContinueTestHelpers.GetMethodMatches(CreateAnalyzer(), methodMatch)); }
private SourcePropertyAccessorSymbol( NamedTypeSymbol containingType, string name, SourcePropertySymbol property, DeclarationModifiers propertyModifiers, ImmutableArray <MethodSymbol> explicitInterfaceImplementations, Location location, AccessorDeclarationSyntax syntax, MethodKind methodKind, bool isAutoPropertyAccessor, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), syntax.Body.GetReferenceOrNull(), location) { this.property = property; this.explicitInterfaceImplementations = explicitInterfaceImplementations; this.name = name; this.isAutoPropertyAccessor = isAutoPropertyAccessor; bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax, location, diagnostics, out modifierErrors); // Include modifiers from the containing property. propertyModifiers &= ~DeclarationModifiers.AccessibilityMask; if ((declarationModifiers & DeclarationModifiers.Private) != 0) { // Private accessors cannot be virtual. propertyModifiers &= ~DeclarationModifiers.Virtual; } declarationModifiers |= propertyModifiers; // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. this.flags = MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any()); var bodyOpt = syntax.Body; if (bodyOpt != null) { if (containingType.IsInterface) { diagnostics.Add(ErrorCode.ERR_InterfaceMemberHasBody, location, this); } else if (IsExtern && !IsAbstract) { diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); } else if (IsAbstract && !IsExtern) { diagnostics.Add(ErrorCode.ERR_AbstractHasBody, location, this); } // Do not report error for IsAbstract && IsExtern. Dev10 reports CS0180 only // in that case ("member cannot be both extern and abstract"). } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (!modifierErrors) { this.CheckModifiers(location, isAutoPropertyAccessor, diagnostics); } if (this.IsOverride) { MethodSymbol overriddenMethod = this.OverriddenMethod; if ((object)overriddenMethod != null) { // If this accessor is overriding a method from metadata, it is possible that // the name of the overridden method doesn't follow the C# get_X/set_X pattern. // We should copy the name so that the runtime will recognize this as an override. this.name = overriddenMethod.Name; } } }
/// <summary> /// Associate the method with a particular event. Returns /// false if the method is already associated with a property or event. /// </summary> internal bool SetAssociatedEvent(PEEventSymbol eventSymbol, MethodKind methodKind) { Debug.Assert((methodKind == MethodKind.EventAdd) || (methodKind == MethodKind.EventRemove)); return this.SetAssociatedPropertyOrEvent(eventSymbol, methodKind); }
internal PEPropertyAccessorSymbol(PEModuleSymbol moduleSymbol, PEPropertySymbol propertySymbol, MethodKind methodKind, Rid methodRid) : base(moduleSymbol, (PENamedTypeSymbol)propertySymbol.ContainingType, methodKind, methodRid) { this.propertySymbol = propertySymbol; }
internal static BlockSyntax MakeMethodBody( string bodySource, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { string source; switch (kind) { case MethodKind.Iterator: source = "class C { IEnumerable<int> F() { " + bodySource + " } }"; break; case MethodKind.Async: source = "class C { async Task<int> F() { " + bodySource + " } }"; break; case MethodKind.ConstructorWithParameters: source = "class C { C" + bodySource + " }"; break; default: source = "class C { void F() { " + bodySource + " } }"; break; } var tree = ParseSource(source, options: options); var root = tree.GetRoot(); tree.GetDiagnostics().Verify(); var declaration = (BaseMethodDeclarationSyntax)((ClassDeclarationSyntax)((CompilationUnitSyntax)root).Members[0]).Members[0]; // We need to preserve the parent node to allow detection of state machine methods in the analyzer. // If we are not testing a state machine method we only use the body to avoid updating positions in all existing tests. if (kind != MethodKind.Regular) { return ((BaseMethodDeclarationSyntax)SyntaxFactory.SyntaxTree(declaration).GetRoot()).Body; } return (BlockSyntax)SyntaxFactory.SyntaxTree(declaration.Body).GetRoot(); }
/// <summary> /// Gets method edits on the current level of the source hierarchy. This means that edits on lower labeled levels of the hierarchy are not expected to be returned. /// </summary> internal static EditScript <SyntaxNode> GetMethodEdits(string src1, string src2, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { var match = GetMethodMatch(src1, src2, options, kind); return(match.GetTreeEdits()); }
private static SyntaxKind GetAccessorSyntaxKind(MethodKind methodKind) { switch (methodKind) { case MethodKind.PropertyGet: return SyntaxKind.GetAccessorDeclaration; case MethodKind.PropertySet: return SyntaxKind.SetAccessorDeclaration; case MethodKind.EventAdd: return SyntaxKind.AddAccessorDeclaration; case MethodKind.EventRemove: return SyntaxKind.RemoveAccessorDeclaration; default: throw Exceptions.ThrowEUnexpected(); } }
internal static IEnumerable <KeyValuePair <SyntaxNode, SyntaxNode> > GetMethodMatches(string src1, string src2, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { var methodMatch = GetMethodMatch(src1, src2, options, kind); return(EditAndContinueTestHelpers.GetMethodMatches(Analyzer, methodMatch)); }
public SymbolKindOrTypeKind(MethodKind methodKind) : this() { SymbolKind = null; TypeKind = null; MethodKind = methodKind; }
protected static IEnumerable <IMethodSymbol> GetMethodsOrderedByLocation(INamedTypeSymbol type, MethodKind kind = MethodKind.Ordinary) => GetMethodsOrderedByLocation(type, type.Locations.First(_ => _.IsInSource).GetLineSpan().Path, kind);
private bool HasAccessorNode(MethodKind methodKind) { SyntaxNode accessorNode; return(CodeModelService.TryGetAccessorNode(LookupNode(), methodKind, out accessorNode)); }
internal static EnvDTE.CodeFunction Create(CodeModelState state, AbstractCodeMember parent, MethodKind kind) { var newElement = new CodeAccessorFunction(state, parent, kind); return((EnvDTE.CodeFunction)ComAggregate.CreateAggregatedObject(newElement)); }
internal static Match <SyntaxNode> GetMethodMatch(string src1, string src2, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { var m1 = MakeMethodBody(src1, options, kind); var m2 = MakeMethodBody(src2, options, kind); var diagnostics = new List <RudeEditDiagnostic>(); var match = Analyzer.GetTestAccessor().ComputeBodyMatch(m1, m2, Array.Empty <AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint); var needsSyntaxMap = oldHasStateMachineSuspensionPoint && newHasStateMachineSuspensionPoint; Assert.Equal(kind != MethodKind.Regular && kind != MethodKind.ConstructorWithParameters, needsSyntaxMap); if (kind == MethodKind.Regular || kind == MethodKind.ConstructorWithParameters) { Assert.Empty(diagnostics); } return(match); }
private CodeAccessorFunction(CodeModelState state, AbstractCodeMember parent, MethodKind kind) : base(state, parent.FileCodeModel) { Debug.Assert(kind == MethodKind.EventAdd || kind == MethodKind.EventRaise || kind == MethodKind.EventRemove || kind == MethodKind.PropertyGet || kind == MethodKind.PropertySet); _parentHandle = new ParentHandle <AbstractCodeMember>(parent); _kind = kind; }
internal static Symbol GetRuntimeMember(NamedTypeSymbol declaringType, ref MemberDescriptor descriptor, SignatureComparer <MethodSymbol, FieldSymbol, PropertySymbol, TypeSymbol, ParameterSymbol> comparer, IAssemblySymbol accessWithinOpt) { Symbol result = null; SymbolKind targetSymbolKind; MethodKind targetMethodKind = MethodKind.Ordinary; bool isStatic = (descriptor.Flags & MemberFlags.Static) != 0; switch (descriptor.Flags & MemberFlags.KindMask) { case MemberFlags.Constructor: targetSymbolKind = SymbolKind.Method; targetMethodKind = MethodKind.Constructor; // static constructors are never called explicitly Debug.Assert(!isStatic); break; case MemberFlags.Method: targetSymbolKind = SymbolKind.Method; break; case MemberFlags.PropertyGet: targetSymbolKind = SymbolKind.Method; targetMethodKind = MethodKind.PropertyGet; break; case MemberFlags.Field: targetSymbolKind = SymbolKind.Field; break; case MemberFlags.Property: targetSymbolKind = SymbolKind.Property; break; default: throw ExceptionUtilities.UnexpectedValue(descriptor.Flags); } foreach (var member in declaringType.GetMembers(descriptor.Name)) { Debug.Assert(member.Name.Equals(descriptor.Name)); if (member.Kind != targetSymbolKind || member.IsStatic != isStatic || !(member.DeclaredAccessibility == Accessibility.Public)) { continue; } switch (targetSymbolKind) { case SymbolKind.Method: { MethodSymbol method = (MethodSymbol)member; MethodKind methodKind = method.MethodKind; // Treat user-defined conversions and operators as ordinary methods for the purpose // of matching them here. if (methodKind == MethodKind.Conversion || methodKind == MethodKind.UserDefinedOperator) { methodKind = MethodKind.Ordinary; } if (method.Arity != descriptor.Arity || methodKind != targetMethodKind || ((descriptor.Flags & MemberFlags.Virtual) != 0) != (method.IsVirtual || method.IsOverride || method.IsAbstract)) { continue; } if (!comparer.MatchMethodSignature(method, descriptor.Signature)) { continue; } } break; case SymbolKind.Property: { PropertySymbol property = (PropertySymbol)member; if (((descriptor.Flags & MemberFlags.Virtual) != 0) != (property.IsVirtual || property.IsOverride || property.IsAbstract)) { continue; } if (!comparer.MatchPropertySignature(property, descriptor.Signature)) { continue; } } break; case SymbolKind.Field: if (!comparer.MatchFieldSignature((FieldSymbol)member, descriptor.Signature)) { continue; } break; default: throw ExceptionUtilities.UnexpectedValue(targetSymbolKind); } // ambiguity if ((object)result != null) { result = null; break; } result = member; } return(result); }
private SourceMemberMethodSymbol( NamedTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, Binder bodyBinder, MethodDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), // Prefer a block body if both exist syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), location) { _name = name; _explicitInterfaceType = explicitInterfaceType; SyntaxTokenList modifiers = syntax.Modifiers; // The following two values are used to compute and store the initial value of the flags // However, these two components are placeholders; the correct value will be // computed lazily later and then the flags will be fixed up. const bool returnsVoid = false; var firstParam = syntax.ParameterList.Parameters.FirstOrDefault(); bool isExtensionMethod = firstParam != null && !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword); bool modifierErrors; var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors); var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers); // NOTE: by creating a WithMethodTypeParametersBinder, we are effectively duplicating the // functionality of the BinderFactory. Unfortunately, we cannot use the BinderFactory // because it depends on having access to the member list of our containing type and // that list cannot be complete because we're not finished constructing this member. // TODO: at least keep this in sync with BinderFactory.VisitMethodDeclaration. bodyBinder = bodyBinder.WithUnsafeRegionIfNecessary(modifiers); Binder withTypeParamsBinder; if (syntax.Arity == 0) { withTypeParamsBinder = bodyBinder; _typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; } else { var parameterBinder = new WithMethodTypeParametersBinder(this, bodyBinder); withTypeParamsBinder = parameterBinder; _typeParameters = MakeTypeParameters(syntax, diagnostics); } bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; if (hasBlockBody || _isExpressionBodied) { CheckModifiersForBody(location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (this.IsPartial) { // Partial methods must be completed early because they are matched up // by signature while producing the enclosing type's member list. However, // that means any type parameter constraints will be bound before the method // is added to the containing type. To enable binding of constraints before the // .ctor completes we hold on to the current binder while the .ctor is executing. // If we change the handling of partial methods, so that partial methods are // completed lazily, the 'constraintClauseBinder' field should be removed. _constraintClauseBinder = withTypeParamsBinder; state.NotePartComplete(CompletionPart.StartMethodChecks); MethodChecks(syntax, withTypeParamsBinder, diagnostics); state.NotePartComplete(CompletionPart.FinishMethodChecks); _constraintClauseBinder = null; } }
private void VerifyAccessor(MethodSymbol accessor, PEPropertySymbol associatedProperty, MethodKind methodKind) { Assert.NotNull(accessor); Assert.Equal(accessor.AssociatedSymbol, associatedProperty); Assert.Equal(accessor.MethodKind, methodKind); if (associatedProperty != null) { var method = (methodKind == MethodKind.PropertyGet) ? associatedProperty.GetMethod : associatedProperty.SetMethod; Assert.Equal(accessor, method); } }
private DeclarationModifiers MakeModifiers(SyntaxTokenList modifiers, MethodKind methodKind, Location location, DiagnosticBag diagnostics, out bool modifierErrors) { bool isInterface = this.ContainingType.IsInterface; var defaultAccess = isInterface ? DeclarationModifiers.Public : DeclarationModifiers.Private; // Check that the set of modifiers is allowed var allowedModifiers = DeclarationModifiers.Partial | DeclarationModifiers.Unsafe; if (methodKind != MethodKind.ExplicitInterfaceImplementation) { allowedModifiers |= DeclarationModifiers.New; if (!isInterface) { allowedModifiers |= DeclarationModifiers.AccessibilityMask | DeclarationModifiers.Sealed | DeclarationModifiers.Abstract | DeclarationModifiers.Static | DeclarationModifiers.Virtual | DeclarationModifiers.Override; } } if (!isInterface) { allowedModifiers |= DeclarationModifiers.Extern | DeclarationModifiers.Async; } var mods = ModifierUtils.MakeAndCheckNontypeMemberModifiers(modifiers, defaultAccess, allowedModifiers, location, diagnostics, out modifierErrors); this.CheckUnsafeModifier(mods, diagnostics); mods = AddImpliedModifiers(mods, isInterface, methodKind); return mods; }
/// <summary> /// Creates a method symbol that can be used to describe a method declaration. /// </summary> public static IMethodSymbol CreateMethodSymbol(IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList<ITypeParameterSymbol> typeParameters, IList<IParameterSymbol> parameters, IList<SyntaxNode> statements = null, IList<SyntaxNode> handlesExpressions = null, IList<AttributeData> returnTypeAttributes = null, MethodKind methodKind = MethodKind.Ordinary) { return CreateMethodSymbol(null, attributes, accessibility, modifiers, returnType, explicitInterfaceSymbol, name, typeParameters, parameters, statements, handlesExpressions, returnTypeAttributes, methodKind); }
private void TestGlyph( StandardGlyphGroup expectedGlyphGroup, SymbolKind kind = SymbolKind.Method, Accessibility declaredAccessibility = Accessibility.NotApplicable, bool isExtensionMethod = true, MethodKind methodKind = MethodKind.Ordinary, INamedTypeSymbol containingType = null, bool isConst = false, ITypeSymbol elementType = null, INamespaceOrTypeSymbol target = null, ITypeSymbol pointedAtType = null, bool isWithEvents = false, TypeKind typeKind = TypeKind.Unknown) { var symbol = CreateSymbolMock(kind, declaredAccessibility, isExtensionMethod, methodKind, containingType, isConst, elementType, target, pointedAtType, isWithEvents, typeKind); Assert.Equal(expectedGlyphGroup, symbol.GetGlyph().GetStandardGlyphGroup()); }
protected override bool IsOnCodeBlockSupported(SymbolKind symbolKind, MethodKind methodKind, bool returnsVoid) { return(base.IsOnCodeBlockSupported(symbolKind, methodKind, returnsVoid) && methodKind != MethodKind.EventRaise); }
public void InitializeMethodKind(MethodKind methodKind) { Debug.Assert((int)methodKind == ((int)methodKind & MethodKindMask)); int bitsToSet = (((int)methodKind & MethodKindMask) << MethodKindOffset) | MethodKindIsPopulatedBit; Debug.Assert(BitsAreUnsetOrSame(_bits, bitsToSet)); ThreadSafeFlagOperations.Set(ref _bits, bitsToSet); }
private SourcePropertyAccessorSymbol( NamedTypeSymbol containingType, string name, SourcePropertySymbol property, DeclarationModifiers propertyModifiers, ImmutableArray<MethodSymbol> explicitInterfaceImplementations, Location location, AccessorDeclarationSyntax syntax, MethodKind methodKind, bool isAutoPropertyAccessor, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), syntax.Body?.GetReference(), location) { _property = property; _explicitInterfaceImplementations = explicitInterfaceImplementations; _name = name; _isAutoPropertyAccessor = isAutoPropertyAccessor; bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax, location, diagnostics, out modifierErrors); // Include modifiers from the containing property. propertyModifiers &= ~DeclarationModifiers.AccessibilityMask; if ((declarationModifiers & DeclarationModifiers.Private) != 0) { // Private accessors cannot be virtual. propertyModifiers &= ~DeclarationModifiers.Virtual; } declarationModifiers |= propertyModifiers & ~DeclarationModifiers.Indexer; // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any()); var bodyOpt = syntax.Body; if (bodyOpt != null) { CheckModifiersForBody(location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (!modifierErrors) { this.CheckModifiers(location, isAutoPropertyAccessor, diagnostics); } if (this.IsOverride) { MethodSymbol overriddenMethod = this.OverriddenMethod; if ((object)overriddenMethod != null) { // If this accessor is overriding a method from metadata, it is possible that // the name of the overridden method doesn't follow the C# get_X/set_X pattern. // We should copy the name so that the runtime will recognize this as an override. _name = overriddenMethod.Name; } } }
private static ISymbol CreateSymbolMock( SymbolKind kind, Accessibility declaredAccessibility = Accessibility.NotApplicable, bool isExtensionMethod = false, MethodKind methodKind = MethodKind.Ordinary, INamedTypeSymbol containingType = null, bool isConst = false, ITypeSymbol elementType = null, INamespaceOrTypeSymbol target = null, ITypeSymbol pointedAtType = null, bool isWithEvents = false, TypeKind typeKind = TypeKind.Unknown) { var symbolMock = new Mock <ISymbol>(MockBehavior.Strict); symbolMock.SetupGet(s => s.Kind).Returns(kind); symbolMock.SetupGet(s => s.DeclaredAccessibility).Returns(declaredAccessibility); symbolMock.SetupGet(s => s.ContainingType).Returns(containingType); if (kind == SymbolKind.ArrayType) { var arrayTypeMock = symbolMock.As <IArrayTypeSymbol>(); arrayTypeMock.SetupGet(s => s.ElementType).Returns(elementType); } if (kind == SymbolKind.Alias) { var aliasMock = symbolMock.As <IAliasSymbol>(); aliasMock.SetupGet(s => s.Target).Returns(target); } if (kind == SymbolKind.Method) { var methodTypeMock = symbolMock.As <IMethodSymbol>(); methodTypeMock.SetupGet(s => s.MethodKind).Returns(methodKind); methodTypeMock.SetupGet(s => s.IsExtensionMethod).Returns(isExtensionMethod); } if (kind == SymbolKind.NamedType) { var namedTypeMock = symbolMock.As <INamedTypeSymbol>(); namedTypeMock.SetupGet(s => s.TypeKind).Returns(typeKind); } if (kind == SymbolKind.Field) { var fieldMock = symbolMock.As <IFieldSymbol>(); fieldMock.SetupGet(s => s.IsConst).Returns(isConst); } if (kind == SymbolKind.PointerType) { var pointerTypeMock = symbolMock.As <IPointerTypeSymbol>(); pointerTypeMock.SetupGet(s => s.PointedAtType).Returns(pointedAtType); } if (kind == SymbolKind.Property) { var propertyMock = symbolMock.As <IPropertySymbol>(); propertyMock.SetupGet(s => s.IsWithEvents).Returns(isWithEvents); } return(symbolMock.Object); }
private static DeclarationModifiers AddImpliedModifiers(DeclarationModifiers mods, bool containingTypeIsInterface, MethodKind methodKind) { // Let's overwrite modifiers for interface and explicit interface implementation methods with what they are supposed to be. // Proper errors must have been reported by now. if (containingTypeIsInterface) { mods = (mods & ~DeclarationModifiers.AccessibilityMask) | DeclarationModifiers.Public | DeclarationModifiers.Abstract; } else if (methodKind == MethodKind.ExplicitInterfaceImplementation) { mods = (mods & ~DeclarationModifiers.AccessibilityMask) | DeclarationModifiers.Private; } return mods; }
private SourcePropertyAccessorSymbol( NamedTypeSymbol containingType, string name, SourcePropertySymbol property, DeclarationModifiers propertyModifiers, ImmutableArray <MethodSymbol> explicitInterfaceImplementations, Location location, AccessorDeclarationSyntax syntax, MethodKind methodKind, bool isAutoPropertyAccessor, bool isExplicitInterfaceImplementation, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), location, isIterator: SyntaxFacts.HasYieldOperations(syntax.Body)) { _property = property; _explicitInterfaceImplementations = explicitInterfaceImplementations; _name = name; _isAutoPropertyAccessor = isAutoPropertyAccessor; Debug.Assert(!_property.IsExpressionBodied, "Cannot have accessors in expression bodied lightweight properties"); var hasBody = syntax.Body != null; var hasExpressionBody = syntax.ExpressionBody != null; _isExpressionBodied = !hasBody && hasExpressionBody; bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax, isExplicitInterfaceImplementation, hasBody || hasExpressionBody, location, diagnostics, out modifierErrors); // Include some modifiers from the containing property, but not the accessibility modifiers. declarationModifiers |= GetAccessorModifiers(propertyModifiers) & ~DeclarationModifiers.AccessibilityMask; if ((declarationModifiers & DeclarationModifiers.Private) != 0) { // Private accessors cannot be virtual. declarationModifiers &= ~DeclarationModifiers.Virtual; } // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any()); CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: hasBody || hasExpressionBody || isAutoPropertyAccessor, diagnostics); if (hasBody || hasExpressionBody) { CheckModifiersForBody(syntax, location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers, this, isExplicitInterfaceImplementation); if (info != null) { diagnostics.Add(info, location); } if (!modifierErrors) { this.CheckModifiers(location, hasBody || hasExpressionBody, isAutoPropertyAccessor, diagnostics); } if (this.IsOverride) { MethodSymbol overriddenMethod = this.OverriddenMethod; if ((object)overriddenMethod != null) { // If this accessor is overriding a method from metadata, it is possible that // the name of the overridden method doesn't follow the C# get_X/set_X pattern. // We should copy the name so that the runtime will recognize this as an override. _name = overriddenMethod.Name; } } CheckForBlockAndExpressionBody( syntax.Body, syntax.ExpressionBody, syntax, diagnostics); }
private static ISymbol CreateSymbolMock( SymbolKind kind, Accessibility declaredAccessibility = Accessibility.NotApplicable, bool isExtensionMethod = false, MethodKind methodKind = MethodKind.Ordinary, INamedTypeSymbol containingType = null, bool isConst = false, ITypeSymbol elementType = null, INamespaceOrTypeSymbol target = null, ITypeSymbol pointedAtType = null, bool isWithEvents = false, TypeKind typeKind = TypeKind.Unknown) { var symbolMock = new Mock<ISymbol>(); symbolMock.SetupGet(s => s.Kind).Returns(kind); symbolMock.SetupGet(s => s.DeclaredAccessibility).Returns(declaredAccessibility); symbolMock.SetupGet(s => s.ContainingType).Returns(containingType); if (kind == SymbolKind.ArrayType) { var arrayTypeMock = symbolMock.As<IArrayTypeSymbol>(); arrayTypeMock.SetupGet(s => s.ElementType).Returns(elementType); } if (kind == SymbolKind.Alias) { var aliasMock = symbolMock.As<IAliasSymbol>(); aliasMock.SetupGet(s => s.Target).Returns(target); } if (kind == SymbolKind.Method) { var methodTypeMock = symbolMock.As<IMethodSymbol>(); methodTypeMock.SetupGet(s => s.MethodKind).Returns(methodKind); methodTypeMock.SetupGet(s => s.IsExtensionMethod).Returns(isExtensionMethod); } if (kind == SymbolKind.NamedType) { var namedTypeMock = symbolMock.As<INamedTypeSymbol>(); namedTypeMock.SetupGet(s => s.TypeKind).Returns(typeKind); } if (kind == SymbolKind.Field) { var fieldMock = symbolMock.As<IFieldSymbol>(); fieldMock.SetupGet(s => s.IsConst).Returns(isConst); } if (kind == SymbolKind.PointerType) { var pointerTypeMock = symbolMock.As<IPointerTypeSymbol>(); pointerTypeMock.SetupGet(s => s.PointedAtType).Returns(pointedAtType); } if (kind == SymbolKind.Property) { var propertyMock = symbolMock.As<IPropertySymbol>(); propertyMock.SetupGet(s => s.IsWithEvents).Returns(isWithEvents); } return symbolMock.Object; }
internal static IMethodSymbol CreateMethodSymbol(INamedTypeSymbol containingType, IList <AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList <ITypeParameterSymbol> typeParameters, IList <IParameterSymbol> parameters, IList <SyntaxNode> statements = null, IList <SyntaxNode> handlesExpressions = null, IList <AttributeData> returnTypeAttributes = null, MethodKind methodKind = MethodKind.Ordinary) { var result = new CodeGenerationMethodSymbol(containingType, attributes, accessibility, modifiers, returnType, explicitInterfaceSymbol, name, typeParameters, parameters, returnTypeAttributes, methodKind); CodeGenerationMethodInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, modifiers.IsPartial, modifiers.IsAsync, statements, handlesExpressions); return(result); }
/// <summary> /// Associate the method with a particular property. Returns /// false if the method is already associated with a property or event. /// </summary> internal bool SetAssociatedProperty(PEPropertySymbol propertySymbol, MethodKind methodKind) { Debug.Assert((methodKind == MethodKind.PropertyGet) || (methodKind == MethodKind.PropertySet)); return this.SetAssociatedPropertyOrEvent(propertySymbol, methodKind); }
/// <summary> /// Creates a method symbol that can be used to describe a method declaration. /// </summary> public static IMethodSymbol CreateMethodSymbol(IList <AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, IMethodSymbol explicitInterfaceSymbol, string name, IList <ITypeParameterSymbol> typeParameters, IList <IParameterSymbol> parameters, IList <SyntaxNode> statements = null, IList <SyntaxNode> handlesExpressions = null, IList <AttributeData> returnTypeAttributes = null, MethodKind methodKind = MethodKind.Ordinary) { return(CreateMethodSymbol(null, attributes, accessibility, modifiers, returnType, explicitInterfaceSymbol, name, typeParameters, parameters, statements, handlesExpressions, returnTypeAttributes, methodKind)); }
private bool SetAssociatedPropertyOrEvent(Symbol propertyOrEventSymbol, MethodKind methodKind) { if ((object)_associatedPropertyOrEventOpt == null) { Debug.Assert(propertyOrEventSymbol.ContainingType == _containingType); // No locking required since SetAssociatedProperty/SetAssociatedEvent will only be called // by the thread that created the method symbol (and will be called before the method // symbol is added to the containing type members and available to other threads). _associatedPropertyOrEventOpt = propertyOrEventSymbol; // NOTE: may be overwriting an existing value. Debug.Assert( _packedFlags.MethodKind == default(MethodKind) || _packedFlags.MethodKind == MethodKind.Ordinary || _packedFlags.MethodKind == MethodKind.ExplicitInterfaceImplementation); _packedFlags.MethodKind = methodKind; return true; } return false; }
protected SourceUserDefinedOperatorSymbolBase( MethodKind methodKind, string name, SourceMemberContainerTypeSymbol containingType, Location location, SyntaxReference syntaxReference, SyntaxReference bodySyntaxReference, SyntaxTokenList modifiersSyntax, DiagnosticBag diagnostics, bool isExpressionBodied) : base(containingType, syntaxReference, bodySyntaxReference, location) { _name = name; _isExpressionBodied = isExpressionBodied; var defaultAccess = DeclarationModifiers.Private; var allowedModifiers = DeclarationModifiers.AccessibilityMask | DeclarationModifiers.Static | DeclarationModifiers.Extern | DeclarationModifiers.Unsafe; bool modifierErrors; var declarationModifiers = ModifierUtils.MakeAndCheckNontypeMemberModifiers( modifiersSyntax, defaultAccess, allowedModifiers, location, diagnostics, out modifierErrors); this.CheckUnsafeModifier(declarationModifiers, diagnostics); // We will bind the formal parameters and the return type lazily. For now, // assume that the return type is non-void; when we do the lazy initialization // of the parameters and return type we will update the flag if necessary. this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false); if (this.ContainingType.IsInterface) { // If we have an operator in an interface, we already have reported that fact as // an error. No need to cascade the error further. return; } if (this.ContainingType.IsStatic) { // Similarly if we're in a static class, though we have not reported it yet. // CS0715: '{0}': static classes cannot contain user-defined operators diagnostics.Add(ErrorCode.ERR_OperatorInStaticClass, location, this); return; } // SPEC: An operator declaration must include both a public and a // SPEC: static modifier if (this.DeclaredAccessibility != Accessibility.Public || !this.IsStatic) { // CS0558: User-defined operator '...' must be declared static and public diagnostics.Add(ErrorCode.ERR_OperatorsMustBeStatic, this.Locations[0], this); } // SPEC: Because an external operator provides no actual implementation, // SPEC: its operator body consists of a semicolon. For expression-bodied // SPEC: operators, the body is an expression. For all other operators, // SPEC: the operator body consists of a block... if (bodySyntaxReference != null && IsExtern) { diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); } else if (bodySyntaxReference == null && !IsExtern && !IsAbstract && !IsPartial) { // Do not report that the body is missing if the operator is marked as // partial or abstract; we will already have given an error for that so // there's no need to "cascade" the error. diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } // SPEC: It is an error for the same modifier to appear multiple times in an // SPEC: operator declaration. var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } }
internal static EditScript<SyntaxNode> GetMethodEdits(string src1, string src2, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { var match = GetMethodMatch(src1, src2, options, kind); return match.GetTreeEdits(); }
private bool HasAccessorNode(MethodKind methodKind) => CodeModelService.TryGetAccessorNode(LookupNode(), methodKind, out _);
internal static IEnumerable<KeyValuePair<SyntaxNode, SyntaxNode>> GetMethodMatches(string src1, string src2, ParseOptions options = null, MethodKind kind = MethodKind.Regular) { var methodMatch = GetMethodMatch(src1, src2, options, kind); return EditAndContinueTestHelpers.GetMethodMatches(Analyzer, methodMatch); }
/// <summary> /// Associate the method with a particular property. Returns /// false if the method is already associated with a property or event. /// </summary> internal bool SetAssociatedProperty(PEPropertySymbol propertySymbol, MethodKind methodKind) { Debug.Assert((methodKind == MethodKind.PropertyGet) || (methodKind == MethodKind.PropertySet)); return(this.SetAssociatedPropertyOrEvent(propertySymbol, methodKind)); }
public override bool TryGetAccessorNode(SyntaxNode parentNode, MethodKind kind, out SyntaxNode accessorNode) { Debug.Assert(parentNode is BasePropertyDeclarationSyntax); var basePropertyDeclaration = (BasePropertyDeclarationSyntax)parentNode; var accessorKind = GetAccessorSyntaxKind(kind); if (basePropertyDeclaration.AccessorList != null) { foreach (var accessor in basePropertyDeclaration.AccessorList.Accessors) { if (accessor.Kind() == accessorKind) { accessorNode = accessor; return true; } } } accessorNode = null; return false; }
/// <summary> /// Associate the method with a particular event. Returns /// false if the method is already associated with a property or event. /// </summary> internal bool SetAssociatedEvent(PEEventSymbol eventSymbol, MethodKind methodKind) { Debug.Assert((methodKind == MethodKind.EventAdd) || (methodKind == MethodKind.EventRemove)); return(this.SetAssociatedPropertyOrEvent(eventSymbol, methodKind)); }