Skip to content

Commit

Permalink
Merge branch 'upstream_master'
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-kallen committed Jan 2, 2014
2 parents 0640c66 + 5a69aa8 commit cedb33a
Show file tree
Hide file tree
Showing 65 changed files with 2,339 additions and 1,091 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)

yield return new CodeAction(context.TranslateString("Convert to auto property"), script => {
script.Rename((IEntity)field, newProperty.Name);
script.Remove (context.RootNode.GetNodeAt<FieldDeclaration> (field.Region.Begin));
var oldField = context.RootNode.GetNodeAt<FieldDeclaration>(field.Region.Begin);
if (oldField.Variables.Count == 1) {
script.Remove(oldField);
} else {
var newField = (FieldDeclaration)oldField.Clone();
foreach (var init in newField.Variables) {
if (init.Name == field.Name) {
init.Remove();
break;
}
}
script.Replace(oldField, newField);
}
script.Replace (property, newProperty);
}, property.NameToken);
}
Expand Down Expand Up @@ -135,6 +147,9 @@ internal static IField ScanSetter (BaseRefactoringContext context, PropertyDecla
var assignment = setAssignment != null ? setAssignment.Expression as AssignmentExpression : null;
if (assignment == null || assignment.Operator != AssignmentOperatorType.Assign)
return null;
var idExpr = assignment.Right as IdentifierExpression;
if (idExpr == null || idExpr.Identifier != "value")
return null;
if (!IsPossibleExpression(assignment.Left))
return null;
var result = context.Resolve (assignment.Left);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
format.Append('"');
if (verbatim)
format.Insert(0, '@');
formatLiteral.LiteralValue = format.ToString();
formatLiteral.SetValue(format.ToString(), format.ToString());
if (arguments.Count > 0)
script.Replace(expr, formatInvocation);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
return;
CheckParameters (method,
method.DeclaringType.GetMethods(m =>
m.Name == method.Name).Cast<IParameterizedMember>().ToList(),
m.Name == method.Name && m.TypeParameters.Count == method.TypeParameters.Count).Cast<IParameterizedMember>().ToList(),
methodDeclaration.Parameters.ToList()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)

