コード例 #1
0
 public static void RunFindReferences(LocalResolveResult local)
 {
     var monitor = SD.StatusBar.CreateProgressMonitor();
     var results = FindReferenceService.FindLocalReferences(local.Variable, monitor);
     SearchResultsPad.Instance.ShowSearchResults(StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new StringTagPair("Name", local.Variable.Name)), results);
     SearchResultsPad.Instance.BringToFront();
 }
コード例 #2
0
		static string GetLocalExpression (TextEditor editor, LocalResolveResult lr, DomRegion expressionRegion)
		{
			var start = new DocumentLocation (expressionRegion.BeginLine, expressionRegion.BeginColumn);
			var end   = new DocumentLocation (expressionRegion.EndLine, expressionRegion.EndColumn);
			int startOffset = editor.Document.LocationToOffset (start);
			int endOffset = editor.Document.LocationToOffset (end);
			var ed = (ExtensibleTextEditor) editor;

			// In a setter, the 'value' variable will have a begin line/column of 0,0 which is an undefined offset
			if (lr.Variable.Region.BeginLine != 0 && lr.Variable.Region.BeginColumn != 0) {
				// Use the start and end offsets of the variable region so that we get the "@" in variable names like "@class"
				start = new DocumentLocation (lr.Variable.Region.BeginLine, lr.Variable.Region.BeginColumn);
				end = new DocumentLocation (lr.Variable.Region.EndLine, lr.Variable.Region.EndColumn);
				startOffset = editor.Document.LocationToOffset (start);
				endOffset = editor.Document.LocationToOffset (end);
			}

			string expression = ed.GetTextBetween (startOffset, endOffset).Trim ();

			// Note: When the LocalResolveResult is a parameter, the Variable.Region includes the type
			if (lr.IsParameter) {
				int index = IndexOfLastWhiteSpace (expression);
				if (index != -1)
					expression = expression.Substring (index + 1);
			}

			return expression;
		}
コード例 #3
0
            void CollectIssues(AstNode variableDecl, BlockStatement rootStatement, LocalResolveResult resolveResult)
            {
                if (rootStatement == null || resolveResult == null)
                    return;

                var references = new HashSet<AstNode> ();
                var refStatements = new HashSet<Statement> ();
                var usedInLambda = false;
                var results = ctx.FindReferences (rootStatement, resolveResult.Variable);
                foreach (var result in results) {
                    var node = result.Node;
                    if (node == variableDecl)
                        continue;

                    var parent = node.Parent;
                    while (!(parent == null || parent is Statement || parent is LambdaExpression))
                        parent = parent.Parent;
                    if (parent == null)
                        continue;

                    var statement = parent as Statement;
                    if (statement != null) {
                        references.Add (node);
                        refStatements.Add (statement);
                    }

                    while (parent != null && parent != rootStatement) {
                        if (parent is LambdaExpression || parent is AnonymousMethodExpression) {
                            usedInLambda = true;
                            break;
                        }
                        parent = parent.Parent;
                    }
                    if (usedInLambda) {
                        break;
                    }
                }

                // stop analyzing if the variable is used in any lambda expression or anonymous method
                if (usedInLambda)
                    return;

                var startNode = new VariableReferenceGraphBuilder (ctx).Build (rootStatement, references, refStatements, ctx);
                var variableInitializer = variableDecl as VariableInitializer;
                if (variableInitializer != null && !variableInitializer.Initializer.IsNull)
                    startNode.References.Insert (0, variableInitializer);

                ProcessNodes (startNode);
            }
コード例 #4
0
			void CollectIssues (AstNode variableDecl, AstNode rootNode, LocalResolveResult resolveResult)
			{
				if (resolveResult == null)
					return;
				var type = resolveResult.Type;
				var typeDef = type.GetDefinition ();
				if (typeDef == null ||
				    (typeDef.KnownTypeCode != KnownTypeCode.IEnumerable &&
				     typeDef.KnownTypeCode != KnownTypeCode.IEnumerableOfT))
					return;

				FindReferences (variableDecl, rootNode, resolveResult.Variable);

				var statements = AnalysisStatementCollector.Collect (variableDecl);
				var builder = new VariableReferenceGraphBuilder (ctx);
				foreach (var statement in statements) {
					var vrNode = builder.Build (statement, references, refStatements, ctx);
					FindMultipleEnumeration (vrNode);
				}
				foreach (var lambda in lambdaExpressions) {
					var vrNode = builder.Build (references, ctx.Resolver, (Expression)lambda.Body);
					FindMultipleEnumeration (vrNode);
				}
			}