Browse Source

[Ast] GetNodeAt now searches from the end - since getting the start

location is more efficient than getting the end location.
newNRvisualizers
Mike Krüger 13 years ago
parent
commit
6ccb54b0d3
  1. 40
      ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

40
ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -652,11 +652,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -652,11 +652,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
AstNode result = null;
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null && child.EndLocation <= location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
while (node.LastChild != null) {
var child = node.LastChild;
while (child != null && child.StartLocation > location)
child = child.prevSibling;
if (child != null && location < child.EndLocation) {
if (pred == null || pred (child))
result = child;
node = child;
@ -687,11 +687,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -687,11 +687,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
T result = null;
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null && child.EndLocation <= location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
while (node.LastChild != null) {
var child = node.LastChild;
while (child != null && child.StartLocation > location)
child = child.prevSibling;
if (child != null && location < child.EndLocation) {
if (child is T)
result = (T)child;
node = child;
@ -725,11 +725,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -725,11 +725,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
AstNode result = null;
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null && child.EndLocation < location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
while (node.LastChild != null) {
var child = node.LastChild;
while (child != null && child.StartLocation > location)
child = child.prevSibling;
if (child != null && location <= child.EndLocation) {
if (pred == null || pred (child))
result = child;
node = child;
@ -760,11 +760,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -760,11 +760,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
T result = null;
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null && child.EndLocation < location)
child = child.nextSibling;
if (child != null && child.StartLocation <= location) {
while (node.LastChild != null) {
var child = node.LastChild;
while (child != null && child.StartLocation > location)
child = child.prevSibling;
if (child != null && location <= child.EndLocation) {
if (child is T)
result = (T)child;
node = child;

Loading…
Cancel
Save