1
// RedundantConstructorIssue.cs
4
// Ji Kun <jikun.nus@gmail.com>
6
// Copyright (c) 2013 Ji Kun
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SaHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
using System.Collections.Generic;
28
using ICSharpCode.NRefactory.CSharp.Resolver;
29
using ICSharpCode.NRefactory.Semantics;
30
using ICSharpCode.NRefactory.TypeSystem;
32
namespace ICSharpCode.NRefactory.CSharp.Refactoring
34
[IssueDescription("Constructor in Abstract Class should not be public",
35
Description = "Constructor in Abstract Class should not be public",
36
Category = IssueCategories.CompilerErrors,
37
Severity = Severity.Suggestion,
38
ResharperDisableKeyword = "PublicConstructorInAbstractClass",
39
IssueMarker = IssueMarker.Underline)]
40
public class PublicConstructorInAbstractClassIssue : ICodeIssueProvider
42
public IEnumerable<CodeIssue> GetIssues(BaseRefactoringContext context)
44
var unit = context.RootNode as SyntaxTree;
46
return Enumerable.Empty<CodeIssue>();
47
return new GatherVisitor(context).GetIssues();
50
class GatherVisitor : GatherVisitorBase<PublicConstructorInAbstractClassIssue>
53
public GatherVisitor(BaseRefactoringContext ctx)
58
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
60
if (!typeDeclaration.HasModifier(Modifiers.Abstract)) {
63
foreach (var constructor in typeDeclaration.Children.OfType<ConstructorDeclaration>()){
64
VisitConstructorDeclaration(constructor);
68
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
70
if (constructorDeclaration.HasModifier (Modifiers.Public)) {
71
AddIssue(constructorDeclaration.NameToken, ctx.TranslateString("Convert public to protected"), script =>
72
script.Replace(constructorDeclaration.ModifierTokens.First (t => t.Modifier == Modifiers.Public), new CSharpModifierToken(TextLocation.Empty, Modifiers.Protected)));