Browse Source

Fixed SD2-504: Explicit implementations of generic interfaces cause parser error

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@690 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
d9df3a65dd
  1. 15
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs
  2. 3
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 35
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  4. 94
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  5. 22
      src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/TypeLevel/IndexerDeclaration.cs
  6. 33
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/EventDeclaration.cs
  7. 35
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/InterfaceImplementation.cs
  8. 10
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/MethodDeclaration.cs
  9. 8
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/PropertyDeclaration.cs
  10. 22
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs
  11. 2351
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  12. 124
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  13. 1903
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  14. 46
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  15. 5
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs
  16. 38
      src/Libraries/NRefactory/Test/Parser/TypeLevel/EventDeclarationTests.cs
  17. 29
      src/Libraries/NRefactory/Test/Parser/TypeLevel/IndexerDeclarationTests.cs
  18. 40
      src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs
  19. 25
      src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs
  20. 16
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  21. 8
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  22. 5
      src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs

15
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs

@ -72,7 +72,7 @@ namespace NRefactoryToBooConverter @@ -72,7 +72,7 @@ namespace NRefactoryToBooConverter
// TODO: Convert handles clauses to [Handles] attribute
AddError(methodDeclaration, "Handles-clause is not supported.");
}
if (methodDeclaration.ImplementsClause.Count > 0) {
if (methodDeclaration.InterfaceImplementations.Count > 0) {
AddError(methodDeclaration, "Explicit interface implementation is not supported.");
}
if (methodDeclaration.Templates.Count > 0) {
@ -168,7 +168,7 @@ namespace NRefactoryToBooConverter @@ -168,7 +168,7 @@ namespace NRefactoryToBooConverter
ConvertParameters(propertyDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetLocation(propertyDeclaration.EndLocation);
m.Type = ConvertTypeReference(propertyDeclaration.TypeReference);
if (propertyDeclaration.ImplementsClause.Count > 0) {
if (propertyDeclaration.InterfaceImplementations.Count > 0) {
AddError(propertyDeclaration, "Explicit interface implementation is not supported.");
}
if (!propertyDeclaration.IsWriteOnly) {
@ -238,25 +238,18 @@ namespace NRefactoryToBooConverter @@ -238,25 +238,18 @@ namespace NRefactoryToBooConverter
public object Visit(EventDeclaration eventDeclaration, object data)
{
B.Event m = new B.Event(GetLexicalInfo(eventDeclaration));
if (eventDeclaration.Name == null || eventDeclaration.Name.Length == 0) {
m.Name = eventDeclaration.VariableDeclarators[0].Name;
} else {
m.Name = eventDeclaration.Name;
}
m.Name = eventDeclaration.Name;
m.Modifiers = ConvertModifier(eventDeclaration, B.TypeMemberModifiers.Private);
ConvertAttributes(eventDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
m.EndSourceLocation = GetLocation(eventDeclaration.EndLocation);
m.Type = ConvertTypeReference(eventDeclaration.TypeReference);
if (eventDeclaration.ImplementsClause.Count > 0) {
if (eventDeclaration.InterfaceImplementations.Count > 0) {
AddError(eventDeclaration, "Explicit interface implementation is not supported.");
}
if (eventDeclaration.Parameters.Count > 0) {
AddError(eventDeclaration, "Events with parameters are not supported.");
}
if (eventDeclaration.VariableDeclarators.Count > 1) {
AddError(eventDeclaration, "You can only define one event per line.");
}
if (eventDeclaration.HasAddRegion) {
m.Add = new B.Method(GetLexicalInfo(eventDeclaration.AddRegion));
ConvertAttributes(eventDeclaration.AddRegion.Attributes, m.Add.Attributes);

3
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -193,6 +193,7 @@ @@ -193,6 +193,7 @@
<Compile Include="Src\Parser\AST\General\TypeLevel\OperatorDeclaration.cs" />
<Compile Include="Src\Output\CodeDOM\CodeDOMVerboseOutputGenerator.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\DefaultValueExpression.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\InterfaceImplementation.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" />
@ -207,4 +208,4 @@ @@ -207,4 +208,4 @@
<Folder Include="Src\Parser\AST\VBNet\Tests\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>
</Project>

35
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -485,6 +485,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -485,6 +485,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
OutputModifier(propertyDeclaration.Modifier);
nodeTracker.TrackedVisit(propertyDeclaration.TypeReference, data);
outputFormatter.Space();
if (propertyDeclaration.InterfaceImplementations.Count > 0) {
nodeTracker.TrackedVisit(propertyDeclaration.InterfaceImplementations[0].InterfaceType, data);
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintIdentifier(propertyDeclaration.Name);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
@ -527,21 +531,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -527,21 +531,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data);
outputFormatter.Space();
if (eventDeclaration.VariableDeclarators != null && eventDeclaration.VariableDeclarators.Count > 0) {
AppendCommaSeparatedList(eventDeclaration.VariableDeclarators);
if (eventDeclaration.InterfaceImplementations.Count > 0) {
nodeTracker.TrackedVisit(eventDeclaration.InterfaceImplementations[0].InterfaceType, data);
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintIdentifier(eventDeclaration.Name);
if (eventDeclaration.AddRegion.IsNull && eventDeclaration.RemoveRegion.IsNull) {
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
} else {
outputFormatter.PrintIdentifier(eventDeclaration.Name);
if (eventDeclaration.AddRegion.IsNull && eventDeclaration.RemoveRegion.IsNull) {
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
} else {
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle);
nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data);
nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data);
outputFormatter.EndBrace();
}
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle);
nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data);
nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data);
outputFormatter.EndBrace();
}
return null;
}
@ -587,6 +590,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -587,6 +590,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
OutputModifier(methodDeclaration.Modifier);
nodeTracker.TrackedVisit(methodDeclaration.TypeReference, data);
outputFormatter.Space();
if (methodDeclaration.InterfaceImplementations.Count > 0) {
nodeTracker.TrackedVisit(methodDeclaration.InterfaceImplementations[0].InterfaceType, data);
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintIdentifier(methodDeclaration.Name);
PrintTemplates(methodDeclaration.Templates);
if (prettyPrintOptions.BeforeMethodDeclarationParentheses) {
@ -649,8 +656,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -649,8 +656,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
OutputModifier(indexerDeclaration.Modifier);
nodeTracker.TrackedVisit(indexerDeclaration.TypeReference, data);
outputFormatter.Space();
if (indexerDeclaration.NamespaceName != null && indexerDeclaration.NamespaceName.Length > 0) {
outputFormatter.PrintIdentifier(indexerDeclaration.NamespaceName);
if (indexerDeclaration.InterfaceImplementations.Count > 0) {
nodeTracker.TrackedVisit(indexerDeclaration.InterfaceImplementations[0].InterfaceType, data);
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintToken(Tokens.This);

94
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -566,70 +566,46 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -566,70 +566,46 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TypeReference currentEventType = null;
public object Visit(EventDeclaration eventDeclaration, object data)
{
if (eventDeclaration.VariableDeclarators.Count > 0) {
foreach (VariableDeclaration var in eventDeclaration.VariableDeclarators) {
VisitAttributes(eventDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(eventDeclaration.Modifier);
outputFormatter.PrintToken(Tokens.Event);
outputFormatter.Space();
outputFormatter.PrintIdentifier(var.Name);
if (eventDeclaration.Parameters.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
this.AppendCommaSeparatedList(eventDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data);
outputFormatter.NewLine();
}
} else {
bool customEvent = eventDeclaration.HasAddRegion || eventDeclaration.HasRemoveRegion;
VisitAttributes(eventDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(eventDeclaration.Modifier);
if (customEvent) {
outputFormatter.PrintText("Custom");
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.Event);
bool customEvent = eventDeclaration.HasAddRegion || eventDeclaration.HasRemoveRegion;
VisitAttributes(eventDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(eventDeclaration.Modifier);
if (customEvent) {
outputFormatter.PrintText("Custom");
outputFormatter.Space();
outputFormatter.PrintIdentifier(eventDeclaration.Name);
}
outputFormatter.PrintToken(Tokens.Event);
outputFormatter.Space();
outputFormatter.PrintIdentifier(eventDeclaration.Name);
if (eventDeclaration.Parameters.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
this.AppendCommaSeparatedList(eventDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data);
outputFormatter.NewLine();
if (customEvent) {
++outputFormatter.IndentationLevel;
currentEventType = eventDeclaration.TypeReference;
exitTokenStack.Push(Tokens.Sub);
nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data);
nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data);
exitTokenStack.Pop();
--outputFormatter.IndentationLevel;
if (eventDeclaration.Parameters.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
this.AppendCommaSeparatedList(eventDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data);
outputFormatter.PrintToken(Tokens.Event);
outputFormatter.NewLine();
if (customEvent) {
++outputFormatter.IndentationLevel;
currentEventType = eventDeclaration.TypeReference;
exitTokenStack.Push(Tokens.Sub);
nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data);
nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data);
exitTokenStack.Pop();
--outputFormatter.IndentationLevel;
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Event);
outputFormatter.NewLine();
}
}
return null;
}

22
src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/TypeLevel/IndexerDeclaration.cs

@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
public class IndexerDeclaration : AttributedNode
{
TypeReference type = TypeReference.Null;
string namespaceName = String.Empty;
List<InterfaceImplementation> interfaceImplementations = new List<InterfaceImplementation>(1);
Point bodyStart = new Point(-1, -1);
Point bodyEnd = new Point(-1, -1);
@ -84,15 +84,6 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -84,15 +84,6 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public string NamespaceName {
get {
return namespaceName;
}
set {
namespaceName = value == null ? String.Empty : value;
}
}
public Point BodyStart {
get {
return bodyStart;
@ -111,6 +102,15 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -111,6 +102,15 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public List<InterfaceImplementation> InterfaceImplementations {
get {
return interfaceImplementations;
}
set {
interfaceImplementations = value ?? new List<InterfaceImplementation>();
}
}
public IndexerDeclaration(Modifier modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes) : base(modifier, attributes)
{
this.Parameters = parameters;
@ -134,7 +134,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -134,7 +134,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
Modifier,
GetCollectionString(Parameters),
GetCollectionString(Attributes),
NamespaceName,
GetCollectionString(InterfaceImplementations),
BodyStart,
BodyEnd);
}

33
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/EventDeclaration.cs

@ -17,9 +17,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -17,9 +17,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
public class EventDeclaration : ParametrizedNode
{
TypeReference typeReference = TypeReference.Null;
List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>(1);
// ArrayList implementsClause = new ArrayList(); // VB only
ArrayList implementsClause = new ArrayList(); // VB only
List<InterfaceImplementation> interfaceImplementations = new List<InterfaceImplementation>(1);
EventAddRegion addRegion = EventAddRegion.Null;
EventRemoveRegion removeRegion = EventRemoveRegion.Null;
EventRaiseRegion raiseRegion = EventRaiseRegion.Null;
@ -34,14 +32,6 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -34,14 +32,6 @@ namespace ICSharpCode.NRefactory.Parser.AST
typeReference = TypeReference.CheckNull(value);
}
}
public List<VariableDeclaration> VariableDeclarators {
get {
return variableDeclarators;
}
set {
variableDeclarators = value == null ? new List<VariableDeclaration>(1) : value;
}
}
public EventAddRegion AddRegion {
get {
@ -101,12 +91,12 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -101,12 +91,12 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public ArrayList ImplementsClause {
public List<InterfaceImplementation> InterfaceImplementations {
get {
return implementsClause;
return interfaceImplementations;
}
set {
implementsClause = value == null ? new ArrayList() : value;
interfaceImplementations = value ?? new List<InterfaceImplementation>();
}
}
@ -114,22 +104,16 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -114,22 +104,16 @@ namespace ICSharpCode.NRefactory.Parser.AST
{
}
public EventDeclaration(TypeReference typeReference, List<VariableDeclaration> variableDeclarators, Modifier modifier, List<AttributeSection> attributes) : base(modifier, attributes)
{
this.TypeReference = typeReference;
this.VariableDeclarators = variableDeclarators;
}
public EventDeclaration(TypeReference typeReference, string name, Modifier modifier, List<AttributeSection> attributes) : base(modifier, attributes, name)
{
this.TypeReference = typeReference;
}
// for VB:
public EventDeclaration(TypeReference typeReference, Modifier modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes, string name, ArrayList implementsClause) : base(modifier, attributes, name, parameters)
public EventDeclaration(TypeReference typeReference, Modifier modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes, string name, List<InterfaceImplementation> interfaceImplementations) : base(modifier, attributes, name, parameters)
{
this.TypeReference = typeReference;
this.ImplementsClause = implementsClause;
this.TypeReference = typeReference;
this.InterfaceImplementations = interfaceImplementations;
}
public override object AcceptVisitor(IASTVisitor visitor, object data)
@ -138,9 +122,8 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -138,9 +122,8 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
public override string ToString()
{
return String.Format("[EventDeclaration: TypeReference={0}, VariableDeclarators={1}, Modifier={2}, Attributes={3}, Name={4}, BodyStart={5}, BodyEnd={6}]",
return String.Format("[EventDeclaration: TypeReference={0}, Modifier={1}, Attributes={2}, Name={3}, BodyStart={4}, BodyEnd={5}]",
TypeReference,
GetCollectionString(VariableDeclarators),
Modifier,
GetCollectionString(Attributes),
Name,

35
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/InterfaceImplementation.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 05.11.2005
* Time: 20:57
*/
using System;
namespace ICSharpCode.NRefactory.Parser.AST
{
public class InterfaceImplementation
{
TypeReference interfaceType;
string memberName;
public TypeReference InterfaceType {
get {
return interfaceType;
}
}
public string MemberName {
get {
return memberName;
}
}
public InterfaceImplementation(TypeReference interfaceType, string memberName)
{
this.interfaceType = interfaceType ?? TypeReference.Null;
this.memberName = memberName ?? "?";
}
}
}

10
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/MethodDeclaration.cs

@ -18,9 +18,9 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -18,9 +18,9 @@ namespace ICSharpCode.NRefactory.Parser.AST
TypeReference typeReference = TypeReference.Null;
BlockStatement body = BlockStatement.Null;
ArrayList handlesClause = new ArrayList(); // VB only
ArrayList implementsClause = new ArrayList(); // VB only
List<InterfaceImplementation> interfaceImplementations = new List<InterfaceImplementation>(1);
AttributeSection returnTypeAttributeSection = AttributeSection.Null;
List<TemplateDefinition> templates = new List<TemplateDefinition>();
List<TemplateDefinition> templates = new List<TemplateDefinition>(1);
public List<TemplateDefinition> Templates {
get {
@ -67,12 +67,12 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -67,12 +67,12 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public ArrayList ImplementsClause {
public List<InterfaceImplementation> InterfaceImplementations {
get {
return implementsClause;
return interfaceImplementations;
}
set {
implementsClause = value == null ? new ArrayList() : value;
interfaceImplementations = value ?? new List<InterfaceImplementation>();
}
}

8
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/PropertyDeclaration.cs

@ -18,7 +18,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -18,7 +18,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
TypeReference typeReference = TypeReference.Null;
Point bodyStart = new Point(-1, -1);
Point bodyEnd = new Point(-1, -1);
ArrayList implementsClause = new ArrayList(); // VB only
List<InterfaceImplementation> interfaceImplementations = new List<InterfaceImplementation>();
PropertyGetRegion propertyGetRegion = PropertyGetRegion.Null;
PropertySetRegion propertySetRegion = PropertySetRegion.Null;
@ -100,12 +100,12 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -100,12 +100,12 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public ArrayList ImplementsClause {
public List<InterfaceImplementation> InterfaceImplementations {
get {
return implementsClause;
return interfaceImplementations;
}
set {
implementsClause = value == null ? new ArrayList() : value;
interfaceImplementations = value ?? new List<InterfaceImplementation>();
}
}

22
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs

@ -117,6 +117,28 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -117,6 +117,28 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
/// <summary>
/// Removes the last identifier from the type.
/// e.g. "System.String.Length" becomes "System.String" or
/// "System.Collections.IEnumerable(of string).Current" becomes "System.Collections.IEnumerable(of string)"
/// This is used for explicit interface implementation in VB.
/// </summary>
public static string StripLastIdentifierFromType(ref TypeReference tr)
{
if (tr is InnerClassTypeReference && ((InnerClassTypeReference)tr).Type.IndexOf('.') < 0) {
string ident = ((InnerClassTypeReference)tr).Type;
tr = ((InnerClassTypeReference)tr).BaseType;
return ident;
} else {
int pos = tr.Type.LastIndexOf('.');
if (pos < 0)
return tr.Type;
string ident = tr.Type.Substring(pos + 1);
tr.Type = tr.Type.Substring(0, pos);
return ident;
}
}
public string SystemType {
get {
return systemType;

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

File diff suppressed because it is too large Load Diff

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

@ -377,6 +377,20 @@ bool IsGenericFollowedBy(int token) @@ -377,6 +377,20 @@ bool IsGenericFollowedBy(int token)
return SkipGeneric(ref t) && t.kind == token;
}
bool IsExplicitInterfaceImplementation()
{
StartPeek();
Token pt = la;
pt = Peek();
if (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon)
return true;
if (pt.kind == Tokens.LessThan) {
if (SkipGeneric(ref pt))
return pt.kind == Tokens.Dot;
}
return false;
}
/* True, if lookahead ident is "where" */
bool IdentIsWhere () {
return la.kind == Tokens.Identifier && la.val == "where";
@ -1166,6 +1180,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1166,6 +1180,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
Statement stmt = null;
List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
List<TemplateDefinition> templates = new List<TemplateDefinition>();
TypeReference explicitInterface = null;
.)
=
/*--- constant declaration: */ (. m.Check(Modifier.Constants); .)
@ -1185,22 +1200,31 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1185,22 +1200,31 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
/*--- void method (procedure) declaration: */
| IF (NotVoidPointer()) (. m.Check(Modifier.PropertysEventsMethods); .)
"void" (. Point startPos = t.Location; .)
Qualident<out qualident>
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
} .)
| ident (. qualident = t.val; .)
)
/* .NET 2.0 */
[ TypeParameterList<templates> ]
"("
[ FormalParameterList<p> ] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
m.Modifier,
new TypeReference("void"),
p,
attributes);
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.Templates = templates;
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
.)
[ FormalParameterList<p> ] ")"
(. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
m.Modifier,
new TypeReference("void"),
p,
attributes);
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.Templates = templates;
if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
.)
/* .NET 2.0 */
{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
@ -1209,27 +1233,32 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1209,27 +1233,32 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.Body = (BlockStatement)stmt;
.)
| /*--- event declaration: */ (. m.Check(Modifier.PropertysEventsMethods); .)
"event" (. EventDeclaration eventDecl = new EventDeclaration(m.Modifier, attributes);
eventDecl.StartLocation = t.Location;
compilationUnit.AddChild(eventDecl);
compilationUnit.BlockStart(eventDecl);
EventAddRegion addBlock = null;
EventRemoveRegion removeBlock = null;
.)
Type<out type> (. eventDecl.TypeReference = type; .)
(
IF (IsVarDecl()) VariableDeclarator<variableDeclarators>
{ "," VariableDeclarator<variableDeclarators> } ";" (. eventDecl.VariableDeclarators = variableDeclarators; eventDecl.EndLocation = t.EndLocation; .)
| Qualident<out qualident> (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .)
"{" (. eventDecl.BodyStart = t.Location; .)
EventAccessorDecls<out addBlock, out removeBlock>
"}" (. eventDecl.BodyEnd = t.EndLocation; .)
) (. compilationUnit.BlockEnd();
eventDecl.AddRegion = addBlock;
eventDecl.RemoveRegion = removeBlock;
.)
| /*--- event declaration: */ (. m.Check(Modifier.PropertysEventsMethods); .)
"event" (. EventDeclaration eventDecl = new EventDeclaration(m.Modifier, attributes);
eventDecl.StartLocation = t.Location;
compilationUnit.AddChild(eventDecl);
compilationUnit.BlockStart(eventDecl);
EventAddRegion addBlock = null;
EventRemoveRegion removeBlock = null;
.)
Type<out type> (. eventDecl.TypeReference = type; .)
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .)
(. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .)
| ident (. qualident = t.val; .)
)
(. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .)
[ "{" (. eventDecl.BodyStart = t.Location; .)
EventAccessorDecls<out addBlock, out removeBlock>
"}" (. eventDecl.BodyEnd = t.EndLocation; .)
]
[ ";" ]
(. compilationUnit.BlockEnd();
eventDecl.AddRegion = addBlock;
eventDecl.RemoveRegion = removeBlock;
.)
/*--- constructor or static contructor declaration: */
| IF (IdentAndLPar()) (. m.Check(Modifier.Constructors | Modifier.StaticConstructors); .)
@ -1312,10 +1341,10 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1312,10 +1341,10 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
.)
/*--- field declaration: */
| IF (IsVarDecl()) (. m.Check(Modifier.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
| IF (IsVarDecl()) (. m.Check(Modifier.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
VariableDeclarator<variableDeclarators>
{ "," VariableDeclarator<variableDeclarators> }
";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .)
@ -1336,7 +1365,16 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1336,7 +1365,16 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
indexer.SetRegion = setRegion;
compilationUnit.AddChild(indexer);
.)
| Qualident<out qualident> (. Point qualIdentEndLocation = t.EndLocation; .)
| IF (la.kind == Tokens.Identifier)
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
} .)
| ident (. qualident = t.val; .)
)
(. Point qualIdentEndLocation = t.EndLocation; .)
(
/*--- "not void" method (function) declaration: */
( (. m.Check(Modifier.PropertysEventsMethods); .)
@ -1348,6 +1386,8 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1348,6 +1386,8 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
type,
p,
attributes);
if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.Templates = templates;
@ -1358,6 +1398,8 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1358,6 +1398,8 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
/*--- property declaration: */
| "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes);
if (explicitInterface != null)
pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
pDecl.EndLocation = qualIdentEndLocation;
pDecl.BodyStart = t.Location;
@ -1379,7 +1421,8 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1379,7 +1421,8 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
indexer.StartLocation = m.GetDeclarationLocation(startPos);
indexer.EndLocation = t.EndLocation;
indexer.NamespaceName = qualident;
if (explicitInterface != null)
indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this"));
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
@ -2375,7 +2418,8 @@ TypeName<out TypeReference typeRef, bool canBeUnbound> @@ -2375,7 +2418,8 @@ TypeName<out TypeReference typeRef, bool canBeUnbound>
typeRef = new TypeReference(alias + "." + qualident, typeArguments);
}
.)
{ "." (. typeArguments = null; .)
{ IF (DotAndIdent())
"." (. typeArguments = null; .)
Qualident<out qualident>
[TypeArgumentList<out typeArguments, canBeUnbound>]
(. typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); .)

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

File diff suppressed because it is too large Load Diff

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

@ -957,7 +957,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -957,7 +957,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
(
(.
string name = String.Empty;
MethodDeclaration methodDeclaration; ArrayList handlesClause = null; ArrayList implementsClause = null;
MethodDeclaration methodDeclaration; ArrayList handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier
(.
@ -986,7 +987,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -986,7 +987,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.Templates = templates;
methodDeclaration.HandlesClause = handlesClause;
methodDeclaration.ImplementsClause = implementsClause;
methodDeclaration.InterfaceImplementations = implementsClause;
compilationUnit.AddChild(methodDeclaration);
.)
@ -999,7 +1000,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -999,7 +1000,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.Templates = templates;
methodDeclaration.HandlesClause = handlesClause;
methodDeclaration.ImplementsClause = implementsClause;
methodDeclaration.InterfaceImplementations = implementsClause;
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
@ -1034,7 +1035,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1034,7 +1035,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
m.Check(Modifier.VBMethods);
string name = String.Empty;
Point startPos = t.Location;
MethodDeclaration methodDeclaration;ArrayList handlesClause = null;ArrayList implementsClause = null;
MethodDeclaration methodDeclaration;ArrayList handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
AttributeSection returnTypeAttributeSection = null;
.)
Identifier (. name = t.val; .)
@ -1064,7 +1066,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1064,7 +1066,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.HandlesClause = handlesClause;
methodDeclaration.Templates = templates;
methodDeclaration.ImplementsClause = implementsClause;
methodDeclaration.InterfaceImplementations = implementsClause;
methodDeclaration.ReturnTypeAttributeSection = returnTypeAttributeSection;
compilationUnit.AddChild(methodDeclaration);
.)
@ -1076,7 +1078,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1076,7 +1078,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.Templates = templates;
methodDeclaration.HandlesClause = handlesClause;
methodDeclaration.ImplementsClause = implementsClause;
methodDeclaration.InterfaceImplementations = implementsClause;
methodDeclaration.ReturnTypeAttributeSection = returnTypeAttributeSection;
compilationUnit.AddChild(methodDeclaration);
@ -1141,7 +1143,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1141,7 +1143,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
m.Check(Modifier.VBEvents);
Point startPos = t.Location;
EventDeclaration eventDeclaration;
string name = String.Empty;ArrayList implementsClause = null;
string name = String.Empty;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. name= t.val; .)
(
@ -1196,7 +1199,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1196,7 +1199,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
(.
m.Check(Modifier.VBProperties);
Point startPos = t.Location;
ArrayList implementsClause = null;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. string propertyName = t.val; .)
[ "(" [ FormalParameterList<p> ] ")" ]
@ -1216,7 +1219,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1216,7 +1219,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
pDecl.EndLocation = t.Location;
pDecl.TypeReference = type;
pDecl.ImplementsClause = implementsClause;
pDecl.InterfaceImplementations = implementsClause;
pDecl.Parameters = p;
compilationUnit.AddChild(pDecl);
.)
@ -1227,7 +1230,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1227,7 +1230,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
pDecl.EndLocation = t.Location;
pDecl.BodyStart = t.Location;
pDecl.TypeReference = type;
pDecl.ImplementsClause = implementsClause;
pDecl.InterfaceImplementations = implementsClause;
pDecl.Parameters = p;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
@ -1250,7 +1253,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1250,7 +1253,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
EventAddRegion addHandlerAccessorDeclaration = null;
EventRemoveRegion removeHandlerAccessorDeclaration = null;
EventRaiseRegion raiseEventAccessorDeclaration = null;
ArrayList implementsClause = null;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. string customEventName = t.val; .)
"As" TypeName<out type>
@ -1658,15 +1661,22 @@ TypeImplementsClause<out List<TypeReference> baseInterfaces> @@ -1658,15 +1661,22 @@ TypeImplementsClause<out List<TypeReference> baseInterfaces>
.
/* 9.1 */
ImplementsClause<out ArrayList baseInterfaces>
ImplementsClause<out List<InterfaceImplementation> baseInterfaces>
(.
baseInterfaces = new ArrayList();
string typename = String.Empty;
string first;
baseInterfaces = new List<InterfaceImplementation>();
TypeReference type = null;
string memberName = null;
.) =
"Implements" Identifier (. first = t.val; .) "." Qualident<out typename> (. baseInterfaces.Add(first + "." + typename); .)
{ "," Identifier (. first = t.val; .) "." Qualident<out typename> (. baseInterfaces.Add(first + "." + typename); .) }
.
"Implements"
NonArrayTypeName<out type, false>
(. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
(. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
{ ","
NonArrayTypeName<out type, false>
(. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
(. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
}
.
EventMemberSpecifier<out string name>
(. string type; name = String.Empty; .) =

5
src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs

@ -240,7 +240,6 @@ namespace ICSharpCode.NRefactory.Parser @@ -240,7 +240,6 @@ namespace ICSharpCode.NRefactory.Parser
Debug.Assert(eventDeclaration.Attributes != null);
Debug.Assert(eventDeclaration.TypeReference != null);
Debug.Assert(eventDeclaration.Parameters != null);
Debug.Assert(eventDeclaration.VariableDeclarators != null);
Debug.Assert(eventDeclaration.AddRegion != null);
Debug.Assert(eventDeclaration.RemoveRegion != null);
@ -253,10 +252,6 @@ namespace ICSharpCode.NRefactory.Parser @@ -253,10 +252,6 @@ namespace ICSharpCode.NRefactory.Parser
Debug.Assert(p != null);
p.AcceptVisitor(this, data);
}
foreach (VariableDeclaration v in eventDeclaration.VariableDeclarators) {
Debug.Assert(v != null);
v.AcceptVisitor(this, data);
}
eventDeclaration.AddRegion.AcceptVisitor(this, data);
eventDeclaration.RemoveRegion.AcceptVisitor(this, data);
return data;

38
src/Libraries/NRefactory/Test/Parser/TypeLevel/EventDeclarationTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -24,14 +24,44 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -24,14 +24,44 @@ namespace ICSharpCode.NRefactory.Tests.AST
public void CSharpSimpleEventDeclarationTest()
{
EventDeclaration ed = (EventDeclaration)ParseUtilCSharp.ParseTypeMember("event System.EventHandler MyEvent;", typeof(EventDeclaration));
Assert.AreEqual(1, ed.VariableDeclarators.Count);
Assert.AreEqual("MyEvent", ((VariableDeclaration)ed.VariableDeclarators[0]).Name);
Assert.AreEqual("MyEvent", ed.Name);
Assert.AreEqual("System.EventHandler", ed.TypeReference.Type);
Assert.IsFalse(ed.HasAddRegion);
Assert.IsFalse(ed.HasRemoveRegion);
}
[Test]
public void CSharpEventImplementingInterfaceDeclarationTest()
{
EventDeclaration ed = (EventDeclaration)ParseUtilCSharp.ParseTypeMember("event EventHandler MyInterface.MyEvent;", typeof(EventDeclaration));
Assert.AreEqual("MyEvent", ed.Name);
Assert.AreEqual("EventHandler", ed.TypeReference.Type);
Assert.IsFalse(ed.HasAddRegion);
Assert.IsFalse(ed.HasRemoveRegion);
Assert.AreEqual("MyInterface", ed.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("MyEvent", ed.InterfaceImplementations[0].MemberName);
}
[Test]
public void CSharpEventImplementingGenericInterfaceDeclarationTest()
{
EventDeclaration ed = (EventDeclaration)ParseUtilCSharp.ParseTypeMember("event EventHandler MyInterface<string>.MyEvent;", typeof(EventDeclaration));
Assert.AreEqual("MyEvent", ed.Name);
Assert.AreEqual("EventHandler", ed.TypeReference.Type);
Assert.IsFalse(ed.HasAddRegion);
Assert.IsFalse(ed.HasRemoveRegion);
Assert.AreEqual("MyInterface", ed.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", ed.InterfaceImplementations[0].InterfaceType.GenericTypes[0].SystemType);
Assert.AreEqual("MyEvent", ed.InterfaceImplementations[0].MemberName);
}
[Test]
public void CSharpAddRemoveEventDeclarationTest()
{
@ -54,6 +84,6 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -54,6 +84,6 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsFalse(ed.HasAddRegion);
Assert.IsFalse(ed.HasRemoveRegion);
}
#endregion
#endregion
}
}

29
src/Libraries/NRefactory/Test/Parser/TypeLevel/IndexerDeclarationTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -28,10 +28,33 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -28,10 +28,33 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsTrue(id.HasGetRegion, "No get region found!");
Assert.IsTrue(id.HasSetRegion, "No set region found!");
}
[Test]
public void CSharpIndexerImplementingInterfaceTest()
{
IndexerDeclaration id = (IndexerDeclaration)ParseUtilCSharp.ParseTypeMember("int MyInterface.this[int a, string b] { get { } set { } }", typeof(IndexerDeclaration));
Assert.AreEqual(2, id.Parameters.Count);
Assert.IsTrue(id.HasGetRegion, "No get region found!");
Assert.IsTrue(id.HasSetRegion, "No set region found!");
Assert.AreEqual("MyInterface", id.InterfaceImplementations[0].InterfaceType.Type);
}
[Test]
public void CSharpIndexerImplementingGenericInterfaceTest()
{
IndexerDeclaration id = (IndexerDeclaration)ParseUtilCSharp.ParseTypeMember("int MyInterface<string>.this[int a, string b] { get { } set { } }", typeof(IndexerDeclaration));
Assert.AreEqual(2, id.Parameters.Count);
Assert.IsTrue(id.HasGetRegion, "No get region found!");
Assert.IsTrue(id.HasSetRegion, "No set region found!");
Assert.AreEqual("MyInterface", id.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", id.InterfaceImplementations[0].InterfaceType.GenericTypes[0].SystemType);
}
#endregion
#region VB.NET
// no vb.net representation (indexers are properties named "item" in vb.net)
#endregion
// no vb.net representation (indexers are properties named "item" in vb.net)
#endregion
}
}

40
src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -151,6 +151,44 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -151,6 +151,44 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual(1, md.Templates[0].Bases.Count);
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
}
[Test]
public void CSharpMethodImplementingInterfaceTest()
{
MethodDeclaration md = (MethodDeclaration)ParseUtilCSharp.ParseTypeMember("int MyInterface.MyMethod() {} ", typeof(MethodDeclaration));
Assert.AreEqual("int", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
}
[Test]
public void CSharpMethodImplementingGenericInterfaceTest()
{
MethodDeclaration md = (MethodDeclaration)ParseUtilCSharp.ParseTypeMember("int MyInterface<string>.MyMethod() {} ", typeof(MethodDeclaration));
Assert.AreEqual("int", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", md.InterfaceImplementations[0].InterfaceType.GenericTypes[0].SystemType);
}
[Test]
public void CSharpVoidMethodImplementingInterfaceTest()
{
MethodDeclaration md = (MethodDeclaration)ParseUtilCSharp.ParseTypeMember("void MyInterface.MyMethod() {} ", typeof(MethodDeclaration));
Assert.AreEqual("void", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
}
[Test]
public void CSharpVoidMethodImplementingGenericInterfaceTest()
{
MethodDeclaration md = (MethodDeclaration)ParseUtilCSharp.ParseTypeMember("void MyInterface<string>.MyMethod() {} ", typeof(MethodDeclaration));
Assert.AreEqual("void", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", md.InterfaceImplementations[0].InterfaceType.GenericTypes[0].SystemType);
}
#endregion
#region VB.NET

25
src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -55,6 +55,29 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -55,6 +55,29 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsTrue(!pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
}
[Test]
public void CSharpPropertyImplementingInterfaceTest()
{
PropertyDeclaration pd = (PropertyDeclaration)ParseUtilCSharp.ParseTypeMember("int MyInterface.MyProperty { get {} } ", typeof(PropertyDeclaration));
Assert.AreEqual("MyProperty", pd.Name);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(!pd.HasSetRegion);
Assert.AreEqual("MyInterface", pd.InterfaceImplementations[0].InterfaceType.Type);
}
[Test]
public void CSharpPropertyImplementingGenericInterfaceTest()
{
PropertyDeclaration pd = (PropertyDeclaration)ParseUtilCSharp.ParseTypeMember("int MyInterface<string>.MyProperty { get {} } ", typeof(PropertyDeclaration));
Assert.AreEqual("MyProperty", pd.Name);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(!pd.HasSetRegion);
Assert.AreEqual("MyInterface", pd.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", pd.InterfaceImplementations[0].InterfaceType.GenericTypes[0].SystemType);
}
#endregion
#region VB.NET

16
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -540,19 +540,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -540,19 +540,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DomRegion bodyRegion = GetRegion(eventDeclaration.BodyStart, eventDeclaration.BodyEnd);
IReturnType type = CreateReturnType(eventDeclaration.TypeReference);
DefaultClass c = GetCurrentClass();
DefaultEvent e = null;
if (eventDeclaration.VariableDeclarators != null && eventDeclaration.VariableDeclarators.Count > 0) {
foreach (ICSharpCode.NRefactory.Parser.AST.VariableDeclaration varDecl in eventDeclaration.VariableDeclarators) {
e = new DefaultEvent(varDecl.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
ConvertAttributes(eventDeclaration, e);
c.Events.Add(e);
}
} else {
e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
ConvertAttributes(eventDeclaration, e);
c.Events.Add(e);
}
DefaultEvent e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
ConvertAttributes(eventDeclaration, e);
c.Events.Add(e);
if (e != null) {
e.Documentation = GetDocumentation(region.BeginLine);
} else {

8
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -383,6 +383,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -383,6 +383,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// <returns>The version number of the solution.</returns>
public static string ReadSolutionInformation(string solutionFileName, Converter.PrjxToSolutionProject.Conversion conversion)
{
LoggingService.Debug("ReadSolutionInformation: " + solutionFileName);
string solutionDirectory = Path.GetDirectoryName(solutionFileName);
using (StreamReader sr = File.OpenText(solutionFileName)) {
string line = GetFirstNonCommentLine(sr);
@ -398,9 +399,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -398,9 +399,10 @@ namespace ICSharpCode.SharpDevelop.Project
string title = match.Result("${Title}");
string location = Path.Combine(solutionDirectory, match.Result("${Location}"));
string guid = match.Result("${Guid}");
conversion.NameToGuid.Add(title, new Guid(guid));
conversion.NameToPath.Add(title, location);
conversion.GuidToPath.Add(new Guid(guid), location);
LoggingService.Debug(guid + ": " + title);
conversion.NameToGuid[title] = new Guid(guid);
conversion.NameToPath[title] = location;
conversion.GuidToPath[new Guid(guid)] = location;
}
}
return version;

5
src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs

@ -372,10 +372,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -372,10 +372,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (targetClassProperties.Find(delegate(IProperty tp) { return p.Name == tp.Name; }) == null) {
AttributedNode pd = ConvertMember(p, context);
if (explicitImpl) {
InterfaceImplementation impl = new InterfaceImplementation(ConvertType(interf, context), p.Name);
if (pd is IndexerDeclaration) {
((IndexerDeclaration)pd).NamespaceName = GetInterfaceName(interf, p, context);
((IndexerDeclaration)pd).InterfaceImplementations.Add(impl);
} else {
((PropertyDeclaration)pd).Name = GetInterfaceName(interf, p, context) + "." + ((PropertyDeclaration)pd).Name;
((PropertyDeclaration)pd).InterfaceImplementations.Add(impl);
}
pd.Modifier = Modifier.None;
} else {

Loading…
Cancel
Save