diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs index ba5a6e617f..a7067ef1a7 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs @@ -19,6 +19,7 @@ using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Visitors; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom; +using ReturnTypeOptions = ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.TypeVisitor.ReturnTypeOptions; namespace ICSharpCode.FormsDesigner { @@ -213,8 +214,8 @@ namespace ICSharpCode.FormsDesigner } TypeDeclaration typeDecl = o as TypeDeclaration; if (typeDecl != null) { - foreach (TypeReference tref in typeDecl.BaseTypes) { - FixTypeReference(tref, typeDecl.StartLocation, domCu); + for (int i = 0; i < typeDecl.BaseTypes.Count; i++) { + typeDecl.BaseTypes[i] = FixTypeReference(typeDecl.BaseTypes[i], typeDecl.StartLocation, domCu, ReturnTypeOptions.BaseTypeReference); } for (int i = 0; i < typeDecl.Children.Count; i++) { object child = typeDecl.Children[i]; @@ -242,28 +243,26 @@ namespace ICSharpCode.FormsDesigner } FieldDeclaration fieldDecl = o as FieldDeclaration; if (fieldDecl != null) { - FixTypeReference(fieldDecl.TypeReference, fieldDecl.StartLocation, domCu); + fieldDecl.TypeReference = FixTypeReference(fieldDecl.TypeReference, fieldDecl.StartLocation, domCu, ReturnTypeOptions.None); foreach (VariableDeclaration var in fieldDecl.Fields) { if (var != null) { - FixTypeReference(var.TypeReference, fieldDecl.StartLocation, domCu); + var.TypeReference = FixTypeReference(var.TypeReference, fieldDecl.StartLocation, domCu, ReturnTypeOptions.None); } } } } - void FixTypeReference(TypeReference type, Location location, ICSharpCode.SharpDevelop.Dom.ICompilationUnit domCu) + TypeReference FixTypeReference(TypeReference type, Location location, ICompilationUnit domCu, ReturnTypeOptions options) { - if (type == null) - return; - if (type.Type != type.Type) - return; - foreach (TypeReference tref in type.GenericTypes) { - FixTypeReference(tref, location, domCu); - } + if (type == null || type.IsKeyword) + return type; ICSharpCode.SharpDevelop.Dom.IClass curType = domCu.GetInnermostClass(location.Y, location.X); - ICSharpCode.SharpDevelop.Dom.IReturnType rt = domCu.ProjectContent.SearchType(new SearchTypeRequest(type.Type, type.GenericTypes.Count, curType, domCu, location.Y, location.X)).Result; - if (rt != null) { - type.Type = rt.FullyQualifiedName; + IReturnType rt = SharpDevelop.Dom.NRefactoryResolver.TypeVisitor.CreateReturnType( + type, curType, null, location.Y, location.X, domCu.ProjectContent, options); + if (rt != null && rt.GetUnderlyingClass() != null) { + return SharpDevelop.Dom.Refactoring.CodeGenerator.ConvertType(rt, null); + } else { + return type; } } diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs index 85ca6c0e4b..e57c5f6dd4 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs @@ -98,9 +98,6 @@ namespace ICSharpCode.NRefactory.Visitors if (type == null) { throw new ArgumentNullException("type"); } - if (string.IsNullOrEmpty(type.Type)) { - throw new InvalidOperationException("empty type"); - } CodeTypeReference t = new CodeTypeReference(GetDotNetNameFromTypeReference(type)); InnerClassTypeReference ictr = type as InnerClassTypeReference; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs index 6110152a19..203b3955d3 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs @@ -72,8 +72,12 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring typeRef = new TypeReference(returnType.FullyQualifiedName, true); else if (context != null && CanUseShortTypeName(returnType, context)) typeRef = new TypeReference(returnType.Name); - else - typeRef = new TypeReference(returnType.FullyQualifiedName); + else { + string fullName = returnType.FullyQualifiedName; + if (string.IsNullOrEmpty(fullName)) + fullName = returnType.Name; + typeRef = new TypeReference(fullName); + } foreach (IReturnType typeArgument in typeArguments) { typeRef.GenericTypes.Add(ConvertType(typeArgument, context)); }