public ToolTipData(ICSharpCode.NRefactory.CSharp.CompilationUnit unit, ICSharpCode.NRefactory.Semantics.ResolveResult result, ICSharpCode.NRefactory.CSharp.AstNode node, CSharpAstResolver file)
 {
     this.Unit     = unit;
     this.Result   = result;
     this.Node     = node;
     this.Resolver = file;
 }
        IType GetDelegateType(RefactoringOptions options, ICSharpCode.NRefactory.CSharp.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 != MonoDevelop.Projects.Dom.ClassType.Delegate)
                    {
                        return(null);
                    }
                    return(type);
                }
                parent = parent.Parent;
            }
            return(null);
        }
Esempio n. 3
0
        public override List <Change> PerformChanges(RefactoringOptions options, object properties)
        {
            List <Change> result = new List <Change> ();

            ICSharpCode.NRefactory.CSharp.CompilationUnit unit = options.GetASTProvider().ParseFile(options.Document.Editor.Text);
            FindTypeReferencesVisitor visitor = new FindTypeReferencesVisitor(options.GetTextEditorData(), options.GetResolver());

            visitor.VisitCompilationUnit(unit, null);

            ProjectDom dom = options.Dom;

            ICompilationUnit compilationUnit = options.ParseDocument().CompilationUnit;
            HashSet <string> usedUsings      = new HashSet <string> ();

            foreach (var r in visitor.PossibleTypeReferences)
            {
                if (r is PrimitiveType)
                {
                    continue;
                }
                IType type = dom.SearchType(compilationUnit, options.ResolveResult != null ? options.ResolveResult.CallingType : null, new DomLocation(options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column), r.ConvertToReturnType());
                if (type != null)
                {
                    usedUsings.Add(type.Namespace);
                }
            }

            Mono.TextEditor.TextEditorData textEditorData = options.GetTextEditorData();
            HashSet <string> currentUsings = new HashSet <string> ();

            foreach (IUsing u in compilationUnit.Usings)
            {
                if (u.IsFromNamespace)
                {
                    continue;
                }
                if (!u.Aliases.Any() && u.Namespaces.All(name => currentUsings.Contains(name) || !usedUsings.Contains(name)))
                {
                    TextReplaceChange change = new TextReplaceChange();
                    change.FileName     = options.Document.FileName;
                    change.Offset       = textEditorData.Document.LocationToOffset(u.Region.Start.Line, u.Region.Start.Column);
                    change.RemovedChars = textEditorData.Document.LocationToOffset(u.Region.End.Line, u.Region.End.Column) - change.Offset;
                    Mono.TextEditor.LineSegment line = textEditorData.Document.GetLineByOffset(change.Offset);
                    if (line != null && line.EditableLength == change.RemovedChars)
                    {
                        change.RemovedChars += line.DelimiterLength;
                    }
                    result.Add(change);
                }
                foreach (string nspace in u.Namespaces)
                {
                    currentUsings.Add(nspace);
                }
            }

            return(result);
        }
        InvocationExpression GetInvocation(ICSharpCode.NRefactory.CSharp.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);
        }
        bool AnalyzeTargetExpression(RefactoringOptions options, ICSharpCode.NRefactory.CSharp.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)
            {
                if (options.ResolveResult != null)
                {
                    declaringType = options.ResolveResult.CallingType;
                }
                else
                {
                    declaringType = options.Document.CompilationUnit.GetTypeAt(options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column);
                }
                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;
                }
                if (declaringType == null || declaringType.CompilationUnit == null)
                {
                    return(false);
                }
                var doc = ProjectDomService.GetParsedDocument(declaringType.SourceProjectDom, declaringType.CompilationUnit.FileName);
                declaringType = doc.CompilationUnit.GetTypeAt(declaringType.Location) ?? declaringType;
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        public void Inspect(MonoDevelop.Ide.Gui.Document doc, IResolver resolver, ICSharpCode.NRefactory.CSharp.CompilationUnit unit)
        {
//			var findTypeReferencesVisitor = new MonoDevelop.Refactoring.RefactorImports.FindTypeReferencesVisitor (doc.Editor, resolver);
//			unit.AcceptVisitor (findTypeReferencesVisitor, null);
//			this.PossibleTypeReferences = findTypeReferencesVisitor.PossibleTypeReferences;
//
//			foreach (var r in PossibleTypeReferences) {
//				if (r is PrimitiveType)
//					continue;
//				var loc = new DomLocation (r.StartLocation.Line, r.StartLocation.Column);
//				IType type = doc.Dom.SearchType (doc.CompilationUnit,
//					doc.CompilationUnit.GetTypeAt (loc),
//					loc,
//					r.ConvertToReturnType ());
//
//				if (type != null)
//					usedUsings.Add (type.Namespace);
//			}
        }
		void HandleDocumentDocumentParsed (object sender, EventArgs e)
		{
			var unit = Document.ParsedDocument;
			if (unit != null) {
				LanguageAST = unit.LanguageAST as ICSharpCode.NRefactory.CSharp.CompilationUnit;
				Editor.Parent.TextViewMargin.PurgeLayoutCache ();
				Editor.Parent.RedrawMarginLines (Editor.Parent.TextViewMargin, 1, Editor.LineCount);
			}
			
			UpdatePath (null, null);
		}
Esempio n. 8
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            CompilationUnit o = other as CompilationUnit;

            return(o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match));
        }
Esempio n. 9
0
 public virtual S VisitCompilationUnit(CompilationUnit unit, T data)
 {
     return(VisitChildren(unit, data));
 }
 public virtual S VisitCompilationUnit(CompilationUnit compilationUnit, T data)
 {
     throw new NotImplementedException();
 }