Esempio n. 1
0
        public override void VisitInvocationExpression(ICSharpCode.NRefactory.CSharp.InvocationExpression invocationExpression)
        {
            base.VisitInvocationExpression(invocationExpression);
            var result = Resolver.Resolve(invocationExpression) as InvocationResolveResult;

            if (result == null)
            {
                Trace.WriteLine(String.Format("Unknown invocation resolution at {0}", invocationExpression));
                return;
            }
            var methodDeclaringType = GetTypeOrCreateExternal(result.Member.DeclaringType);

            CheckCallForSubtype(invocationExpression.Arguments, result.Member);

            var targetDeclaringType         = GetTypeOrCreateExternal(result.TargetResult.Type);
            var currentDeclaringTypeResolve = Resolver.Resolve(invocationExpression.GetParent <TypeDeclaration>());

            if (currentDeclaringTypeResolve.IsError)
            {
                return;
            }
            var    currentMethod        = invocationExpression.GetParent <MethodDeclaration>();
            string fromReference        = currentMethod == null ? "(field initializer)" : currentMethod.Name;
            var    currentDeclaringType = (Class)GetTypeOrCreateExternal(currentDeclaringTypeResolve.Type);

            if (currentDeclaringType.IsChildOf(methodDeclaringType))
            {
                var  items  = currentDeclaringType.GetPathTo(methodDeclaringType);
                bool direct = currentDeclaringType.IsDirectChildOf(methodDeclaringType);
                foreach (var item in items)
                {
                    item.InternalReuse.Add(new Reuse(direct, ReuseType.MethodCall, result.Member.Name,
                                                     currentDeclaringType, fromReference));
                }
            }
            else if (targetDeclaringType.IsChildOf(methodDeclaringType))
            {
                var  items  = targetDeclaringType.GetPathTo(methodDeclaringType);
                bool direct = targetDeclaringType.IsDirectChildOf(methodDeclaringType);
                foreach (var item in items)
                {
                    item.InternalReuse.Add(new Reuse(direct, ReuseType.MethodCall, result.Member.Name,
                                                     currentDeclaringType, fromReference));
                }
            }

            if (result.IsVirtualCall && (currentDeclaringType == methodDeclaringType || currentDeclaringType.IsChildOf(methodDeclaringType)))
            {
                var method = CreateMethod(result.Member);
                //maybe a downcall somewhere
                foreach (var downcallCandidate in methodDeclaringType.AllDerivedTypes().Where(t => t.DeclaredMethods.Contains(method)))
                {
                    var relation = downcallCandidate.GetImmediateParent(methodDeclaringType);
                    relation.Downcalls.Add(
                        new Downcall(relation.BaseType, relation.DerivedType, method, fromReference));
                }
            }
        }
Esempio n. 2
0
            public override void VisitInvocationExpression(InvocationExpression invocationExpression)
            {
                base.VisitInvocationExpression(invocationExpression);
                var mr = invocationExpression.Target as MemberReferenceExpression;

                if (mr == null || !(mr.Target is BaseReferenceExpression))
                {
                    return;
                }

                var invocationRR = ctx.Resolve(invocationExpression) as InvocationResolveResult;

                if (invocationRR == null)
                {
                    return;
                }

                var parentEntity = invocationExpression.GetParent <EntityDeclaration>();

                if (parentEntity == null)
                {
                    return;
                }
                var rr = ctx.Resolve(parentEntity) as MemberResolveResult;

                if (rr == null)
                {
                    return;
                }

                if (invocationExpression.Arguments.Count >= invocationRR.Member.Parameters.Count ||
                    invocationRR.Member.Parameters.Count == 0 ||
                    !invocationRR.Member.Parameters.Last().IsOptional)
                {
                    return;
                }

                if (!InheritanceHelper.GetBaseMembers(rr.Member, false).Any(m => m == invocationRR.Member))
                {
                    return;
                }
                AddIssue(new CodeIssue(
                             invocationExpression.RParToken,
                             ctx.TranslateString("Call to base member with implicit default parameters")
                             ));
            }