Esempio n. 1
0
        public override void VisitIdentifierExpression(IdentifierExpression identifier)
        {
            base.VisitIdentifierExpression(identifier);
            //prevent duplicate entries from member reference
            if (identifier.GetParent <MemberReferenceExpression>() != null)
            {
                return;
            }
            var resolveResult = Resolver.Resolve(identifier);
            var memberResolve = resolveResult as MemberResolveResult;

            //variable access without this qualifier
            if (memberResolve != null && memberResolve.Member.DeclaringType.Kind != TypeKind.Enum)
            {
                var targetType = GetTypeOrCreateExternal(memberResolve.Member.DeclaringType);
                var currentDeclaringTypeResolve = Resolver.Resolve(identifier.GetParent <TypeDeclaration>());
                //it is possible that we are inside an enumeration, inside a nested type, referencing an identifier
                //defined in the outer type. In that case, we want to use the outer type as the source
                //22-9: fixed refernce to boolean constant defined in outer type
                if (currentDeclaringTypeResolve.Type.Kind == TypeKind.Enum ||
                    currentDeclaringTypeResolve.Type.Kind == TypeKind.Interface ||
                    currentDeclaringTypeResolve.Type.Kind == TypeKind.Delegate)
                {
                    currentDeclaringTypeResolve =
                        Resolver.Resolve(identifier.GetParent <TypeDeclaration>().GetParent <TypeDeclaration>());
                }

                string currentReferenceName = identifier.GetParent <MethodDeclaration>() == null
                    ? "(field initializer)"
                    : identifier.GetParent <MethodDeclaration>().Name;
                var  currentDeclaringType = (Class)GetTypeOrCreateExternal(currentDeclaringTypeResolve.Type);
                bool possibleUpCall       = currentDeclaringType.IsChildOf(targetType);
                if (possibleUpCall)
                {
                    bool direct = currentDeclaringType.IsDirectChildOf(targetType);
                    foreach (var item in currentDeclaringType.GetPathTo(targetType))
                    {
                        item.InternalReuse.Add(new Reuse(direct, ReuseType.FieldAccess, memberResolve.Member.Name, currentDeclaringType, currentReferenceName));
                    }
                }
            }
        }
Esempio n. 2
0
        static TypeDeclaration CreateClassFromIdentifier(RefactoringContext context, ClassType classType, IdentifierExpression identifierExpression)
        {
            var result = new TypeDeclaration {
                Name = identifierExpression.Identifier, ClassType = classType
            };
            var entity = identifierExpression.GetParent <EntityDeclaration>();

            if (entity != null)
            {
                result.Modifiers |= entity.Modifiers & Modifiers.Public;
            }
            return(result);
        }
 static TypeDeclaration CreateClassFromIdentifier(RefactoringContext context, ClassType classType, IdentifierExpression identifierExpression)
 {
     var result = new TypeDeclaration { Name = identifierExpression.Identifier, ClassType = classType };
     var entity = identifierExpression.GetParent<EntityDeclaration>();
     if (entity != null)
         result.Modifiers |= entity.Modifiers & Modifiers.Public;
     return result;
 }