Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Refactoring/CodeGenerationService.cs

Last change on this file was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 2.7 KB
Line 
1//
2// CodeGenerationService.cs
3//
4// Author:
5//       Mike KrÃŒger <mkrueger@xamarin.com>
6//
7// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
8//
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the Software is
14// furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included in
17// all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25// THE SOFTWARE.
26using System;
27using ICSharpCode.NRefactory.CSharp.Refactoring;
28using ICSharpCode.NRefactory.TypeSystem;
29
30namespace ICSharpCode.NRefactory.CSharp
31{
32  public abstract class CodeGenerationService
33  {
34    public abstract EntityDeclaration GenerateMemberImplementation(RefactoringContext context, IMember member, bool explicitImplementation);
35  }
36
37  public class DefaultCodeGenerationService : CodeGenerationService
38  {
39    public override EntityDeclaration GenerateMemberImplementation(RefactoringContext context, IMember member, bool explicitImplementation)
40    {
41      var builder = context.CreateTypeSystemAstBuilder();
42      builder.GenerateBody = true;
43      builder.ShowModifiers = false;
44      builder.ShowAccessibility = true;
45      builder.ShowConstantValues = !explicitImplementation;
46      builder.ShowTypeParameterConstraints = !explicitImplementation;
47      builder.UseCustomEvents = explicitImplementation;
48      var decl = builder.ConvertEntity(member);
49      if (explicitImplementation) {
50        decl.Modifiers = Modifiers.None;
51        decl.AddChild(builder.ConvertType(member.DeclaringType), EntityDeclaration.PrivateImplementationTypeRole);
52      } else if (member.DeclaringType.Kind == TypeKind.Interface) {
53        decl.Modifiers |= Modifiers.Public;
54      } else {
55        // Remove 'internal' modifier from 'protected internal' members if the override is in a different assembly than the member
56        if (!member.ParentAssembly.InternalsVisibleTo(context.Compilation.MainAssembly)) {
57          decl.Modifiers &= ~Modifiers.Internal;
58        }
59      }
60      return decl;
61    }
62  }
63}
64
Note: See TracBrowser for help on using the repository browser.