Browse Source

NRefactory: Support parsing statements like "SomeDelegate d = GenericMethod<string>;"

Renamed FieldReferenceExpression to MemberReferenceExpression.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2676 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
0c51983690
  1. 13
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs
  2. 7
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorStatements.cs
  3. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBNetToCSharpConvertVisitorWithMyFormsSupport.cs
  4. 2
      src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/BclNRefactoryResourceResolver.cs
  5. 2
      src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/ICSharpCodeCoreNRefactoryResourceResolver.cs
  6. 23
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs
  7. 137
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  8. 4
      src/Libraries/NRefactory/Project/Src/IAstVisitor.cs
  9. 2
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt
  10. 1
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs
  11. 88
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
  12. 930
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  13. 60
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  14. 18
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  15. 18
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  16. 20
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  17. 23
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  18. 24
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  19. 28
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  20. 54
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  21. 2
      src/Libraries/NRefactory/Project/Src/Visitors/CSharpConstructsConvertVisitor.cs
  22. 55
      src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs
  23. 22
      src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs
  24. 4
      src/Libraries/NRefactory/Project/Src/Visitors/PrefixFieldsVisitor.cs
  25. 4
      src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs
  26. 4
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs
  27. 22
      src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs
  28. 2
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  29. 8
      src/Libraries/NRefactory/Test/Output/CodeDOM/InvocationExpressionTest.cs
  30. 4
      src/Libraries/NRefactory/Test/Parser/Expressions/BaseReferenceExpressionTests.cs
  31. 4
      src/Libraries/NRefactory/Test/Parser/Expressions/CastExpressionTests.cs
  32. 2
      src/Libraries/NRefactory/Test/Parser/Expressions/ClassReferenceExpressionTests.cs
  33. 8
      src/Libraries/NRefactory/Test/Parser/Expressions/ConditionalExpressionTests.cs
  34. 8
      src/Libraries/NRefactory/Test/Parser/Expressions/IdentifierExpressionTests.cs
  35. 39
      src/Libraries/NRefactory/Test/Parser/Expressions/InvocationExpressionTests.cs
  36. 24
      src/Libraries/NRefactory/Test/Parser/Expressions/MemberReferenceExpressionTests.cs
  37. 2
      src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs
  38. 2
      src/Libraries/NRefactory/Test/Parser/Expressions/PointerReferenceExpressionTests.cs
  39. 4
      src/Libraries/NRefactory/Test/Parser/Expressions/PrimitiveExpressionTests.cs
  40. 12
      src/Libraries/NRefactory/Test/Parser/Expressions/TypeReferenceExpressionTests.cs
  41. 4
      src/Libraries/NRefactory/Test/Parser/Statements/ExpressionStatementTests.cs
  42. 18
      src/Libraries/NRefactory/Test/Parser/TypeLevel/ConstructorDeclarationTests.cs
  43. 16
      src/Libraries/NRefactory/Test/Parser/TypeLevel/DestructorDeclarationTests.cs
  44. 17
      src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs
  45. 2
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/ConstructorCodeGenerator.cs
  46. 12
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/EqualsCodeGenerator.cs
  47. 6
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/ToStringCodeGenerator.cs
  48. 20
      src/Main/Base/Test/CSharpExpressionFinderTests.cs
  49. 10
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs
  50. 8
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/CSharpToVBNetConvertVisitor.cs
  51. 34
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs
  52. 44
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs
  53. 28
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/VBNetToCSharpConvertVisitor.cs
  54. 10
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs

13
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorExpressions.cs

