Ejemplo n.º 1
0
 public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
 {
     base.VisitMemberReferenceExpression(memberReferenceExpression);
     HandleMemberReference(
         memberReferenceExpression, memberReferenceExpression.Target, memberReferenceExpression.MemberNameToken, memberReferenceExpression.TypeArguments, NameLookupMode.Expression,
         script => {
         script.Replace(memberReferenceExpression, RefactoringAstHelper.RemoveTarget(memberReferenceExpression));
     });
 }
Ejemplo n.º 2
0
 public override void VisitMemberType(MemberType memberType)
 {
     base.VisitMemberType(memberType);
     HandleMemberReference(
         memberType, memberType.Target, memberType.MemberNameToken, memberType.TypeArguments, memberType.GetNameLookupMode(),
         script => {
         script.Replace(memberType, RefactoringAstHelper.RemoveTarget(memberType));
     });
 }
            public override void VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression)
            {
                base.VisitThisReferenceExpression(thisReferenceExpression);
                var memberReference = thisReferenceExpression.Parent as MemberReferenceExpression;

                if (memberReference == null)
                {
                    return;
                }

                var state       = ctx.GetResolverStateAfter(thisReferenceExpression);
                var wholeResult = ctx.Resolve(memberReference);

                IMember member = GetMember(wholeResult);

                if (member == null)
                {
                    return;
                }

                var result = state.LookupSimpleNameOrTypeName(memberReference.MemberName, EmptyList <IType> .Instance, NameLookupMode.Expression);

                bool isRedundant;

                if (result is MemberResolveResult)
                {
                    isRedundant = ((MemberResolveResult)result).Member.Region.Equals(member.Region);
                }
                else if (result is MethodGroupResolveResult)
                {
                    isRedundant = ((MethodGroupResolveResult)result).Methods.Any(m => m.Region.Equals(member.Region));
                }
                else
                {
                    return;
                }

                if (isRedundant)
                {
                    AddIssue(thisReferenceExpression.StartLocation, memberReference.MemberNameToken.StartLocation, ctx.TranslateString("Remove redundant 'this.'"), script => {
                        script.Replace(memberReference, RefactoringAstHelper.RemoveTarget(memberReference));
                    }
                             );
                }
            }