diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 11:23:02 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 11:23:02 +0400 |
commit | c1c3e6cd7921e158bf5826b6cf7a08e1967e19e1 (patch) | |
tree | 5b271e1130c0ae00e6467617a82ad274a08495ce /main/src/addins/CSharpBinding | |
parent | e397f88ca1002c52701ab2b95db44106a8df8f9f (diff) |
[Refactoring] Track API changes.
Diffstat (limited to 'main/src/addins/CSharpBinding')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs index 5c692d9dba..87c69095b6 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs @@ -164,6 +164,10 @@ namespace MonoDevelop.CSharp.Refactoring void AppendReturnType (StringBuilder result, ITypeDefinition implementingType, ITypeReference type) { + if (type == null) + throw new ArgumentNullException ("type"); + if (type == SharedTypes.UnknownType) + throw new ArgumentException ("type is unknown", "type"); var loc = implementingType.Region.Begin; var pf = implementingType.ProjectContent.GetFile (implementingType.Region.FileName); @@ -172,13 +176,21 @@ namespace MonoDevelop.CSharp.Refactoring var file = pf as CSharpParsedFile; var project = implementingType.ProjectContent.Annotation<MonoDevelop.Projects.Project> (); var ctx = TypeSystemService.GetContext (project); - var shortType = CreateShortType (ctx, file, loc, type.Resolve (ctx)); + var resolved = type.Resolve (ctx); + if (resolved == SharedTypes.UnknownType) { + result.Append (type.ToString ()); + return; + } + var shortType = CreateShortType (ctx, file, loc, resolved); using (var stringWriter = new System.IO.StringWriter ()) { var formatter = new TextWriterOutputFormatter (stringWriter); stringWriter.NewLine = EolMarker; var visitor = new CSharpOutputVisitor (formatter, project.GetFormattingOptions ()); shortType.AcceptVisitor (visitor, null); - result.Append (stringWriter.ToString ()); + var typeString = stringWriter.ToString (); + if (typeString.StartsWith ("global::")) + typeString = typeString.Substring ("global::".Length); + result.Append (typeString); } } @@ -301,10 +313,15 @@ namespace MonoDevelop.CSharp.Refactoring result.Append (")"); var typeParameters = method.TypeParameters; + foreach (var p in typeParameters) { + Console.WriteLine (p.GetEffectiveBaseClass (options.Ctx)); + } if (typeParameters.Any (p => p.GetConstraints (options.Ctx).Any () /*|| (p.TypeParameterModifier & TypeParameterModifier.HasDefaultConstructorConstraint) != 0*/)) { result.Append (" where "); int typeParameterCount = 0; foreach (var p in typeParameters) { + var bc = p.GetEffectiveBaseClass (options.Ctx); + if (!p.GetConstraints (options.Ctx).Any () /*&& (p.TypeParameterModifier & TypeParameterModifier.HasDefaultConstructorConstraint) == 0*/) continue; if (typeParameterCount != 0) @@ -314,12 +331,14 @@ namespace MonoDevelop.CSharp.Refactoring result.Append (p.Name); result.Append (" : "); int constraintCount = 0; - // if ((p.TypeParameterModifier & TypeParameterModifier.HasDefaultConstructorConstraint) != 0) { // result.Append ("new ()"); // constraintCount++; // } + foreach (var c in p.GetConstraints (options.Ctx)) { + if (c == SharedTypes.UnknownType) + continue; if (constraintCount != 0) result.Append (", "); constraintCount++; @@ -332,6 +351,7 @@ namespace MonoDevelop.CSharp.Refactoring result.Append ("class"); continue; } + AppendReturnType (result, options.ImplementingType, c); } } |