@ -133,20 +133,20 @@ namespace NRefactoryToBooConverter @@ -133,20 +133,20 @@ namespace NRefactoryToBooConverter
return new B.ReferenceExpression(GetLexicalInfo(identifierExpression), identifierExpression.Identifier);
}
public object VisitFieldReferenceExpression(FieldReferenceExpression fre, object data)
public object VisitMemberReferenceExpression(MemberReferenceExpression mre, object data)
{
B.Expression target = null;
if (fre.TargetObject is TypeReferenceExpression) {
if (mre.TargetObject is TypeReferenceExpression) {
// not typeof, so this is something like int.Parse() or Class<string>.StaticMethod
TypeReference typeRef = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
TypeReference typeRef = ((TypeReferenceExpression)mre.TargetObject).TypeReference;
if (!typeRef.IsArrayType)
target = MakeReferenceExpression(typeRef);
}
if (target == null) {
target = (B.Expression)fre.TargetObject.AcceptVisitor(this, data);
target = (B.Expression)mre.TargetObject.AcceptVisitor(this, data);
if (target == null) return null;
}
return new B.MemberReferenceExpression(GetLexicalInfo(fre), target, fre.FieldName);
return new B.MemberReferenceExpression(GetLexicalInfo(mre), target, mre.FieldName);
}
public object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data)
@ -331,9 +331,6 @@ namespace NRefactoryToBooConverter @@ -331,9 +331,6 @@ namespace NRefactoryToBooConverter
public object VisitInvocationExpression(InvocationExpression ie, object data)
{
if (ie.TypeArguments != null && ie.TypeArguments.Count > 0) {
AddError(ie, "Generic method calls are not supported.");
}
B.Expression e = ConvertExpression(ie.TargetObject);
if (e == null)
return null;

7
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorStatements.cs

@ -325,13 +325,14 @@ namespace NRefactoryToBooConverter @@ -325,13 +325,14 @@ namespace NRefactoryToBooConverter
AddError(reDimStatement, "Redim Preserve is not supported.");
ArrayList list = new ArrayList();
foreach (InvocationExpression o in reDimStatement.ReDimClauses) {
if (o.TypeArguments != null && o.TypeArguments.Count > 0) {
AddError(o, "Type parameter are not allowed here.");
}
IdentifierExpression identifier = o.TargetObject as IdentifierExpression;
if (identifier == null) {
AddError(o, "Sorry, that expression is too complex to be resolved by the converter.");
} else {
if (identifier.TypeArguments != null && identifier.TypeArguments.Count > 0) {
AddError(o, "Type parameters are not allowed here.");
}
// first we need to find out the array type
VariableResolver resolver = new VariableResolver(nameComparer);
TypeReference r = resolver.FindType(identifier.Identifier, reDimStatement);

4
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBNetToCSharpConvertVisitorWithMyFormsSupport.cs

@ -52,9 +52,9 @@ namespace CSharpBinding @@ -52,9 +52,9 @@ namespace CSharpBinding
return null;
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
ResolveResult fieldRR = base.VisitFieldReferenceExpression(fieldReferenceExpression, data) as ResolveResult;
ResolveResult fieldRR = base.VisitMemberReferenceExpression(fieldReferenceExpression, data) as ResolveResult;
if (vbMyFormsClass != null && IsReferenceToInstanceMember(fieldRR)) {
TypeResolveResult trr = Resolve(fieldReferenceExpression.TargetObject) as TypeResolveResult;

2
src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/BclNRefactoryResourceResolver.cs

@ -687,7 +687,7 @@ namespace Hornung.ResourceToolkit.Resolver @@ -687,7 +687,7 @@ namespace Hornung.ResourceToolkit.Resolver
InvocationExpression invocation = expr as InvocationExpression;
if (invocation != null) {
FieldReferenceExpression fre = invocation.TargetObject as FieldReferenceExpression;
MemberReferenceExpression fre = invocation.TargetObject as MemberReferenceExpression;
if (fre != null) {
if (fre.FieldName == "GetString" || fre.FieldName == "GetObject" || fre.FieldName == "GetStream") {
if (invocation.Arguments.Count > 0) {

2
src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/ICSharpCodeCoreNRefactoryResourceResolver.cs

@ -100,7 +100,7 @@ namespace Hornung.ResourceToolkit.Resolver @@ -100,7 +100,7 @@ namespace Hornung.ResourceToolkit.Resolver
InvocationExpression invocation = expr as InvocationExpression;
if (invocation != null) {
FieldReferenceExpression fre = invocation.TargetObject as FieldReferenceExpression;
MemberReferenceExpression fre = invocation.TargetObject as MemberReferenceExpression;
if (fre != null) {
if (fre.FieldName == "GetString") {
if (invocation.Arguments.Count > 0) {

23
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs

@ -101,16 +101,26 @@ namespace NRefactoryASTGenerator.Ast @@ -101,16 +101,26 @@ namespace NRefactoryASTGenerator.Ast
public CastExpression(TypeReference castTo, Expression expression, CastType castType) {}
}
class FieldReferenceExpression : Expression
class MemberReferenceExpression : Expression
{
Expression targetObject;
string fieldName;
List<TypeReference> typeArguments;
public FieldReferenceExpression(Expression targetObject, string fieldName) {}
public MemberReferenceExpression(Expression targetObject, string fieldName) {}
}
class PointerReferenceExpression : Expression {
Expression targetObject;
string identifier;
List<TypeReference> typeArguments;
public PointerReferenceExpression(Expression targetObject, string identifier) {}
}
class IdentifierExpression : Expression {
string identifier;
List<TypeReference> typeArguments;
public IdentifierExpression(string identifier) {}
}
@ -118,11 +128,9 @@ namespace NRefactoryASTGenerator.Ast @@ -118,11 +128,9 @@ namespace NRefactoryASTGenerator.Ast
class InvocationExpression : Expression {
Expression targetObject;
List<Expression> arguments;
List<TypeReference> typeArguments;
public InvocationExpression(Expression targetObject) {}
public InvocationExpression(Expression targetObject, List<Expression> arguments) {}
public InvocationExpression(Expression targetObject, List<Expression> arguments, List<TypeReference> typeArguments) {}
}
class ParenthesizedExpression : Expression {
@ -204,13 +212,6 @@ namespace NRefactoryASTGenerator.Ast @@ -204,13 +212,6 @@ namespace NRefactoryASTGenerator.Ast
public IndexerExpression(Expression targetObject, List<Expression> indexes) {}
}
class PointerReferenceExpression : Expression {
Expression targetObject;
string identifier;
public PointerReferenceExpression(Expression targetObject, string identifier) {}
}
class SizeOfExpression : Expression {
TypeReference typeReference;

137
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -1792,45 +1792,6 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1792,45 +1792,6 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public class FieldReferenceExpression : Expression {
Expression targetObject;
string fieldName;
public Expression TargetObject {
get {
return targetObject;
}
set {
targetObject = value ?? Expression.Null;
if (!targetObject.IsNull) targetObject.Parent = this;
}
}
public string FieldName {
get {
return fieldName;
}
set {
fieldName = value ?? "";
}
}
public FieldReferenceExpression(Expression targetObject, string fieldName) {
TargetObject = targetObject;
FieldName = fieldName;
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitFieldReferenceExpression(this, data);
}
public override string ToString() {
return string.Format("[FieldReferenceExpression TargetObject={0} FieldName={1}]", TargetObject, FieldName);
}
}
public class FixedStatement : StatementWithEmbeddedStatement {
TypeReference typeReference;
@ -2150,6 +2111,8 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2150,6 +2111,8 @@ namespace ICSharpCode.NRefactory.Ast {
string identifier;
List<TypeReference> typeArguments;
public string Identifier {
get {
return identifier;
@ -2159,8 +2122,18 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2159,8 +2122,18 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public List<TypeReference> TypeArguments {
get {
return typeArguments;
}
set {
typeArguments = value ?? new List<TypeReference>();
}
}
public IdentifierExpression(string identifier) {
Identifier = identifier;
typeArguments = new List<TypeReference>();
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
@ -2168,7 +2141,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2168,7 +2141,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
public override string ToString() {
return string.Format("[IdentifierExpression Identifier={0}]", Identifier);
return string.Format("[IdentifierExpression Identifier={0} TypeArguments={1}]", Identifier, GetCollectionString(TypeArguments));
}
}
@ -2232,6 +2205,12 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2232,6 +2205,12 @@ namespace ICSharpCode.NRefactory.Ast {
this.trueStatement.Add(Statement.CheckNull(trueStatement));
}
public bool HasElseIfSections {
get {
return elseIfSections.Count > 0;
}
}
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement)
: this(condition) {
@ -2245,12 +2224,6 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2245,12 +2224,6 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public bool HasElseIfSections {
get {
return elseIfSections.Count > 0;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitIfElseStatement(this, data);
}
@ -2482,8 +2455,6 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2482,8 +2455,6 @@ namespace ICSharpCode.NRefactory.Ast {
List<Expression> arguments;
List<TypeReference> typeArguments;
public Expression TargetObject {
get {
return targetObject;
@ -2503,31 +2474,14 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2503,31 +2474,14 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public List<TypeReference> TypeArguments {
get {
return typeArguments;
}
set {
typeArguments = value ?? new List<TypeReference>();
}
}
public InvocationExpression(Expression targetObject) {
TargetObject = targetObject;
arguments = new List<Expression>();
typeArguments = new List<TypeReference>();
}
public InvocationExpression(Expression targetObject, List<Expression> arguments) {
TargetObject = targetObject;
Arguments = arguments;
typeArguments = new List<TypeReference>();
}
public InvocationExpression(Expression targetObject, List<Expression> arguments, List<TypeReference> typeArguments) {
TargetObject = targetObject;
Arguments = arguments;
TypeArguments = typeArguments;
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
@ -2535,7 +2489,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2535,7 +2489,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
public override string ToString() {
return string.Format("[InvocationExpression TargetObject={0} Arguments={1} TypeArguments={2}]", TargetObject, GetCollectionString(Arguments), GetCollectionString(TypeArguments));
return string.Format("[InvocationExpression TargetObject={0} Arguments={1}]", TargetObject, GetCollectionString(Arguments));
}
}
@ -2684,6 +2638,57 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2684,6 +2638,57 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public class MemberReferenceExpression : Expression {
Expression targetObject;
string fieldName;
List<TypeReference> typeArguments;
public Expression TargetObject {
get {
return targetObject;
}
set {
targetObject = value ?? Expression.Null;
if (!targetObject.IsNull) targetObject.Parent = this;
}
}
public string FieldName {
get {
return fieldName;
}
set {
fieldName = value ?? "";
}
}
public List<TypeReference> TypeArguments {
get {
return typeArguments;
}
set {
typeArguments = value ?? new List<TypeReference>();
}
}
public MemberReferenceExpression(Expression targetObject, string fieldName) {
TargetObject = targetObject;
FieldName = fieldName;
typeArguments = new List<TypeReference>();
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitMemberReferenceExpression(this, data);
}
public override string ToString() {
return string.Format("[MemberReferenceExpression TargetObject={0} FieldName={1} TypeArguments={2}]", TargetObject, FieldName, GetCollectionString(TypeArguments));
}
}
public class MethodDeclaration : MemberNode {
BlockStatement body;

4
src/Libraries/NRefactory/Project/Src/IAstVisitor.cs

@ -97,8 +97,6 @@ namespace ICSharpCode.NRefactory { @@ -97,8 +97,6 @@ namespace ICSharpCode.NRefactory {
object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data);
object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data);
object VisitFixedStatement(FixedStatement fixedStatement, object data);
object VisitForeachStatement(ForeachStatement foreachStatement, object data);
@ -133,6 +131,8 @@ namespace ICSharpCode.NRefactory { @@ -133,6 +131,8 @@ namespace ICSharpCode.NRefactory {
object VisitLockStatement(LockStatement lockStatement, object data);
object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data);
object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data);
object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data);

2
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt

@ -190,6 +190,8 @@ CastFollower(@SimpleTypeName, Literal, "(", "~", "!", @ExpressionStart) @@ -190,6 +190,8 @@ CastFollower(@SimpleTypeName, Literal, "(", "~", "!", @ExpressionStart)
AssgnOps("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=")
UnaryOp("+", "-", "!", "~", "*", "++", "--", "&")
TypeDeclarationKW("class", "interface", "struct", "enum", "delegate")
# for §7.5.4.2 "Grammar ambiguities" disambiguation for F(G<A,B>(7))
GenericFollower("(", ")", "]", "}", ":", ";", Comma, ".", "?", "==", "!=")
ValidInsideTypeName(@IdentifierTokens, @TypeKW, "<", ">", ".", "?", "[", Comma, "]", "*", "::")

1
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs

@ -176,6 +176,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -176,6 +176,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
public static BitArray AssgnOps = NewSet(Assign, PlusAssign, MinusAssign, TimesAssign, DivAssign, ModAssign, BitwiseAndAssign, BitwiseOrAssign, ShiftLeftAssign);
public static BitArray UnaryOp = NewSet(Plus, Minus, Not, BitwiseComplement, Times, Increment, Decrement, BitwiseAnd);
public static BitArray TypeDeclarationKW = NewSet(Class, Interface, Struct, Enum, Delegate);
public static BitArray GenericFollower = NewSet(OpenParenthesis, CloseParenthesis, CloseSquareBracket, CloseCurlyBrace, Colon, Semicolon, Comma, Dot, Question, Equal, NotEqual);
public static BitArray ValidInsideTypeName = NewSet(Identifier, Partial, Where, Get, Set, Add, Remove, Yield, Select, Group, By, Into, From, Ascending, Descending, Orderby, Let, Join, On, Equals, Char, Bool, Object, String, Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Decimal, LessThan, GreaterThan, Dot, Question, OpenSquareBracket, Comma, CloseSquareBracket, Times, DoubleColon);
public static BitArray KCCClassModifiers = NewSet(Abstract, Sealed, Static, Unsafe, Partial);
public static BitArray KCCTypeDeclarationStart = NewSet(Public, Internal, Class, Interface, Struct, Enum, Delegate, Abstract, Sealed, Static, Unsafe, Partial);

88
src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs

@ -448,13 +448,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -448,13 +448,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt);
}
/* True if lookahead is type parameters (<...>) followed by the specified token */
bool IsGenericFollowedBy(int token)
/* True if lookahead is a type argument list (<...>) followed by
* one of "( ) ] } : ; , . ? == !=" */
bool IsGenericInSimpleNameOrMemberAccess()
{
Token t = la;
if (t.kind != Tokens.LessThan) return false;
StartPeek();
return SkipGeneric(ref t) && t.kind == token;
return SkipGeneric(ref t) && Tokens.GenericFollower[t.kind];
}
bool IsExplicitInterfaceImplementation()
@ -497,61 +498,50 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -497,61 +498,50 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
return (la.kind == Tokens.GreaterThan && next.kind == Tokens.GreaterThan);
}
bool IsTypeReferenceExpression(Expression expr)
bool IsGenericExpression(Expression expr)
{
if (expr is TypeReferenceExpression) return ((TypeReferenceExpression)expr).TypeReference.GenericTypes.Count == 0;
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
if (expr is TypeReferenceExpression) return true;
}
return expr is IdentifierExpression;
if (expr is IdentifierExpression)
return ((IdentifierExpression)expr).TypeArguments.Count > 0;
else if (expr is MemberReferenceExpression)
return ((MemberReferenceExpression)expr).TypeArguments.Count > 0;
else
return false;
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
bool ShouldConvertTargetExpressionToTypeReference(Expression targetExpr)
{
if (targetExpr is IdentifierExpression)
return ((IdentifierExpression)targetExpr).TypeArguments.Count > 0;
else if (targetExpr is MemberReferenceExpression)
return ((MemberReferenceExpression)targetExpr).TypeArguments.Count > 0;
else
return false;
}
TypeReference GetTypeReferenceFromExpression(Expression expr)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
if (expr is TypeReferenceExpression)
return (expr as TypeReferenceExpression).TypeReference;
IdentifierExpression ident = expr as IdentifierExpression;
if (ident != null) {
return new TypeReference(ident.Identifier, ident.TypeArguments);
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
MemberReferenceExpression member = expr as MemberReferenceExpression;
if (member != null) {
TypeReference targetType = GetTypeReferenceFromExpression(member.TargetObject);
if (targetType != null) {
if (targetType.GenericTypes.Count == 0 && targetType.IsArrayType == false) {
TypeReference tr = new TypeReference(targetType.Type + "." + member.FieldName, member.TypeArguments);
tr.IsGlobal = targetType.IsGlobal;
return tr;
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
return new InnerClassTypeReference(targetType, member.FieldName, member.TypeArguments);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
return null;
}
bool IsMostNegativeIntegerWithoutTypeSuffix()

930
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

60
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -1748,7 +1748,6 @@ UnaryExpr<out Expression uExpr> @@ -1748,7 +1748,6 @@ UnaryExpr<out Expression uExpr>
PrimaryExpr<out Expression pexpr>
(.
TypeReference type = null;
List<TypeReference> typeList = null;
Expression expr;
pexpr = null;
.)
@ -1769,7 +1768,12 @@ PrimaryExpr<out Expression pexpr> @@ -1769,7 +1768,12 @@ PrimaryExpr<out Expression pexpr>
(. pexpr = new IdentifierExpression(t.val); .)
(. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
[ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr> ]
[ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr>
| IF (IsGenericInSimpleNameOrMemberAccess())
(. List<TypeReference> typeList; .)
TypeArgumentList<out typeList, false>
(. ((IdentifierExpression)pexpr).TypeArguments = typeList; .)
]
| IF (IsLambdaExpression()) /* Lambda expression */
LambdaExpression<out pexpr>
/*--- parenthesized expression: */
@ -1792,13 +1796,14 @@ PrimaryExpr<out Expression pexpr> @@ -1792,13 +1796,14 @@ PrimaryExpr<out Expression pexpr>
| "uint" (. val = "uint"; .)
| "ulong" (. val = "ulong"; .)
| "ushort" (. val = "ushort"; .)
) (. t.val = ""; .) "." Identifier (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .)
)
MemberAccess<out pexpr, new TypeReferenceExpression(val)>
/*--- this access: */
| "this" (. pexpr = new ThisReferenceExpression(); .)
/*--- base access: */
| "base" (. Expression retExpr = new BaseReferenceExpression(); .)
(
"." Identifier (. retExpr = new FieldReferenceExpression(retExpr, t.val); .)
MemberAccess<out retExpr, retExpr>
| "[" Expr<out expr> (. List<Expression> indices = new List<Expression>(); if (expr != null) { indices.Add(expr); } .)
{ "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .) }
"]" (. retExpr = new IndexerExpression(retExpr, indices); .)
@ -1825,23 +1830,14 @@ PrimaryExpr<out Expression pexpr> @@ -1825,23 +1830,14 @@ PrimaryExpr<out Expression pexpr>
| "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
)
/*--- member access */
| "->" Identifier (. pexpr = new PointerReferenceExpression(pexpr, t.val); .)
| "." Identifier (. pexpr = new FieldReferenceExpression(pexpr, t.val);.)
/* member access on generic type */
| ( IF (IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr))
TypeArgumentList<out typeList, false> )
"." Identifier
(. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeList), t.val);.)
| PointerMemberAccess<out pexpr, pexpr>
| MemberAccess<out pexpr, pexpr>
/*--- invocation expression: */
| "(" (. List<Expression> parameters = new List<Expression>(); .)
[ Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
{ "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
} ] ")" (. pexpr = new InvocationExpression(pexpr, parameters); .)
| ( IF (IsGenericFollowedBy(Tokens.OpenParenthesis)) TypeArgumentList<out typeList, false> )
"(" (. List<Expression> parameters = new List<Expression>(); .)
[ Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
{ "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
} ] ")" (. pexpr = new InvocationExpression(pexpr, parameters, typeList); .)
/*--- element access */
| (. /*if (isArrayCreation) Error("element access not allow on array creation");*/
List<Expression> indices = new List<Expression>();
@ -1852,6 +1848,38 @@ PrimaryExpr<out Expression pexpr> @@ -1852,6 +1848,38 @@ PrimaryExpr<out Expression pexpr>
}
.
MemberAccess<out Expression expr, Expression target>
(. List<TypeReference> typeList; .)
=
(. if (ShouldConvertTargetExpressionToTypeReference(target)) {
TypeReference type = GetTypeReferenceFromExpression(target);
if (type != null) {
target = new TypeReferenceExpression(type);
}
}
t.val = ""; // required for TypeReferenceExpressionTests.StandaloneIntReferenceExpression hack
.)
"."
Identifier
(. expr = new MemberReferenceExpression(target, t.val); .)
[ IF (IsGenericInSimpleNameOrMemberAccess())
TypeArgumentList<out typeList, false>
(. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)
]
.
PointerMemberAccess<out Expression expr, Expression target>
(. List<TypeReference> typeList; .)
=
"->"
Identifier
(. expr = new PointerReferenceExpression(target, t.val); .)
[ IF (IsGenericInSimpleNameOrMemberAccess())
TypeArgumentList<out typeList, false>
(. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)
]
.
NewExpression<out Expression pexpr>
(. pexpr = null;
List<Expression> parameters = new List<Expression>();

18
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

@ -3536,7 +3536,7 @@ out pexpr); @@ -3536,7 +3536,7 @@ out pexpr);
out name);
#line 1588 "VBNET.ATG"
pexpr = new FieldReferenceExpression(pexpr, name);
pexpr = new MemberReferenceExpression(pexpr, name);
} else {
InvocationExpression(
#line 1589 "VBNET.ATG"
@ -3669,7 +3669,7 @@ out val); @@ -3669,7 +3669,7 @@ out val);
Identifier();
#line 1620 "VBNET.ATG"
pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val);
pexpr = new MemberReferenceExpression(new TypeReferenceExpression(val), t.val);
break;
}
case 119: {
@ -3700,7 +3700,7 @@ out val); @@ -3700,7 +3700,7 @@ out val);
out name);
#line 1626 "VBNET.ATG"
pexpr = new FieldReferenceExpression(retExpr, name);
pexpr = new MemberReferenceExpression(retExpr, name);
break;
}
case 199: {
@ -3816,7 +3816,7 @@ out type); @@ -3816,7 +3816,7 @@ out type);
out name);
#line 1648 "VBNET.ATG"
pexpr = new FieldReferenceExpression(null, name);
pexpr = new MemberReferenceExpression(null, name);
} else SynErr(243);
}
@ -3855,7 +3855,7 @@ out type); @@ -3855,7 +3855,7 @@ out type);
Identifier();
#line 1667 "VBNET.ATG"
pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val);
pexpr = new MemberReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val);
} else if (la.kind == 24) {
lexer.NextToken();
ArgumentList(
@ -3864,7 +3864,7 @@ out parameters); @@ -3864,7 +3864,7 @@ out parameters);
Expect(25);
#line 1671 "VBNET.ATG"
pexpr = new InvocationExpression(pexpr, parameters, typeParameters);
pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters);
} else SynErr(244);
} else if (StartOf(30)) {
ArgumentList(
@ -3873,7 +3873,7 @@ out parameters); @@ -3873,7 +3873,7 @@ out parameters);
Expect(25);
#line 1675 "VBNET.ATG"
pexpr = new InvocationExpression(pexpr, parameters, typeParameters);
pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters);
} else SynErr(245);
#line 1677 "VBNET.ATG"
@ -5647,7 +5647,7 @@ out val); @@ -5647,7 +5647,7 @@ out val);
#line 2531 "VBNET.ATG"
// a field reference expression that stands alone is a
// invocation expression without parantheses and arguments
if(expr is FieldReferenceExpression || expr is IdentifierExpression) {
if(expr is MemberReferenceExpression || expr is IdentifierExpression) {
expr = new InvocationExpression(expr);
}
statement = new ExpressionStatement(expr);
@ -6079,7 +6079,7 @@ la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { @@ -6079,7 +6079,7 @@ la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) {
out name);
#line 2658 "VBNET.ATG"
expr = new FieldReferenceExpression(expr, name);
expr = new MemberReferenceExpression(expr, name);
} else {
InvocationExpression(
#line 2660 "VBNET.ATG"

18
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1585,7 +1585,7 @@ SimpleExpr<out Expression pexpr> @@ -1585,7 +1585,7 @@ SimpleExpr<out Expression pexpr>
=
SimpleNonInvocationExpression<out pexpr>
{ (. string name; .)
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(pexpr, name); .)
| InvocationExpression<ref pexpr>
}
.
@ -1617,13 +1617,13 @@ SimpleNonInvocationExpression<out Expression pexpr> @@ -1617,13 +1617,13 @@ SimpleNonInvocationExpression<out Expression pexpr>
(. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
| (. string val = String.Empty; .)
( PrimitiveTypeName<out val> | "Object" (. val = "Object"; .) )
"." (. t.val = ""; .) Identifier (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .)
"." (. t.val = ""; .) Identifier (. pexpr = new MemberReferenceExpression(new TypeReferenceExpression(val), t.val); .)
| "Me" (. pexpr = new ThisReferenceExpression(); .)
| (. Expression retExpr = null; .)
( "MyBase" (. retExpr = new BaseReferenceExpression(); .)
| "MyClass" (. retExpr = new ClassReferenceExpression(); .)
)
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(retExpr, name); .)
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(retExpr, name); .)
| "Global" "."
Identifier (. type = new TypeReference(t.val ?? ""); .)
/* fallback to "" is required if the token wasn't an identifier (->parser error but no exception) */
@ -1645,7 +1645,7 @@ SimpleNonInvocationExpression<out Expression pexpr> @@ -1645,7 +1645,7 @@ SimpleNonInvocationExpression<out Expression pexpr>
)
|
/* this form only occurs in WithStatements*/
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(null, name);.)
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(null, name);.)
)
.
@ -1664,15 +1664,15 @@ InvocationExpression<ref Expression pexpr> @@ -1664,15 +1664,15 @@ InvocationExpression<ref Expression pexpr>
")"
(
"." Identifier
(. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); .)
(. pexpr = new MemberReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); .)
| "("
ArgumentList<out parameters>
")"
(. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
(. pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); .)
)
| ArgumentList<out parameters>
")"
(. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
(. pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); .)
)
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
.
@ -2530,7 +2530,7 @@ EmbeddedStatement<out Statement statement> @@ -2530,7 +2530,7 @@ EmbeddedStatement<out Statement statement>
(.
// a field reference expression that stands alone is a
// invocation expression without parantheses and arguments
if(expr is FieldReferenceExpression || expr is IdentifierExpression) {
if(expr is MemberReferenceExpression || expr is IdentifierExpression) {
expr = new InvocationExpression(expr);
}
statement = new ExpressionStatement(expr);
@ -2655,7 +2655,7 @@ ReDimClause<out Expression expr> @@ -2655,7 +2655,7 @@ ReDimClause<out Expression expr>
ReDimClauseInternal<ref Expression expr>
(. List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; .)
=
{ "." IdentifierOrKeyword<out name> (. expr = new FieldReferenceExpression(expr, name); .)
{ "." IdentifierOrKeyword<out name> (. expr = new MemberReferenceExpression(expr, name); .)
| IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
InvocationExpression<ref expr>
}

20
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -218,8 +218,8 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -218,8 +218,8 @@ namespace ICSharpCode.NRefactory.Parser.VB
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
while (expr is MemberReferenceExpression) {
expr = ((MemberReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
@ -242,7 +242,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -242,7 +242,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
MemberReferenceExpression fre = expr as MemberReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
@ -272,6 +272,20 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -272,6 +272,20 @@ namespace ICSharpCode.NRefactory.Parser.VB
Error("lower bound of array must be zero");
}
InvocationExpression CreateInvocationExpression(Expression target, List<Expression> parameters, List<TypeReference> typeArguments)
{
if (typeArguments != null && typeArguments.Count > 0) {
if (target is IdentifierExpression) {
((IdentifierExpression)target).TypeArguments = typeArguments;
} else if (target is MemberReferenceExpression) {
((MemberReferenceExpression)target).TypeArguments = typeArguments;
} else {
Error("Type arguments only allowed on IdentifierExpression and MemberReferenceExpression");
}
}
return new InvocationExpression(target, parameters);
}
/// <summary>
/// Adds a child item to a collection stored in the parent node.
/// Also set's the item's parent to <paramref name="parent"/>.

23
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -2035,12 +2035,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2035,12 +2035,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
TrackVisit(invocationExpression.TargetObject, data);
if (invocationExpression.TypeArguments != null && invocationExpression.TypeArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.LessThan);
AppendCommaSeparatedList(invocationExpression.TypeArguments);
outputFormatter.PrintToken(Tokens.GreaterThan);
}
if (prettyPrintOptions.BeforeMethodCallParentheses) {
outputFormatter.Space();
}
@ -2054,9 +2048,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2054,9 +2048,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{
outputFormatter.PrintIdentifier(identifierExpression.Identifier);
PrintTypeArgumentList(identifierExpression.TypeArguments);
return null;
}
void PrintTypeArgumentList(List<TypeReference> typeArguments)
{
if (typeArguments != null && typeArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.LessThan);
AppendCommaSeparatedList(typeArguments);
outputFormatter.PrintToken(Tokens.GreaterThan);
}
}
public override object TrackedVisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data)
{
TrackVisit(typeReferenceExpression.TypeReference, data);
@ -2410,9 +2414,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2410,9 +2414,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public override object TrackedVisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object TrackedVisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
Expression target = fieldReferenceExpression.TargetObject;
Expression target = memberReferenceExpression.TargetObject;
if (target is BinaryOperatorExpression || target is CastExpression) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
@ -2422,7 +2426,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2422,7 +2426,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.PrintToken(Tokens.Dot);
outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName);
outputFormatter.PrintIdentifier(memberReferenceExpression.FieldName);
PrintTypeArgumentList(memberReferenceExpression.TypeArguments);
return null;
}

24
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -2183,22 +2183,27 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2183,22 +2183,27 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
TrackedVisit(invocationExpression.TargetObject, data);
if (invocationExpression.TypeArguments != null && invocationExpression.TypeArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(invocationExpression.Arguments);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
}
void PrintTypeArguments(List<TypeReference> typeArguments)
{
if (typeArguments != null && typeArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
outputFormatter.PrintToken(Tokens.Of);
outputFormatter.Space();
AppendCommaSeparatedList(invocationExpression.TypeArguments);
AppendCommaSeparatedList(typeArguments);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(invocationExpression.Arguments);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
}
public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{
outputFormatter.PrintIdentifier(identifierExpression.Identifier);
PrintTypeArguments(identifierExpression.TypeArguments);
return null;
}
@ -2546,11 +2551,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2546,11 +2551,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public override object TrackedVisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object TrackedVisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
TrackedVisit(fieldReferenceExpression.TargetObject, data);
TrackedVisit(memberReferenceExpression.TargetObject, data);
outputFormatter.PrintToken(Tokens.Dot);
outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName);
outputFormatter.PrintIdentifier(memberReferenceExpression.FieldName);
PrintTypeArguments(memberReferenceExpression.TypeArguments);
return null;
}