void VisitParameterizedEntityDeclaration(string memberType, EntityDeclaration entityDeclaration, AstNodeCollection<ParameterDeclaration> parameters)
{
// Ignore explicit interface implementations (those should have no optional parameters as there can't be any direct calls)
if (!entityDeclaration.GetChildByRole(EntityDeclaration.PrivateImplementationTypeRole).IsNull)
return;
//Override is not strictly necessary because methodDeclaration
//might still implement an interface member
var memberResolveResult = ctx.Resolve(entityDeclaration) as MemberResolveResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[IssueDescription (
"Check if a namespace corresponds to a file location",
Description = "Check if a namespace corresponds to a file location",
"Possible assignment to readonly field",
Description = "Check if a readonly field is used as assignment target",
Category = IssueCategories.CodeQualityIssues,
Severity = Severity.Warning,
AnalysisDisableKeyword = "PossibleAssignmentToReadonlyField")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[IssueDescription(
"Redundant explicit size in array creation",
Description = "Redundant explicit size in array creation",
"Redundant explicit type in array creation",
Description = "Redundant explicit type in array creation",
Category = IssueCategories.RedundanciesInCode,
Severity = Severity.Warning,
AnalysisDisableKeyword = "RedundantExplicitArrayCreation")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[IssueDescription("Redundant 'object.ToString()' call for value types",
Description = "Finds calls to ToString() which would be generated automatically by the compiler.",
Description = "Finds value type calls to ToString() which would be generated automatically by the compiler.",
Category = IssueCategories.RedundanciesInCode,
Severity = Severity.Hint)]
public class RedundantToStringCallForValueTypesIssue : GatherVisitorCodeIssueProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,27 +473,28 @@ void TransformBody(List<InvocationExpression> validInvocations, bool isVoid, boo
var awaitedExpression = new UnaryOperatorExpression(UnaryOperatorType.Await, target);
var replacements = new List<Statement>();
var lambdaExpression = originalInvocation.Arguments.First();
var continuationLambdaResolveResult = ctx.Resolve(lambdaExpression) as LambdaResolveResult;
var continuationLambdaResolveResult = (LambdaResolveResult) ctx.Resolve(lambdaExpression);

if (!continuationLambdaResolveResult.HasParameterList ||
!continuationLambdaResolveResult.Parameters.First().Type.IsParameterized)
if (!continuationLambdaResolveResult.HasParameterList)
{
//Either precedent is of type Task or the result is not used
//Lambda has no parameter, so creating a variable for the argument is not needed
// (since you can't use an argument that doesn't exist).
replacements.Add(new ExpressionStatement(awaitedExpression));
} else {
//Precedent is of type Task<T>
var lambdaParameter = continuationLambdaResolveResult.Parameters.First();
var precedentTaskType = lambdaParameter.Type;
var precedentResultType = precedentTaskType.TypeArguments.First();
//Lambda has a parameter, which can either be a Task or a Task<T>.

//We might need to separate the task creation and awaiting
var taskIdentifiers = lambdaExpression.Descendants.OfType<IdentifierExpression>().Where(identifier => {
var lambdaParameter = continuationLambdaResolveResult.Parameters[0];
bool isTaskIdentifierUsed = lambdaExpression.Descendants.OfType<IdentifierExpression>().Any(identifier => {
if (identifier.Identifier != lambdaParameter.Name)
return false;
var identifierMre = identifier.Parent as MemberReferenceExpression;
return identifierMre == null || identifierMre.MemberName != "Result";
});
if (taskIdentifiers.Any()) {

var precedentTaskType = lambdaParameter.Type;

//We might need to separate the task creation and awaiting
if (isTaskIdentifierUsed) {
//Create new task variable
var taskExpression = awaitedExpression.Expression;
taskExpression.Detach();
Expand All @@ -503,7 +504,14 @@ void TransformBody(List<InvocationExpression> validInvocations, bool isVoid, boo
awaitedExpression.Expression = new IdentifierExpression(effectiveTaskName);
}

replacements.Add(new VariableDeclarationStatement(CreateShortType(originalInvocation, precedentResultType), resultName, awaitedExpression));
if (precedentTaskType.IsParameterized) {
//precedent is Task<T>
var precedentResultType = precedentTaskType.TypeArguments.First();
replacements.Add(new VariableDeclarationStatement(CreateShortType(originalInvocation, precedentResultType), resultName, awaitedExpression));
} else {
//precedent is Task
replacements.Add(awaitedExpression);
}
}

var parentStatement = continuation.GetParent<Statement>();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@
<Compile Include="CodeIssues\Uncategorized\ExplicitConversionInForEachIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ExpressionIsNeverOfProvidedTypeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\IncorrectCallToObjectGetHashCodeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\MethodOverloadHidesOptionalParameterIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\OptionalParameterCouldBeSkippedIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\RedundantAssignmentIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ResultOfAsyncCallShouldNotBeIgnoredIssue.cs" />
Expand Down
16 changes: 16 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,29 @@ public void AddChild<T> (T child, Role<T> role) where T : AstNode
if (child == null || child.IsNull)
return;
ThrowIfFrozen();
if (child == this)
throw new ArgumentException ("Cannot add a node to itself as a child.", "child");
if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child");
if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child");
AddChildUnsafe (child, role);
}

public void AddChildWithExistingRole (AstNode child)
{
if (child == null || child.IsNull)
return;
ThrowIfFrozen();
if (child == this)
throw new ArgumentException ("Cannot add a node to itself as a child.", "child");
if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child");
if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child");
AddChildUnsafe (child, child.Role);
}

/// <summary>
/// Adds a child without performing any safety checks.
/// </summary>
Expand Down
45 changes: 45 additions & 0 deletions ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,50 @@ public static int GetModifierLength(Modifiers modifier)
throw new NotSupportedException("Invalid value for Modifiers");
}
}

public static Modifiers GetModifierValue(string modifier)
{
switch (modifier) {
case "private":
return Modifiers.Private;
case "internal":
return Modifiers.Internal;
case "protected":
return Modifiers.Protected;
case "public":
return Modifiers.Public;
case "abstract":
return Modifiers.Abstract;
case "virtual":
return Modifiers.Virtual;
case "sealed":
return Modifiers.Sealed;
case "static":
return Modifiers.Static;
case "override":
return Modifiers.Override;
case "readonly":
return Modifiers.Readonly;
case "const":
return Modifiers.Const;
case "new":
return Modifiers.New;
case "partial":
return Modifiers.Partial;
case "extern":
return Modifiers.Extern;
case "volatile":
return Modifiers.Volatile;
case "unsafe":
return Modifiers.Unsafe;
case "async":
return Modifiers.Async;
case "any":
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
return Modifiers.Any;
default:
throw new NotSupportedException("Invalid value for Modifiers");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// NullReferenceExpression.cs
//
//
// Author:
// Mike Krüger <[email protected]>
//
Expand Down Expand Up @@ -38,6 +38,12 @@ public override TextLocation StartLocation {
}
}

internal void SetStartLocation(TextLocation value)
{
ThrowIfFrozen();
this.location = value;
}

public override TextLocation EndLocation {
get {
return new TextLocation (location.Line, location.Column + "null".Length);
Expand All @@ -57,7 +63,7 @@ public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitNullReferenceExpression (this);
}

public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitNullReferenceExpression (this);
Expand Down
Loading

0 comments on commit cedb33a

Please sign in to comment.