Browse Source

ValueParameterUnusedIssue: highlight only the 'get'/'set'/'add'/'remove' keyword, not the whole accessor body

pull/32/merge
Daniel Grunwald 13 years ago
parent
commit
a567138c23
  1. 16
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/Accessor.cs
  2. 6
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertToInitializer/StatementsToInitializerConverter.cs
  3. 9
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ValueParameterUnusedIssue.cs

16
ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/Accessor.cs

@ -71,6 +71,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,6 +71,22 @@ namespace ICSharpCode.NRefactory.CSharp
get { return EntityType.Method; }
}
/// <summary>
/// Gets the 'get'/'set'/'add'/'remove' keyword
/// </summary>
public CSharpTokenNode Keyword {
get {
for (AstNode child = this.FirstChild; child != null; child = child.NextSibling) {
if (child.Role == PropertyDeclaration.GetKeywordRole || child.Role == PropertyDeclaration.SetKeywordRole
|| child.Role == CustomEventDeclaration.AddKeywordRole || child.Role == CustomEventDeclaration.RemoveKeywordRole)
{
return (CSharpTokenNode)child;
}
}
return CSharpTokenNode.Null;
}
}
public BlockStatement Body {
get { return GetChildByRole (Roles.Body); }
set { SetChildByRole (Roles.Body, value); }

6
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertToInitializer/StatementsToInitializerConverter.cs

@ -416,10 +416,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -416,10 +416,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
return
from n in node.DescendantsAndSelf
from annotation in n.Annotations
let replacementAnnotation = annotation as ReplacementNodeAnnotation
where replacementAnnotation != null
select replacementAnnotation;
from replacementAnnotation in n.Annotations.OfType<ReplacementNodeAnnotation>()
select replacementAnnotation;
}
public static IList<AstNode> GetReplacedNodes(AstNode expression)

9
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ValueParameterUnusedIssue.cs

@ -51,12 +51,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -51,12 +51,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
{
FindIssuesInNode(indexerDeclaration.Setter, indexerDeclaration.Setter.Body);
FindIssuesInAccessor(indexerDeclaration.Setter);
}
public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
{
FindIssuesInNode(propertyDeclaration.Setter, propertyDeclaration.Setter.Body);
FindIssuesInAccessor(propertyDeclaration.Setter);
}
public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
@ -70,8 +70,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -70,8 +70,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
FindIssuesInNode(removeAccessor, removeAccessor.Body, "remove accessor");
}
void FindIssuesInNode(AstNode anchor, BlockStatement body, string accessorName = "setter")
void FindIssuesInAccessor(Accessor accessor, string accessorName = "setter")
{
var body = accessor.Body;
if (!IsEligible(body))
return;
@ -90,7 +91,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -90,7 +91,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
if(!referenceFound)
AddIssue(anchor, ctx.TranslateString("The " + accessorName + " does not use the 'value' parameter"));
AddIssue(accessor.Keyword, ctx.TranslateString("The " + accessorName + " does not use the 'value' parameter"));
}
static bool IsEligible(BlockStatement body)

Loading…
Cancel
Save