28
src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs

@ -423,12 +423,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -423,12 +423,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return null;
}
public virtual object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) {
Debug.Assert((fieldReferenceExpression != null));
Debug.Assert((fieldReferenceExpression.TargetObject != null));
return fieldReferenceExpression.TargetObject.AcceptVisitor(this, data);
}
public virtual object VisitFixedStatement(FixedStatement fixedStatement, object data) {
Debug.Assert((fixedStatement != null));
Debug.Assert((fixedStatement.TypeReference != null));
@ -504,6 +498,11 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -504,6 +498,11 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) {
Debug.Assert((identifierExpression != null));
Debug.Assert((identifierExpression.TypeArguments != null));
foreach (TypeReference o in identifierExpression.TypeArguments) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}
@ -587,16 +586,11 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -587,16 +586,11 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((invocationExpression != null));
Debug.Assert((invocationExpression.TargetObject != null));
Debug.Assert((invocationExpression.Arguments != null));
Debug.Assert((invocationExpression.TypeArguments != null));
invocationExpression.TargetObject.AcceptVisitor(this, data);
foreach (Expression o in invocationExpression.Arguments) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
foreach (TypeReference o in invocationExpression.TypeArguments) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}
@ -638,6 +632,18 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -638,6 +632,18 @@ namespace ICSharpCode.NRefactory.Visitors {
return lockStatement.EmbeddedStatement.AcceptVisitor(this, data);
}
public virtual object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) {
Debug.Assert((memberReferenceExpression != null));
Debug.Assert((memberReferenceExpression.TargetObject != null));
Debug.Assert((memberReferenceExpression.TypeArguments != null));
memberReferenceExpression.TargetObject.AcceptVisitor(this, data);
foreach (TypeReference o in memberReferenceExpression.TypeArguments) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}
public virtual object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
Debug.Assert((methodDeclaration != null));
Debug.Assert((methodDeclaration.Attributes != null));

