示例#1
0
        IType GetDelegateType(RefactoringOptions options, MonoDevelop.CSharp.Ast.CompilationUnit unit)
        {
            var data           = options.GetTextEditorData();
            var containingNode = unit.GetNodeAt(data.Caret.Line, data.Caret.Column);
            var parent         = containingNode.Parent;

            while (parent != null)
            {
                if (parent is AssignmentExpression)
                {
                    AssignmentExpression assignment = (AssignmentExpression)parent;
                    if (assignment.Operator != AssignmentOperatorType.Add && assignment.Operator != AssignmentOperatorType.Subtract && assignment.Operator != AssignmentOperatorType.Assign)
                    {
                        return(null);
                    }

                    var resolveResult = ResolveAssignment(options, assignment);
                    if (resolveResult == null)
                    {
                        return(null);
                    }
                    IType type = options.Dom.GetType(resolveResult.ResolvedType);
                    if (type == null || type.ClassType != ClassType.Delegate)
                    {
                        return(null);
                    }
                    return(type);
                }
                parent = parent.Parent;
            }
            return(null);
        }
示例#2
0
        InvocationExpression GetInvocation(MonoDevelop.CSharp.Ast.CompilationUnit unit, TextEditorData data)
        {
            var containingNode = unit.GetNodeAt(data.Caret.Line, data.Caret.Column);
            var curNode        = containingNode;

            while (curNode != null && !(curNode is InvocationExpression))
            {
                curNode = curNode.Parent;
            }
            return(curNode as InvocationExpression);
        }
示例#3
0
        bool AnalyzeTargetExpression(RefactoringOptions options, MonoDevelop.CSharp.Ast.CompilationUnit unit)
        {
            var data   = options.GetTextEditorData();
            var target = unit.GetNodeAt(data.Caret.Line, data.Caret.Column);

            if (target == null)
            {
                return(false);
            }
            if (target.Parent is MemberReferenceExpression && ((MemberReferenceExpression)target.Parent).GetChildByRole(MemberReferenceExpression.Roles.Identifier) == target)
            {
                var memberReference = (MemberReferenceExpression)target.Parent;
                target = memberReference.Target;
                var targetResult = options.GetResolver().Resolve(new ExpressionResult(data.GetTextBetween(target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column)), resolvePosition);
                if (targetResult.StaticResolve)
                {
                    modifiers = MonoDevelop.Projects.Dom.Modifiers.Static;
                }
                declaringType = options.Dom.GetType(targetResult.ResolvedType);
                methodName    = memberReference.MemberName;
            }
            else if (target is Identifier)
            {
                declaringType = options.ResolveResult.CallingType;
                methodName    = data.GetTextBetween(target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column);
            }

            if (declaringType != null && !HasCompatibleMethod(declaringType, methodName, invocation))
            {
                if (declaringType.HasParts)
                {
                    declaringType = declaringType.Parts.FirstOrDefault(t => t.CompilationUnit.FileName == options.Document.FileName) ?? declaringType;
                }
                var doc = ProjectDomService.GetParsedDocument(declaringType.SourceProjectDom, declaringType.CompilationUnit.FileName);
                declaringType = doc.CompilationUnit.GetTypeAt(declaringType.Location) ?? declaringType;
                return(true);
            }
            return(false);
        }