
Hi,
On our product we now have a requirement that we to "refactor" some code.
For doing this I using dotNetProjectResolver.SourceProjectContent.GetTypesForSourceKey.
I am working with the Ast classes ( ClassDeclaration, MethodDeclaration, etc).
I traverse the nodes and in certain cases I need to change it.
(get's appended to different string so i am not modifying original one).
For doing that i am using the TextRange of the IAstNode to retrieve the original source.
(see below for simple helper)
Example: If i pass to my program this c# source:Doing a ToStringTree (BTW, excellent , really helpful this method)
for the MethodDeclaration statements show the following:
[1082-1098] StatementExpression
[1082-1098] InvocationExpression
[1082-1090] SimpleName: Validate
[1091-1097] SimpleName: entity
[1125-1138] ReturnStatement
[1132-1137] LiteralExpression
So far, so good.
Lets look at my source "after the conversion":
#1 Validate(entity)
#2 return false;
In line #1 the ; is missing.
My question is the following: Is there a reason why the TextRange for that case
is not including the ";" . It does not look consistent with the other cases
(at least not with ReturnStatement where it's included.
Am i missing something here?
Simple helper method that retrieves the text based on the textranges.
On our product we now have a requirement that we to "refactor" some code.
For doing this I using dotNetProjectResolver.SourceProjectContent.GetTypesForSourceKey.
I am working with the Ast classes ( ClassDeclaration, MethodDeclaration, etc).
I traverse the nodes and in certain cases I need to change it.
(get's appended to different string so i am not modifying original one).
For doing that i am using the TextRange of the IAstNode to retrieve the original source.
(see below for simple helper)
Example: If i pass to my program this c# source:
public bool OnFlushDirty(object entity, object id, object[] currentState,
object[] previousState, string[] propertyNames,
NHibernate.Type.IType[] types)
{
Validate(entity);
return false;
}
for the MethodDeclaration statements show the following:
[1082-1098] StatementExpression
[1082-1098] InvocationExpression
[1082-1090] SimpleName: Validate
[1091-1097] SimpleName: entity
[1125-1138] ReturnStatement
[1132-1137] LiteralExpression
So far, so good.
Lets look at my source "after the conversion":
#1 Validate(entity)
#2 return false;
In line #1 the ; is missing.
My question is the following: Is there a reason why the TextRange for that case
is not including the ";" . It does not look consistent with the other cases
(at least not with ReturnStatement where it's included.
Am i missing something here?
Simple helper method that retrieves the text based on the textranges.
private string GetSource(TextRange pTextRange)
{
if ( pTextRange == null ) throw new ArgumentNullException("pTextRange");
string source= _source.Substring(pTextRange.StartOffset, pTextRange.Length );
return source;
}