54
src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs

@ -765,15 +765,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -765,15 +765,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return null;
}
public virtual object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) {
Debug.Assert((fieldReferenceExpression != null));
Debug.Assert((fieldReferenceExpression.TargetObject != null));
nodeStack.Push(fieldReferenceExpression.TargetObject);
fieldReferenceExpression.TargetObject.AcceptVisitor(this, data);
fieldReferenceExpression.TargetObject = ((Expression)(nodeStack.Pop()));
return null;
}
public virtual object VisitFixedStatement(FixedStatement fixedStatement, object data) {
Debug.Assert((fixedStatement != null));
Debug.Assert((fixedStatement.TypeReference != null));
@ -910,6 +901,18 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -910,6 +901,18 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) {
Debug.Assert((identifierExpression != null));
Debug.Assert((identifierExpression.TypeArguments != null));
for (int i = 0; i < identifierExpression.TypeArguments.Count; i++) {
TypeReference o = identifierExpression.TypeArguments[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (TypeReference)nodeStack.Pop();
if (o == null)
identifierExpression.TypeArguments.RemoveAt(i--);
else
identifierExpression.TypeArguments[i] = o;
}
return null;
}
@ -1066,7 +1069,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1066,7 +1069,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((invocationExpression != null));
Debug.Assert((invocationExpression.TargetObject != null));
Debug.Assert((invocationExpression.Arguments != null));
Debug.Assert((invocationExpression.TypeArguments != null));
nodeStack.Push(invocationExpression.TargetObject);
invocationExpression.TargetObject.AcceptVisitor(this, data);
invocationExpression.TargetObject = ((Expression)(nodeStack.Pop()));
@ -1081,17 +1083,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1081,17 +1083,6 @@ namespace ICSharpCode.NRefactory.Visitors {
else
invocationExpression.Arguments[i] = o;
}
for (int i = 0; i < invocationExpression.TypeArguments.Count; i++) {
TypeReference o = invocationExpression.TypeArguments[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (TypeReference)nodeStack.Pop();
if (o == null)
invocationExpression.TypeArguments.RemoveAt(i--);
else
invocationExpression.TypeArguments[i] = o;
}
return null;
}
@ -1159,6 +1150,27 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1159,6 +1150,27 @@ namespace ICSharpCode.NRefactory.Visitors {
return null;
}
public virtual object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) {
Debug.Assert((memberReferenceExpression != null));
Debug.Assert((memberReferenceExpression.TargetObject != null));
Debug.Assert((memberReferenceExpression.TypeArguments != null));
nodeStack.Push(memberReferenceExpression.TargetObject);
memberReferenceExpression.TargetObject.AcceptVisitor(this, data);
memberReferenceExpression.TargetObject = ((Expression)(nodeStack.Pop()));
for (int i = 0; i < memberReferenceExpression.TypeArguments.Count; i++) {
TypeReference o = memberReferenceExpression.TypeArguments[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (TypeReference)nodeStack.Pop();
if (o == null)
memberReferenceExpression.TypeArguments.RemoveAt(i--);
else
memberReferenceExpression.TypeArguments[i] = o;
}
return null;
}
public virtual object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
Debug.Assert((methodDeclaration != null));
Debug.Assert((methodDeclaration.Attributes != null));

2
src/Libraries/NRefactory/Project/Src/Visitors/CSharpConstructsConvertVisitor.cs

@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.Visitors
IdentifierExpression ident = expression as IdentifierExpression;
if (ident != null)
return ident.Identifier;
FieldReferenceExpression fre = expression as FieldReferenceExpression;
MemberReferenceExpression fre = expression as MemberReferenceExpression;
if (fre != null && fre.TargetObject is ThisReferenceExpression)
return fre.FieldName;
return null;

55
src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using ICSharpCode.NRefactory.Ast;
@ -103,6 +104,24 @@ namespace ICSharpCode.NRefactory.Visitors @@ -103,6 +104,24 @@ namespace ICSharpCode.NRefactory.Visitors
return attr;
}
static TypeAttributes ConvTypeAttributes(Modifiers modifier)
{
TypeAttributes attr = (TypeAttributes)0;
if ((modifier & Modifiers.Abstract) != 0)
attr |= TypeAttributes.Abstract;
if ((modifier & Modifiers.Sealed) != 0)
attr |= TypeAttributes.Sealed;
if ((modifier & Modifiers.Static) != 0)
attr |= TypeAttributes.Abstract | TypeAttributes.Sealed;
if ((modifier & Modifiers.Public) != 0)
attr |= TypeAttributes.Public;
else
attr |= TypeAttributes.NotPublic;
return attr;
}
#region ICSharpCode.SharpRefactory.Parser.IASTVisitor interface implementation
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
@ -153,10 +172,12 @@ namespace ICSharpCode.NRefactory.Visitors @@ -153,10 +172,12 @@ namespace ICSharpCode.NRefactory.Visitors
TypeDeclaration oldTypeDeclaration = currentTypeDeclaration;
this.currentTypeDeclaration = typeDeclaration;
CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration(typeDeclaration.Name);
codeTypeDeclaration.TypeAttributes = ConvTypeAttributes(typeDeclaration.Modifier);
codeTypeDeclaration.IsClass = typeDeclaration.Type == ClassType.Class;
codeTypeDeclaration.IsEnum = typeDeclaration.Type == ClassType.Enum;
codeTypeDeclaration.IsInterface = typeDeclaration.Type == ClassType.Interface;
codeTypeDeclaration.IsStruct = typeDeclaration.Type == ClassType.Struct;
codeTypeDeclaration.IsPartial = (typeDeclaration.Modifier & Modifiers.Partial) != 0;
if (typeDeclaration.BaseTypes != null) {
foreach (TypeReference typeRef in typeDeclaration.BaseTypes) {
@ -558,12 +579,12 @@ namespace ICSharpCode.NRefactory.Visitors @@ -558,12 +579,12 @@ namespace ICSharpCode.NRefactory.Visitors
string methodName = null;
if (target == null) {
targetExpr = new CodeThisReferenceExpression();
} else if (target is FieldReferenceExpression) {
FieldReferenceExpression fRef = (FieldReferenceExpression)target;
} else if (target is MemberReferenceExpression) {
MemberReferenceExpression fRef = (MemberReferenceExpression)target;
targetExpr = null;
if (fRef.TargetObject is FieldReferenceExpression) {
if (IsPossibleTypeReference((FieldReferenceExpression)fRef.TargetObject)) {
targetExpr = ConvertToTypeReference((FieldReferenceExpression)fRef.TargetObject);
if (fRef.TargetObject is MemberReferenceExpression) {
if (IsPossibleTypeReference((MemberReferenceExpression)fRef.TargetObject)) {
targetExpr = ConvertToTypeReference((MemberReferenceExpression)fRef.TargetObject);
}
}
if (targetExpr == null)
@ -678,7 +699,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -678,7 +699,7 @@ namespace ICSharpCode.NRefactory.Visitors
AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), ((IdentifierExpression)eventExpr).Identifier),
methodInvoker));
} else {
FieldReferenceExpression fr = (FieldReferenceExpression)eventExpr;
MemberReferenceExpression fr = (MemberReferenceExpression)eventExpr;
AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression((CodeExpression)fr.TargetObject.AcceptVisitor(this, data), fr.FieldName),
methodInvoker));
}
@ -771,7 +792,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -771,7 +792,7 @@ namespace ICSharpCode.NRefactory.Visitors
return isField;
}
bool IsFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression)
bool IsFieldReferenceExpression(MemberReferenceExpression fieldReferenceExpression)
{
if (fieldReferenceExpression.TargetObject is ThisReferenceExpression
|| fieldReferenceExpression.TargetObject is BaseReferenceExpression)
@ -782,7 +803,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -782,7 +803,7 @@ namespace ICSharpCode.NRefactory.Visitors
return false;
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
if (methodReference) {
methodReference = false;
@ -792,9 +813,9 @@ namespace ICSharpCode.NRefactory.Visitors @@ -792,9 +813,9 @@ namespace ICSharpCode.NRefactory.Visitors
return new CodeFieldReferenceExpression((CodeExpression)fieldReferenceExpression.TargetObject.AcceptVisitor(this, data),
fieldReferenceExpression.FieldName);
} else {
if (fieldReferenceExpression.TargetObject is FieldReferenceExpression) {
if (IsPossibleTypeReference((FieldReferenceExpression)fieldReferenceExpression.TargetObject)) {
CodeTypeReferenceExpression typeRef = ConvertToTypeReference((FieldReferenceExpression)fieldReferenceExpression.TargetObject);
if (fieldReferenceExpression.TargetObject is MemberReferenceExpression) {
if (IsPossibleTypeReference((MemberReferenceExpression)fieldReferenceExpression.TargetObject)) {
CodeTypeReferenceExpression typeRef = ConvertToTypeReference((MemberReferenceExpression)fieldReferenceExpression.TargetObject);
if (IsField(typeRef.Type.BaseType, typeRef.Type.TypeArguments.Count, fieldReferenceExpression.FieldName)) {
return new CodeFieldReferenceExpression(typeRef,
fieldReferenceExpression.FieldName);
@ -813,10 +834,10 @@ namespace ICSharpCode.NRefactory.Visitors @@ -813,10 +834,10 @@ namespace ICSharpCode.NRefactory.Visitors
#endregion
#endregion
bool IsPossibleTypeReference(FieldReferenceExpression fieldReferenceExpression)
bool IsPossibleTypeReference(MemberReferenceExpression fieldReferenceExpression)
{
while (fieldReferenceExpression.TargetObject is FieldReferenceExpression) {
fieldReferenceExpression = (FieldReferenceExpression)fieldReferenceExpression.TargetObject;
while (fieldReferenceExpression.TargetObject is MemberReferenceExpression) {
fieldReferenceExpression = (MemberReferenceExpression)fieldReferenceExpression.TargetObject;
}
IdentifierExpression identifier = fieldReferenceExpression.TargetObject as IdentifierExpression;
if (identifier != null)
@ -855,14 +876,14 @@ namespace ICSharpCode.NRefactory.Visitors @@ -855,14 +876,14 @@ namespace ICSharpCode.NRefactory.Visitors
return false;
}
static CodeTypeReferenceExpression ConvertToTypeReference(FieldReferenceExpression fieldReferenceExpression)
static CodeTypeReferenceExpression ConvertToTypeReference(MemberReferenceExpression fieldReferenceExpression)
{
StringBuilder type = new StringBuilder("");
while (fieldReferenceExpression.TargetObject is FieldReferenceExpression) {
while (fieldReferenceExpression.TargetObject is MemberReferenceExpression) {
type.Insert(0,'.');
type.Insert(1,fieldReferenceExpression.FieldName.ToCharArray());
fieldReferenceExpression = (FieldReferenceExpression)fieldReferenceExpression.TargetObject;
fieldReferenceExpression = (MemberReferenceExpression)fieldReferenceExpression.TargetObject;
}
type.Insert(0,'.');

22
src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs

@ -318,13 +318,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -318,13 +318,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return result;
}
public sealed override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) {
this.BeginVisit(fieldReferenceExpression);
object result = this.TrackedVisitFieldReferenceExpression(fieldReferenceExpression, data);
this.EndVisit(fieldReferenceExpression);
return result;
}
public sealed override object VisitFixedStatement(FixedStatement fixedStatement, object data) {
this.BeginVisit(fixedStatement);
object result = this.TrackedVisitFixedStatement(fixedStatement, data);
@ -444,6 +437,13 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -444,6 +437,13 @@ namespace ICSharpCode.NRefactory.Visitors {
return result;
}
public sealed override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) {
this.BeginVisit(memberReferenceExpression);
object result = this.TrackedVisitMemberReferenceExpression(memberReferenceExpression, data);
this.EndVisit(memberReferenceExpression);
return result;
}
public sealed override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
this.BeginVisit(methodDeclaration);
object result = this.TrackedVisitMethodDeclaration(methodDeclaration, data);
@ -972,10 +972,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -972,10 +972,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return base.VisitFieldDeclaration(fieldDeclaration, data);
}
public virtual object TrackedVisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) {
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
}
public virtual object TrackedVisitFixedStatement(FixedStatement fixedStatement, object data) {
return base.VisitFixedStatement(fixedStatement, data);
}
@ -1044,6 +1040,10 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1044,6 +1040,10 @@ namespace ICSharpCode.NRefactory.Visitors {
return base.VisitLockStatement(lockStatement, data);
}
public virtual object TrackedVisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) {
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
public virtual object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
return base.VisitMethodDeclaration(methodDeclaration, data);
}

4
src/Libraries/NRefactory/Project/Src/Visitors/PrefixFieldsVisitor.cs

@ -121,7 +121,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -121,7 +121,7 @@ namespace ICSharpCode.NRefactory.Visitors
return base.VisitIdentifierExpression(identifierExpression, data);
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
if (fieldReferenceExpression.TargetObject is ThisReferenceExpression) {
string name = fieldReferenceExpression.FieldName;
@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.Visitors
}
}
}
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
return base.VisitMemberReferenceExpression(fieldReferenceExpression, data);
}
bool IsLocal(string name)

4
src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs

@ -179,13 +179,13 @@ namespace ICSharpCode.NRefactory.Visitors @@ -179,13 +179,13 @@ namespace ICSharpCode.NRefactory.Visitors
this.replaceWith = replaceWith;
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
if (fieldReferenceExpression.TargetObject.IsNull) {
fieldReferenceExpression.TargetObject = replaceWith;
return null;
} else {
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
return base.VisitMemberReferenceExpression(fieldReferenceExpression, data);
}
}

4
src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

@ -124,7 +124,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -124,7 +124,7 @@ namespace ICSharpCode.NRefactory.Visitors
IdentifierExpression ident = expr as IdentifierExpression;
if (ident != null)
return ident.Identifier;
FieldReferenceExpression fre = expr as FieldReferenceExpression;
MemberReferenceExpression fre = expr as MemberReferenceExpression;
if (fre != null && fre.TargetObject is ThisReferenceExpression)
return fre.FieldName;
return null;
@ -256,7 +256,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -256,7 +256,7 @@ namespace ICSharpCode.NRefactory.Visitors
break;
case "CharSet":
{
FieldReferenceExpression fre = arg.Expression as FieldReferenceExpression;
MemberReferenceExpression fre = arg.Expression as MemberReferenceExpression;
if (fre == null || !(fre.TargetObject is IdentifierExpression))
return false;
if ((fre.TargetObject as IdentifierExpression).Identifier != "CharSet")

22
src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs

@ -108,7 +108,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -108,7 +108,7 @@ namespace ICSharpCode.NRefactory.Visitors
if (se != null) {
InvocationExpression ie = se.Expression as InvocationExpression;
if (ie != null) {
FieldReferenceExpression fre = ie.TargetObject as FieldReferenceExpression;
MemberReferenceExpression fre = ie.TargetObject as MemberReferenceExpression;
if (fre != null && "New".Equals(fre.FieldName, StringComparison.InvariantCultureIgnoreCase)) {
if (fre.TargetObject is BaseReferenceExpression || fre.TargetObject is ClassReferenceExpression || fre.TargetObject is ThisReferenceExpression) {
body.Children.RemoveAt(0);
@ -159,17 +159,17 @@ namespace ICSharpCode.NRefactory.Visitors @@ -159,17 +159,17 @@ namespace ICSharpCode.NRefactory.Visitors
switch (declareDeclaration.Charset) {
case CharsetModifier.Auto:
att.NamedArguments.Add(new NamedArgumentExpression("CharSet",
new FieldReferenceExpression(new IdentifierExpression("CharSet"),
new MemberReferenceExpression(new IdentifierExpression("CharSet"),
"Auto")));
break;
case CharsetModifier.Unicode:
att.NamedArguments.Add(new NamedArgumentExpression("CharSet",
new FieldReferenceExpression(new IdentifierExpression("CharSet"),
new MemberReferenceExpression(new IdentifierExpression("CharSet"),
"Unicode")));
break;
default:
att.NamedArguments.Add(new NamedArgumentExpression("CharSet",
new FieldReferenceExpression(new IdentifierExpression("CharSet"),
new MemberReferenceExpression(new IdentifierExpression("CharSet"),
"Ansi")));
break;
}
@ -209,9 +209,9 @@ namespace ICSharpCode.NRefactory.Visitors @@ -209,9 +209,9 @@ namespace ICSharpCode.NRefactory.Visitors
InvocationExpression ie = se.Expression as InvocationExpression;
if (ie != null
&& ie.Arguments.Count == 0
&& ie.TargetObject is FieldReferenceExpression
&& (ie.TargetObject as FieldReferenceExpression).TargetObject is BaseReferenceExpression
&& "Finalize".Equals((ie.TargetObject as FieldReferenceExpression).FieldName, StringComparison.InvariantCultureIgnoreCase))
&& ie.TargetObject is MemberReferenceExpression
&& (ie.TargetObject as MemberReferenceExpression).TargetObject is BaseReferenceExpression
&& "Finalize".Equals((ie.TargetObject as MemberReferenceExpression).FieldName, StringComparison.InvariantCultureIgnoreCase))
{
DestructorDeclaration des = new DestructorDeclaration("Destructor", Modifiers.None, methodDeclaration.Attributes);
ReplaceCurrentNode(des);
@ -364,9 +364,9 @@ namespace ICSharpCode.NRefactory.Visitors @@ -364,9 +364,9 @@ namespace ICSharpCode.NRefactory.Visitors
}
Expression expr;
if (constantTable.TryGetValue(identifierExpression.Identifier, out expr)) {
FieldReferenceExpression fre = new FieldReferenceExpression(expr, identifierExpression.Identifier);
MemberReferenceExpression fre = new MemberReferenceExpression(expr, identifierExpression.Identifier);
ReplaceCurrentNode(fre);
return base.VisitFieldReferenceExpression(fre, data);
return base.VisitMemberReferenceExpression(fre, data);
}
return base.VisitIdentifierExpression(identifierExpression, data);
}
@ -399,7 +399,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -399,7 +399,7 @@ namespace ICSharpCode.NRefactory.Visitors
}
Expression expr;
if (methodTable.TryGetValue(ident.Identifier, out expr)) {
FieldReferenceExpression fre = new FieldReferenceExpression(expr, ident.Identifier);
MemberReferenceExpression fre = new MemberReferenceExpression(expr, ident.Identifier);
invocationExpression.TargetObject = fre;
}
}
@ -467,7 +467,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -467,7 +467,7 @@ namespace ICSharpCode.NRefactory.Visitors
List<Expression> arguments = new List<Expression>();
arguments.Add(stringVariable);
return new InvocationExpression(
new FieldReferenceExpression(new TypeReferenceExpression("System.String"), "IsNullOrEmpty"),
new MemberReferenceExpression(new TypeReferenceExpression("System.String"), "IsNullOrEmpty"),
arguments);
}

2
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
<Compile Include="Parser\Expressions\BinaryOperatorExpressionTests.cs" />
<Compile Include="Parser\Expressions\UnaryOperatorExpressionTests.cs" />
<Compile Include="Parser\Expressions\CastExpressionTests.cs" />
<Compile Include="Parser\Expressions\FieldReferenceExpressionTests.cs" />
<Compile Include="Parser\Expressions\MemberReferenceExpressionTests.cs" />
<Compile Include="Parser\Expressions\InvocationExpressionTests.cs" />
<Compile Include="Parser\Expressions\TypeOfExpressionTests.cs" />
<Compile Include="Parser\Expressions\ArrayCreateExpressionTests.cs" />

8
src/Libraries/NRefactory/Test/Output/CodeDOM/InvocationExpressionTest.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Tests.Output.CodeDom.Tests @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Tests.Output.CodeDom.Tests
public void MethodOnThisReferenceInvocation()
{
// InitializeComponents();
FieldReferenceExpression field = new FieldReferenceExpression(new ThisReferenceExpression(), "InitializeComponents");
MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression);
@ -48,9 +48,9 @@ namespace ICSharpCode.NRefactory.Tests.Output.CodeDom.Tests @@ -48,9 +48,9 @@ namespace ICSharpCode.NRefactory.Tests.Output.CodeDom.Tests
public void InvocationOfStaticMethod()
{
// System.Drawing.Color.FromArgb();
FieldReferenceExpression field = new FieldReferenceExpression(new IdentifierExpression("System"), "Drawing");
field = new FieldReferenceExpression(field, "Color");
field = new FieldReferenceExpression(field, "FromArgb");
MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing");
field = new MemberReferenceExpression(field, "Color");
field = new MemberReferenceExpression(field, "FromArgb");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression);

4
src/Libraries/NRefactory/Test/Parser/Expressions/BaseReferenceExpressionTests.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpBaseReferenceExpressionTest1()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("base.myField");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("base.myField");
Assert.IsTrue(fre.TargetObject is BaseReferenceExpression);
}
#endregion
@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetBaseReferenceExpressionTest1()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("MyBase.myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("MyBase.myField");
Assert.IsTrue(fre.TargetObject is BaseReferenceExpression);
}
#endregion

4
src/Libraries/NRefactory/Test/Parser/Expressions/CastExpressionTests.cs

@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
// yes, we really wanted to evaluate .Member on expr and THEN cast the result to MyType
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType)(expr).Member");
Assert.AreEqual("MyType", ce.CastTo.Type);
Assert.IsTrue(ce.Expression is FieldReferenceExpression);
Assert.IsTrue(ce.Expression is MemberReferenceExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
}
@ -139,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -139,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(BigInt)int.MaxValue");
Assert.AreEqual("BigInt", ce.CastTo.ToString());
Assert.IsTrue(ce.Expression is FieldReferenceExpression);
Assert.IsTrue(ce.Expression is MemberReferenceExpression);
}
#endregion

2
src/Libraries/NRefactory/Test/Parser/Expressions/ClassReferenceExpressionTests.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetClassReferenceExpressionTest1()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("MyClass.myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("MyClass.myField");
Assert.IsTrue(fre.TargetObject is ClassReferenceExpression);
}
#endregion

8
src/Libraries/NRefactory/Test/Parser/Expressions/ConditionalExpressionTests.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(ce.Condition is BinaryOperatorExpression);
Assert.IsTrue(ce.TrueExpression is InvocationExpression);
Assert.IsTrue(ce.FalseExpression is FieldReferenceExpression);
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression);
}
[Test]
@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(ce.Condition is TypeOfIsExpression);
Assert.IsTrue(ce.TrueExpression is InvocationExpression);
Assert.IsTrue(ce.FalseExpression is FieldReferenceExpression);
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression);
}
[Test]
@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(ce.Condition is TypeOfIsExpression);
Assert.IsTrue(ce.TrueExpression is InvocationExpression);
Assert.IsTrue(ce.FalseExpression is FieldReferenceExpression);
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression);
}
[Test]
@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(ce.Condition is TypeOfIsExpression);
Assert.IsTrue(ce.TrueExpression is ParenthesizedExpression);
Assert.IsTrue(ce.FalseExpression is FieldReferenceExpression);
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression);
}
[Test]

