Browse Source

Merge some bugfixes from SharpDevelop to NRefactory.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
ca103100c6
  1. 11
      ICSharpCode.NRefactory.CSharp/Analysis/ReachabilityAnalysis.cs
  2. 9
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ParameterCanBeDemotedIssue/ParameterCanBeDemotedIssue.cs
  4. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/UnreachableCodeIssue.cs
  5. 13
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs
  6. 6
      ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs
  7. 3
      ICSharpCode.NRefactory/TypeSystem/InheritanceHelper.cs
  8. 2
      ICSharpCode.NRefactory/Utils/LazyInit.cs

11
ICSharpCode.NRefactory.CSharp/Analysis/ReachabilityAnalysis.cs

@ -56,10 +56,13 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -56,10 +56,13 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
if (controlFlowGraph == null)
throw new ArgumentNullException("controlFlowGraph");
ReachabilityAnalysis ra = new ReachabilityAnalysis();
ra.stack.Push(controlFlowGraph[0]);
while (ra.stack.Count > 0) {
cancellationToken.ThrowIfCancellationRequested();
ra.MarkReachable(ra.stack.Pop());
// Analysing a null node can result in an empty control flow graph
if (controlFlowGraph.Count > 0) {
ra.stack.Push(controlFlowGraph[0]);
while (ra.stack.Count > 0) {
cancellationToken.ThrowIfCancellationRequested();
ra.MarkReachable(ra.stack.Pop());
}
}
ra.stack = null;
ra.visitedNodes = null;

9
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs

@ -129,11 +129,6 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -129,11 +129,6 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return newVariableDeclarationStatement;
}
List<Type> scopeContainers = new List<Type>() {
typeof (MethodDeclaration),
typeof (Accessor)
};
AstNode FindCurrentScopeEntryNode(Statement startNode)
{
// Start one node up in the tree, otherwise we may stop at the BlockStatement
@ -143,9 +138,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -143,9 +138,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
do {
lastNode = currentNode;
currentNode = currentNode.Parent;
if (scopeContainers.Contains(currentNode.GetType()))
if (currentNode == null)
return null;
} while (currentNode.GetType() != typeof(BlockStatement));
} while (!(currentNode is BlockStatement));
return lastNode;
}
#endregion

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ParameterCanBeDemotedIssue/ParameterCanBeDemotedIssue.cs

@ -119,6 +119,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -119,6 +119,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
void ProcessParameter(ParameterDeclaration parameter, AstNode rootResolutionNode, TypeCriteriaCollector collector)
{
var localResolveResult = ctx.Resolve(parameter) as LocalResolveResult;
if (localResolveResult == null)
return;
var variable = localResolveResult.Variable;
var typeKind = variable.Type.Kind;
if (!(typeKind == TypeKind.Class ||

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/UnreachableCodeIssue.cs

@ -118,6 +118,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -118,6 +118,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
public static void Collect (GatherVisitor visitor, BlockStatement body)
{
if (body.IsNull)
return;
var reachability = visitor.ctx.CreateReachabilityAnalysis (body);
var collector = new StatementIssueCollector (visitor, reachability);

13
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs

@ -136,6 +136,19 @@ class A @@ -136,6 +136,19 @@ class A
});
");
}
[Test]
public void IgnoresDeclarationDirectlyInConstructorBody()
{
TestWrongContext<MoveToOuterScopeAction>(@"
class A
{
public A()
{
int $i = 2;
}
}");
}
}
}

6
ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs

@ -270,17 +270,17 @@ namespace ICSharpCode.NRefactory.Editor @@ -270,17 +270,17 @@ namespace ICSharpCode.NRefactory.Editor
void IDocument.Insert(int offset, ITextSource text)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
void IDocument.Insert(int offset, ITextSource text, AnchorMovementType defaultAnchorMovementType)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
void IDocument.Replace(int offset, int length, ITextSource newText)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
void IDocument.StartUndoableAction()

3
ICSharpCode.NRefactory/TypeSystem/InheritanceHelper.cs

@ -99,6 +99,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -99,6 +99,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (derivedType == null)
throw new ArgumentNullException("derivedType");
if (baseMember.Compilation != derivedType.Compilation)
throw new ArgumentException("baseMember and derivedType must be from the same compilation");
baseMember = baseMember.MemberDefinition;
bool includeInterfaces = baseMember.DeclaringTypeDefinition.Kind == TypeKind.Interface;
IMethod method = baseMember as IMethod;

2
ICSharpCode.NRefactory/Utils/LazyInit.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Utils @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Utils
}
/// <summary>
/// Atomatically performs the following operation:
/// Atomically performs the following operation:
/// - If target is null: stores newValue in target and returns newValue.
/// - If target is not null: returns target.
/// </summary>

Loading…
Cancel
Save