From 20199d196af9e7c65488f9eccc9abcf4d584fc81 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 7 Aug 2005 10:42:23 +0000 Subject: [PATCH] Fixed SD2-401: Using aliases for classes. Usings like "using StringCollection = System.Collections.Generic.List" are now valid and code completion works correctly for them. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@329 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Parser/ExpressionFinder.cs | 3 +- .../FormDesignerSecondaryDisplayBinding.cs | 23 +- .../Src/Output/CSharp/CSharpOutputVisitor.cs | 5 +- .../Src/Output/VBNet/VBNetOutputVisitor.cs | 6 +- .../General/GlobalScope/UsingDeclaration.cs | 28 +- .../Project/Src/Parser/CSharp/Parser.cs | 253 +++++++++--------- .../Project/Src/Parser/CSharp/cs.ATG | 10 +- .../Project/Src/Parser/VBNet/Parser.cs | 101 ++++--- .../Project/Src/Parser/VBNet/VBNET.ATG | 10 +- .../NRefactory/Test/NRefactoryTests.csproj | 2 +- .../GlobalScope/UsingDeclarationTests.cs | 44 +-- src/Main/Base/Project/Src/Dom/ClassFinder.cs | 2 +- src/Main/Base/Project/Src/Dom/IClass.cs | 8 +- src/Main/Base/Project/Src/Dom/IUsing.cs | 4 +- .../Src/Dom/Implementations/DefaultClass.cs | 35 ++- .../Src/Dom/Implementations/DefaultUsing.cs | 29 +- .../Implementations/SearchClassReturnType.cs | 3 +- .../Dom/Implementations/SpecificReturnType.cs | 9 +- .../NRefactoryASTConvertVisitor.cs | 13 +- .../NRefactoryResolver/NRefactoryResolver.cs | 26 +- .../Src/Dom/NRefactoryResolver/TypeVisitor.cs | 17 +- .../Pads/ClassBrowser/Nodes/BaseTypesNode.cs | 3 +- .../ParserService/DefaultProjectContent.cs | 39 ++- .../Services/ParserService/IProjectContent.cs | 4 +- .../RefactoringService/RefactoringService.cs | 2 +- .../AbstractClassImplementorCodeGenerator.cs | 72 ++--- .../InterfaceImplementorCodeGenerator.cs | 217 ++++++++------- 27 files changed, 499 insertions(+), 469 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs index b22722eec3..01be5542c5 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs @@ -69,7 +69,8 @@ namespace CSharpBinding.Parser genericPart = null; } ClassFinder finder = new ClassFinder(fileName, text, typeStart); - IClass c = finder.SearchClass(nonGenericClassName); + IReturnType t = finder.SearchType(nonGenericClassName); + IClass c = (t != null) ? t.GetUnderlyingClass() : null; if (c != null) { ExpressionContext context = ExpressionContext.TypeDerivingFrom(c, true); if (context.ShowEntry(c)) { diff --git a/src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerSecondaryDisplayBinding.cs b/src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerSecondaryDisplayBinding.cs index 6402c1ea42..0e52e8a36f 100644 --- a/src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerSecondaryDisplayBinding.cs +++ b/src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerSecondaryDisplayBinding.cs @@ -56,28 +56,11 @@ namespace ICSharpCode.FormDesigner return null; } - static Hashtable oldTypes = new Hashtable(); - public static bool BaseClassIsFormOrControl(IClass c) { - if (c == null || oldTypes.Contains(c.FullyQualifiedName)) { - oldTypes.Clear(); - return false; - } - oldTypes.Add(c.FullyQualifiedName, null); - - foreach (string baseType in c.BaseTypes) { - IClass type = ParserService.CurrentProjectContent.SearchType(baseType, c, c.Region != null ? c.Region.BeginLine : 0, c.Region != null ? c.Region.BeginColumn : 0); - string typeName = type != null ? type.FullyQualifiedName : baseType; - if (typeName == "System.Windows.Forms.Form" || - typeName == "System.Windows.Forms.UserControl" || - BaseClassIsFormOrControl(type)) { - oldTypes.Clear(); - return true; - } - } - oldTypes.Clear(); - return false; + IProjectContent pc = ProjectContentRegistry.GetExistingProjectContent(new AssemblyName("System.Windows.Forms")); + return c.IsTypeInInheritanceTree(pc.GetClass("System.Windows.Forms.Form")) || + c.IsTypeInInheritanceTree(pc.GetClass("System.Windows.Forms.UserControl")); } public bool CanAttachTo(IViewContent viewContent) diff --git a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs index b46e0e948b..9fbf414ee1 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs @@ -246,14 +246,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Using); outputFormatter.Space(); + outputFormatter.PrintIdentifier(u.Name); + if (u.IsAlias) { - outputFormatter.PrintIdentifier(u.Alias); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); + nodeTracker.TrackedVisit(u.Alias, data); } - outputFormatter.PrintIdentifier(u.Name); outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.NewLine(); return null; diff --git a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs index fabd2b57ef..a295cfa614 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs @@ -230,13 +230,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Imports); outputFormatter.Space(); for (int i = 0; i < usingDeclaration.Usings.Count; ++i) { + outputFormatter.PrintIdentifier(((Using)usingDeclaration.Usings[i]).Name); if (((Using)usingDeclaration.Usings[i]).IsAlias) { - outputFormatter.PrintIdentifier(((Using)usingDeclaration.Usings[i]).Alias); outputFormatter.Space(); - outputFormatter.PrintToken(Tokens.As); + outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); + nodeTracker.TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data); } - outputFormatter.PrintIdentifier(((Using)usingDeclaration.Usings[i]).Name); if (i + 1 < usingDeclaration.Usings.Count) { outputFormatter.PrintToken(Tokens.Comma); outputFormatter.Space(); diff --git a/src/Libraries/NRefactory/Project/Src/Parser/AST/General/GlobalScope/UsingDeclaration.cs b/src/Libraries/NRefactory/Project/Src/Parser/AST/General/GlobalScope/UsingDeclaration.cs index 6aa7f2d202..f0c314f7bb 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/AST/General/GlobalScope/UsingDeclaration.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/AST/General/GlobalScope/UsingDeclaration.cs @@ -7,14 +7,14 @@ using System; using System.Diagnostics; -using System.Collections; +using System.Collections.Generic; namespace ICSharpCode.NRefactory.Parser.AST { public class Using : AbstractNode { string name; - string alias; + TypeReference alias; public string Name { get { @@ -25,23 +25,22 @@ namespace ICSharpCode.NRefactory.Parser.AST } } - public string Alias { + public TypeReference Alias { get { return alias; } set { - alias = value == null ? String.Empty : value; + alias = TypeReference.CheckNull(value); } } public bool IsAlias { get { - Debug.Assert(alias != null); - return alias.Length > 0; + return !alias.IsNull; } } - public Using(string name, string alias) + public Using(string name, TypeReference alias) { this.Name = name; this.Alias = alias; @@ -66,15 +65,14 @@ namespace ICSharpCode.NRefactory.Parser.AST public class UsingDeclaration : AbstractNode { -// List namespaces; - ArrayList usings; + List usings; - public ArrayList Usings { + public List Usings { get { return usings; } set { - usings = value == null ? new ArrayList(1) : value; + usings = value == null ? new List(1) : value; } } @@ -82,14 +80,14 @@ namespace ICSharpCode.NRefactory.Parser.AST { } - public UsingDeclaration(string nameSpace, string alias) + public UsingDeclaration(string nameSpace, TypeReference alias) { Debug.Assert(nameSpace != null); - usings = new ArrayList(1); + usings = new List(1); usings.Add(new Using(nameSpace, alias)); } - public UsingDeclaration(ArrayList usings) + public UsingDeclaration(List usings) { this.Usings = usings; } @@ -101,7 +99,7 @@ namespace ICSharpCode.NRefactory.Parser.AST public override string ToString() { - return String.Format("[UsingDeclaration: Namespace={0}]", + return String.Format("[UsingDeclaration: Usings={0}]", GetCollectionString(usings)); } } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs index 2d4cb5b1ea..f419f787bb 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs @@ -453,31 +453,28 @@ IsGlobalAttrTarget()) { void UsingDirective() { #line 562 "cs.ATG" - string qualident = null, aliasident = null; + string qualident = null; TypeReference aliasedType = null; Expect(119); #line 565 "cs.ATG" Point startPos = t.Location; - if ( + Qualident( #line 566 "cs.ATG" -IsAssignment()) { +out qualident); + if (la.kind == 3) { lexer.NextToken(); - -#line 566 "cs.ATG" - aliasident = t.val; - Expect(3); - } - Qualident( + NonArrayType( #line 567 "cs.ATG" -out qualident); +out aliasedType); + } Expect(11); #line 569 "cs.ATG" if (qualident != null && qualident.Length > 0) { INode node; - if (aliasident != null) { - node = new UsingDeclaration(aliasident, qualident); + if (aliasedType != null) { + node = new UsingDeclaration(qualident, aliasedType); } else { node = new UsingDeclaration(qualident); } @@ -614,6 +611,46 @@ DotAndIdent()) { qualident = qualidentBuilder.ToString(); } + void NonArrayType( +#line 920 "cs.ATG" +out TypeReference type) { + +#line 922 "cs.ATG" + string name; + int pointer = 0; + type = null; + + if (la.kind == 1 || la.kind == 89 || la.kind == 106) { + ClassType( +#line 927 "cs.ATG" +out type); + } else if (StartOf(4)) { + SimpleType( +#line 928 "cs.ATG" +out name); + +#line 928 "cs.ATG" + type = new TypeReference(name); + } else if (la.kind == 121) { + lexer.NextToken(); + Expect(6); + +#line 929 "cs.ATG" + pointer = 1; type = new TypeReference("void"); + } else SynErr(126); + while ( +#line 932 "cs.ATG" +IsPointer()) { + Expect(6); + +#line 933 "cs.ATG" + ++pointer; + } + +#line 935 "cs.ATG" + if (type != null) { type.PointerNestingLevel = pointer; } + } + void Attribute( #line 601 "cs.ATG" out ASTAttribute attribute) { @@ -649,7 +686,7 @@ List positional, List named) { Expression expr; Expect(19); - if (StartOf(4)) { + if (StartOf(5)) { if ( #line 621 "cs.ATG" IsAssignment()) { @@ -684,11 +721,11 @@ IsAssignment()) { #line 633 "cs.ATG" name = t.val; Expect(3); - } else if (StartOf(4)) { + } else if (StartOf(5)) { #line 635 "cs.ATG" if (nameFound) Error("no positional argument after named argument"); - } else SynErr(126); + } else SynErr(127); Expr( #line 636 "cs.ATG" out expr); @@ -712,7 +749,7 @@ out Expression expr) { UnaryExpr( #line 1880 "cs.ATG" out expr); - if (StartOf(5)) { + if (StartOf(6)) { ConditionalOrExpr( #line 1883 "cs.ATG" ref expr); @@ -729,7 +766,7 @@ out expr2); #line 1883 "cs.ATG" expr = new ConditionalExpression(expr, expr1, expr2); } - } else if (StartOf(6)) { + } else if (StartOf(7)) { #line 1885 "cs.ATG" AssignmentOperatorType op; Expression val; @@ -742,7 +779,7 @@ out val); #line 1885 "cs.ATG" expr = new AssignmentExpression(expr, op, val); - } else SynErr(127); + } else SynErr(128); } void AttributeSection( @@ -889,7 +926,7 @@ Modifiers m) { if (t.val == "partial") { m.Add(Modifier.Partial, t.Location); } break; } - default: SynErr(128); break; + default: SynErr(129); break; } } @@ -952,7 +989,7 @@ templates); newType.EndLocation = t.Location; compilationUnit.BlockEnd(); - } else if (StartOf(7)) { + } else if (StartOf(8)) { #line 734 "cs.ATG" m.Check(Modifier.StructsInterfacesEnumsDelegates); @@ -1091,14 +1128,14 @@ NotVoidPointer()) { #line 798 "cs.ATG" delegateDeclr.ReturnType = new TypeReference("void", 0, null); - } else if (StartOf(8)) { + } else if (StartOf(9)) { Type( #line 799 "cs.ATG" out type); #line 799 "cs.ATG" delegateDeclr.ReturnType = type; - } else SynErr(129); + } else SynErr(130); Expect(1); #line 801 "cs.ATG" @@ -1109,7 +1146,7 @@ out type); templates); } Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { FormalParameterList( #line 806 "cs.ATG" p); @@ -1132,7 +1169,7 @@ templates); compilationUnit.AddChild(delegateDeclr); } - } else SynErr(130); + } else SynErr(131); } void TypeParameterList( @@ -1253,7 +1290,7 @@ out type); #line 838 "cs.ATG" AttributeSection section; Expect(15); - while (StartOf(10)) { + while (StartOf(11)) { #line 841 "cs.ATG" List attributes = new List(); @@ -1267,7 +1304,7 @@ out section); #line 844 "cs.ATG" attributes.Add(section); } - while (StartOf(11)) { + while (StartOf(12)) { MemberModifier( #line 845 "cs.ATG" m); @@ -1310,7 +1347,7 @@ out typeRef); #line 862 "cs.ATG" AttributeSection section; Expect(15); - while (StartOf(12)) { + while (StartOf(13)) { #line 865 "cs.ATG" List attributes = new List(); @@ -1324,7 +1361,7 @@ out section); #line 868 "cs.ATG" attributes.Add(section); } - while (StartOf(11)) { + while (StartOf(12)) { MemberModifier( #line 869 "cs.ATG" m); @@ -1364,7 +1401,7 @@ out typeRef); void InterfaceBody() { Expect(15); - while (StartOf(13)) { + while (StartOf(14)) { InterfaceMemberDecl(); } Expect(16); @@ -1440,7 +1477,7 @@ out string name) { name = "char"; break; } - default: SynErr(131); break; + default: SynErr(132); break; } } @@ -1487,7 +1524,7 @@ out TypeReference type) { ClassType( #line 903 "cs.ATG" out type); - } else if (StartOf(14)) { + } else if (StartOf(4)) { SimpleType( #line 904 "cs.ATG" out name); @@ -1500,7 +1537,7 @@ out name); #line 905 "cs.ATG" pointer = 1; type = new TypeReference("void"); - } else SynErr(132); + } else SynErr(133); #line 906 "cs.ATG" List r = new List(); @@ -1527,7 +1564,7 @@ IsPointerOrDims()) { #line 910 "cs.ATG" r.Add(i); - } else SynErr(133); + } else SynErr(134); } #line 913 "cs.ATG" @@ -1592,7 +1629,7 @@ out p); #line 968 "cs.ATG" paramsFound = true; p.Attributes = attributes; parameter.Add(p); - } else SynErr(134); + } else SynErr(135); } } else if (la.kind == 93) { ParameterArray( @@ -1601,7 +1638,7 @@ out p); #line 971 "cs.ATG" p.Attributes = attributes; parameter.Add(p); - } else SynErr(135); + } else SynErr(136); } void ClassType( @@ -1627,7 +1664,7 @@ out r); #line 1014 "cs.ATG" typeRef = new TypeReference("string"); - } else SynErr(136); + } else SynErr(137); } void TypeName( @@ -1771,7 +1808,7 @@ Modifiers m) { m.Add(Modifier.Volatile, t.Location); break; } - default: SynErr(137); break; + default: SynErr(138); break; } } @@ -1808,13 +1845,13 @@ m, attributes); out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(138); + } else SynErr(139); #line 1296 "cs.ATG" d.Body = (BlockStatement)stmt; compilationUnit.AddChild(d); - } else SynErr(139); + } else SynErr(140); } void StructMemberDecl( @@ -1895,7 +1932,7 @@ out qualident); templates); } Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { FormalParameterList( #line 1081 "cs.ATG" p); @@ -1927,7 +1964,7 @@ templates); out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(140); + } else SynErr(141); #line 1096 "cs.ATG" compilationUnit.BlockEnd(); @@ -1987,7 +2024,7 @@ out addBlock, out removeBlock); #line 1115 "cs.ATG" eventDecl.BodyEnd = t.EndLocation; - } else SynErr(141); + } else SynErr(142); #line 1116 "cs.ATG" compilationUnit.BlockEnd(); @@ -2006,7 +2043,7 @@ IdentAndLPar()) { #line 1124 "cs.ATG" string name = t.val; Point startPos = t.Location; Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { #line 1124 "cs.ATG" m.Check(Modifier.Constructors); @@ -2038,7 +2075,7 @@ out init); out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(142); + } else SynErr(143); #line 1136 "cs.ATG" cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); @@ -2089,7 +2126,7 @@ out stmt); #line 1148 "cs.ATG" stmt = null; - } else SynErr(143); + } else SynErr(144); #line 1151 "cs.ATG" List parameters = new List(); @@ -2109,7 +2146,7 @@ out stmt); TypeDecl( #line 1166 "cs.ATG" m, attributes); - } else if (StartOf(8)) { + } else if (StartOf(9)) { Type( #line 1167 "cs.ATG" out type); @@ -2148,7 +2185,7 @@ out secondType); #line 1175 "cs.ATG" secondName = t.val; } else if (la.kind == 20) { - } else SynErr(144); + } else SynErr(145); #line 1183 "cs.ATG" Point endPos = t.Location; @@ -2159,7 +2196,7 @@ out secondType); out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(145); + } else SynErr(146); #line 1186 "cs.ATG" List parameters = new List(); @@ -2251,7 +2288,7 @@ out qualident); templates); } Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { FormalParameterList( #line 1233 "cs.ATG" p); @@ -2282,7 +2319,7 @@ templates); out stmt); } else if (la.kind == 11) { lexer.NextToken(); - } else SynErr(146); + } else SynErr(147); #line 1245 "cs.ATG" methodDeclaration.Body = (BlockStatement)stmt; @@ -2345,9 +2382,9 @@ out getRegion, out setRegion); indexer.SetRegion = setRegion; compilationUnit.AddChild(indexer); - } else SynErr(147); - } else SynErr(148); - } else SynErr(149); + } else SynErr(148); + } else SynErr(149); + } else SynErr(150); } void InterfaceMemberDecl() { @@ -2396,7 +2433,7 @@ NotVoidPointer()) { templates); } Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { FormalParameterList( #line 1322 "cs.ATG" parameters); @@ -2419,7 +2456,7 @@ templates); compilationUnit.AddChild(md); } else if (StartOf(18)) { - if (StartOf(8)) { + if (StartOf(9)) { Type( #line 1332 "cs.ATG" out type); @@ -2438,7 +2475,7 @@ out type); templates); } Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { FormalParameterList( #line 1339 "cs.ATG" parameters); @@ -2475,7 +2512,7 @@ out getBlock, out setBlock); #line 1350 "cs.ATG" pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; - } else SynErr(150); + } else SynErr(151); } else if (la.kind == 109) { lexer.NextToken(); Expect(17); @@ -2500,7 +2537,7 @@ out getBlock, out setBlock); #line 1354 "cs.ATG" id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation; - } else SynErr(151); + } else SynErr(152); } else { lexer.NextToken(); @@ -2520,7 +2557,7 @@ out type); #line 1360 "cs.ATG" ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; } - } else SynErr(152); + } else SynErr(153); } void EnumMemberDecl( @@ -2590,47 +2627,7 @@ out name); #line 945 "cs.ATG" name = "bool"; - } else SynErr(153); - } - - void NonArrayType( -#line 920 "cs.ATG" -out TypeReference type) { - -#line 922 "cs.ATG" - string name; - int pointer = 0; - type = null; - - if (la.kind == 1 || la.kind == 89 || la.kind == 106) { - ClassType( -#line 927 "cs.ATG" -out type); - } else if (StartOf(14)) { - SimpleType( -#line 928 "cs.ATG" -out name); - -#line 928 "cs.ATG" - type = new TypeReference(name); - } else if (la.kind == 121) { - lexer.NextToken(); - Expect(6); - -#line 929 "cs.ATG" - pointer = 1; type = new TypeReference("void"); } else SynErr(154); - while ( -#line 932 "cs.ATG" -IsPointer()) { - Expect(6); - -#line 933 "cs.ATG" - ++pointer; - } - -#line 935 "cs.ATG" - if (type != null) { type.PointerNestingLevel = pointer; } } void FixedParameter( @@ -3234,7 +3231,7 @@ out Expression initializerExpression) { #line 1528 "cs.ATG" TypeReference type = null; Expression expr = null; initializerExpression = null; - if (StartOf(4)) { + if (StartOf(5)) { Expr( #line 1530 "cs.ATG" out initializerExpression); @@ -3668,19 +3665,19 @@ out expr); #line 1698 "cs.ATG" ArrayList initializer = null; ArrayList iterator = null; Expect(19); - if (StartOf(4)) { + if (StartOf(5)) { ForInitializer( #line 1699 "cs.ATG" out initializer); } Expect(11); - if (StartOf(4)) { + if (StartOf(5)) { Expr( #line 1700 "cs.ATG" out expr); } Expect(11); - if (StartOf(4)) { + if (StartOf(5)) { ForIterator( #line 1701 "cs.ATG" out iterator); @@ -3752,7 +3749,7 @@ out expr); Expect(11); } else if (la.kind == 99) { lexer.NextToken(); - if (StartOf(4)) { + if (StartOf(5)) { Expr( #line 1714 "cs.ATG" out expr); @@ -3763,7 +3760,7 @@ out expr); statement = new ReturnStatement(expr); } else if (la.kind == 110) { lexer.NextToken(); - if (StartOf(4)) { + if (StartOf(5)) { Expr( #line 1715 "cs.ATG" out expr); @@ -3772,7 +3769,7 @@ out expr); #line 1715 "cs.ATG" statement = new ThrowStatement(expr); - } else if (StartOf(4)) { + } else if (StartOf(5)) { StatementExpr( #line 1717 "cs.ATG" out statement); @@ -3917,7 +3914,7 @@ out stmt); #line 1750 "cs.ATG" initializer.Add(stmt); - } else if (StartOf(4)) { + } else if (StartOf(5)) { StatementExpr( #line 1751 "cs.ATG" out stmt); @@ -4008,7 +4005,7 @@ out Statement stmt) { UnaryExpr( #line 1869 "cs.ATG" out expr); - if (StartOf(6)) { + if (StartOf(7)) { #line 1872 "cs.ATG" AssignmentOperatorType op; Expression val; @@ -4079,7 +4076,7 @@ IsLocalVarDecl()) { LocalVariableDecl( #line 1849 "cs.ATG" out stmt); - } else if (StartOf(4)) { + } else if (StartOf(5)) { Expr( #line 1850 "cs.ATG" out expr); @@ -4558,7 +4555,7 @@ out expr); int dims = 0; ArrayList rank = new ArrayList(); ArrayList parameterExpression = new ArrayList(); - if (StartOf(4)) { + if (StartOf(5)) { Expr( #line 2002 "cs.ATG" out expr); @@ -4661,7 +4658,7 @@ NotVoidPointer()) { #line 2029 "cs.ATG" type = new TypeReference("void"); - } else if (StartOf(8)) { + } else if (StartOf(9)) { Type( #line 2030 "cs.ATG" out type); @@ -4848,7 +4845,7 @@ out Expression outExpr) { outExpr = expr; Expect(19); - if (StartOf(9)) { + if (StartOf(10)) { FormalParameterList( #line 2089 "cs.ATG" p); @@ -5232,7 +5229,7 @@ out TypeReference type) { #line 2306 "cs.ATG" type = new TypeReference("struct"); - } else if (StartOf(8)) { + } else if (StartOf(9)) { Type( #line 2307 "cs.ATG" out t); @@ -5417,21 +5414,21 @@ out t); case 123: s = "\"while\" expected"; break; case 124: s = "??? expected"; break; case 125: s = "invalid NamespaceMemberDecl"; break; - case 126: s = "invalid AttributeArguments"; break; - case 127: s = "invalid Expr"; break; - case 128: s = "invalid TypeModifier"; break; - case 129: s = "invalid TypeDecl"; break; + case 126: s = "invalid NonArrayType"; break; + case 127: s = "invalid AttributeArguments"; break; + case 128: s = "invalid Expr"; break; + case 129: s = "invalid TypeModifier"; break; case 130: s = "invalid TypeDecl"; break; - case 131: s = "invalid IntegralType"; break; - case 132: s = "invalid Type"; break; + case 131: s = "invalid TypeDecl"; break; + case 132: s = "invalid IntegralType"; break; case 133: s = "invalid Type"; break; - case 134: s = "invalid FormalParameterList"; break; + case 134: s = "invalid Type"; break; case 135: s = "invalid FormalParameterList"; break; - case 136: s = "invalid ClassType"; break; - case 137: s = "invalid MemberModifier"; break; - case 138: s = "invalid ClassMemberDecl"; break; + case 136: s = "invalid FormalParameterList"; break; + case 137: s = "invalid ClassType"; break; + case 138: s = "invalid MemberModifier"; break; case 139: s = "invalid ClassMemberDecl"; break; - case 140: s = "invalid StructMemberDecl"; break; + case 140: s = "invalid ClassMemberDecl"; break; case 141: s = "invalid StructMemberDecl"; break; case 142: s = "invalid StructMemberDecl"; break; case 143: s = "invalid StructMemberDecl"; break; @@ -5441,11 +5438,11 @@ out t); case 147: s = "invalid StructMemberDecl"; break; case 148: s = "invalid StructMemberDecl"; break; case 149: s = "invalid StructMemberDecl"; break; - case 150: s = "invalid InterfaceMemberDecl"; break; + case 150: s = "invalid StructMemberDecl"; break; case 151: s = "invalid InterfaceMemberDecl"; break; case 152: s = "invalid InterfaceMemberDecl"; break; - case 153: s = "invalid SimpleType"; break; - case 154: s = "invalid NonArrayType"; break; + case 153: s = "invalid InterfaceMemberDecl"; break; + case 154: s = "invalid SimpleType"; break; case 155: s = "invalid EventAccessorDecls"; break; case 156: s = "invalid ConstructorInitializer"; break; case 157: s = "invalid OverloadableOperator"; break; @@ -5492,6 +5489,7 @@ out t); {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,T,T, x,x,x,x, x,x,T,T, T,x,x,x, x,T,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x}, {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,T, x,x,x,x, x,x,T,T, T,x,x,x, x,T,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x}, {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,T,T, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, x,x,x,x, x,x}, {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,x,T,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, T,x,x,T, T,x,x,x, T,x,T,x, T,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,T,x,T, T,T,x,x, x,x,x,x, x,x,x,x, T,x,T,T, x,x,T,x, x,T,x,T, x,T,T,T, T,x,T,x, x,x,x,x, x,x}, {x,x,x,x, T,T,T,T, T,T,x,T, T,T,x,x, T,x,T,x, T,T,T,x, T,T,x,T, T,T,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x}, {x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x}, @@ -5502,7 +5500,6 @@ out t); {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,T,x, x,x}, {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, T,x,x,T, x,T,T,x, T,x,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,x,T,x, T,T,T,x, x,T,x,T, x,T,x,x, T,x,T,T, T,T,x,x, T,T,T,x, x,T,T,T, x,x,x,x, x,x,T,T, x,T,T,x, T,T,T,x, x,x}, {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, x,x,x,x, T,x,x,x, T,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, T,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,x,T,x, x,x,x,x, x,x,T,T, x,x,T,x, x,T,x,x, x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, x,x,x,x, x,x}, {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,T,x,T, x,x,x,x, x,x,T,x, T,x,T,x, x,x,T,x, x,x,x,x, x,x,T,T, x,x,T,x, x,T,x,x, x,x}, {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, x,T,T,x, T,x,T,x, T,x,T,T, T,x,x,x, x,T,x,x, x,x,T,x, T,T,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,x,T,T, x,x,x,x, x,x,T,T, x,x,T,x, x,T,x,x, x,x}, {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x}, diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG index 3dc40eebe6..c523fc00d9 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG @@ -559,17 +559,17 @@ CS UsingDirective (. - string qualident = null, aliasident = null; + string qualident = null; TypeReference aliasedType = null; .) = "using" (. Point startPos = t.Location; .) - [ IF (IsAssignment()) ident (. aliasident = t.val; .) "=" ] /*--- using alias directive */ - Qualident + Qualident + [ "=" NonArrayType ] ";" (. if (qualident != null && qualident.Length > 0) { INode node; - if (aliasident != null) { - node = new UsingDeclaration(aliasident, qualident); + if (aliasedType != null) { + node = new UsingDeclaration(qualident, aliasedType); } else { node = new UsingDeclaration(qualident); } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs index 98c8b201e4..17a168a165 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs @@ -315,7 +315,7 @@ ref val); void ImportsStmt() { #line 474 "VBNET.ATG" - ArrayList usings = new ArrayList(); + List usings = new List(); Expect(107); @@ -488,26 +488,23 @@ out Using u) { #line 496 "VBNET.ATG" string qualident = null; - string aliasident = null; + TypeReference aliasedType = null; u = null; - if ( -#line 500 "VBNET.ATG" -IsAssignment()) { - Identifier(); - -#line 500 "VBNET.ATG" - aliasident = t.val; - Expect(11); - } Qualident( -#line 501 "VBNET.ATG" +#line 500 "VBNET.ATG" out qualident); + if (la.kind == 11) { + lexer.NextToken(); + TypeName( +#line 501 "VBNET.ATG" +out aliasedType); + } #line 503 "VBNET.ATG" if (qualident != null && qualident.Length > 0) { - if (aliasident != null) { - u = new Using(aliasident, qualident); + if (aliasedType != null) { + u = new Using(qualident, aliasedType); } else { u = new Using(qualident); } @@ -515,18 +512,6 @@ out qualident); } - void Identifier() { - if (la.kind == 2) { - lexer.NextToken(); - } else if (la.kind == 169) { - lexer.NextToken(); - } else if (la.kind == 50) { - lexer.NextToken(); - } else if (la.kind == 69) { - lexer.NextToken(); - } else SynErr(209); - } - void Qualident( #line 2732 "VBNET.ATG" out string qualident) { @@ -555,6 +540,26 @@ out name); qualident = qualidentBuilder.ToString(); } + void TypeName( +#line 1928 "VBNET.ATG" +out TypeReference typeref) { + +#line 1929 "VBNET.ATG" + ArrayList rank = null; typeref = null; + NonArrayTypeName( +#line 1931 "VBNET.ATG" +out typeref); + ArrayTypeModifiers( +#line 1932 "VBNET.ATG" +out rank); + +#line 1934 "VBNET.ATG" + if (rank != null && typeref != null) { + typeref.RankSpecifier = (int[])rank.ToArray(typeof(int)); + } + + } + void NamespaceBody() { while (StartOf(1)) { NamespaceMemberDecl(); @@ -694,7 +699,7 @@ Modifiers m) { m.Add(Modifier.Sealed, t.Location); break; } - default: SynErr(210); break; + default: SynErr(209); break; } } @@ -957,7 +962,7 @@ out type); #line 700 "VBNET.ATG" delegateDeclr.ReturnType = type; } - } else SynErr(211); + } else SynErr(210); #line 702 "VBNET.ATG" delegateDeclr.EndLocation = t.EndLocation; @@ -968,7 +973,7 @@ out type); break; } - default: SynErr(212); break; + default: SynErr(211); break; } } @@ -1019,6 +1024,18 @@ template); } } + void Identifier() { + if (la.kind == 2) { + lexer.NextToken(); + } else if (la.kind == 169) { + lexer.NextToken(); + } else if (la.kind == 50) { + lexer.NextToken(); + } else if (la.kind == 69) { + lexer.NextToken(); + } else SynErr(212); + } + void TypeParameterConstraints( #line 572 "VBNET.ATG" TemplateDefinition template) { @@ -1055,26 +1072,6 @@ out constraint); } else SynErr(213); } - void TypeName( -#line 1928 "VBNET.ATG" -out TypeReference typeref) { - -#line 1929 "VBNET.ATG" - ArrayList rank = null; typeref = null; - NonArrayTypeName( -#line 1931 "VBNET.ATG" -out typeref); - ArrayTypeModifiers( -#line 1932 "VBNET.ATG" -out rank); - -#line 1934 "VBNET.ATG" - if (rank != null && typeref != null) { - typeref.RankSpecifier = (int[])rank.ToArray(typeof(int)); - } - - } - void ClassBaseType( #line 882 "VBNET.ATG" out TypeReference typeRef) { @@ -7150,10 +7147,10 @@ out blockStmt); case 206: s = "invalid NamespaceMemberDecl"; break; case 207: s = "invalid OptionValue"; break; case 208: s = "invalid EndOfStmt"; break; - case 209: s = "invalid Identifier"; break; - case 210: s = "invalid TypeModifier"; break; + case 209: s = "invalid TypeModifier"; break; + case 210: s = "invalid NonModuleDeclaration"; break; case 211: s = "invalid NonModuleDeclaration"; break; - case 212: s = "invalid NonModuleDeclaration"; break; + case 212: s = "invalid Identifier"; break; case 213: s = "invalid TypeParameterConstraints"; break; case 214: s = "invalid PrimitiveTypeName"; break; case 215: s = "invalid MemberModifier"; break; diff --git a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG index 489d9ea7db..3342b8e94c 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG @@ -471,7 +471,7 @@ EndOfStmt = . ImportsStmt - (.ArrayList usings = new ArrayList(); + (.List usings = new List(); .) = "Imports" (. @@ -494,15 +494,15 @@ ImportsStmt ImportClause (. string qualident = null; - string aliasident = null; + TypeReference aliasedType = null; u = null; .) = - [ IF (IsAssignment()) Identifier (. aliasident = t.val; .) "=" ] Qualident + [ "=" TypeName ] (. if (qualident != null && qualident.Length > 0) { - if (aliasident != null) { - u = new Using(aliasident, qualident); + if (aliasedType != null) { + u = new Using(qualident, aliasedType); } else { u = new Using(qualident); } diff --git a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj index fa733135db..d49da13a9c 100644 --- a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj +++ b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj @@ -17,7 +17,7 @@ True True DEBUG - C:\corsavy\trunk\SharpDevelop\bin + ..\..\..\..\bin\ True diff --git a/src/Libraries/NRefactory/Test/Parser/GlobalScope/UsingDeclarationTests.cs b/src/Libraries/NRefactory/Test/Parser/GlobalScope/UsingDeclarationTests.cs index 7e719e57d3..3c018661e6 100644 --- a/src/Libraries/NRefactory/Test/Parser/GlobalScope/UsingDeclarationTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/GlobalScope/UsingDeclarationTests.cs @@ -25,34 +25,42 @@ namespace ICSharpCode.NRefactory.Tests.AST Assert.IsTrue(u.Children[0] is UsingDeclaration); UsingDeclaration ud = (UsingDeclaration)u.Children[0]; Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(!((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("System", ((Using)ud.Usings[0]).Name); + Assert.IsTrue(!ud.Usings[0].IsAlias); + Assert.AreEqual("System", ud.Usings[0].Name); Assert.IsTrue(u.Children[1] is UsingDeclaration); ud = (UsingDeclaration)u.Children[1]; Assert.AreEqual(1, ud.Usings.Count); - Assert.IsTrue(!((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("My.Name.Space", ((Using)ud.Usings[0]).Name); + Assert.IsTrue(!ud.Usings[0].IsAlias); + Assert.AreEqual("My.Name.Space", ud.Usings[0].Name); } - void CheckTwoSimpleAliases(CompilationUnit u) + void CheckAliases(CompilationUnit u) { - Assert.AreEqual(2, u.Children.Count); + Assert.AreEqual(3, u.Children.Count); Assert.IsTrue(u.Children[0] is UsingDeclaration); UsingDeclaration ud = (UsingDeclaration)u.Children[0]; Assert.AreEqual(1, ud.Usings.Count); Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("TESTME", ((Using)ud.Usings[0]).Alias); - Assert.AreEqual("System", ((Using)ud.Usings[0]).Name); + Assert.AreEqual("TESTME", ud.Usings[0].Name); + Assert.AreEqual("System", ud.Usings[0].Alias.Type); Assert.IsTrue(u.Children[1] is UsingDeclaration); ud = (UsingDeclaration)u.Children[1]; Assert.AreEqual(1, ud.Usings.Count); Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); - Assert.AreEqual("myAlias", ((Using)ud.Usings[0]).Alias); - Assert.AreEqual("My.Name.Space", ((Using)ud.Usings[0]).Name); + Assert.AreEqual("myAlias", ud.Usings[0].Name); + Assert.AreEqual("My.Name.Space", ud.Usings[0].Alias.Type); + + Assert.IsTrue(u.Children[2] is UsingDeclaration); + ud = (UsingDeclaration)u.Children[2]; + Assert.AreEqual(1, ud.Usings.Count); + Assert.IsTrue(((Using)ud.Usings[0]).IsAlias); + Assert.AreEqual("StringCollection", ud.Usings[0].Name); + Assert.AreEqual("System.Collections.Generic.List", ud.Usings[0].Alias.Type); + Assert.AreEqual("System.String", ud.Usings[0].Alias.GenericTypes[0].SystemType); } #region C# @@ -69,7 +77,7 @@ namespace ICSharpCode.NRefactory.Tests.AST public void CSharpDeclarationTest() { string program = "using System;\n" + - "using My.Name.Space;\n"; + "using My.Name.Space;\n"; IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(program)); parser.Parse(); @@ -81,12 +89,13 @@ namespace ICSharpCode.NRefactory.Tests.AST public void CSharpUsingAliasDeclarationTest() { string program = "using TESTME=System;\n" + - "using myAlias=My.Name.Space;\n"; + "using myAlias=My.Name.Space;\n" + + "using StringCollection = System.Collections.Generic.List;\n"; IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); - + CheckAliases(parser.CompilationUnit); } #endregion @@ -103,7 +112,7 @@ namespace ICSharpCode.NRefactory.Tests.AST public void VBNetDeclarationTest() { string program = "Imports System\n" + - "Imports My.Name.Space\n"; + "Imports My.Name.Space\n"; IParser parser = ParserFactory.CreateParser(SupportedLanguages.VBNet, new StringReader(program)); parser.Parse(); @@ -115,12 +124,13 @@ namespace ICSharpCode.NRefactory.Tests.AST public void VBNetUsingAliasDeclarationTest() { string program = "Imports TESTME=System\n" + - "Imports myAlias=My.Name.Space\n"; + "Imports myAlias=My.Name.Space\n" + + "Imports StringCollection = System.Collections.Generic.List(Of string)\n"; IParser parser = ParserFactory.CreateParser(SupportedLanguages.VBNet, new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); - + CheckAliases(parser.CompilationUnit); } [Test] @@ -131,7 +141,7 @@ namespace ICSharpCode.NRefactory.Tests.AST parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); - // TODO : Extend test ... + // TODO : Extend test ... } #endregion } diff --git a/src/Main/Base/Project/Src/Dom/ClassFinder.cs b/src/Main/Base/Project/Src/Dom/ClassFinder.cs index 9028ed4b04..d823c3823d 100644 --- a/src/Main/Base/Project/Src/Dom/ClassFinder.cs +++ b/src/Main/Base/Project/Src/Dom/ClassFinder.cs @@ -65,7 +65,7 @@ namespace ICSharpCode.SharpDevelop.Dom return projectContent.GetClass(fullName); } - public IClass SearchClass(string name) + public IReturnType SearchType(string name) { return projectContent.SearchType(name, callingClass, cu, caretLine, caretColumn); } diff --git a/src/Main/Base/Project/Src/Dom/IClass.cs b/src/Main/Base/Project/Src/Dom/IClass.cs index d0e94afd65..5069bda41b 100644 --- a/src/Main/Base/Project/Src/Dom/IClass.cs +++ b/src/Main/Base/Project/Src/Dom/IClass.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.SharpDevelop.Dom } /// Gets the class associated with the base type with the same index. - IClass GetBaseClass(int index); + IReturnType GetBaseType(int index); List InnerClasses { get; @@ -102,6 +102,10 @@ namespace ICSharpCode.SharpDevelop.Dom get; } + IReturnType BaseType { + get; + } + IClass GetInnermostClass(int caretLine, int caretColumn); List GetAccessibleTypes(IClass callingClass); @@ -114,7 +118,5 @@ namespace ICSharpCode.SharpDevelop.Dom /// Return true if the specified class is a base class of this class; otherwise return false. /// Returns false when possibleBaseClass is null. bool IsTypeInInheritanceTree(IClass possibleBaseClass); - - List GetAccessibleMembers(IClass callingClass, bool showStatic); } } diff --git a/src/Main/Base/Project/Src/Dom/IUsing.cs b/src/Main/Base/Project/Src/Dom/IUsing.cs index 91a4ddf0b6..704ec0fbf6 100644 --- a/src/Main/Base/Project/Src/Dom/IUsing.cs +++ b/src/Main/Base/Project/Src/Dom/IUsing.cs @@ -20,11 +20,11 @@ namespace ICSharpCode.SharpDevelop.Dom get; } - SortedList Aliases { + SortedList Aliases { get; } - IClass SearchType(string partitialTypeName); + IReturnType SearchType(string partitialTypeName); string SearchNamespace(string partitialNamespaceName); } } diff --git a/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs b/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs index 3444ad694b..5f574e3231 100644 --- a/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs +++ b/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs @@ -246,7 +246,7 @@ namespace ICSharpCode.SharpDevelop.Dom // used to prevent StackOverflowException because SearchType might search for inner classes in the base type bool blockBaseClassSearch = false; - public IClass GetBaseClass(int index) + public IReturnType GetBaseType(int index) { if (blockBaseClassSearch) return null; @@ -260,6 +260,13 @@ namespace ICSharpCode.SharpDevelop.Dom IClass cachedBaseClass; + public IReturnType BaseType { + get { + IClass baseClass = cachedBaseClass; + return (baseClass != null) ? baseClass.DefaultReturnType : null; + } + } + public IClass BaseClass { get { Debug.Assert(ProjectContent != null); @@ -267,7 +274,8 @@ namespace ICSharpCode.SharpDevelop.Dom if (BaseTypes.Count > 0) { if (UseInheritanceCache && cachedBaseClass != null) return cachedBaseClass; - IClass baseClass = GetBaseClass(0); + IReturnType baseType = GetBaseType(0); + IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; if (baseClass != null && baseClass.ClassType != ClassType.Interface) { if (UseInheritanceCache) cachedBaseClass = baseClass; @@ -374,6 +382,7 @@ namespace ICSharpCode.SharpDevelop.Dom return types; } + /* public List GetAccessibleMembers(IClass callingClass, bool showStatic) { List members = new List(); @@ -408,20 +417,23 @@ namespace ICSharpCode.SharpDevelop.Dom if (ClassType == ClassType.Interface && !showStatic) { foreach (string s in BaseTypes) { - IClass baseClass = ProjectContent.SearchType(s, this, Region != null ? Region.BeginLine : -1, Region != null ? Region.BeginColumn : -1); - if (baseClass != null && baseClass.ClassType == ClassType.Interface) { - members.AddRange(baseClass.GetAccessibleMembers(callingClass, showStatic).ToArray()); + IReturnType baseType = ProjectContent.SearchType(s, this, Region != null ? Region.BeginLine : -1, Region != null ? Region.BeginColumn : -1); + List baseTypeMembers = new List(); + if (baseType != null && baseType.GetUnderlyingClass() != null && baseType.GetUnderlyingClass().ClassType == ClassType.Interface) { + //members.AddRange(baseClass.GetAccessibleMembers(callingClass, showStatic).ToArray()); + } } } else { IClass baseClass = BaseClass; if (baseClass != null) { - members.AddRange(baseClass.GetAccessibleMembers(callingClass, showStatic).ToArray()); + members.AddRange(baseClass.GetAccessibleMembers(callingClass, showStatic)); } } return members; } + */ public class ClassInheritanceEnumerator : IEnumerator, IEnumerable { @@ -494,18 +506,19 @@ namespace ICSharpCode.SharpDevelop.Dom BaseType baseTypeStruct = baseTypeQueue.Dequeue(); - IClass baseType; + IClass baseClass; if (baseTypeStruct.parent == null) { - baseType = ProjectContentRegistry.Mscorlib.GetClass(baseTypeStruct.name); + baseClass = ProjectContentRegistry.Mscorlib.GetClass(baseTypeStruct.name); } else { - baseType = baseTypeStruct.parent.ProjectContent.SearchType(baseTypeStruct.name, baseTypeStruct.parent, 1, 1); + IReturnType baseType = baseTypeStruct.parent.ProjectContent.SearchType(baseTypeStruct.name, baseTypeStruct.parent, 1, 1); + baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; } - if (baseType == null || finishedClasses.Contains(baseType)) { + if (baseClass == null || finishedClasses.Contains(baseClass)) { // prevent enumerating interfaces multiple times and endless loops when // circular inheritance is found return MoveNext(); } else { - currentClass = baseType; + currentClass = baseClass; finishedClasses.Add(currentClass); PutBaseClassesOnStack(currentClass); diff --git a/src/Main/Base/Project/Src/Dom/Implementations/DefaultUsing.cs b/src/Main/Base/Project/Src/Dom/Implementations/DefaultUsing.cs index 889f0e38cb..c732506293 100644 --- a/src/Main/Base/Project/Src/Dom/Implementations/DefaultUsing.cs +++ b/src/Main/Base/Project/Src/Dom/Implementations/DefaultUsing.cs @@ -29,7 +29,7 @@ namespace ICSharpCode.SharpDevelop.Dom } List usings = new List(); - SortedList aliases = new SortedList(); + SortedList aliases = new SortedList(); public IRegion Region { get { @@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Dom } } - public SortedList Aliases { + public SortedList Aliases { get { return aliases; } @@ -51,13 +51,15 @@ namespace ICSharpCode.SharpDevelop.Dom public string SearchNamespace(string partitialNamespaceName) { - foreach (KeyValuePair entry in aliases) { + foreach (KeyValuePair entry in aliases) { + if (!entry.Value.IsDefaultReturnType) + continue; string aliasString = entry.Key; if (projectContent.Language.NameComparer.Equals(partitialNamespaceName, aliasString)) - return entry.Value; + return entry.Value.FullyQualifiedName; if (partitialNamespaceName.Length > aliasString.Length) { if (projectContent.Language.NameComparer.Equals(partitialNamespaceName.Substring(0, aliasString.Length + 1), aliasString + ".")) { - string nsName = nsName = String.Concat(entry.Value, partitialNamespaceName.Remove(0, aliasString.Length)); + string nsName = nsName = String.Concat(entry.Value.FullyQualifiedName, partitialNamespaceName.Remove(0, aliasString.Length)); if (projectContent.NamespaceExists(nsName)) { return nsName; } @@ -74,16 +76,19 @@ namespace ICSharpCode.SharpDevelop.Dom return null; } - public IClass SearchType(string partitialTypeName) + public IReturnType SearchType(string partitialTypeName) { - foreach (KeyValuePair entry in aliases) { + foreach (KeyValuePair entry in aliases) { string aliasString = entry.Key; + if (projectContent.Language.NameComparer.Equals(partitialTypeName, aliasString)) { + return entry.Value; + } if (partitialTypeName.Length > aliasString.Length) { if (projectContent.Language.NameComparer.Equals(partitialTypeName.Substring(0, aliasString.Length + 1), aliasString + ".")) { string className = String.Concat(entry.Value, partitialTypeName.Remove(0, aliasString.Length)); IClass c = projectContent.GetClass(className); if (c != null) { - return c; + return c.DefaultReturnType; } } } @@ -92,7 +97,7 @@ namespace ICSharpCode.SharpDevelop.Dom foreach (string str in usings) { IClass c = projectContent.GetClass(str + "." + partitialTypeName); if (c != null) { - return c; + return c.DefaultReturnType; } } } else { @@ -110,7 +115,7 @@ namespace ICSharpCode.SharpDevelop.Dom if (c != null) { c = projectContent.GetClass(str + "." + partitialTypeName); if (c != null) { - return c; + return c.DefaultReturnType; } } } @@ -125,10 +130,10 @@ namespace ICSharpCode.SharpDevelop.Dom builder.Append(str); builder.Append(", "); } - foreach (KeyValuePair p in aliases) { + foreach (KeyValuePair p in aliases) { builder.Append(p.Key); builder.Append("="); - builder.Append(p.Value); + builder.Append(p.Value.ToString()); builder.Append(", "); } builder.Length -= 2; // remove last ", " diff --git a/src/Main/Base/Project/Src/Dom/Implementations/SearchClassReturnType.cs b/src/Main/Base/Project/Src/Dom/Implementations/SearchClassReturnType.cs index 4240e9074f..c430eb6b1a 100644 --- a/src/Main/Base/Project/Src/Dom/Implementations/SearchClassReturnType.cs +++ b/src/Main/Base/Project/Src/Dom/Implementations/SearchClassReturnType.cs @@ -62,8 +62,7 @@ namespace ICSharpCode.SharpDevelop.Dom // TODO: Cache BaseType until a new CompilationUnit is generated (static counter in ParserService) public override IReturnType BaseType { get { - IClass c = pc.SearchType(name, declaringClass, caretLine, caretColumn); - return (c != null) ? c.DefaultReturnType : null; + return pc.SearchType(name, declaringClass, caretLine, caretColumn); } } diff --git a/src/Main/Base/Project/Src/Dom/Implementations/SpecificReturnType.cs b/src/Main/Base/Project/Src/Dom/Implementations/SpecificReturnType.cs index fff5d41c9a..72c980eb79 100644 --- a/src/Main/Base/Project/Src/Dom/Implementations/SpecificReturnType.cs +++ b/src/Main/Base/Project/Src/Dom/Implementations/SpecificReturnType.cs @@ -221,7 +221,14 @@ namespace ICSharpCode.SharpDevelop.Dom public override string ToString() { - return String.Format("[SpecificReturnType: {0}<{1}>]", baseType, typeParameters); + string r = "[SpecificReturnType: "; + r += baseType; + r += "<"; + for (int i = 0; i < typeParameters.Count; i++) { + if (i > 0) r += ","; + r += typeParameters[i]; + } + return r + ">]"; } } } diff --git a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs index 271141fe13..3af3daccfe 100644 --- a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs +++ b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs @@ -164,7 +164,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver Debug.Assert(data is DefaultUsing); DefaultUsing us = (DefaultUsing)data; if (u.IsAlias) { - us.Aliases[u.Name] = u.Alias; + IReturnType rt = CreateReturnType(u.Alias); + if (rt != null) { + us.Aliases[u.Name] = rt; + } } else { us.Usings.Add(u.Name); } @@ -550,9 +553,11 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver IReturnType CreateReturnType(AST.TypeReference reference, IMethod method) { IClass c = GetCurrentClass(); - if (c == null) - return null; - return TypeVisitor.CreateReturnType(reference, c, method, c.Region.BeginLine + 1, 1, cu.ProjectContent, true); + if (c == null) { + return TypeVisitor.CreateReturnType(reference, new DefaultClass(cu, "___DummyClass"), method, 1, 1, cu.ProjectContent, true); + } else { + return TypeVisitor.CreateReturnType(reference, c, method, c.Region.BeginLine + 1, 1, cu.ProjectContent, true); + } } IReturnType CreateReturnType(AST.TypeReference reference) diff --git a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs index d1eba94e8e..b181009268 100644 --- a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs +++ b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs @@ -441,9 +441,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver ResolveResult result2 = null; - IClass c = SearchClass(identifier); - if (c != null) { - result2 = new TypeResolveResult(callingClass, callingMember, c); + IReturnType t = SearchType(identifier); + if (t != null) { + result2 = new TypeResolveResult(callingClass, callingMember, t); } else { if (callingClass != null) { if (callingMember is IMethod) { @@ -652,6 +652,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver /// use the usings and the name of the namespace to find a class /// public IClass SearchClass(string name) + { + IReturnType t = SearchType(name); + return (t != null) ? t.GetUnderlyingClass() : null; + } + + public IReturnType SearchType(string name) { return projectContent.SearchType(name, callingClass, cu, caretLine, caretColumn); } @@ -898,10 +904,18 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver inStatic = callingMember.IsStatic; if (callingClass != null) { - if (!inStatic) { - result.AddRange(callingClass.GetAccessibleMembers(callingClass, false)); + ArrayList members = new ArrayList(); + IReturnType t = callingClass.DefaultReturnType; + members.AddRange(t.GetMethods()); + members.AddRange(t.GetFields()); + members.AddRange(t.GetEvents()); + members.AddRange(t.GetProperties()); + members.AddRange(t.GetIndexers()); + foreach (IMember m in members) { + if ((m.IsStatic || !inStatic) && m.IsAccessible(callingClass, true)) { + result.Add(m); + } } - result.AddRange(callingClass.GetAccessibleMembers(callingClass, true)); } foreach (KeyValuePair> pair in lookupTableVisitor.Variables) { if (pair.Value != null && pair.Value.Count > 0) { diff --git a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs index c9f5fec6b4..55ed4b8d01 100644 --- a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs +++ b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs @@ -426,11 +426,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver if (resolver.CallingClass == null) { return null; } - IClass baseClass = resolver.CallingClass.BaseClass; - if (baseClass == null) { - return null; - } - return baseClass.DefaultReturnType; + return resolver.CallingClass.BaseType; } public override object Visit(ObjectCreateExpression objectCreateExpression, object data) @@ -519,11 +515,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver t = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.SystemType); } else { IClass c; - if (reference.IsGlobal) + if (reference.IsGlobal) { c = projectContent.GetClass(reference.SystemType); - else - c = projectContent.SearchType(reference.SystemType, callingClass, caretLine, caretColumn); - if (c == null) { + t = (c != null) ? c.DefaultReturnType : null; + } else { + t = projectContent.SearchType(reference.SystemType, callingClass, caretLine, caretColumn); + } + if (t == null) { if (reference.GenericTypes.Count == 0 && !reference.IsArrayType) { // reference to namespace is possible if (reference.IsGlobal) { @@ -537,7 +535,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } return null; } - t = c.DefaultReturnType; } } } diff --git a/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/BaseTypesNode.cs b/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/BaseTypesNode.cs index 8e7ee83be2..6e4583759e 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/BaseTypesNode.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/BaseTypesNode.cs @@ -64,7 +64,8 @@ namespace ICSharpCode.SharpDevelop.Gui if (content != null) { int count = c.BaseTypes.Count; for (int i = 0; i < count; i++) { - IClass baseClass = c.GetBaseClass(i); + IReturnType baseType = c.GetBaseType(i); + IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; if (baseClass != null) { new ClassNode(project, baseClass).AddTo(this); } diff --git a/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs b/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs index 269c52bf33..0d587e7338 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs @@ -454,7 +454,22 @@ namespace ICSharpCode.Core if (language.ShowInNamespaceCompletion(c)) list.Add(c); if (language.ImportModules && c.ClassType == ClassType.Module) { - list.AddRange(c.GetAccessibleMembers(null, true)); + foreach (IMember m in c.Methods) { + if (m.IsAccessible(null, false)) + list.Add(m); + } + foreach (IMember m in c.Events) { + if (m.IsAccessible(null, false)) + list.Add(m); + } + foreach (IMember m in c.Fields) { + if (m.IsAccessible(null, false)) + list.Add(m); + } + foreach (IMember m in c.Properties) { + if (m.IsAccessible(null, false)) + list.Add(m); + } } } foreach (string subns in ns.SubNamespaces) { @@ -534,7 +549,7 @@ namespace ICSharpCode.Core return null; } - public IClass SearchType(string name, IClass curType, int caretLine, int caretColumn) + public IReturnType SearchType(string name, IClass curType, int caretLine, int caretColumn) { if (curType == null) { return SearchType(name, null, null, caretLine, caretColumn); @@ -542,7 +557,7 @@ namespace ICSharpCode.Core return SearchType(name, curType, curType.CompilationUnit, caretLine, caretColumn); } - public IClass SearchType(string name, IClass curType, ICompilationUnit unit, int caretLine, int caretColumn) + public IReturnType SearchType(string name, IClass curType, ICompilationUnit unit, int caretLine, int caretColumn) { if (name == null || name.Length == 0) { return null; @@ -551,7 +566,7 @@ namespace ICSharpCode.Core // Try if name is already the full type name IClass c = GetClass(name); if (c != null) { - return c; + return c.DefaultReturnType; } if (curType != null) { // Try parent namespaces of the current class @@ -565,7 +580,7 @@ namespace ICSharpCode.Core curnamespace.Append(name); c = GetClass(curnamespace.ToString()); if (c != null) { - return c; + return c.DefaultReturnType; } // remove class name again to try next namespace curnamespace.Length -= name.Length; @@ -576,7 +591,7 @@ namespace ICSharpCode.Core while ((curType = curType.BaseClass) != null) { foreach (IClass innerClass in curType.InnerClasses) { if (language.NameComparer.Equals(innerClass.Name, name)) - return innerClass; + return innerClass.DefaultReturnType; } } } @@ -585,17 +600,17 @@ namespace ICSharpCode.Core // Combine name with usings foreach (IUsing u in unit.Usings) { if (u != null) { - c = u.SearchType(name); - if (c != null) { - return c; + IReturnType r = u.SearchType(name); + if (r != null) { + return r; } } } } if (defaultImports != null) { - c = defaultImports.SearchType(name); - if (c != null) { - return c; + IReturnType r = defaultImports.SearchType(name); + if (r != null) { + return r; } } return null; diff --git a/src/Main/Base/Project/Src/Services/ParserService/IProjectContent.cs b/src/Main/Base/Project/Src/Services/ParserService/IProjectContent.cs index 0e17e3e082..5834d784a0 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/IProjectContent.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/IProjectContent.cs @@ -72,8 +72,8 @@ namespace ICSharpCode.Core void AddNamespaceContents(ArrayList list, string subNameSpace, LanguageProperties language, bool lookInReferences); string SearchNamespace(string name, IClass curType, ICompilationUnit unit, int caretLine, int caretColumn); - IClass SearchType(string name, IClass curType, int caretLine, int caretColumn); - IClass SearchType(string name, IClass curType, ICompilationUnit unit, int caretLine, int caretColumn); + IReturnType SearchType(string name, IClass curType, int caretLine, int caretColumn); + IReturnType SearchType(string name, IClass curType, ICompilationUnit unit, int caretLine, int caretColumn); Position GetPosition(string fullMemberName); } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs index e90f02f6df..304cf59dca 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs @@ -42,7 +42,7 @@ namespace ICSharpCode.Core string baseType = c.BaseTypes[i]; if (pc.Language.NameComparer.Equals(baseType, baseClassName) || pc.Language.NameComparer.Equals(baseType, baseClassFullName)) { - IClass possibleBaseClass = c.GetBaseClass(i); + IReturnType possibleBaseClass = c.GetBaseType(i); if (possibleBaseClass != null && possibleBaseClass.FullyQualifiedName == baseClass.FullyQualifiedName) { list.Add(c); diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/AbstractClassImplementorCodeGenerator.cs b/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/AbstractClassImplementorCodeGenerator.cs index 5d146a177f..837ac8f13f 100644 --- a/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/AbstractClassImplementorCodeGenerator.cs +++ b/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/AbstractClassImplementorCodeGenerator.cs @@ -39,23 +39,10 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands public AbstractClassImplementorCodeGenerator(IClass currentClass) : base(currentClass) { - - - foreach (string className in currentClass.BaseTypes) { - IClass baseType = ParserService.CurrentProjectContent.GetClass(className); - if (baseType == null) { - this.unit = currentClass == null ? null : currentClass.CompilationUnit; - if (unit != null) { - foreach (IUsing u in unit.Usings) { - baseType = u.SearchType(className); - if (baseType != null) { - break; - } - } - } - } - - if (baseType != null && baseType.ClassType == ClassType.Class && baseType.IsAbstract) { + for (int i = 0; i < currentClass.BaseTypes.Count; i++) { + IReturnType baseType = currentClass.GetBaseType(i); + IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; + if (baseClass != null && baseClass.ClassType == ClassType.Class && baseClass.IsAbstract) { Content.Add(new ClassWrapper(baseType)); } } @@ -65,30 +52,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands { for (int i = 0; i < items.Count; ++i) { ClassWrapper cw = (ClassWrapper)items[i]; - Queue interfaces = new Queue(); - interfaces.Enqueue(cw.Class); - while (interfaces.Count > 0) { - IClass intf = (IClass)interfaces.Dequeue(); - GenerateInterface(intf, fileExtension); - /* - // search an enqueue all base interfaces - foreach (string interfaceName in intf.BaseTypes) { - IClass baseType = null; - foreach (IUsing u in unit.Usings) { - baseType = u.SearchType(interfaceName); - if (baseType != null) { - break; - } - } - if (baseType != null) { - interfaces.Enqueue(baseType); - } - }*/ - } + GenerateInterface(cw.ClassType, fileExtension); } } - void GenerateInterface(IClass intf, string fileExtension) + void GenerateInterface(IReturnType intf, string fileExtension) { Return();Return(); @@ -99,7 +67,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands } ++numOps; - foreach (IProperty property in intf.Properties) { + foreach (IProperty property in intf.GetProperties()) { if (!property.IsAbstract) { continue; } @@ -183,14 +151,13 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands } else { editActionHandler.InsertChar('}');++numOps; } - + Return(); Return(); IndentLine(); } - for (int i = 0; i < intf.Methods.Count; ++i) { - IMethod method = intf.Methods[i]; + foreach (IMethod method in intf.GetMethods()) { string parameters = String.Empty; string returnType = (fileExtension == ".vb" ? vba : csa).Convert(method.ReturnType); if (!method.IsAbstract) { @@ -249,13 +216,9 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands } else { editActionHandler.InsertChar('}');++numOps; } - if (i + 1 < intf.Methods.Count) { - Return(); - Return(); - IndentLine(); - } else { - IndentLine(); - } + Return(); + Return(); + IndentLine(); } Return(); if (fileExtension == ".vb") { @@ -294,21 +257,22 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands class ClassWrapper { - IClass c; - public IClass Class { + IReturnType c; + public IReturnType ClassType { get { return c; } } - public ClassWrapper(IClass c) + public ClassWrapper(IReturnType c) { this.c = c; } public override string ToString() { - - return AmbienceService.CurrentAmbience.Convert(c); + IAmbience ambience = AmbienceService.CurrentAmbience; + ambience.ConversionFlags = ConversionFlags.None; + return ambience.Convert(c); } } } diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/InterfaceImplementorCodeGenerator.cs b/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/InterfaceImplementorCodeGenerator.cs index 77c9b8e00f..9a5f3ef1f7 100644 --- a/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/InterfaceImplementorCodeGenerator.cs +++ b/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/InterfaceImplementorCodeGenerator.cs @@ -39,28 +39,10 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands public InterfaceImplementorCodeGenerator(IClass currentClass) : base(currentClass) { - - - foreach (string className in currentClass.BaseTypes) { - IClass baseType = ParserService.CurrentProjectContent.GetClass(className); - - if (baseType == null) { - baseType = ParserService.CurrentProjectContent.GetClass(currentClass.Namespace + "." + className); - } - - if (baseType == null) { - this.unit = currentClass == null ? null : currentClass.CompilationUnit; - if (unit != null) { - foreach (IUsing u in unit.Usings) { - baseType = u.SearchType(className); - if (baseType != null) { - break; - } - } - } - } - - if (baseType != null && baseType.ClassType == ClassType.Interface) { + for (int i = 0; i < currentClass.BaseTypes.Count; i++) { + IReturnType baseType = currentClass.GetBaseType(i); + IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null; + if (baseClass != null && baseClass.ClassType == ClassType.Interface) { Content.Add(new ClassWrapper(baseType)); } } @@ -70,129 +52,168 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands { for (int i = 0; i < items.Count; ++i) { ClassWrapper cw = (ClassWrapper)items[i]; - Queue interfaces = new Queue(); - interfaces.Enqueue(cw.Class); - while (interfaces.Count > 0) { - IClass intf = (IClass)interfaces.Dequeue(); - GenerateInterface(intf); - - // search an enqueue all base interfaces - foreach (string interfaceName in intf.BaseTypes) { - - // first look if the interface is in the same namespace - IClass baseType = ParserService.CurrentProjectContent.GetClass(intf.Namespace + "." + interfaceName); - - if (baseType == null && unit != null && unit.Usings != null) { - foreach (IUsing u in unit.Usings) { - baseType = u.SearchType(interfaceName); - if (baseType != null) { - break; - } - } - } - if (baseType != null) { - interfaces.Enqueue(baseType); - } - } - } + GenerateInterface(cw.ClassType, fileExtension); } } - void GenerateInterface(IClass intf) + void GenerateInterface(IReturnType intf, string fileExtension) { Return(); Return(); editActionHandler.InsertString("#region " + intf.FullyQualifiedName + " interface implementation\n\t\t");++numOps; - foreach (IProperty property in intf.Properties) { - string returnType = csa.Convert(property.ReturnType); - editActionHandler.InsertString("public " + returnType + " " + property.Name);++numOps; - if (StartCodeBlockInSameLine) { - editActionHandler.InsertString(" {");++numOps; + foreach (IProperty property in intf.GetProperties()) { + if (!property.IsAbstract) { + continue; + } + string returnType = (fileExtension == ".vb" ? vba : csa).Convert(property.ReturnType); + if (property.IsProtected) { + if (fileExtension == ".vb") { + editActionHandler.InsertString("Protected "); + } else { + editActionHandler.InsertString("protected "); + } + ++numOps; } else { - Return(); - editActionHandler.InsertString("{");++numOps; + if (fileExtension == ".vb") { + editActionHandler.InsertString("Public "); + } else { + editActionHandler.InsertString("public "); + } + ++numOps; } - Return(); - if (property.CanGet) { - editActionHandler.InsertString("\tget");++numOps; + if (fileExtension == ".vb") { + editActionHandler.InsertString("override " + returnType + " " + property.Name); if (StartCodeBlockInSameLine) { editActionHandler.InsertString(" {");++numOps; } else { Return(); editActionHandler.InsertString("{");++numOps; } - Return(); - Indent();Indent(); - editActionHandler.InsertString("return " + GetReturnValue(returnType) +";");++numOps; - Return(); - Indent(); - editActionHandler.InsertString("}");++numOps; - Return(); + } else { + editActionHandler.InsertString("Overrides Property " + property.Name + " As " + returnType + "\n"); + } + ++numOps; + if (property.CanGet) { + if (fileExtension == ".vb") { + editActionHandler.InsertString("\tGet");++numOps; + Return(); + editActionHandler.InsertString("\t\tReturn " + GetReturnValue(returnType));++numOps; + Return(); + editActionHandler.InsertString("\tEnd Get");++numOps; + Return(); + } else { + editActionHandler.InsertString("\tget");++numOps; + if (StartCodeBlockInSameLine) { + editActionHandler.InsertString(" {");++numOps; + } else { + Return(); + editActionHandler.InsertString("{");++numOps; + } + + Return(); + editActionHandler.InsertString("\t\treturn " + GetReturnValue(returnType) +";");++numOps; + Return(); + editActionHandler.InsertString("\t}");++numOps; + Return(); + } } if (property.CanSet) { - Indent(); - editActionHandler.InsertString("set");++numOps; - if (StartCodeBlockInSameLine) { - editActionHandler.InsertString(" {");++numOps; + if (fileExtension == ".vb") { + editActionHandler.InsertString("\tSet");++numOps; + Return(); + editActionHandler.InsertString("\tEnd Set");++numOps; + Return(); } else { + editActionHandler.InsertString("\tset");++numOps; + if (StartCodeBlockInSameLine) { + editActionHandler.InsertString(" {");++numOps; + } else { + Return(); + editActionHandler.InsertString("{");++numOps; + } + + Return(); + editActionHandler.InsertString("\t}");++numOps; Return(); - editActionHandler.InsertString("{");++numOps; } - Return(); - Indent(); - editActionHandler.InsertString("}");++numOps; - Return(); } - editActionHandler.InsertChar('}');++numOps; + if (fileExtension == ".vb") { + editActionHandler.InsertString("End Property");++numOps; + } else { + editActionHandler.InsertChar('}');++numOps; + } + Return(); Return(); IndentLine(); } - for (int i = 0; i < intf.Methods.Count; ++i) { - IMethod method = intf.Methods[i]; + foreach (IMethod method in intf.GetMethods()) { string parameters = String.Empty; - string returnType = csa.Convert(method.ReturnType); - + string returnType = (fileExtension == ".vb" ? vba : csa).Convert(method.ReturnType); + if (!method.IsAbstract) { + continue; + } for (int j = 0; j < method.Parameters.Count; ++j) { - parameters += csa.Convert(method.Parameters[j]); + parameters += (fileExtension == ".vb" ? vba : csa).Convert(method.Parameters[j]); if (j + 1 < method.Parameters.Count) { parameters += ", "; } } - - editActionHandler.InsertString("public " + returnType + " " + method.Name + "(" + parameters + ")");++numOps; - if (StartCodeBlockInSameLine) { - editActionHandler.InsertString(" {");++numOps; + if (method.IsProtected) { + if (fileExtension == ".vb") { + editActionHandler.InsertString("Protected "); + } else { + editActionHandler.InsertString("protected "); + } } else { + if (fileExtension == ".vb") { + editActionHandler.InsertString("Public "); + } else { + editActionHandler.InsertString("public "); + } + } + bool isSub = returnType == "void"; + if (fileExtension == ".vb") { + + editActionHandler.InsertString("Overrides " + (isSub ? "Sub " : "Function ") + method.Name + "(" + parameters + ") As " + returnType);++numOps; + Return(); + } else { + editActionHandler.InsertString("override " + returnType + " " + method.Name + "(" + parameters + ")");++numOps; + if (StartCodeBlockInSameLine) { + editActionHandler.InsertString(" {");++numOps; + } else { + Return(); + editActionHandler.InsertString("{");++numOps; + } Return(); - editActionHandler.InsertString("{");++numOps; } - Return(); - switch (returnType) { case "void": break; default: - Indent(); - editActionHandler.InsertString("return " + GetReturnValue(returnType) + ";");++numOps; + if (fileExtension == ".vb") { + editActionHandler.InsertString("Return " + GetReturnValue(returnType));++numOps; + } else { + editActionHandler.InsertString("return " + GetReturnValue(returnType) + ";");++numOps; + } break; } Return(); - editActionHandler.InsertChar('}');++numOps; - if (i + 1 < intf.Methods.Count) { - Return(); - Return(); - IndentLine(); + if (fileExtension == ".vb") { + editActionHandler.InsertString("End " + (isSub ? "Sub" : "Function")); } else { - IndentLine(); + editActionHandler.InsertChar('}');++numOps; } + Return(); + Return(); + IndentLine(); } Return(); @@ -227,13 +248,13 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands class ClassWrapper { - IClass c; - public IClass Class { + IReturnType c; + public IReturnType ClassType { get { return c; } } - public ClassWrapper(IClass c) + public ClassWrapper(IReturnType c) { this.c = c; }