8
src/Libraries/NRefactory/Test/Parser/Expressions/IdentifierExpressionTests.cs

@ -30,6 +30,14 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -30,6 +30,14 @@ namespace ICSharpCode.NRefactory.Tests.Ast
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("@public");
Assert.AreEqual("public", ident.Identifier);
}
[Test]
public void CSharpGenericMethodReference()
{
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("M<int>");
Assert.AreEqual("M", ident.Identifier);
Assert.AreEqual(1, ident.TypeArguments.Count);
}
#endregion
#region VB.NET

39
src/Libraries/NRefactory/Test/Parser/Expressions/InvocationExpressionTests.cs

@ -27,19 +27,21 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -27,19 +27,21 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
Assert.AreEqual(1, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.AreEqual(1, expr.TypeArguments.Count);
Assert.AreEqual("System.Char", expr.TypeArguments[0].SystemType);
IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual(1, ident.TypeArguments.Count);
Assert.AreEqual("System.Char", ident.TypeArguments[0].SystemType);
}
void CheckGenericInvoke2(InvocationExpression expr)
{
Assert.AreEqual(0, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.AreEqual(2, expr.TypeArguments.Count);
Assert.AreEqual("T", expr.TypeArguments[0].SystemType);
Assert.AreEqual("System.Boolean", expr.TypeArguments[1].SystemType);
IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual(2, ident.TypeArguments.Count);
Assert.AreEqual("T", ident.TypeArguments[0].SystemType);
Assert.AreEqual("System.Boolean", ident.TypeArguments[1].SystemType);
}
@ -62,6 +64,29 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -62,6 +64,29 @@ namespace ICSharpCode.NRefactory.Tests.Ast
CheckGenericInvoke2(ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod<T,bool>()"));
}
[Test]
public void CSharpAmbiguousGrammarGenericMethodCall()
{
InvocationExpression ie = ParseUtilCSharp.ParseExpression<InvocationExpression>("F(G<A,B>(7))");
Assert.IsTrue(ie.TargetObject is IdentifierExpression);
Assert.AreEqual(1, ie.Arguments.Count);
ie = (InvocationExpression)ie.Arguments[0];
Assert.AreEqual(1, ie.Arguments.Count);
Assert.IsTrue(ie.Arguments[0] is PrimitiveExpression);
IdentifierExpression ident = (IdentifierExpression)ie.TargetObject;
Assert.AreEqual("G", ident.Identifier);
Assert.AreEqual(2, ident.TypeArguments.Count);
}
[Test]
public void CSharpAmbiguousGrammarNotAGenericMethodCall()
{
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("F<A>+y");
Assert.AreEqual(BinaryOperatorType.GreaterThan, boe.Op);
Assert.IsTrue(boe.Left is BinaryOperatorExpression);
Assert.IsTrue(boe.Right is UnaryOperatorExpression);
}
[Test]
public void CSharpInvalidNestedInvocationExpressionTest()
{

24
src/Libraries/NRefactory/Test/Parser/Expressions/FieldReferenceExpressionTests.cs → src/Libraries/NRefactory/Test/Parser/Expressions/MemberReferenceExpressionTests.cs

@ -14,13 +14,13 @@ using ICSharpCode.NRefactory.Ast; @@ -14,13 +14,13 @@ using ICSharpCode.NRefactory.Ast;
namespace ICSharpCode.NRefactory.Tests.Ast
{
[TestFixture]
public class FieldReferenceExpressionTests
public class MemberReferenceExpressionTests
{
#region C#
[Test]
public void CSharpSimpleFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("myTargetObject.myField");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("myTargetObject.myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is IdentifierExpression);
Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("SomeClass<string>.myField");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("SomeClass<string>.myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpFullNamespaceGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("Namespace.Subnamespace.SomeClass<string>.myField");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("Namespace.Subnamespace.SomeClass<string>.myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpGlobalFullNamespaceGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("global::Namespace.Subnamespace.SomeClass<string>.myField");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("global::Namespace.Subnamespace.SomeClass<string>.myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpNestedGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("MyType<string>.InnerClass<int>.myField");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("MyType<string>.InnerClass<int>.myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetSimpleFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("myTargetObject.myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("myTargetObject.myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is IdentifierExpression);
Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
@ -93,7 +93,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -93,7 +93,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetFieldReferenceExpressionWithoutTargetTest()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>(".myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>(".myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject.IsNull);
}
@ -101,7 +101,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -101,7 +101,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("SomeClass(of string).myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("SomeClass(of string).myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetFullNamespaceGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("System.Subnamespace.SomeClass(of string).myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("System.Subnamespace.SomeClass(of string).myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -125,7 +125,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -125,7 +125,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetGlobalFullNamespaceGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("Global.System.Subnamespace.SomeClass(of string).myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("Global.System.Subnamespace.SomeClass(of string).myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -139,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -139,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetNestedGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("MyType(of string).InnerClass(of integer).myField");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("MyType(of string).InnerClass(of integer).myField");
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference;

2
src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -185,7 +185,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(3, oce.ObjectInitializer.CreateExpressions.Count);
Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "Name"));
Assert.IsInstanceOfType(typeof(IdentifierExpression), oce.ObjectInitializer.CreateExpressions[1]);
Assert.IsInstanceOfType(typeof(FieldReferenceExpression), oce.ObjectInitializer.CreateExpressions[2]);
Assert.IsInstanceOfType(typeof(MemberReferenceExpression), oce.ObjectInitializer.CreateExpressions[2]);
}
#endregion

2
src/Libraries/NRefactory/Test/Parser/Expressions/PointerReferenceExpressionTests.cs

@ -21,7 +21,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -21,7 +21,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public void CSharpPointerReferenceExpressionTest()
{
PointerReferenceExpression pre = ParseUtilCSharp.ParseExpression<PointerReferenceExpression>("myObj.field->b");
Assert.IsTrue(pre.TargetObject is FieldReferenceExpression);
Assert.IsTrue(pre.TargetObject is MemberReferenceExpression);
Assert.AreEqual("b", pre.Identifier);
}
#endregion

4
src/Libraries/NRefactory/Test/Parser/Expressions/PrimitiveExpressionTests.cs

@ -22,8 +22,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -22,8 +22,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
InvocationExpression invExpr = ParseUtilCSharp.ParseExpression<InvocationExpression>("0xAFFE.ToString()");
Assert.AreEqual(0, invExpr.Arguments.Count);
Assert.IsTrue(invExpr.TargetObject is FieldReferenceExpression);
FieldReferenceExpression fre = invExpr.TargetObject as FieldReferenceExpression;
Assert.IsTrue(invExpr.TargetObject is MemberReferenceExpression);
MemberReferenceExpression fre = invExpr.TargetObject as MemberReferenceExpression;
Assert.AreEqual("ToString", fre.FieldName);
Assert.IsTrue(fre.TargetObject is PrimitiveExpression);

12
src/Libraries/NRefactory/Test/Parser/Expressions/TypeReferenceExpressionTests.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void IntReferenceExpression()
{
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("int.MaxValue");
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("int.MaxValue");
Assert.AreEqual("MaxValue", fre.FieldName);
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.SystemType);
}
@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
// this is propably not what really should be returned for a standalone int
// reference, but it has to stay consistent because NRefactoryResolver depends
// on this trick.
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("int", true);
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("int", true);
Assert.AreEqual("", fre.FieldName);
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.SystemType);
}
@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBIntReferenceExpression()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("inTeGer.MaxValue");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("inTeGer.MaxValue");
Assert.AreEqual("MaxValue", fre.FieldName);
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.SystemType);
}
@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
// this is propably not what really should be returned for a standalone int
// reference, but it has to stay consistent because NRefactoryResolver depends
// on this trick.
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("inTeGer", true);
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("inTeGer", true);
Assert.AreEqual("", fre.FieldName);
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.SystemType);
}
@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBObjectReferenceExpression()
{
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("Object.ReferenceEquals");
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("Object.ReferenceEquals");
Assert.AreEqual("ReferenceEquals", fre.FieldName);
Assert.AreEqual("System.Object", ((TypeReferenceExpression)fre.TargetObject).TypeReference.SystemType);
}
@ -96,7 +96,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -96,7 +96,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
// this is propably not what really should be returned for a standalone int
// reference, but it has to stay consistent because NRefactoryResolver depends
// on this trick.
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("obJeCt", true);
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("obJeCt", true);
Assert.AreEqual("", fre.FieldName);
Assert.AreEqual("System.Object", ((TypeReferenceExpression)fre.TargetObject).TypeReference.SystemType);
}

