Example #1
0
        public static bool IsRequiredPort([NotNull] this IMethodSymbol methodSymbol, [NotNull] SemanticModel semanticModel)
        {
            Requires.NotNull(methodSymbol, nameof(methodSymbol));
            Requires.NotNull(semanticModel, nameof(semanticModel));

            return(methodSymbol.IsRequiredPort(semanticModel.Compilation));
        }
        /// <summary>
        ///   Normalizes the <paramref name="accessors" />.
        /// </summary>
        private IEnumerable <AccessorDeclarationSyntax> NormalizerAccessors(IEnumerable <AccessorDeclarationSyntax> accessors)
        {
            foreach (var accessor in accessors)
            {
                _methodSymbol = accessor.GetMethodSymbol(SemanticModel);
                var body = CreateBindingCode();

                if (_methodSymbol.IsRequiredPort(SemanticModel))
                {
                    // Cannot use the SyntaxGenerator extension method due to a Roslyn bug
                    var hiddenAttribute   = (AttributeListSyntax)Syntax.Attribute(typeof(DebuggerHiddenAttribute).GetGlobalName());
                    var delegateFieldName = Syntax.LiteralExpression(GetBindingDelegateFieldName());
                    var infoFieldName     = Syntax.LiteralExpression(GetBinderFieldName());
                    var defaultMethod     = Syntax.LiteralExpression(GetUnboundPortAssignmentMethodName());
                    var fieldAttribute    = (AttributeListSyntax)Syntax.Attribute(typeof(BindingMetadataAttribute).GetGlobalName(),
                                                                                  delegateFieldName, infoFieldName, defaultMethod);

                    var requiredPortAccessor = accessor.AddAttributeLists(hiddenAttribute, fieldAttribute);
                    yield return(requiredPortAccessor.WithBody(body).WithSemicolonToken(default(SyntaxToken)));
                }
                else
                {
                    yield return(accessor.WithBody(body));
                }
            }
        }
Example #3
0
        public static bool CanBeAffectedByFaults([NotNull] this IMethodSymbol methodSymbol, [NotNull] Compilation compilation)
        {
            Requires.NotNull(methodSymbol, nameof(methodSymbol));

            // Faults can only affect non-abstract methods that can be overwritten
            if (methodSymbol.IsAbstract || methodSymbol.IsSealed || (!methodSymbol.IsVirtual && !methodSymbol.IsOverride))
            {
                return(false);
            }

            // Faults affect only component methods
            return(methodSymbol.IsProvidedPort(compilation) ||
                   methodSymbol.IsRequiredPort(compilation) ||
                   methodSymbol.IsUpdateMethod(compilation));
        }
		/// <summary>
		///   Normalizes the <paramref name="declaration" />.
		/// </summary>
		public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax declaration)
		{
			_methodSymbol = declaration.GetMethodSymbol(SemanticModel);
			if (!_methodSymbol.ContainingType.IsComponent(SemanticModel) || !_methodSymbol.IsRequiredPort(SemanticModel))
				return declaration;

			var body = CreateBindingCode();
			var originalDeclaration = declaration;
			var index = declaration.Modifiers.IndexOf(SyntaxKind.ExternKeyword);
			var delegateFieldName = Syntax.LiteralExpression(GetBindingDelegateFieldName());
			var infoFieldName = Syntax.LiteralExpression(GetBinderFieldName());
			var defaultMethod = Syntax.LiteralExpression(GetUnboundPortAssignmentMethodName());

			declaration = declaration.WithModifiers(declaration.Modifiers.RemoveAt(index)).WithSemicolonToken(default(SyntaxToken));
			declaration = (MethodDeclarationSyntax)Syntax.AddAttribute<DebuggerHiddenAttribute>(declaration);
			declaration = (MethodDeclarationSyntax)Syntax.AddAttribute<BindingMetadataAttribute>(declaration,
				delegateFieldName, infoFieldName, defaultMethod);

			return declaration.WithBody(body).EnsureLineCount(originalDeclaration);
		}
        /// <summary>
        ///   Normalizes the <paramref name="declaration" />.
        /// </summary>
        public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax declaration)
        {
            _methodSymbol = declaration.GetMethodSymbol(SemanticModel);
            if (!_methodSymbol.ContainingType.IsComponent(SemanticModel) || !_methodSymbol.IsRequiredPort(SemanticModel))
            {
                return(declaration);
            }

            var body = CreateBindingCode();
            var originalDeclaration = declaration;
            var index             = declaration.Modifiers.IndexOf(SyntaxKind.ExternKeyword);
            var delegateFieldName = Syntax.LiteralExpression(GetBindingDelegateFieldName());
            var infoFieldName     = Syntax.LiteralExpression(GetBinderFieldName());
            var defaultMethod     = Syntax.LiteralExpression(GetUnboundPortAssignmentMethodName());

            declaration = declaration.WithModifiers(declaration.Modifiers.RemoveAt(index)).WithSemicolonToken(default(SyntaxToken));
            declaration = (MethodDeclarationSyntax)Syntax.AddAttribute <DebuggerHiddenAttribute>(declaration);
            declaration = (MethodDeclarationSyntax)Syntax.AddAttribute <BindingMetadataAttribute>(declaration,
                                                                                                  delegateFieldName, infoFieldName, defaultMethod);

            return(declaration.WithBody(body).EnsureLineCount(originalDeclaration));
        }
		/// <summary>
		///   Normalizes the <paramref name="accessors" />.
		/// </summary>
		private IEnumerable<AccessorDeclarationSyntax> NormalizerAccessors(IEnumerable<AccessorDeclarationSyntax> accessors)
		{
			foreach (var accessor in accessors)
			{
				_methodSymbol = accessor.GetMethodSymbol(SemanticModel);
				var body = CreateBindingCode();

				if (_methodSymbol.IsRequiredPort(SemanticModel))
				{
					// Cannot use the SyntaxGenerator extension method due to a Roslyn bug
					var hiddenAttribute = (AttributeListSyntax)Syntax.Attribute(typeof(DebuggerHiddenAttribute).GetGlobalName());
					var delegateFieldName = Syntax.LiteralExpression(GetBindingDelegateFieldName());
					var infoFieldName = Syntax.LiteralExpression(GetBinderFieldName());
					var defaultMethod = Syntax.LiteralExpression(GetUnboundPortAssignmentMethodName());
					var fieldAttribute = (AttributeListSyntax)Syntax.Attribute(typeof(BindingMetadataAttribute).GetGlobalName(),
						delegateFieldName, infoFieldName, defaultMethod);

					var requiredPortAccessor = accessor.AddAttributeLists(hiddenAttribute, fieldAttribute);
					yield return requiredPortAccessor.WithBody(body).WithSemicolonToken(default(SyntaxToken));
				}
				else
					yield return accessor.WithBody(body);
			}
		}