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
return new B.ReferenceExpression(GetLexicalInfo(identifierExpression), identifierExpression.Identifier); 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; 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 // 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) if (!typeRef.IsArrayType)
target = MakeReferenceExpression(typeRef); target = MakeReferenceExpression(typeRef);
} }
if (target == null) { if (target == null) {
target = (B.Expression)fre.TargetObject.AcceptVisitor(this, data); target = (B.Expression)mre.TargetObject.AcceptVisitor(this, data);
if (target == null) return null; 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) public object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data)
@ -331,9 +331,6 @@ namespace NRefactoryToBooConverter
public object VisitInvocationExpression(InvocationExpression ie, object data) 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); B.Expression e = ConvertExpression(ie.TargetObject);
if (e == null) if (e == null)
return null; return null;

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

@ -325,13 +325,14 @@ namespace NRefactoryToBooConverter
AddError(reDimStatement, "Redim Preserve is not supported."); AddError(reDimStatement, "Redim Preserve is not supported.");
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
foreach (InvocationExpression o in reDimStatement.ReDimClauses) { 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; IdentifierExpression identifier = o.TargetObject as IdentifierExpression;
if (identifier == null) { if (identifier == null) {
AddError(o, "Sorry, that expression is too complex to be resolved by the converter."); AddError(o, "Sorry, that expression is too complex to be resolved by the converter.");
} else { } 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 // first we need to find out the array type
VariableResolver resolver = new VariableResolver(nameComparer); VariableResolver resolver = new VariableResolver(nameComparer);
TypeReference r = resolver.FindType(identifier.Identifier, reDimStatement); TypeReference r = resolver.FindType(identifier.Identifier, reDimStatement);

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

@ -52,9 +52,9 @@ namespace CSharpBinding
return null; 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)) { if (vbMyFormsClass != null && IsReferenceToInstanceMember(fieldRR)) {
TypeResolveResult trr = Resolve(fieldReferenceExpression.TargetObject) as TypeResolveResult; 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
InvocationExpression invocation = expr as InvocationExpression; InvocationExpression invocation = expr as InvocationExpression;
if (invocation != null) { if (invocation != null) {
FieldReferenceExpression fre = invocation.TargetObject as FieldReferenceExpression; MemberReferenceExpression fre = invocation.TargetObject as MemberReferenceExpression;
if (fre != null) { if (fre != null) {
if (fre.FieldName == "GetString" || fre.FieldName == "GetObject" || fre.FieldName == "GetStream") { if (fre.FieldName == "GetString" || fre.FieldName == "GetObject" || fre.FieldName == "GetStream") {
if (invocation.Arguments.Count > 0) { if (invocation.Arguments.Count > 0) {

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

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

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

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

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

@ -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 { public class FixedStatement : StatementWithEmbeddedStatement {
TypeReference typeReference; TypeReference typeReference;
@ -2150,6 +2111,8 @@ namespace ICSharpCode.NRefactory.Ast {
string identifier; string identifier;
List<TypeReference> typeArguments;
public string Identifier { public string Identifier {
get { get {
return identifier; return identifier;
@ -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) { public IdentifierExpression(string identifier) {
Identifier = identifier; Identifier = identifier;
typeArguments = new List<TypeReference>();
} }
public override object AcceptVisitor(IAstVisitor visitor, object data) { public override object AcceptVisitor(IAstVisitor visitor, object data) {
@ -2168,7 +2141,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
public override string ToString() { 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 {
this.trueStatement.Add(Statement.CheckNull(trueStatement)); this.trueStatement.Add(Statement.CheckNull(trueStatement));
} }
public bool HasElseIfSections {
get {
return elseIfSections.Count > 0;
}
}
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement)
: this(condition) { : this(condition) {
@ -2245,12 +2224,6 @@ namespace ICSharpCode.NRefactory.Ast {
} }
} }
public bool HasElseIfSections {
get {
return elseIfSections.Count > 0;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) { public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitIfElseStatement(this, data); return visitor.VisitIfElseStatement(this, data);
} }
@ -2482,8 +2455,6 @@ namespace ICSharpCode.NRefactory.Ast {
List<Expression> arguments; List<Expression> arguments;
List<TypeReference> typeArguments;
public Expression TargetObject { public Expression TargetObject {
get { get {
return targetObject; return targetObject;
@ -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) { public InvocationExpression(Expression targetObject) {
TargetObject = targetObject; TargetObject = targetObject;
arguments = new List<Expression>(); arguments = new List<Expression>();
typeArguments = new List<TypeReference>();
} }
public InvocationExpression(Expression targetObject, List<Expression> arguments) { public InvocationExpression(Expression targetObject, List<Expression> arguments) {
TargetObject = targetObject; TargetObject = targetObject;
Arguments = arguments; 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) { public override object AcceptVisitor(IAstVisitor visitor, object data) {
@ -2535,7 +2489,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
public override string ToString() { 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 {
} }
} }
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 { public class MethodDeclaration : MemberNode {
BlockStatement body; BlockStatement body;

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

@ -97,8 +97,6 @@ namespace ICSharpCode.NRefactory {
object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data); object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data);
object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data);
object VisitFixedStatement(FixedStatement fixedStatement, object data); object VisitFixedStatement(FixedStatement fixedStatement, object data);
object VisitForeachStatement(ForeachStatement foreachStatement, object data); object VisitForeachStatement(ForeachStatement foreachStatement, object data);
@ -133,6 +131,8 @@ namespace ICSharpCode.NRefactory {
object VisitLockStatement(LockStatement lockStatement, object data); object VisitLockStatement(LockStatement lockStatement, object data);
object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data);
object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data); object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data);
object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, 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)
AssgnOps("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=") AssgnOps("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=")
UnaryOp("+", "-", "!", "~", "*", "++", "--", "&") UnaryOp("+", "-", "!", "~", "*", "++", "--", "&")
TypeDeclarationKW("class", "interface", "struct", "enum", "delegate") 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, "]", "*", "::") ValidInsideTypeName(@IdentifierTokens, @TypeKW, "<", ">", ".", "?", "[", Comma, "]", "*", "::")

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

@ -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 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 UnaryOp = NewSet(Plus, Minus, Not, BitwiseComplement, Times, Increment, Decrement, BitwiseAnd);
public static BitArray TypeDeclarationKW = NewSet(Class, Interface, Struct, Enum, Delegate); 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 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 KCCClassModifiers = NewSet(Abstract, Sealed, Static, Unsafe, Partial);
public static BitArray KCCTypeDeclarationStart = NewSet(Public, Internal, Class, Interface, Struct, Enum, Delegate, 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
return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt); return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt);
} }
/* True if lookahead is type parameters (<...>) followed by the specified token */ /* True if lookahead is a type argument list (<...>) followed by
bool IsGenericFollowedBy(int token) * one of "( ) ] } : ; , . ? == !=" */
bool IsGenericInSimpleNameOrMemberAccess()
{ {
Token t = la; Token t = la;
if (t.kind != Tokens.LessThan) return false; if (t.kind != Tokens.LessThan) return false;
StartPeek(); StartPeek();
return SkipGeneric(ref t) && t.kind == token; return SkipGeneric(ref t) && Tokens.GenericFollower[t.kind];
} }
bool IsExplicitInterfaceImplementation() bool IsExplicitInterfaceImplementation()
@ -497,61 +498,50 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
return (la.kind == Tokens.GreaterThan && next.kind == Tokens.GreaterThan); 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; if (expr is IdentifierExpression)
while (expr is FieldReferenceExpression) { return ((IdentifierExpression)expr).TypeArguments.Count > 0;
expr = ((FieldReferenceExpression)expr).TargetObject; else if (expr is MemberReferenceExpression)
if (expr is TypeReferenceExpression) return true; return ((MemberReferenceExpression)expr).TypeArguments.Count > 0;
} else
return expr is IdentifierExpression; 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 (expr is TypeReferenceExpression)
if (tre != null) { return (expr as TypeReferenceExpression).TypeReference;
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
IdentifierExpression ident = expr as IdentifierExpression;
if (ident != null) {
return new TypeReference(ident.Identifier, ident.TypeArguments);
} }
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) { MemberReferenceExpression member = expr as MemberReferenceExpression;
// there is some TypeReferenceExpression hidden in the expression if (member != null) {
while (expr is FieldReferenceExpression) { TypeReference targetType = GetTypeReferenceFromExpression(member.TargetObject);
expr = ((FieldReferenceExpression)expr).TargetObject; if (targetType != null) {
} if (targetType.GenericTypes.Count == 0 && targetType.IsArrayType == false) {
tre = expr as TypeReferenceExpression; TypeReference tr = new TypeReference(targetType.Type + "." + member.FieldName, member.TypeArguments);
if (tre != null) { tr.IsGlobal = targetType.IsGlobal;
TypeReference typeRef = tre.TypeReference; return tr;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else { } 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)); return null;
}
/* 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;
}
} }
bool IsMostNegativeIntegerWithoutTypeSuffix() 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>
PrimaryExpr<out Expression pexpr> PrimaryExpr<out Expression pexpr>
(. (.
TypeReference type = null; TypeReference type = null;
List<TypeReference> typeList = null;
Expression expr; Expression expr;
pexpr = null; pexpr = null;
.) .)
@ -1769,7 +1768,12 @@ PrimaryExpr<out Expression pexpr>
(. pexpr = new IdentifierExpression(t.val); .) (. pexpr = new IdentifierExpression(t.val); .)
(. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .) (. 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 */ | IF (IsLambdaExpression()) /* Lambda expression */
LambdaExpression<out pexpr> LambdaExpression<out pexpr>
/*--- parenthesized expression: */ /*--- parenthesized expression: */
@ -1792,13 +1796,14 @@ PrimaryExpr<out Expression pexpr>
| "uint" (. val = "uint"; .) | "uint" (. val = "uint"; .)
| "ulong" (. val = "ulong"; .) | "ulong" (. val = "ulong"; .)
| "ushort" (. val = "ushort"; .) | "ushort" (. val = "ushort"; .)
) (. t.val = ""; .) "." Identifier (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .) )
MemberAccess<out pexpr, new TypeReferenceExpression(val)>
/*--- this access: */ /*--- this access: */
| "this" (. pexpr = new ThisReferenceExpression(); .) | "this" (. pexpr = new ThisReferenceExpression(); .)
/*--- base access: */ /*--- base access: */
| "base" (. Expression retExpr = new BaseReferenceExpression(); .) | "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> (. List<Expression> indices = new List<Expression>(); if (expr != null) { indices.Add(expr); } .)
{ "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .) } { "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .) }
"]" (. retExpr = new IndexerExpression(retExpr, indices); .) "]" (. retExpr = new IndexerExpression(retExpr, indices); .)
@ -1825,23 +1830,14 @@ PrimaryExpr<out Expression pexpr>
| "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .) | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
) )
/*--- member access */ /*--- member access */
| "->" Identifier (. pexpr = new PointerReferenceExpression(pexpr, t.val); .) | PointerMemberAccess<out pexpr, pexpr>
| "." Identifier (. pexpr = new FieldReferenceExpression(pexpr, t.val);.) | MemberAccess<out pexpr, pexpr>
/* member access on generic type */
| ( IF (IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr))
TypeArgumentList<out typeList, false> )
"." Identifier
(. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeList), t.val);.)
/*--- invocation expression: */ /*--- invocation expression: */
| "(" (. List<Expression> parameters = new List<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);} .)
{ "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .) { "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
} ] ")" (. pexpr = new InvocationExpression(pexpr, parameters); .) } ] ")" (. 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 */ /*--- element access */
| (. /*if (isArrayCreation) Error("element access not allow on array creation");*/ | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/
List<Expression> indices = new List<Expression>(); List<Expression> indices = new List<Expression>();
@ -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> NewExpression<out Expression pexpr>
(. pexpr = null; (. pexpr = null;
List<Expression> parameters = new List<Expression>(); List<Expression> parameters = new List<Expression>();

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

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

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

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

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

@ -218,8 +218,8 @@ namespace ICSharpCode.NRefactory.Parser.VB
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) { if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression // there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) { while (expr is MemberReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject; expr = ((MemberReferenceExpression)expr).TargetObject;
} }
tre = expr as TypeReferenceExpression; tre = expr as TypeReferenceExpression;
if (tre != null) { if (tre != null) {
@ -242,7 +242,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */ /* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr) bool WriteFullTypeName(StringBuilder b, Expression expr)
{ {
FieldReferenceExpression fre = expr as FieldReferenceExpression; MemberReferenceExpression fre = expr as MemberReferenceExpression;
if (fre != null) { if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject); bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.'); if (b.Length > 0) b.Append('.');
@ -272,6 +272,20 @@ namespace ICSharpCode.NRefactory.Parser.VB
Error("lower bound of array must be zero"); 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> /// <summary>
/// Adds a child item to a collection stored in the parent node. /// Adds a child item to a collection stored in the parent node.
/// Also set's the item's parent to <paramref name="parent"/>. /// 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
{ {
TrackVisit(invocationExpression.TargetObject, data); 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) { if (prettyPrintOptions.BeforeMethodCallParentheses) {
outputFormatter.Space(); outputFormatter.Space();
} }
@ -2054,9 +2048,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data) public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{ {
outputFormatter.PrintIdentifier(identifierExpression.Identifier); outputFormatter.PrintIdentifier(identifierExpression.Identifier);
PrintTypeArgumentList(identifierExpression.TypeArguments);
return null; 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) public override object TrackedVisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data)
{ {
TrackVisit(typeReferenceExpression.TypeReference, data); TrackVisit(typeReferenceExpression.TypeReference, data);
@ -2410,9 +2414,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null; 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) { if (target is BinaryOperatorExpression || target is CastExpression) {
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
@ -2422,7 +2426,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
outputFormatter.PrintToken(Tokens.Dot); outputFormatter.PrintToken(Tokens.Dot);
outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName); outputFormatter.PrintIdentifier(memberReferenceExpression.FieldName);
PrintTypeArgumentList(memberReferenceExpression.TypeArguments);
return null; return null;
} }

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

@ -2183,22 +2183,27 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data) public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{ {
TrackedVisit(invocationExpression.TargetObject, 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.OpenParenthesis);
outputFormatter.PrintToken(Tokens.Of); outputFormatter.PrintToken(Tokens.Of);
outputFormatter.Space(); outputFormatter.Space();
AppendCommaSeparatedList(invocationExpression.TypeArguments); AppendCommaSeparatedList(typeArguments);
outputFormatter.PrintToken(Tokens.CloseParenthesis); 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) public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{ {
outputFormatter.PrintIdentifier(identifierExpression.Identifier); outputFormatter.PrintIdentifier(identifierExpression.Identifier);
PrintTypeArguments(identifierExpression.TypeArguments);
return null; return null;
} }
@ -2546,11 +2551,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null; 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.PrintToken(Tokens.Dot);
outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName); outputFormatter.PrintIdentifier(memberReferenceExpression.FieldName);
PrintTypeArguments(memberReferenceExpression.TypeArguments);
return null; return null;
} }

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

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

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

@ -765,15 +765,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return null; 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) { public virtual object VisitFixedStatement(FixedStatement fixedStatement, object data) {
Debug.Assert((fixedStatement != null)); Debug.Assert((fixedStatement != null));
Debug.Assert((fixedStatement.TypeReference != null)); Debug.Assert((fixedStatement.TypeReference != null));
@ -910,6 +901,18 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { public virtual object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) {
Debug.Assert((identifierExpression != null)); 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; return null;
} }
@ -1066,7 +1069,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((invocationExpression != null)); Debug.Assert((invocationExpression != null));
Debug.Assert((invocationExpression.TargetObject != null)); Debug.Assert((invocationExpression.TargetObject != null));
Debug.Assert((invocationExpression.Arguments != null)); Debug.Assert((invocationExpression.Arguments != null));
Debug.Assert((invocationExpression.TypeArguments != null));
nodeStack.Push(invocationExpression.TargetObject); nodeStack.Push(invocationExpression.TargetObject);
invocationExpression.TargetObject.AcceptVisitor(this, data); invocationExpression.TargetObject.AcceptVisitor(this, data);
invocationExpression.TargetObject = ((Expression)(nodeStack.Pop())); invocationExpression.TargetObject = ((Expression)(nodeStack.Pop()));
@ -1081,17 +1083,6 @@ namespace ICSharpCode.NRefactory.Visitors {
else else
invocationExpression.Arguments[i] = o; 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; return null;
} }
@ -1159,6 +1150,27 @@ namespace ICSharpCode.NRefactory.Visitors {
return null; 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) { public virtual object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
Debug.Assert((methodDeclaration != null)); Debug.Assert((methodDeclaration != null));
Debug.Assert((methodDeclaration.Attributes != null)); Debug.Assert((methodDeclaration.Attributes != null));

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

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

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

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

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

@ -318,13 +318,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return result; 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) { public sealed override object VisitFixedStatement(FixedStatement fixedStatement, object data) {
this.BeginVisit(fixedStatement); this.BeginVisit(fixedStatement);
object result = this.TrackedVisitFixedStatement(fixedStatement, data); object result = this.TrackedVisitFixedStatement(fixedStatement, data);
@ -444,6 +437,13 @@ namespace ICSharpCode.NRefactory.Visitors {
return result; 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) { public sealed override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
this.BeginVisit(methodDeclaration); this.BeginVisit(methodDeclaration);
object result = this.TrackedVisitMethodDeclaration(methodDeclaration, data); object result = this.TrackedVisitMethodDeclaration(methodDeclaration, data);
@ -972,10 +972,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return base.VisitFieldDeclaration(fieldDeclaration, data); 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) { public virtual object TrackedVisitFixedStatement(FixedStatement fixedStatement, object data) {
return base.VisitFixedStatement(fixedStatement, data); return base.VisitFixedStatement(fixedStatement, data);
} }
@ -1044,6 +1040,10 @@ namespace ICSharpCode.NRefactory.Visitors {
return base.VisitLockStatement(lockStatement, data); 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) { public virtual object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) {
return base.VisitMethodDeclaration(methodDeclaration, data); return base.VisitMethodDeclaration(methodDeclaration, data);
} }

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

@ -121,7 +121,7 @@ namespace ICSharpCode.NRefactory.Visitors
return base.VisitIdentifierExpression(identifierExpression, data); 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) { if (fieldReferenceExpression.TargetObject is ThisReferenceExpression) {
string name = fieldReferenceExpression.FieldName; string name = fieldReferenceExpression.FieldName;
@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.Visitors
} }
} }
} }
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data); return base.VisitMemberReferenceExpression(fieldReferenceExpression, data);
} }
bool IsLocal(string name) bool IsLocal(string name)

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

@ -179,13 +179,13 @@ namespace ICSharpCode.NRefactory.Visitors
this.replaceWith = replaceWith; this.replaceWith = replaceWith;
} }
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{ {
if (fieldReferenceExpression.TargetObject.IsNull) { if (fieldReferenceExpression.TargetObject.IsNull) {
fieldReferenceExpression.TargetObject = replaceWith; fieldReferenceExpression.TargetObject = replaceWith;
return null; return null;
} else { } 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
IdentifierExpression ident = expr as IdentifierExpression; IdentifierExpression ident = expr as IdentifierExpression;
if (ident != null) if (ident != null)
return ident.Identifier; return ident.Identifier;
FieldReferenceExpression fre = expr as FieldReferenceExpression; MemberReferenceExpression fre = expr as MemberReferenceExpression;
if (fre != null && fre.TargetObject is ThisReferenceExpression) if (fre != null && fre.TargetObject is ThisReferenceExpression)
return fre.FieldName; return fre.FieldName;
return null; return null;
@ -256,7 +256,7 @@ namespace ICSharpCode.NRefactory.Visitors
break; break;
case "CharSet": case "CharSet":
{ {
FieldReferenceExpression fre = arg.Expression as FieldReferenceExpression; MemberReferenceExpression fre = arg.Expression as MemberReferenceExpression;
if (fre == null || !(fre.TargetObject is IdentifierExpression)) if (fre == null || !(fre.TargetObject is IdentifierExpression))
return false; return false;
if ((fre.TargetObject as IdentifierExpression).Identifier != "CharSet") if ((fre.TargetObject as IdentifierExpression).Identifier != "CharSet")

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

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

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

@ -62,7 +62,7 @@
<Compile Include="Parser\Expressions\BinaryOperatorExpressionTests.cs" /> <Compile Include="Parser\Expressions\BinaryOperatorExpressionTests.cs" />
<Compile Include="Parser\Expressions\UnaryOperatorExpressionTests.cs" /> <Compile Include="Parser\Expressions\UnaryOperatorExpressionTests.cs" />
<Compile Include="Parser\Expressions\CastExpressionTests.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\InvocationExpressionTests.cs" />
<Compile Include="Parser\Expressions\TypeOfExpressionTests.cs" /> <Compile Include="Parser\Expressions\TypeOfExpressionTests.cs" />
<Compile Include="Parser\Expressions\ArrayCreateExpressionTests.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
public void MethodOnThisReferenceInvocation() public void MethodOnThisReferenceInvocation()
{ {
// InitializeComponents(); // InitializeComponents();
FieldReferenceExpression field = new FieldReferenceExpression(new ThisReferenceExpression(), "InitializeComponents"); MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression); Assert.IsTrue(output is CodeMethodInvokeExpression);
@ -48,9 +48,9 @@ namespace ICSharpCode.NRefactory.Tests.Output.CodeDom.Tests
public void InvocationOfStaticMethod() public void InvocationOfStaticMethod()
{ {
// System.Drawing.Color.FromArgb(); // System.Drawing.Color.FromArgb();
FieldReferenceExpression field = new FieldReferenceExpression(new IdentifierExpression("System"), "Drawing"); MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing");
field = new FieldReferenceExpression(field, "Color"); field = new MemberReferenceExpression(field, "Color");
field = new FieldReferenceExpression(field, "FromArgb"); field = new MemberReferenceExpression(field, "FromArgb");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression); Assert.IsTrue(output is CodeMethodInvokeExpression);

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

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

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

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

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

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

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

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

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

@ -30,6 +30,14 @@ namespace ICSharpCode.NRefactory.Tests.Ast
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("@public"); IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("@public");
Assert.AreEqual("public", ident.Identifier); 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 #endregion
#region VB.NET #region VB.NET

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

@ -27,19 +27,21 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
Assert.AreEqual(1, expr.Arguments.Count); Assert.AreEqual(1, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression); Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier); IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual(1, expr.TypeArguments.Count); Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual("System.Char", expr.TypeArguments[0].SystemType); Assert.AreEqual(1, ident.TypeArguments.Count);
Assert.AreEqual("System.Char", ident.TypeArguments[0].SystemType);
} }
void CheckGenericInvoke2(InvocationExpression expr) void CheckGenericInvoke2(InvocationExpression expr)
{ {
Assert.AreEqual(0, expr.Arguments.Count); Assert.AreEqual(0, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression); Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier); IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual(2, expr.TypeArguments.Count); Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual("T", expr.TypeArguments[0].SystemType); Assert.AreEqual(2, ident.TypeArguments.Count);
Assert.AreEqual("System.Boolean", expr.TypeArguments[1].SystemType); Assert.AreEqual("T", ident.TypeArguments[0].SystemType);
Assert.AreEqual("System.Boolean", ident.TypeArguments[1].SystemType);
} }
@ -62,6 +64,29 @@ namespace ICSharpCode.NRefactory.Tests.Ast
CheckGenericInvoke2(ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod<T,bool>()")); 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] [Test]
public void CSharpInvalidNestedInvocationExpressionTest() 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;
namespace ICSharpCode.NRefactory.Tests.Ast namespace ICSharpCode.NRefactory.Tests.Ast
{ {
[TestFixture] [TestFixture]
public class FieldReferenceExpressionTests public class MemberReferenceExpressionTests
{ {
#region C# #region C#
[Test] [Test]
public void CSharpSimpleFieldReferenceExpressionTest() public void CSharpSimpleFieldReferenceExpressionTest()
{ {
FieldReferenceExpression fre = ParseUtilCSharp.ParseExpression<FieldReferenceExpression>("myTargetObject.myField"); MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("myTargetObject.myField");
Assert.AreEqual("myField", fre.FieldName); Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is IdentifierExpression); Assert.IsTrue(fre.TargetObject is IdentifierExpression);
Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier); Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void CSharpGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void CSharpFullNamespaceGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void CSharpGlobalFullNamespaceGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void CSharpNestedGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference; InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetSimpleFieldReferenceExpressionTest() public void VBNetSimpleFieldReferenceExpressionTest()
{ {
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>("myTargetObject.myField"); MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("myTargetObject.myField");
Assert.AreEqual("myField", fre.FieldName); Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is IdentifierExpression); Assert.IsTrue(fre.TargetObject is IdentifierExpression);
Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier); Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
@ -93,7 +93,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetFieldReferenceExpressionWithoutTargetTest() public void VBNetFieldReferenceExpressionWithoutTargetTest()
{ {
FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression<FieldReferenceExpression>(".myField"); MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>(".myField");
Assert.AreEqual("myField", fre.FieldName); Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject.IsNull); Assert.IsTrue(fre.TargetObject.IsNull);
} }
@ -101,7 +101,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetFullNamespaceGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -125,7 +125,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetGlobalFullNamespaceGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
@ -139,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetNestedGenericFieldReferenceExpressionTest() 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.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference; 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
Assert.AreEqual(3, oce.ObjectInitializer.CreateExpressions.Count); Assert.AreEqual(3, oce.ObjectInitializer.CreateExpressions.Count);
Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "Name")); Assert.IsInstanceOfType(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "Name"));
Assert.IsInstanceOfType(typeof(IdentifierExpression), oce.ObjectInitializer.CreateExpressions[1]); 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 #endregion

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

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

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

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

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

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

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

@ -37,6 +37,22 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(ConstructorInitializerType.Base, cd.ConstructorInitializer.ConstructorInitializerType); Assert.AreEqual(ConstructorInitializerType.Base, cd.ConstructorInitializer.ConstructorInitializerType);
Assert.AreEqual(3, cd.ConstructorInitializer.Arguments.Count); 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 #endregion
#region VB.NET #region VB.NET
@ -58,6 +74,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("String", cd.Parameters[1].TypeReference.Type); Assert.AreEqual("String", cd.Parameters[1].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.Optional, cd.Parameters[1].ParamModifier & ParameterModifiers.Optional); 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
{ {
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("~MyClass() {}"); 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 #endregion
#region VB.NET #region VB.NET
// No VB.NET representation // 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
DomRegion fullRegion = language.RefactoringProvider.GetFullCodeRangeForType(existingCode, c); DomRegion fullRegion = language.RefactoringProvider.GetFullCodeRangeForType(existingCode, c);
if (fullRegion.IsEmpty) return; 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); newCode = language.RefactoringProvider.CreateNewFileLikeExisting(existingCode, newCode);
if (newCode == null)
return;
IViewContent viewContent = FileService.NewFile(newFileName, newCode); IViewContent viewContent = FileService.NewFile(newFileName, newCode);
viewContent.PrimaryFile.SaveToDisk(newFileName); 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; IProject project = (IProject)c.ProjectContent.Project;
if (project != null) { if (project != null) {
@ -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); ICSharpCode.TextEditor.Document.IDocument doc = GetDocument(c);
if (indentationLine < 1) indentationLine = 1; if (indentationLine < 1) indentationLine = 1;
@ -204,9 +209,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
int endOffset = segment.Offset + segment.Length; int endOffset = segment.Offset + segment.Length;
StringReader reader = new StringReader(doc.GetText(startOffset, endOffset - startOffset)); StringReader reader = new StringReader(doc.GetText(startOffset, endOffset - startOffset));
doc.Remove(startOffset, endOffset - startOffset); removeExtractedCodeAction = delegate {
doc.RequestUpdate(new ICSharpCode.TextEditor.TextAreaUpdate(ICSharpCode.TextEditor.TextAreaUpdateType.WholeTextArea)); doc.Remove(startOffset, endOffset - startOffset);
doc.CommitUpdate(); doc.RequestUpdate(new ICSharpCode.TextEditor.TextAreaUpdate(ICSharpCode.TextEditor.TextAreaUpdateType.WholeTextArea));
doc.CommitUpdate();
};
// now remove indentation from extracted source code // now remove indentation from extracted source code
string line; string line;

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

@ -41,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
string parameterName = codeGen.GetParameterName(w.Field.Name); string parameterName = codeGen.GetParameterName(w.Field.Name);
ctor.Parameters.Add(new ParameterDeclarationExpression(ConvertType(w.Field.ReturnType), ctor.Parameters.Add(new ParameterDeclarationExpression(ConvertType(w.Field.ReturnType),
parameterName)); 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 right = new IdentifierExpression(parameterName);
Expression expr = new AssignmentExpression(left, AssignmentOperatorType.Assign, right); Expression expr = new AssignmentExpression(left, AssignmentOperatorType.Assign, right);
ctor.Body.AddChild(new ExpressionStatement(expr)); 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
expr = new AssignmentExpression(new IdentifierExpression(var.Name), expr = new AssignmentExpression(new IdentifierExpression(var.Name),
AssignmentOperatorType.ExclusiveOr, AssignmentOperatorType.ExclusiveOr,
new InvocationExpression(new FieldReferenceExpression(new IdentifierExpression(field.Name), "GetHashCode"))); new InvocationExpression(new MemberReferenceExpression(new IdentifierExpression(field.Name), "GetHashCode")));
if (IsValueType(field.ReturnType)) { if (IsValueType(field.ReturnType)) {
method.Body.AddChild(new ExpressionStatement(expr)); method.Body.AddChild(new ExpressionStatement(expr));
} else { } else {
@ -124,15 +124,15 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
static Expression TestEquality(string other, IField field) static Expression TestEquality(string other, IField field)
{ {
if (CanCompareEqualityWithOperator(field.ReturnType)) { if (CanCompareEqualityWithOperator(field.ReturnType)) {
return new BinaryOperatorExpression(new FieldReferenceExpression(new ThisReferenceExpression(), field.Name), return new BinaryOperatorExpression(new MemberReferenceExpression(new ThisReferenceExpression(), field.Name),
BinaryOperatorType.Equality, BinaryOperatorType.Equality,
new FieldReferenceExpression(new IdentifierExpression(other), field.Name)); new MemberReferenceExpression(new IdentifierExpression(other), field.Name));
} else { } else {
InvocationExpression ie = new InvocationExpression( 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 MemberReferenceExpression(new ThisReferenceExpression(), field.Name));
ie.Arguments.Add(new FieldReferenceExpression(new IdentifierExpression(other), field.Name)); ie.Arguments.Add(new MemberReferenceExpression(new IdentifierExpression(other), field.Name));
return ie; return ie;
} }
} }

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

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

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

@ -398,6 +398,26 @@ class MyClass {
Assert.AreEqual(ExpressionContext.IdentifierExpected.ToString(), result.Context.ToString()); 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] [Test]
public void GenericClassDeclaration() public void GenericClassDeclaration()
{ {

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

@ -359,6 +359,10 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
frame.SetDefaultContext(); frame.SetDefaultContext();
} }
break; break;
case Tokens.Question:
// do not reset context - TrackCurrentContext will take care of this
frame.lastExpressionStart = Location.Empty;
break;
case Tokens.Dot: case Tokens.Dot:
case Tokens.DoubleColon: case Tokens.DoubleColon:
// let the current expression continue // let the current expression continue
@ -495,6 +499,12 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
frame.parenthesisChildType = FrameType.Expression; frame.parenthesisChildType = FrameType.Expression;
} }
break; 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: default:
if (Tokens.SimpleTypeName[token.kind]) { if (Tokens.SimpleTypeName[token.kind]) {
if (frame.type == FrameType.Interface || frame.type == FrameType.TypeDecl) { 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
Expression CreateExplicitConversionToString(Expression expr) Expression CreateExplicitConversionToString(Expression expr)
{ {
InvocationExpression ie = new InvocationExpression( InvocationExpression ie = new InvocationExpression(
new FieldReferenceExpression(new IdentifierExpression("Convert"), "ToString")); new MemberReferenceExpression(new IdentifierExpression("Convert"), "ToString"));
ie.Arguments.Add(expr); ie.Arguments.Add(expr);
return ie; return ie;
} }
@ -373,9 +373,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return null; 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) if (resolver.CompilationUnit == null)
return null; return null;
@ -410,7 +410,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
IClass c = rr.ResolvedType.GetUnderlyingClass(); IClass c = rr.ResolvedType.GetUnderlyingClass();
if (c.ClassType == ClassType.Delegate) { if (c.ClassType == ClassType.Delegate) {
InvocationExpression invocation = new InvocationExpression( InvocationExpression invocation = new InvocationExpression(
new FieldReferenceExpression( new MemberReferenceExpression(
new IdentifierExpression("Delegate"), new IdentifierExpression("Delegate"),
assignmentExpression.Op == AssignmentOperatorType.Add ? "Combine" : "Remove")); assignmentExpression.Op == AssignmentOperatorType.Add ? "Combine" : "Remove"));
invocation.Arguments.Add(assignmentExpression.Left); 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
while (tmp != null) { while (tmp != null) {
if (tmp is IdentifierExpression) if (tmp is IdentifierExpression)
return ResolveInternal(expr, ExpressionContext.Type); return ResolveInternal(expr, ExpressionContext.Type);
if (tmp is FieldReferenceExpression) if (tmp is MemberReferenceExpression)
tmp = (tmp as FieldReferenceExpression).TargetObject; tmp = (tmp as MemberReferenceExpression).TargetObject;
else else
break; break;
} }
@ -259,13 +259,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} }
private class DummyFindVisitor : AbstractAstVisitor { private class DummyFindVisitor : AbstractAstVisitor {
internal const string dummyName = "___withStatementExpressionDummy"; internal const string dummyName = "___withStatementExpressionDummy";
internal FieldReferenceExpression result; internal MemberReferenceExpression result;
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data) public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{ {
IdentifierExpression ie = fieldReferenceExpression.TargetObject as IdentifierExpression; IdentifierExpression ie = fieldReferenceExpression.TargetObject as IdentifierExpression;
if (ie != null && ie.Identifier == dummyName) if (ie != null && ie.Identifier == dummyName)
result = fieldReferenceExpression; result = fieldReferenceExpression;
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data); return base.VisitMemberReferenceExpression(fieldReferenceExpression, data);
} }
} }
@ -315,9 +315,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{ {
if (expr is IdentifierExpression) { if (expr is IdentifierExpression) {
return (expr as IdentifierExpression).Identifier; return (expr as IdentifierExpression).Identifier;
} else if (expr is FieldReferenceExpression) { } else if (expr is MemberReferenceExpression) {
TypeVisitor typeVisitor = new TypeVisitor(this); TypeVisitor typeVisitor = new TypeVisitor(this);
FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)expr; MemberReferenceExpression fieldReferenceExpression = (MemberReferenceExpression)expr;
IReturnType type = fieldReferenceExpression.TargetObject.AcceptVisitor(typeVisitor, null) as IReturnType; IReturnType type = fieldReferenceExpression.TargetObject.AcceptVisitor(typeVisitor, null) as IReturnType;
if (type is TypeVisitor.NamespaceReturnType) { if (type is TypeVisitor.NamespaceReturnType) {
return type.FullyQualifiedName + "." + fieldReferenceExpression.FieldName; return type.FullyQualifiedName + "." + fieldReferenceExpression.FieldName;
@ -397,8 +397,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} }
} else if (expr is IndexerExpression) { } else if (expr is IndexerExpression) {
return CreateMemberResolveResult(typeVisitor.GetIndexer(expr as IndexerExpression)); return CreateMemberResolveResult(typeVisitor.GetIndexer(expr as IndexerExpression));
} else if (expr is FieldReferenceExpression) { } else if (expr is MemberReferenceExpression) {
FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)expr; MemberReferenceExpression fieldReferenceExpression = (MemberReferenceExpression)expr;
if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName.Length == 0) { if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName.Length == 0) {
// NRefactory creates this "dummy" fieldReferenceExpression when it should // NRefactory creates this "dummy" fieldReferenceExpression when it should
// parse a primitive type name (int, short; Integer, Decimal) // parse a primitive type name (int, short; Integer, Decimal)
@ -471,16 +471,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return new ResolveResult(callingClass, callingMember, type); return new ResolveResult(callingClass, callingMember, type);
} }
ResolveResult ResolveMemberReferenceExpression(IReturnType type, FieldReferenceExpression fieldReferenceExpression) ResolveResult ResolveMemberReferenceExpression(IReturnType type, MemberReferenceExpression memberReferenceExpression)
{ {
IClass c; IClass c;
IMember member; IMember member;
if (type is TypeVisitor.NamespaceReturnType) { if (type is TypeVisitor.NamespaceReturnType) {
string combinedName; string combinedName;
if (type.FullyQualifiedName == "") if (type.FullyQualifiedName == "")
combinedName = fieldReferenceExpression.FieldName; combinedName = memberReferenceExpression.FieldName;
else else
combinedName = type.FullyQualifiedName + "." + fieldReferenceExpression.FieldName; combinedName = type.FullyQualifiedName + "." + memberReferenceExpression.FieldName;
if (projectContent.NamespaceExists(combinedName)) { if (projectContent.NamespaceExists(combinedName)) {
return new NamespaceResolveResult(callingClass, callingMember, combinedName); return new NamespaceResolveResult(callingClass, callingMember, combinedName);
} }
@ -492,14 +492,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// go through the members of the modules // go through the members of the modules
foreach (object o in projectContent.GetNamespaceContents(type.FullyQualifiedName)) { foreach (object o in projectContent.GetNamespaceContents(type.FullyQualifiedName)) {
member = o as IMember; member = o as IMember;
if (member != null && IsSameName(member.Name, fieldReferenceExpression.FieldName)) { if (member != null && IsSameName(member.Name, memberReferenceExpression.FieldName)) {
return CreateMemberResolveResult(member); return CreateMemberResolveResult(member);
} }
} }
} }
return null; return null;
} }
member = GetMember(type, fieldReferenceExpression.FieldName); member = GetMember(type, memberReferenceExpression.FieldName);
if (member != null) if (member != null)
return CreateMemberResolveResult(member); return CreateMemberResolveResult(member);
c = type.GetUnderlyingClass(); c = type.GetUnderlyingClass();
@ -508,14 +508,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
List<IClass> innerClasses = baseClass.InnerClasses; List<IClass> innerClasses = baseClass.InnerClasses;
if (innerClasses != null) { if (innerClasses != null) {
foreach (IClass innerClass in innerClasses) { foreach (IClass innerClass in innerClasses) {
if (IsSameName(innerClass.Name, fieldReferenceExpression.FieldName)) { if (IsSameName(innerClass.Name, memberReferenceExpression.FieldName)) {
return new TypeResolveResult(callingClass, callingMember, innerClass); return new TypeResolveResult(callingClass, callingMember, innerClass);
} }
} }
} }
} }
} }
return ResolveMethod(type, fieldReferenceExpression.FieldName); return ResolveMethod(type, memberReferenceExpression.FieldName);
} }
public TextReader ExtractCurrentMethod(string fileContent) public TextReader ExtractCurrentMethod(string fileContent)
@ -773,7 +773,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} else if (language == NR.SupportedLanguage.CSharp) { } else if (language == NR.SupportedLanguage.CSharp) {
// generic type names are no expressions, only property access on them is an expression // generic type names are no expressions, only property access on them is an expression
if (expression.EndsWith(">")) { if (expression.EndsWith(">")) {
FieldReferenceExpression expr = ParseExpression(expression + ".Prop") as FieldReferenceExpression; MemberReferenceExpression expr = ParseExpression(expression + ".Prop") as MemberReferenceExpression;
if (expr != null) { if (expr != null) {
return expr.TargetObject; return expr.TargetObject;
} }

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

@ -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> /// <summary>
/// Gets the method called by the InvocationExpression. In Visual Basic, the result /// Gets the method called by the InvocationExpression. In Visual Basic, the result
/// can also be an Indexer. /// can also be an Indexer.
/// </summary> /// </summary>
public IMethodOrProperty GetMethod(InvocationExpression invocationExpression) public IMethodOrProperty GetMethod(InvocationExpression invocationExpression)
{ {
IReturnType[] typeParameters = CreateReturnTypes(invocationExpression.TypeArguments); IReturnType[] typeParameters = CreateReturnTypes(GetTypeArguments(invocationExpression.TargetObject));
if (invocationExpression.TargetObject is FieldReferenceExpression) { if (invocationExpression.TargetObject is MemberReferenceExpression) {
FieldReferenceExpression field = (FieldReferenceExpression)invocationExpression.TargetObject; MemberReferenceExpression field = (MemberReferenceExpression)invocationExpression.TargetObject;
IReturnType targetType = field.TargetObject.AcceptVisitor(this, null) as IReturnType; IReturnType targetType = field.TargetObject.AcceptVisitor(this, null) as IReturnType;
List<IMethod> methods = resolver.SearchMethod(targetType, field.FieldName); List<IMethod> methods = resolver.SearchMethod(targetType, field.FieldName);
@ -239,8 +249,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// collection(index) - use indexer // collection(index) - use indexer
// collection.Item(index) - use parametrized property // collection.Item(index) - use parametrized property
if (invocationExpression.TargetObject is IdentifierExpression || invocationExpression.TargetObject is FieldReferenceExpression) { if (invocationExpression.TargetObject is IdentifierExpression || invocationExpression.TargetObject is MemberReferenceExpression) {
// only IdentifierExpression/FieldReferenceExpression can represent a parametrized property // only IdentifierExpression/MemberReferenceExpression can represent a parametrized property
// - the check is necessary because collection.Items and collection.Item(index) both // - 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 // resolve to the same property, but we want to use the default indexer for the second call in
// collection.Item(index1)(index2) // collection.Item(index1)(index2)
@ -281,26 +291,26 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return MemberLookupHelper.FindOverload(indexers.ToArray(), parameters); 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; return null;
} }
// int. generates a FieldreferenceExpression with TargetObject TypeReferenceExpression and no FieldName // int. generates a FieldreferenceExpression with TargetObject TypeReferenceExpression and no FieldName
if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName == "") { if (memberReferenceExpression.FieldName == null || memberReferenceExpression.FieldName == "") {
if (fieldReferenceExpression.TargetObject is TypeReferenceExpression) { if (memberReferenceExpression.TargetObject is TypeReferenceExpression) {
return CreateReturnType(((TypeReferenceExpression)fieldReferenceExpression.TargetObject).TypeReference); 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 != null) {
if (returnType is NamespaceReturnType) { if (returnType is NamespaceReturnType) {
string name = returnType.FullyQualifiedName; string name = returnType.FullyQualifiedName;
string combinedName; string combinedName;
if (name.Length == 0) if (name.Length == 0)
combinedName = fieldReferenceExpression.FieldName; combinedName = memberReferenceExpression.FieldName;
else else
combinedName = name + "." + fieldReferenceExpression.FieldName; combinedName = name + "." + memberReferenceExpression.FieldName;
if (resolver.ProjectContent.NamespaceExists(combinedName)) { if (resolver.ProjectContent.NamespaceExists(combinedName)) {
return new NamespaceReturnType(combinedName); return new NamespaceReturnType(combinedName);
} }
@ -312,13 +322,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// go through the members of the modules // go through the members of the modules
foreach (object o in resolver.ProjectContent.GetNamespaceContents(name)) { foreach (object o in resolver.ProjectContent.GetNamespaceContents(name)) {
IMember member = o as IMember; 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 member.ReturnType;
} }
} }
return null; return null;
} }
return resolver.SearchMember(returnType, fieldReferenceExpression.FieldName); return resolver.SearchMember(returnType, memberReferenceExpression.FieldName);
} }
return null; return null;
} }
@ -485,8 +495,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
static string GetAnonymousTypeFieldName(Expression expr) static string GetAnonymousTypeFieldName(Expression expr)
{ {
if (expr is FieldReferenceExpression) { if (expr is MemberReferenceExpression) {
return ((FieldReferenceExpression)expr).FieldName; return ((MemberReferenceExpression)expr).FieldName;
} }
if (expr is AssignmentExpression) { if (expr is AssignmentExpression) {
expr = ((AssignmentExpression)expr).Left; // use left side if it is an IdentifierExpression 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
// insert code to remove the event handler // insert code to remove the event handler
IfElseStatement ies = (IfElseStatement)createdProperty.SetRegion.Block.Children[0]; IfElseStatement ies = (IfElseStatement)createdProperty.SetRegion.Block.Children[0];
ies.TrueStatement[0].AddChild(new RemoveHandlerStatement( ies.TrueStatement[0].AddChild(new RemoveHandlerStatement(
new FieldReferenceExpression(backingFieldNameExpression, eventName), new MemberReferenceExpression(backingFieldNameExpression, eventName),
new AddressOfExpression(new IdentifierExpression(m.Name)))); new AddressOfExpression(new IdentifierExpression(m.Name))));
// insert code to add the event handler // insert code to add the event handler
ies = (IfElseStatement)createdProperty.SetRegion.Block.Children[2]; ies = (IfElseStatement)createdProperty.SetRegion.Block.Children[2];
ies.TrueStatement[0].AddChild(new AddHandlerStatement( ies.TrueStatement[0].AddChild(new AddHandlerStatement(
new FieldReferenceExpression(backingFieldNameExpression, eventName), new MemberReferenceExpression(backingFieldNameExpression, eventName),
new AddressOfExpression(new IdentifierExpression(m.Name)))); new AddressOfExpression(new IdentifierExpression(m.Name))));
} }
} }
@ -347,20 +347,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return null; 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) if (resolver.CompilationUnit == null)
return null; return null;
ResolveResult rr = Resolve(fieldReferenceExpression); ResolveResult rr = Resolve(memberReferenceExpression);
string ident = GetIdentifierFromResult(rr); string ident = GetIdentifierFromResult(rr);
if (ident != null) { if (ident != null) {
fieldReferenceExpression.FieldName = ident; memberReferenceExpression.FieldName = ident;
} }
if (ReplaceWithInvocation(fieldReferenceExpression, rr)) {} if (ReplaceWithInvocation(memberReferenceExpression, rr)) {}
else if (FullyQualifyModuleMemberReference(fieldReferenceExpression, rr)) {} else if (FullyQualifyModuleMemberReference(memberReferenceExpression, rr)) {}
return rr; return rr;
} }
@ -416,7 +416,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (resolver.CallingClass.IsTypeInInheritanceTree(containingType.GetUnderlyingClass())) if (resolver.CallingClass.IsTypeInInheritanceTree(containingType.GetUnderlyingClass()))
return false; return false;
} }
ReplaceCurrentNode(new FieldReferenceExpression( ReplaceCurrentNode(new MemberReferenceExpression(
new TypeReferenceExpression(ConvertType(containingType)), new TypeReferenceExpression(ConvertType(containingType)),
ident.Identifier ident.Identifier
)); ));
@ -428,15 +428,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return Refactoring.CodeGenerator.ConvertType(type, CreateContext()); return Refactoring.CodeGenerator.ConvertType(type, CreateContext());
} }
bool FullyQualifyModuleMemberReference(FieldReferenceExpression fre, ResolveResult rr) bool FullyQualifyModuleMemberReference(MemberReferenceExpression mre, ResolveResult rr)
{ {
IReturnType containingType = GetContainingTypeOfStaticMember(rr); IReturnType containingType = GetContainingTypeOfStaticMember(rr);
if (containingType == null) if (containingType == null)
return false; return false;
ResolveResult targetRR = resolver.ResolveInternal(fre.TargetObject, ExpressionContext.Default); ResolveResult targetRR = resolver.ResolveInternal(mre.TargetObject, ExpressionContext.Default);
if (targetRR is NamespaceResolveResult) { if (targetRR is NamespaceResolveResult) {
fre.TargetObject = new TypeReferenceExpression(ConvertType(containingType)); mre.TargetObject = new TypeReferenceExpression(ConvertType(containingType));
return true; return true;
} }
return false; return false;
@ -474,7 +474,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (p != null && invocationExpression.Arguments.Count > 0) { if (p != null && invocationExpression.Arguments.Count > 0) {
// col(i) -> col[i] or col.Items(i) -> col[i] ? // col(i) -> col[i] or col.Items(i) -> col[i] ?
Expression targetObject = invocationExpression.TargetObject; Expression targetObject = invocationExpression.TargetObject;
FieldReferenceExpression targetObjectFre = targetObject as FieldReferenceExpression; MemberReferenceExpression targetObjectFre = targetObject as MemberReferenceExpression;
if (p.IsIndexer && targetObjectFre != null) { if (p.IsIndexer && targetObjectFre != null) {
MemberResolveResult rr2 = Resolve(targetObjectFre) as MemberResolveResult; MemberResolveResult rr2 = Resolve(targetObjectFre) as MemberResolveResult;
if (rr2 != null && rr2.ResolvedMember == rr.ResolvedMember) { if (rr2 != null && rr2.ResolvedMember == rr.ResolvedMember) {
@ -569,7 +569,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (e == null) if (e == null)
e = new IdentifierExpression(n); e = new IdentifierExpression(n);
else else
e = new FieldReferenceExpression(e, n); e = new MemberReferenceExpression(e, n);
} }
return e; return e;
} }

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

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

Loading…
Cancel
Save