4
src/Libraries/NRefactory/Test/Parser/Statements/ExpressionStatementTests.cs

@ -21,13 +21,13 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -21,13 +21,13 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public void CSharpStatementExpressionTest()
{
ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement<ExpressionStatement>("my.Obj.PropCall;");
Assert.IsTrue(stmtExprStmt.Expression is FieldReferenceExpression);
Assert.IsTrue(stmtExprStmt.Expression is MemberReferenceExpression);
}
[Test]
public void CSharpStatementExpressionTest1()
{
ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement<ExpressionStatement>("yield.yield;");
Assert.IsTrue(stmtExprStmt.Expression is FieldReferenceExpression);
Assert.IsTrue(stmtExprStmt.Expression is MemberReferenceExpression);
}
#endregion

18
src/Libraries/NRefactory/Test/Parser/TypeLevel/ConstructorDeclarationTests.cs

@ -37,6 +37,22 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -37,6 +37,22 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(ConstructorInitializerType.Base, cd.ConstructorInitializer.ConstructorInitializerType);
Assert.AreEqual(3, cd.ConstructorInitializer.Arguments.Count);
}
[Test]
public void CSharpStaticConstructorDeclarationTest1()
{
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("static MyClass() {}");
Assert.IsTrue(cd.ConstructorInitializer.IsNull);
Assert.AreEqual(Modifiers.Static, cd.Modifier);
}
[Test]
public void CSharpExternStaticConstructorDeclarationTest()
{
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("extern static MyClass();");
Assert.IsTrue(cd.ConstructorInitializer.IsNull);
Assert.AreEqual(Modifiers.Static | Modifiers.Extern, cd.Modifier);
}
#endregion
#region VB.NET
@ -58,6 +74,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -58,6 +74,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("String", cd.Parameters[1].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.Optional, cd.Parameters[1].ParamModifier & ParameterModifiers.Optional);
}
#endregion
#endregion
}
}

