70 changed files with 3278 additions and 2232 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@ |
|||||||
|
//
|
||||||
|
// CodeAction.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
public class CodeAction |
||||||
|
{ |
||||||
|
public string Description { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public Action<Script> Run { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public CodeAction (string description, Action<Script> action) |
||||||
|
{ |
||||||
|
if (action == null) { |
||||||
|
throw new ArgumentNullException ("action"); |
||||||
|
} |
||||||
|
if (description == null) { |
||||||
|
throw new ArgumentNullException ("description"); |
||||||
|
} |
||||||
|
Description = description; |
||||||
|
Run = action; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,76 @@ |
|||||||
|
//
|
||||||
|
// CreateBackingStore.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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.Collections.Generic; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[ContextAction("Create backing store for auto property", Description = "Creates a backing field for an auto property.")] |
||||||
|
public class CreateBackingStore : ICodeActionProvider |
||||||
|
{ |
||||||
|
public IEnumerable<CodeAction> GetActions(RefactoringContext context) |
||||||
|
{ |
||||||
|
var property = context.GetNode<PropertyDeclaration>(); |
||||||
|
if (!(property != null && |
||||||
|
!property.Getter.IsNull && !property.Setter.IsNull && // automatic properties always need getter & setter
|
||||||
|
property.Getter.Body.IsNull && |
||||||
|
property.Setter.Body.IsNull)) { |
||||||
|
yield break; |
||||||
|
} |
||||||
|
|
||||||
|
yield return new CodeAction (context.TranslateString("Add null check for parameter"), script => { |
||||||
|
string backingStoreName = context.GetNameProposal (property.Name); |
||||||
|
|
||||||
|
// create field
|
||||||
|
var backingStore = new FieldDeclaration (); |
||||||
|
backingStore.ReturnType = property.ReturnType.Clone (); |
||||||
|
|
||||||
|
var initializer = new VariableInitializer (backingStoreName); |
||||||
|
backingStore.Variables.Add (initializer); |
||||||
|
|
||||||
|
// create new property & implement the get/set bodies
|
||||||
|
var newProperty = (PropertyDeclaration)property.Clone (); |
||||||
|
Expression id1; |
||||||
|
if (backingStoreName == "value") |
||||||
|
id1 = new ThisReferenceExpression().Member("value"); |
||||||
|
else |
||||||
|
id1 = new IdentifierExpression (backingStoreName); |
||||||
|
Expression id2 = id1.Clone(); |
||||||
|
newProperty.Getter.Body = new BlockStatement () { |
||||||
|
new ReturnStatement (id1) |
||||||
|
}; |
||||||
|
newProperty.Setter.Body = new BlockStatement () { |
||||||
|
new AssignmentExpression (id2, AssignmentOperatorType.Assign, new IdentifierExpression ("value")) |
||||||
|
}; |
||||||
|
|
||||||
|
script.Replace (property, newProperty); |
||||||
|
script.InsertBefore (property, backingStore); |
||||||
|
script.Link (initializer, id1, id2); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,112 @@ |
|||||||
|
//
|
||||||
|
// CreateEventInvocator.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using System.Threading; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[ContextAction("Create event invocator", Description = "Creates a standard OnXXX event method.")] |
||||||
|
public class CreateEventInvocator : ICodeActionProvider |
||||||
|
{ |
||||||
|
public IEnumerable<CodeAction> GetActions(RefactoringContext context) |
||||||
|
{ |
||||||
|
VariableInitializer initializer; |
||||||
|
var eventDeclaration = GetEventDeclaration(context, out initializer); |
||||||
|
if (eventDeclaration == null) { |
||||||
|
yield break; |
||||||
|
} |
||||||
|
var type = (TypeDeclaration)eventDeclaration.Parent; |
||||||
|
if (type.Members.Any(m => m is MethodDeclaration && ((MethodDeclaration)m).Name == "On" + initializer.Name)) { |
||||||
|
yield break; |
||||||
|
} |
||||||
|
var resolvedType = context.Resolve(eventDeclaration.ReturnType).Type; |
||||||
|
if (resolvedType.Kind == TypeKind.Unknown) { |
||||||
|
yield break; |
||||||
|
} |
||||||
|
var invokeMethod = resolvedType.GetDelegateInvokeMethod(); |
||||||
|
if (invokeMethod == null) { |
||||||
|
yield break; |
||||||
|
} |
||||||
|
yield return new CodeAction (context.TranslateString("Create event invocator"), script => { |
||||||
|
bool hasSenderParam = false; |
||||||
|
IEnumerable<IParameter> pars = invokeMethod.Parameters; |
||||||
|
if (invokeMethod.Parameters.Any ()) { |
||||||
|
var first = invokeMethod.Parameters [0]; |
||||||
|
if (first.Name == "sender" /*&& first.Type == "System.Object"*/) { |
||||||
|
hasSenderParam = true; |
||||||
|
pars = invokeMethod.Parameters.Skip (1); |
||||||
|
} |
||||||
|
} |
||||||
|
const string handlerName = "handler"; |
||||||
|
|
||||||
|
var arguments = new List<Expression> (); |
||||||
|
if (hasSenderParam) |
||||||
|
arguments.Add (new ThisReferenceExpression ()); |
||||||
|
foreach (var par in pars) |
||||||
|
arguments.Add (new IdentifierExpression (par.Name)); |
||||||
|
|
||||||
|
var methodDeclaration = new MethodDeclaration () { |
||||||
|
Name = "On" + initializer.Name, |
||||||
|
ReturnType = new PrimitiveType ("void"), |
||||||
|
Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Protected | ICSharpCode.NRefactory.CSharp.Modifiers.Virtual, |
||||||
|
Body = new BlockStatement () { |
||||||
|
new VariableDeclarationStatement (eventDeclaration.ReturnType.Clone (), handlerName, new MemberReferenceExpression (new ThisReferenceExpression (), initializer.Name)), |
||||||
|
new IfElseStatement () { |
||||||
|
Condition = new BinaryOperatorExpression (new IdentifierExpression (handlerName), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), |
||||||
|
TrueStatement = new ExpressionStatement (new InvocationExpression (new IdentifierExpression (handlerName), arguments)) |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
foreach (var par in pars) { |
||||||
|
var typeName = context.CreateShortType (par.Type); |
||||||
|
var decl = new ParameterDeclaration (typeName, par.Name); |
||||||
|
methodDeclaration.Parameters.Add (decl); |
||||||
|
} |
||||||
|
|
||||||
|
script.InsertWithCursor (context.TranslateString("Create event invocator"), methodDeclaration, Script.InsertPosition.After); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static EventDeclaration GetEventDeclaration (RefactoringContext context, out VariableInitializer initializer) |
||||||
|
{ |
||||||
|
var result = context.GetNode<EventDeclaration> (); |
||||||
|
if (result == null) { |
||||||
|
initializer = null; |
||||||
|
return null; |
||||||
|
} |
||||||
|
initializer = result.Variables.FirstOrDefault (v => v.NameToken.Contains (context.Location)); |
||||||
|
return initializer != null ? result : null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,41 @@ |
|||||||
|
//
|
||||||
|
// IssueCategories.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp |
||||||
|
{ |
||||||
|
public class IssueCategories |
||||||
|
{ |
||||||
|
public const string Improvements = "Code Improvements"; |
||||||
|
public const string CodeQualityIssues = "Code Quality Issues"; |
||||||
|
public const string ConstraintViolations = "Constraint Violations"; |
||||||
|
public const string Redundancies = "Redundancies"; |
||||||
|
public const string Opportunities = "Language Usage Opportunities"; |
||||||
|
public const string Notifications = "Code Notifications"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,128 @@ |
|||||||
|
//
|
||||||
|
// RedundantUsingInspector.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 ICSharpCode.NRefactory.PatternMatching; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||||
|
using System.Linq; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Finds redundant using declarations.
|
||||||
|
/// </summary>
|
||||||
|
[IssueDescription("Remove unused usings", |
||||||
|
Description = "Removes used declarations that are not required.", |
||||||
|
Category = IssueCategories.Redundancies, |
||||||
|
Severity = Severity.Hint, |
||||||
|
IssueMarker = IssueMarker.GrayOut)] |
||||||
|
public class RedundantUsingInspector : ICodeIssueProvider |
||||||
|
{ |
||||||
|
public IEnumerable<CodeIssue> GetIssues (BaseRefactoringContext context) |
||||||
|
{ |
||||||
|
var visitor = new GatherVisitor (context, this); |
||||||
|
context.RootNode.AcceptVisitor (visitor); |
||||||
|
visitor.Collect (); |
||||||
|
return visitor.FoundIssues; |
||||||
|
} |
||||||
|
|
||||||
|
class GatherVisitor : GatherVisitorBase |
||||||
|
{ |
||||||
|
readonly RedundantUsingInspector inspector; |
||||||
|
Dictionary<UsingDeclaration, bool> usingDeclarations = new Dictionary<UsingDeclaration, bool> (); |
||||||
|
|
||||||
|
Stack<List<UsingDeclaration>> usingStack = new Stack<List<UsingDeclaration>> (); |
||||||
|
|
||||||
|
public GatherVisitor (BaseRefactoringContext ctx, RedundantUsingInspector inspector) : base (ctx) |
||||||
|
{ |
||||||
|
this.inspector = inspector; |
||||||
|
usingStack.Push (new List<UsingDeclaration> ()); |
||||||
|
} |
||||||
|
|
||||||
|
public void Collect() |
||||||
|
{ |
||||||
|
foreach (var u in usingDeclarations.Where (u => !u.Value)) { |
||||||
|
var decl = u.Key; |
||||||
|
AddIssue(decl, ctx.TranslateString("Remove redundant usings"), script => { |
||||||
|
foreach (var u2 in usingDeclarations.Where (a => !a.Value)) { |
||||||
|
script.Remove (u2.Key); |
||||||
|
} |
||||||
|
} |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override void VisitUsingDeclaration(UsingDeclaration usingDeclaration) |
||||||
|
{ |
||||||
|
base.VisitUsingDeclaration(usingDeclaration); |
||||||
|
usingDeclarations [usingDeclaration] = false; |
||||||
|
usingStack.Peek().Add(usingDeclaration); |
||||||
|
} |
||||||
|
|
||||||
|
public override void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration) |
||||||
|
{ |
||||||
|
usingStack.Push(new List<UsingDeclaration> (usingStack.Peek())); |
||||||
|
base.VisitNamespaceDeclaration(namespaceDeclaration); |
||||||
|
usingStack.Pop(); |
||||||
|
} |
||||||
|
|
||||||
|
void UseNamespace(string ns) |
||||||
|
{ |
||||||
|
foreach (var u in usingStack.Peek ()) { |
||||||
|
if (u.Namespace == ns) { |
||||||
|
usingDeclarations [u] = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override void VisitIdentifierExpression(IdentifierExpression identifierExpression) |
||||||
|
{ |
||||||
|
base.VisitIdentifierExpression(identifierExpression); |
||||||
|
UseNamespace(ctx.Resolve(identifierExpression).Type.Namespace); |
||||||
|
} |
||||||
|
|
||||||
|
public override void VisitSimpleType(SimpleType simpleType) |
||||||
|
{ |
||||||
|
base.VisitSimpleType(simpleType); |
||||||
|
UseNamespace(ctx.Resolve(simpleType).Type.Namespace); |
||||||
|
} |
||||||
|
|
||||||
|
public override void VisitInvocationExpression (InvocationExpression invocationExpression) |
||||||
|
{ |
||||||
|
base.VisitInvocationExpression (invocationExpression); |
||||||
|
var mg = ctx.Resolve (invocationExpression) as CSharpInvocationResolveResult; |
||||||
|
if (mg == null || !mg.IsExtensionMethodInvocation) { |
||||||
|
return; |
||||||
|
} |
||||||
|
UseNamespace (mg.Member.DeclaringType.Namespace); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,78 +0,0 @@ |
|||||||
//
|
|
||||||
// CreateBackingStore.cs
|
|
||||||
//
|
|
||||||
// Author:
|
|
||||||
// Mike Krüger <mkrueger@novell.com>
|
|
||||||
//
|
|
||||||
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// 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.Threading; |
|
||||||
|
|
||||||
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
||||||
{ |
|
||||||
public class CreateBackingStore : IContextAction |
|
||||||
{ |
|
||||||
public bool IsValid (RefactoringContext context) |
|
||||||
{ |
|
||||||
var propertyDeclaration = context.GetNode<PropertyDeclaration> (); |
|
||||||
return propertyDeclaration != null && |
|
||||||
!propertyDeclaration.Getter.IsNull && !propertyDeclaration.Setter.IsNull && // automatic properties always need getter & setter
|
|
||||||
propertyDeclaration.Getter.Body.IsNull && |
|
||||||
propertyDeclaration.Setter.Body.IsNull; |
|
||||||
} |
|
||||||
|
|
||||||
public void Run (RefactoringContext context) |
|
||||||
{ |
|
||||||
var property = context.GetNode<PropertyDeclaration> (); |
|
||||||
|
|
||||||
string backingStoreName = context.GetNameProposal (property.Name); |
|
||||||
|
|
||||||
// create field
|
|
||||||
var backingStore = new FieldDeclaration (); |
|
||||||
backingStore.ReturnType = property.ReturnType.Clone (); |
|
||||||
|
|
||||||
var initializer = new VariableInitializer (backingStoreName); |
|
||||||
backingStore.Variables.Add (initializer); |
|
||||||
|
|
||||||
// create new property & implement the get/set bodies
|
|
||||||
var newProperty = (PropertyDeclaration)property.Clone (); |
|
||||||
Expression id1; |
|
||||||
if (backingStoreName == "value") |
|
||||||
id1 = new ThisReferenceExpression().Member("value"); |
|
||||||
else |
|
||||||
id1 = new IdentifierExpression (backingStoreName); |
|
||||||
Expression id2 = id1.Clone(); |
|
||||||
newProperty.Getter.Body = new BlockStatement () { |
|
||||||
new ReturnStatement (id1) |
|
||||||
}; |
|
||||||
newProperty.Setter.Body = new BlockStatement () { |
|
||||||
new AssignmentExpression (id2, AssignmentOperatorType.Assign, new IdentifierExpression ("value")) |
|
||||||
}; |
|
||||||
|
|
||||||
using (var script = context.StartScript ()) { |
|
||||||
script.Replace (property, newProperty); |
|
||||||
script.InsertBefore (property, backingStore); |
|
||||||
script.Link (initializer, id1, id2); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@ -1,110 +0,0 @@ |
|||||||
//
|
|
||||||
// CreateEventInvocator.cs
|
|
||||||
//
|
|
||||||
// Author:
|
|
||||||
// Mike Krüger <mkrueger@novell.com>
|
|
||||||
//
|
|
||||||
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// 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 ICSharpCode.NRefactory.TypeSystem; |
|
||||||
using System.Threading; |
|
||||||
|
|
||||||
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
||||||
{ |
|
||||||
public class CreateEventInvocator : IContextAction |
|
||||||
{ |
|
||||||
public bool IsValid (RefactoringContext context) |
|
||||||
{ |
|
||||||
VariableInitializer initializer; |
|
||||||
var eventDeclaration = GetEventDeclaration (context, out initializer); |
|
||||||
if (eventDeclaration == null) |
|
||||||
return false; |
|
||||||
var type = (TypeDeclaration)eventDeclaration.Parent; |
|
||||||
return !type.Members.Any (m => m is MethodDeclaration && ((MethodDeclaration)m).Name == "On" + initializer.Name); |
|
||||||
} |
|
||||||
|
|
||||||
public void Run (RefactoringContext context) |
|
||||||
{ |
|
||||||
VariableInitializer initializer; |
|
||||||
var eventDeclaration = GetEventDeclaration (context, out initializer); |
|
||||||
var type = context.Resolve (eventDeclaration.ReturnType).Type; |
|
||||||
if (type == null) |
|
||||||
return; |
|
||||||
var invokeMethod = type.GetDelegateInvokeMethod (); |
|
||||||
if (invokeMethod == null) |
|
||||||
return; |
|
||||||
|
|
||||||
bool hasSenderParam = false; |
|
||||||
IEnumerable<IParameter> pars = invokeMethod.Parameters; |
|
||||||
if (invokeMethod.Parameters.Any ()) { |
|
||||||
var first = invokeMethod.Parameters [0]; |
|
||||||
if (first.Name == "sender" /*&& first.Type == "System.Object"*/) { |
|
||||||
hasSenderParam = true; |
|
||||||
pars = invokeMethod.Parameters.Skip (1); |
|
||||||
} |
|
||||||
} |
|
||||||
const string handlerName = "handler"; |
|
||||||
|
|
||||||
var arguments = new List<Expression> (); |
|
||||||
if (hasSenderParam) |
|
||||||
arguments.Add (new ThisReferenceExpression ()); |
|
||||||
foreach (var par in pars) |
|
||||||
arguments.Add (new IdentifierExpression (par.Name)); |
|
||||||
|
|
||||||
var methodDeclaration = new MethodDeclaration () { |
|
||||||
Name = "On" + initializer.Name, |
|
||||||
ReturnType = new PrimitiveType ("void"), |
|
||||||
Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Protected | ICSharpCode.NRefactory.CSharp.Modifiers.Virtual, |
|
||||||
Body = new BlockStatement () { |
|
||||||
new VariableDeclarationStatement (eventDeclaration.ReturnType.Clone (), handlerName, new MemberReferenceExpression (new ThisReferenceExpression (), initializer.Name)), |
|
||||||
new IfElseStatement () { |
|
||||||
Condition = new BinaryOperatorExpression (new IdentifierExpression (handlerName), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), |
|
||||||
TrueStatement = new ExpressionStatement (new InvocationExpression (new IdentifierExpression (handlerName), arguments)) |
|
||||||
} |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
foreach (var par in pars) { |
|
||||||
var typeName = context.CreateShortType (par.Type); |
|
||||||
var decl = new ParameterDeclaration (typeName, par.Name); |
|
||||||
methodDeclaration.Parameters.Add (decl); |
|
||||||
} |
|
||||||
|
|
||||||
using (var script = context.StartScript ()) { |
|
||||||
script.InsertWithCursor ("Create event invocator", methodDeclaration, Script.InsertPosition.After); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
static EventDeclaration GetEventDeclaration (RefactoringContext context, out VariableInitializer initializer) |
|
||||||
{ |
|
||||||
var result = context.GetNode<EventDeclaration> (); |
|
||||||
if (result == null) { |
|
||||||
initializer = null; |
|
||||||
return null; |
|
||||||
} |
|
||||||
initializer = result.Variables.FirstOrDefault (v => v.NameToken.Contains (context.Location)); |
|
||||||
return initializer != null ? result : null; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@ -0,0 +1,42 @@ |
|||||||
|
//
|
||||||
|
// ProviderDescriptionAttribute.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp |
||||||
|
{ |
||||||
|
public class ContextActionAttribute : System.Attribute |
||||||
|
{ |
||||||
|
public string Title { get; private set;} |
||||||
|
public string Description { get; set; } |
||||||
|
public string Category { get; set; } |
||||||
|
|
||||||
|
public ContextActionAttribute (string title) |
||||||
|
{ |
||||||
|
Title = title; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -1,77 +0,0 @@ |
|||||||
//
|
|
||||||
// RedundantUsingInspector.cs
|
|
||||||
//
|
|
||||||
// Author:
|
|
||||||
// Mike Krüger <mkrueger@xamarin.com>
|
|
||||||
//
|
|
||||||
// Copyright (c) 2012 Xamarin <http://xamarin.com>
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// 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 ICSharpCode.NRefactory.PatternMatching; |
|
||||||
using System.Collections.Generic; |
|
||||||
using ICSharpCode.NRefactory.TypeSystem; |
|
||||||
using ICSharpCode.NRefactory.Semantics; |
|
||||||
|
|
||||||
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Finds redundant using declarations.
|
|
||||||
/// </summary>
|
|
||||||
public class RedundantUsingInspector : IInspector |
|
||||||
{ |
|
||||||
string title = "Remove redundant using"; |
|
||||||
|
|
||||||
public string Title { |
|
||||||
get { |
|
||||||
return title; |
|
||||||
} |
|
||||||
set { |
|
||||||
title = value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public IEnumerable<InspectionIssue> Run (BaseRefactoringContext context) |
|
||||||
{ |
|
||||||
var visitor = new GatherVisitor (context, this); |
|
||||||
context.RootNode.AcceptVisitor (visitor); |
|
||||||
return visitor.FoundIssues; |
|
||||||
} |
|
||||||
|
|
||||||
class GatherVisitor : GatherVisitorBase |
|
||||||
{ |
|
||||||
readonly RedundantUsingInspector inspector; |
|
||||||
|
|
||||||
public GatherVisitor (BaseRefactoringContext ctx, RedundantUsingInspector inspector) : base (ctx) |
|
||||||
{ |
|
||||||
this.inspector = inspector; |
|
||||||
} |
|
||||||
|
|
||||||
public override void VisitUsingDeclaration(UsingDeclaration usingDeclaration) |
|
||||||
{ |
|
||||||
base.VisitUsingDeclaration(usingDeclaration); |
|
||||||
// TODO
|
|
||||||
// return cSharpResolver.usedScopes
|
|
||||||
// .OfType<ITypeOrNamespaceReference> ()
|
|
||||||
// .Any (u => u.ResolveNamespace (ctx).NamespaceName == ns) || additionalNamespaces.Contains (ns);
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,50 @@ |
|||||||
|
//
|
||||||
|
// IssueAttribute.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp |
||||||
|
{ |
||||||
|
public class IssueDescriptionAttribute : System.Attribute |
||||||
|
{ |
||||||
|
public string Title { get; private set;} |
||||||
|
|
||||||
|
public string Description { get; set; } |
||||||
|
|
||||||
|
public string Category { get; set; } |
||||||
|
|
||||||
|
public Severity Severity { get; set; } |
||||||
|
|
||||||
|
public IssueMarker IssueMarker { get; set; } |
||||||
|
|
||||||
|
public IssueDescriptionAttribute (string title) |
||||||
|
{ |
||||||
|
Title = title; |
||||||
|
Severity = Severity.Suggestion; |
||||||
|
IssueMarker = IssueMarker.Underline; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,52 @@ |
|||||||
|
//
|
||||||
|
// IssueMarker.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The issue marker is used to set how an issue should be marked inside the text editor.
|
||||||
|
/// </summary>
|
||||||
|
public enum IssueMarker |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The issue is not shown inside the text editor. (But in the task bar)
|
||||||
|
/// </summary>
|
||||||
|
None, |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The region is marked as underline in the severity color.
|
||||||
|
/// </summary>
|
||||||
|
Underline, |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text is grayed out.
|
||||||
|
/// </summary>
|
||||||
|
GrayOut |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,61 @@ |
|||||||
|
//
|
||||||
|
// Severity.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The severity influences how the task bar reacts on found issues.
|
||||||
|
/// </summary>
|
||||||
|
public enum Severity |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// None means that the task bar doesn't show the issue.
|
||||||
|
/// </summary>
|
||||||
|
None, |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Errors are shown in red and that the task bar is in error state if 1 error is found.
|
||||||
|
/// </summary>
|
||||||
|
Error, |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Warnings are shown in yellow and set the task bar to warning state (if no error is found).
|
||||||
|
/// </summary>
|
||||||
|
Warning, |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Suggestions are shown in green and doesn't influence the task bar state
|
||||||
|
/// </summary>
|
||||||
|
Suggestion, |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hints are shown in blue and doesn't influence the task bar state
|
||||||
|
/// </summary>
|
||||||
|
Hint |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,133 @@ |
|||||||
|
//
|
||||||
|
// ConditionalToNullCoalescingInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ConditionalToNullCoalescingInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = str != null ? str : ""default""; |
||||||
|
} |
||||||
|
}";
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new ConditionalToNullCoalescingInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
|
||||||
|
CheckFix (context, issues [0], @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = str ?? ""default""; |
||||||
|
} |
||||||
|
}");
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestInspectorCase2 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = null != str ? str : ""default""; |
||||||
|
} |
||||||
|
}";
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new ConditionalToNullCoalescingInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
|
||||||
|
CheckFix (context, issues [0], @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = str ?? ""default""; |
||||||
|
} |
||||||
|
}");
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestInspectorCase3 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = null == str ? ""default"" : str; |
||||||
|
} |
||||||
|
}";
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new ConditionalToNullCoalescingInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
|
||||||
|
CheckFix (context, issues [0], @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = str ?? ""default""; |
||||||
|
} |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestInspectorCase4 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = str == null ? ""default"" : str; |
||||||
|
} |
||||||
|
}";
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new ConditionalToNullCoalescingInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
|
||||||
|
CheckFix (context, issues [0], @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
string c = str ?? ""default""; |
||||||
|
} |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,53 @@ |
|||||||
|
//
|
||||||
|
// InspectionActionTestBase.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
using System.Collections.Generic; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
public abstract class InspectionActionTestBase |
||||||
|
{ |
||||||
|
protected static List<CodeIssue> GetIssues (ICodeIssueProvider action, string input, out TestRefactoringContext context) |
||||||
|
{ |
||||||
|
context = TestRefactoringContext.Create (input); |
||||||
|
|
||||||
|
return new List<CodeIssue> (action.GetIssues (context)); |
||||||
|
} |
||||||
|
|
||||||
|
protected static void CheckFix (TestRefactoringContext ctx, CodeIssue issue, string expectedOutput) |
||||||
|
{ |
||||||
|
using (var script = ctx.StartScript ()) |
||||||
|
issue.Action.Run (script); |
||||||
|
Assert.AreEqual (expectedOutput, ctx.Text); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
//
|
||||||
|
// NotImplementedExceptionInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NotImplementedExceptionInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
throw new System.NotImplementedException (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new NotImplementedExceptionInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,51 @@ |
|||||||
|
//
|
||||||
|
// RedundantInternalInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RedundantInternalInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"internal class Foo
|
||||||
|
{ |
||||||
|
internal void Bar (string str) |
||||||
|
{ |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new RedundantInternalInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
//
|
||||||
|
// RedundantNamespaceUsageInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RedundantNamespaceUsageInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"using System;
|
||||||
|
class Foo |
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
System.Console.WriteLine (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new RedundantNamespaceUsageInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
//
|
||||||
|
// RedundantPrivateInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RedundantPrivateInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
private void Bar (string str) |
||||||
|
{ |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new RedundantPrivateInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
//
|
||||||
|
// RedundantThisInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RedundantThisInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
this.Bar (str); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new RedundantThisInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
//
|
||||||
|
// RedundantUsingInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RedundantUsingInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"using System;
|
||||||
|
|
||||||
|
class Foo |
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new RedundantUsingInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
//
|
||||||
|
// StringIsNullOrEmptyInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class StringIsNullOrEmptyInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (string str) |
||||||
|
{ |
||||||
|
if (str != null && str != """") |
||||||
|
; |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new StringIsNullOrEmptyInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
//
|
||||||
|
// UseVarKeywordInspectorTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Mike Krüger <mkrueger@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// 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 NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Inspector |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class UseVarKeywordInspectorTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestInspectorCase1 () |
||||||
|
{ |
||||||
|
var input = @"class Foo
|
||||||
|
{ |
||||||
|
void Bar (object o) |
||||||
|
{ |
||||||
|
Foo foo = (Foo)o; |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues (new UseVarKeywordInspector (), input, out context); |
||||||
|
Assert.AreEqual (1, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue