Browse Source

Fixed SD2-1625 - Forms Designer corrupts field declarations with inner class type references

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5300 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
0824719cc9
  1. 29
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs
  2. 3
      src/Libraries/NRefactory/Project/Src/Visitors/CodeDOMOutputVisitor.cs
  3. 8
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs

29
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs

@ -19,6 +19,7 @@ using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors; using ICSharpCode.NRefactory.Visitors;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ReturnTypeOptions = ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.TypeVisitor.ReturnTypeOptions;
namespace ICSharpCode.FormsDesigner namespace ICSharpCode.FormsDesigner
{ {
@ -213,8 +214,8 @@ namespace ICSharpCode.FormsDesigner
} }
TypeDeclaration typeDecl = o as TypeDeclaration; TypeDeclaration typeDecl = o as TypeDeclaration;
if (typeDecl != null) { if (typeDecl != null) {
foreach (TypeReference tref in typeDecl.BaseTypes) { for (int i = 0; i < typeDecl.BaseTypes.Count; i++) {
FixTypeReference(tref, typeDecl.StartLocation, domCu); typeDecl.BaseTypes[i] = FixTypeReference(typeDecl.BaseTypes[i], typeDecl.StartLocation, domCu, ReturnTypeOptions.BaseTypeReference);
} }
for (int i = 0; i < typeDecl.Children.Count; i++) { for (int i = 0; i < typeDecl.Children.Count; i++) {
object child = typeDecl.Children[i]; object child = typeDecl.Children[i];
@ -242,28 +243,26 @@ namespace ICSharpCode.FormsDesigner
} }
FieldDeclaration fieldDecl = o as FieldDeclaration; FieldDeclaration fieldDecl = o as FieldDeclaration;
if (fieldDecl != null) { 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) { foreach (VariableDeclaration var in fieldDecl.Fields) {
if (var != null) { 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) if (type == null || type.IsKeyword)
return; return type;
if (type.Type != type.Type)
return;
foreach (TypeReference tref in type.GenericTypes) {
FixTypeReference(tref, location, domCu);
}
ICSharpCode.SharpDevelop.Dom.IClass curType = domCu.GetInnermostClass(location.Y, location.X); 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; IReturnType rt = SharpDevelop.Dom.NRefactoryResolver.TypeVisitor.CreateReturnType(
if (rt != null) { type, curType, null, location.Y, location.X, domCu.ProjectContent, options);
type.Type = rt.FullyQualifiedName; if (rt != null && rt.GetUnderlyingClass() != null) {
return SharpDevelop.Dom.Refactoring.CodeGenerator.ConvertType(rt, null);
} else {
return type;
} }
} }

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

@ -98,9 +98,6 @@ namespace ICSharpCode.NRefactory.Visitors
if (type == null) { if (type == null) {
throw new ArgumentNullException("type"); throw new ArgumentNullException("type");
} }
if (string.IsNullOrEmpty(type.Type)) {
throw new InvalidOperationException("empty type");
}
CodeTypeReference t = new CodeTypeReference(GetDotNetNameFromTypeReference(type)); CodeTypeReference t = new CodeTypeReference(GetDotNetNameFromTypeReference(type));
InnerClassTypeReference ictr = type as InnerClassTypeReference; InnerClassTypeReference ictr = type as InnerClassTypeReference;

8
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); typeRef = new TypeReference(returnType.FullyQualifiedName, true);
else if (context != null && CanUseShortTypeName(returnType, context)) else if (context != null && CanUseShortTypeName(returnType, context))
typeRef = new TypeReference(returnType.Name); typeRef = new TypeReference(returnType.Name);
else else {
typeRef = new TypeReference(returnType.FullyQualifiedName); string fullName = returnType.FullyQualifiedName;
if (string.IsNullOrEmpty(fullName))
fullName = returnType.Name;
typeRef = new TypeReference(fullName);
}
foreach (IReturnType typeArgument in typeArguments) { foreach (IReturnType typeArgument in typeArguments) {
typeRef.GenericTypes.Add(ConvertType(typeArgument, context)); typeRef.GenericTypes.Add(ConvertType(typeArgument, context));
} }

Loading…
Cancel
Save