diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs index fbde16fec2..03da34a8f6 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PartialGenerator.cs @@ -23,12 +23,14 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; + +using System.Linq; using System.Collections.Generic; using Gtk; -using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Core; -using MonoDevelop.Ide.TypeSystem; +using System.Threading; +using ICSharpCode.NRefactory6.CSharp; +using MonoDevelop.CSharp.Refactoring; namespace MonoDevelop.CodeGeneration { @@ -76,21 +78,37 @@ namespace MonoDevelop.CodeGeneration if (type == null || Options.EnclosingMember != null) yield break; - foreach (var method in Options.EnclosingType.Methods) { - if (method.IsPartial && method.BodyRegion.IsEmpty) { + foreach (var method in Options.EnclosingType.GetMembers ().OfType<Microsoft.CodeAnalysis.IMethodSymbol> ()) { + if (method.MethodKind != Microsoft.CodeAnalysis.MethodKind.Ordinary) + continue; + if (IsEmptyPartialMethod(method)) { yield return method; } } } + static bool IsEmptyPartialMethod(Microsoft.CodeAnalysis.ISymbol member, CancellationToken cancellationToken = default(CancellationToken)) + { + var method = member as Microsoft.CodeAnalysis.IMethodSymbol; + if (method == null || method.IsDefinedInMetadata ()) + return false; + foreach (var r in method.DeclaringSyntaxReferences) { + var node = r.GetSyntax (cancellationToken) as Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax; + if (node == null) + continue; + if (node.Body != null || !node.Modifiers.Any(m => m.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.PartialKeyword))) + return false; + } + + return true; + } + + protected override IEnumerable<string> GenerateCode (List<object> includedMembers) { - var generator = Options.CreateCodeGenerator (); - generator.AutoIndent = false; - foreach (IMethod member in includedMembers) - yield return generator.CreateMemberImplementation (Options.EnclosingType, Options.EnclosingPart, member, false).Code; + foreach (Microsoft.CodeAnalysis.IMethodSymbol member in includedMembers) + yield return CSharpCodeGenerator.CreatePartialMemberImplementation (Options.DocumentContext, Options.Editor, Options.EnclosingType, Options.EnclosingPart.GetLocation (), member, false).Code; } } } } - |