16
src/Libraries/NRefactory/Test/Parser/TypeLevel/DestructorDeclarationTests.cs

@ -20,10 +20,24 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -20,10 +20,24 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("~MyClass() {}");
}
[Test]
public void CSharpExternDestructorDeclarationTest()
{
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("extern ~MyClass();");
Assert.AreEqual(Modifiers.Extern, dd.Modifier);
}
[Test]
public void CSharpUnsafeDestructorDeclarationTest()
{
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("unsafe ~MyClass() {}");
Assert.AreEqual(Modifiers.Unsafe, dd.Modifier);
}
#endregion
#region VB.NET
// No VB.NET representation
#endregion
#endregion
}
}

17
src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

@ -171,11 +171,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -171,11 +171,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
DomRegion fullRegion = language.RefactoringProvider.GetFullCodeRangeForType(existingCode, c);
if (fullRegion.IsEmpty) return;
string newCode = ExtractCode(c, fullRegion, c.BodyRegion.BeginLine);
Action removeExtractedCodeAction;
string newCode = ExtractCode(c, fullRegion, c.BodyRegion.BeginLine, out removeExtractedCodeAction);
newCode = language.RefactoringProvider.CreateNewFileLikeExisting(existingCode, newCode);
if (newCode == null)
return;
IViewContent viewContent = FileService.NewFile(newFileName, newCode);
viewContent.PrimaryFile.SaveToDisk(newFileName);
// now that the code is saved in the other file, remove it from the original document
removeExtractedCodeAction();
IProject project = (IProject)c.ProjectContent.Project;
if (project != null) {
@ -188,7 +193,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -188,7 +193,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
}
}
static string ExtractCode(IClass c, DomRegion codeRegion, int indentationLine)
static string ExtractCode(IClass c, DomRegion codeRegion, int indentationLine, out Action removeExtractedCodeAction)
{
ICSharpCode.TextEditor.Document.IDocument doc = GetDocument(c);
if (indentationLine < 1) indentationLine = 1;
@ -204,9 +209,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -204,9 +209,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
int endOffset = segment.Offset + segment.Length;
StringReader reader = new StringReader(doc.GetText(startOffset, endOffset - startOffset));
doc.Remove(startOffset, endOffset - startOffset);
doc.RequestUpdate(new ICSharpCode.TextEditor.TextAreaUpdate(ICSharpCode.TextEditor.TextAreaUpdateType.WholeTextArea));
doc.CommitUpdate();
removeExtractedCodeAction = delegate {
doc.Remove(startOffset, endOffset - startOffset);
doc.RequestUpdate(new ICSharpCode.TextEditor.TextAreaUpdate(ICSharpCode.TextEditor.TextAreaUpdateType.WholeTextArea));
doc.CommitUpdate();
};
// now remove indentation from extracted source code
string line;

2
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/ConstructorCodeGenerator.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -41,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
string parameterName = codeGen.GetParameterName(w.Field.Name);
ctor.Parameters.Add(new ParameterDeclarationExpression(ConvertType(w.Field.ReturnType),
parameterName));
Expression left = new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name);
Expression left = new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name);
Expression right = new IdentifierExpression(parameterName);
Expression expr = new AssignmentExpression(left, AssignmentOperatorType.Assign, right);
ctor.Body.AddChild(new ExpressionStatement(expr));

12
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/EqualsCodeGenerator.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
expr = new AssignmentExpression(new IdentifierExpression(var.Name),
AssignmentOperatorType.ExclusiveOr,
new InvocationExpression(new FieldReferenceExpression(new IdentifierExpression(field.Name), "GetHashCode")));
new InvocationExpression(new MemberReferenceExpression(new IdentifierExpression(field.Name), "GetHashCode")));
if (IsValueType(field.ReturnType)) {
method.Body.AddChild(new ExpressionStatement(expr));
} else {
@ -124,15 +124,15 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -124,15 +124,15 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
static Expression TestEquality(string other, IField field)
{
if (CanCompareEqualityWithOperator(field.ReturnType)) {
return new BinaryOperatorExpression(new FieldReferenceExpression(new ThisReferenceExpression(), field.Name),
return new BinaryOperatorExpression(new MemberReferenceExpression(new ThisReferenceExpression(), field.Name),
BinaryOperatorType.Equality,
new FieldReferenceExpression(new IdentifierExpression(other), field.Name));
new MemberReferenceExpression(new IdentifierExpression(other), field.Name));
} else {
InvocationExpression ie = new InvocationExpression(
new FieldReferenceExpression(new TypeReferenceExpression("System.Object"), "Equals")
new MemberReferenceExpression(new TypeReferenceExpression("System.Object"), "Equals")
);
ie.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), field.Name));
ie.Arguments.Add(new FieldReferenceExpression(new IdentifierExpression(other), field.Name));
ie.Arguments.Add(new MemberReferenceExpression(new ThisReferenceExpression(), field.Name));
ie.Arguments.Add(new MemberReferenceExpression(new IdentifierExpression(other), field.Name));
return ie;
}
}

6
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/ToStringCodeGenerator.cs

@ -25,8 +25,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -25,8 +25,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
TypeReference = stringReference,
};
method.Body = new BlockStatement();
Expression target = new FieldReferenceExpression(new TypeReferenceExpression(stringReference),
"Format");
Expression target = new MemberReferenceExpression(new TypeReferenceExpression(stringReference),
"Format");
InvocationExpression methodCall = new InvocationExpression(target);
StringBuilder formatString = new StringBuilder();
formatString.Append('[');
@ -41,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -41,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
formatString.Append(']');
methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
foreach (FieldWrapper w in items) {
methodCall.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
methodCall.Arguments.Add(new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
}
method.Body.AddChild(new ReturnStatement(methodCall));
nodes.Add(method);

20
src/Main/Base/Test/CSharpExpressionFinderTests.cs

@ -398,6 +398,26 @@ class MyClass { @@ -398,6 +398,26 @@ class MyClass {
Assert.AreEqual(ExpressionContext.IdentifierExpected.ToString(), result.Context.ToString());
}
[Test]
public void FieldWithNullableType()
{
const string program = @"using System;
class MyClass {
int? ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.IdentifierExpected.ToString(), result.Context.ToString());
}
[Test]
public void FieldWithArrayType()
{
const string program = @"using System;
class MyClass {
int[,][] ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.IdentifierExpected.ToString(), result.Context.ToString());
}
[Test]
public void GenericClassDeclaration()
{

10
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs

@ -359,6 +359,10 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -359,6 +359,10 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
frame.SetDefaultContext();
}
break;
case Tokens.Question:
// do not reset context - TrackCurrentContext will take care of this
frame.lastExpressionStart = Location.Empty;
break;
case Tokens.Dot:
case Tokens.DoubleColon:
// let the current expression continue
@ -495,6 +499,12 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -495,6 +499,12 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
frame.parenthesisChildType = FrameType.Expression;
}
break;
case Tokens.Question:
// IdentifierExpected = this is after a type name = the ? was a nullable marker
if (frame.context != ExpressionContext.IdentifierExpected) {
frame.SetDefaultContext();
}
break;
default:
if (Tokens.SimpleTypeName[token.kind]) {
if (frame.type == FrameType.Interface || frame.type == FrameType.TypeDecl) {

8
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/CSharpToVBNetConvertVisitor.cs

@ -350,7 +350,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -350,7 +350,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
Expression CreateExplicitConversionToString(Expression expr)
{
InvocationExpression ie = new InvocationExpression(
new FieldReferenceExpression(new IdentifierExpression("Convert"), "ToString"));
new MemberReferenceExpression(new IdentifierExpression("Convert"), "ToString"));
ie.Arguments.Add(expr);
return ie;
}
@ -373,9 +373,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -373,9 +373,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return null;
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
base.VisitMemberReferenceExpression(fieldReferenceExpression, data);
if (resolver.CompilationUnit == null)
return null;
@ -410,7 +410,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -410,7 +410,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
IClass c = rr.ResolvedType.GetUnderlyingClass();
if (c.ClassType == ClassType.Delegate) {
InvocationExpression invocation = new InvocationExpression(
new FieldReferenceExpression(
new MemberReferenceExpression(
new IdentifierExpression("Delegate"),
assignmentExpression.Op == AssignmentOperatorType.Add ? "Combine" : "Remove"));
invocation.Arguments.Add(assignmentExpression.Left);

34
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs

@ -205,8 +205,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -205,8 +205,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
while (tmp != null) {
if (tmp is IdentifierExpression)
return ResolveInternal(expr, ExpressionContext.Type);
if (tmp is FieldReferenceExpression)
tmp = (tmp as FieldReferenceExpression).TargetObject;
if (tmp is MemberReferenceExpression)
tmp = (tmp as MemberReferenceExpression).TargetObject;
else
break;
}
@ -259,13 +259,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -259,13 +259,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
private class DummyFindVisitor : AbstractAstVisitor {
internal const string dummyName = "___withStatementExpressionDummy";
internal FieldReferenceExpression result;
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
internal MemberReferenceExpression result;
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
IdentifierExpression ie = fieldReferenceExpression.TargetObject as IdentifierExpression;
if (ie != null && ie.Identifier == dummyName)
result = fieldReferenceExpression;
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
return base.VisitMemberReferenceExpression(fieldReferenceExpression, data);
}
}
@ -315,9 +315,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -315,9 +315,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{
if (expr is IdentifierExpression) {
return (expr as IdentifierExpression).Identifier;
} else if (expr is FieldReferenceExpression) {
} else if (expr is MemberReferenceExpression) {
TypeVisitor typeVisitor = new TypeVisitor(this);
FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)expr;
MemberReferenceExpression fieldReferenceExpression = (MemberReferenceExpression)expr;
IReturnType type = fieldReferenceExpression.TargetObject.AcceptVisitor(typeVisitor, null) as IReturnType;
if (type is TypeVisitor.NamespaceReturnType) {
return type.FullyQualifiedName + "." + fieldReferenceExpression.FieldName;
@ -397,8 +397,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -397,8 +397,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
} else if (expr is IndexerExpression) {
return CreateMemberResolveResult(typeVisitor.GetIndexer(expr as IndexerExpression));
} else if (expr is FieldReferenceExpression) {
FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)expr;
} else if (expr is MemberReferenceExpression) {
MemberReferenceExpression fieldReferenceExpression = (MemberReferenceExpression)expr;
if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName.Length == 0) {
// NRefactory creates this "dummy" fieldReferenceExpression when it should
// parse a primitive type name (int, short; Integer, Decimal)
@ -471,16 +471,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -471,16 +471,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return new ResolveResult(callingClass, callingMember, type);
}
ResolveResult ResolveMemberReferenceExpression(IReturnType type, FieldReferenceExpression fieldReferenceExpression)
ResolveResult ResolveMemberReferenceExpression(IReturnType type, MemberReferenceExpression memberReferenceExpression)
{
IClass c;
IMember member;
if (type is TypeVisitor.NamespaceReturnType) {
string combinedName;
if (type.FullyQualifiedName == "")
combinedName = fieldReferenceExpression.FieldName;
combinedName = memberReferenceExpression.FieldName;
else
combinedName = type.FullyQualifiedName + "." + fieldReferenceExpression.FieldName;
combinedName = type.FullyQualifiedName + "." + memberReferenceExpression.FieldName;
if (projectContent.NamespaceExists(combinedName)) {
return new NamespaceResolveResult(callingClass, callingMember, combinedName);
}
@ -492,14 +492,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -492,14 +492,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// go through the members of the modules
foreach (object o in projectContent.GetNamespaceContents(type.FullyQualifiedName)) {
member = o as IMember;
if (member != null && IsSameName(member.Name, fieldReferenceExpression.FieldName)) {
if (member != null && IsSameName(member.Name, memberReferenceExpression.FieldName)) {
return CreateMemberResolveResult(member);
}
}
}
return null;
}
member = GetMember(type, fieldReferenceExpression.FieldName);
member = GetMember(type, memberReferenceExpression.FieldName);
if (member != null)
return CreateMemberResolveResult(member);
c = type.GetUnderlyingClass();
@ -508,14 +508,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -508,14 +508,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
List<IClass> innerClasses = baseClass.InnerClasses;
if (innerClasses != null) {
foreach (IClass innerClass in innerClasses) {
if (IsSameName(innerClass.Name, fieldReferenceExpression.FieldName)) {
if (IsSameName(innerClass.Name, memberReferenceExpression.FieldName)) {
return new TypeResolveResult(callingClass, callingMember, innerClass);
}
}
}
}
}
return ResolveMethod(type, fieldReferenceExpression.FieldName);
return ResolveMethod(type, memberReferenceExpression.FieldName);
}
public TextReader ExtractCurrentMethod(string fileContent)
@ -773,7 +773,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -773,7 +773,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} else if (language == NR.SupportedLanguage.CSharp) {
// generic type names are no expressions, only property access on them is an expression
if (expression.EndsWith(">")) {
FieldReferenceExpression expr = ParseExpression(expression + ".Prop") as FieldReferenceExpression;
MemberReferenceExpression expr = ParseExpression(expression + ".Prop") as MemberReferenceExpression;
if (expr != null) {
return expr.TargetObject;
}

44
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs

@ -170,15 +170,25 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -170,15 +170,25 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
}
List<TypeReference> GetTypeArguments(Expression expr)
{
if (expr is IdentifierExpression)
return ((IdentifierExpression)expr).TypeArguments;
else if (expr is MemberReferenceExpression)
return ((MemberReferenceExpression)expr).TypeArguments;
else
return null;
}
/// <summary>
/// Gets the method called by the InvocationExpression. In Visual Basic, the result
/// can also be an Indexer.
/// </summary>
public IMethodOrProperty GetMethod(InvocationExpression invocationExpression)
{
IReturnType[] typeParameters = CreateReturnTypes(invocationExpression.TypeArguments);
if (invocationExpression.TargetObject is FieldReferenceExpression) {
FieldReferenceExpression field = (FieldReferenceExpression)invocationExpression.TargetObject;
IReturnType[] typeParameters = CreateReturnTypes(GetTypeArguments(invocationExpression.TargetObject));
if (invocationExpression.TargetObject is MemberReferenceExpression) {
MemberReferenceExpression field = (MemberReferenceExpression)invocationExpression.TargetObject;
IReturnType targetType = field.TargetObject.AcceptVisitor(this, null) as IReturnType;
List<IMethod> methods = resolver.SearchMethod(targetType, field.FieldName);
@ -239,8 +249,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -239,8 +249,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// collection(index) - use indexer
// collection.Item(index) - use parametrized property
if (invocationExpression.TargetObject is IdentifierExpression || invocationExpression.TargetObject is FieldReferenceExpression) {
// only IdentifierExpression/FieldReferenceExpression can represent a parametrized property
if (invocationExpression.TargetObject is IdentifierExpression || invocationExpression.TargetObject is MemberReferenceExpression) {
// only IdentifierExpression/MemberReferenceExpression can represent a parametrized property
// - the check is necessary because collection.Items and collection.Item(index) both
// resolve to the same property, but we want to use the default indexer for the second call in
// collection.Item(index1)(index2)
@ -281,26 +291,26 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -281,26 +291,26 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return MemberLookupHelper.FindOverload(indexers.ToArray(), parameters);
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
if (fieldReferenceExpression == null) {
if (memberReferenceExpression == null) {
return null;
}
// int. generates a FieldreferenceExpression with TargetObject TypeReferenceExpression and no FieldName
if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName == "") {
if (fieldReferenceExpression.TargetObject is TypeReferenceExpression) {
return CreateReturnType(((TypeReferenceExpression)fieldReferenceExpression.TargetObject).TypeReference);
if (memberReferenceExpression.FieldName == null || memberReferenceExpression.FieldName == "") {
if (memberReferenceExpression.TargetObject is TypeReferenceExpression) {
return CreateReturnType(((TypeReferenceExpression)memberReferenceExpression.TargetObject).TypeReference);
}
}
IReturnType returnType = fieldReferenceExpression.TargetObject.AcceptVisitor(this, data) as IReturnType;
IReturnType returnType = memberReferenceExpression.TargetObject.AcceptVisitor(this, data) as IReturnType;
if (returnType != null) {
if (returnType is NamespaceReturnType) {
string name = returnType.FullyQualifiedName;
string combinedName;
if (name.Length == 0)
combinedName = fieldReferenceExpression.FieldName;
combinedName = memberReferenceExpression.FieldName;
else
combinedName = name + "." + fieldReferenceExpression.FieldName;
combinedName = name + "." + memberReferenceExpression.FieldName;
if (resolver.ProjectContent.NamespaceExists(combinedName)) {
return new NamespaceReturnType(combinedName);
}
@ -312,13 +322,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -312,13 +322,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// go through the members of the modules
foreach (object o in resolver.ProjectContent.GetNamespaceContents(name)) {
IMember member = o as IMember;
if (member != null && resolver.IsSameName(member.Name, fieldReferenceExpression.FieldName))
if (member != null && resolver.IsSameName(member.Name, memberReferenceExpression.FieldName))
return member.ReturnType;
}
}
return null;
}
return resolver.SearchMember(returnType, fieldReferenceExpression.FieldName);
return resolver.SearchMember(returnType, memberReferenceExpression.FieldName);
}
return null;
}
@ -485,8 +495,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -485,8 +495,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
static string GetAnonymousTypeFieldName(Expression expr)
{
if (expr is FieldReferenceExpression) {
return ((FieldReferenceExpression)expr).FieldName;
if (expr is MemberReferenceExpression) {
return ((MemberReferenceExpression)expr).FieldName;
}
if (expr is AssignmentExpression) {
expr = ((AssignmentExpression)expr).Left; // use left side if it is an IdentifierExpression

28
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/VBNetToCSharpConvertVisitor.cs

@ -265,13 +265,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -265,13 +265,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// insert code to remove the event handler
IfElseStatement ies = (IfElseStatement)createdProperty.SetRegion.Block.Children[0];
ies.TrueStatement[0].AddChild(new RemoveHandlerStatement(
new FieldReferenceExpression(backingFieldNameExpression, eventName),
new MemberReferenceExpression(backingFieldNameExpression, eventName),
new AddressOfExpression(new IdentifierExpression(m.Name))));
// insert code to add the event handler
ies = (IfElseStatement)createdProperty.SetRegion.Block.Children[2];
ies.TrueStatement[0].AddChild(new AddHandlerStatement(
new FieldReferenceExpression(backingFieldNameExpression, eventName),
new MemberReferenceExpression(backingFieldNameExpression, eventName),
new AddressOfExpression(new IdentifierExpression(m.Name))));
}
}
@ -347,20 +347,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -347,20 +347,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return null;
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
base.VisitMemberReferenceExpression(memberReferenceExpression, data);
if (resolver.CompilationUnit == null)
return null;
ResolveResult rr = Resolve(fieldReferenceExpression);
ResolveResult rr = Resolve(memberReferenceExpression);
string ident = GetIdentifierFromResult(rr);
if (ident != null) {
fieldReferenceExpression.FieldName = ident;
memberReferenceExpression.FieldName = ident;
}
if (ReplaceWithInvocation(fieldReferenceExpression, rr)) {}
else if (FullyQualifyModuleMemberReference(fieldReferenceExpression, rr)) {}
if (ReplaceWithInvocation(memberReferenceExpression, rr)) {}
else if (FullyQualifyModuleMemberReference(memberReferenceExpression, rr)) {}
return rr;
}
@ -416,7 +416,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -416,7 +416,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (resolver.CallingClass.IsTypeInInheritanceTree(containingType.GetUnderlyingClass()))
return false;
}
ReplaceCurrentNode(new FieldReferenceExpression(
ReplaceCurrentNode(new MemberReferenceExpression(
new TypeReferenceExpression(ConvertType(containingType)),
ident.Identifier
));
@ -428,15 +428,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -428,15 +428,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return Refactoring.CodeGenerator.ConvertType(type, CreateContext());
}
bool FullyQualifyModuleMemberReference(FieldReferenceExpression fre, ResolveResult rr)
bool FullyQualifyModuleMemberReference(MemberReferenceExpression mre, ResolveResult rr)
{
IReturnType containingType = GetContainingTypeOfStaticMember(rr);
if (containingType == null)
return false;
ResolveResult targetRR = resolver.ResolveInternal(fre.TargetObject, ExpressionContext.Default);
ResolveResult targetRR = resolver.ResolveInternal(mre.TargetObject, ExpressionContext.Default);
if (targetRR is NamespaceResolveResult) {
fre.TargetObject = new TypeReferenceExpression(ConvertType(containingType));
mre.TargetObject = new TypeReferenceExpression(ConvertType(containingType));
return true;
}
return false;
@ -474,7 +474,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -474,7 +474,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (p != null && invocationExpression.Arguments.Count > 0) {
// col(i) -> col[i] or col.Items(i) -> col[i] ?
Expression targetObject = invocationExpression.TargetObject;
FieldReferenceExpression targetObjectFre = targetObject as FieldReferenceExpression;
MemberReferenceExpression targetObjectFre = targetObject as MemberReferenceExpression;
if (p.IsIndexer && targetObjectFre != null) {
MemberResolveResult rr2 = Resolve(targetObjectFre) as MemberResolveResult;
if (rr2 != null && rr2.ResolvedMember == rr.ResolvedMember) {
@ -569,7 +569,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -569,7 +569,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (e == null)
e = new IdentifierExpression(n);
else
e = new FieldReferenceExpression(e, n);
e = new MemberReferenceExpression(e, n);
}
return e;
}

10
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs

@ -391,7 +391,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -391,7 +391,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
arguments.Add(new PrimitiveExpression(null, "null"));
else
arguments.Add(new ThisReferenceExpression());
arguments.Add(new FieldReferenceExpression(new IdentifierExpression("EventArgs"), "Empty"));
arguments.Add(new MemberReferenceExpression(new IdentifierExpression("EventArgs"), "Empty"));
InsertCodeAtEnd(property.SetterRegion, document,
new RaiseEventStatement(name, arguments));
}
@ -617,8 +617,8 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -617,8 +617,8 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
}
PropertyDeclaration property = node as PropertyDeclaration;
if (property != null) {
Expression field = new FieldReferenceExpression(new BaseReferenceExpression(),
property.Name);
Expression field = new MemberReferenceExpression(new BaseReferenceExpression(),
property.Name);
if (!property.GetRegion.Block.IsNull) {
property.GetRegion.Block.Children.Clear();
property.GetRegion.Block.AddChild(new ReturnStatement(field));
@ -637,8 +637,8 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -637,8 +637,8 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
static InvocationExpression CreateForwardingMethodCall(MethodDeclaration method)
{
Expression methodName = new FieldReferenceExpression(new BaseReferenceExpression(),
method.Name);
Expression methodName = new MemberReferenceExpression(new BaseReferenceExpression(),
method.Name);
InvocationExpression ie = new InvocationExpression(methodName, null);
foreach (ParameterDeclarationExpression param in method.Parameters) {
Expression expr = new IdentifierExpression(param.ParameterName);

Loading…
Cancel
Save