Browse Source

Update NRefactory to commit 1663c9a.

1663c9a Fix NamespaceDefinitionOverwritesTypeName unit test.
b6845ed Fix icsharpcode/NRefactory#385 - Can't resolve indexer with protected access modifier
16f49e7 Try to fix a namespace name lookup bug.
5aded3f Fixed bug in 'ConvertToLambdaExpressionIssue'.
61c10b1 Categorized some code issues.
2b54760 Fixed bug in 'DelegateSubtractionIssue'.
bae55fb Fixed 'IsInactiveConditionalMethod' in SemanticHighlightingVisitor.
2a7a8bb Fixed possible infinite loop.
8acf7df Fix CSharpAmbience output for classes in the global namespace.
830e7d6 Fixed bug in xmldoc issue.
df27cc6 Revert "Merged Hint & Suggestion severity. (These two are too close and"
fc6f5c7 Merged Hint & Suggestion severity. (These two are too close and doesn't really make sense to separate)
7eaf69e Fixed 'Bug 17945 - Bad 'unnecessary cast' warning'.
008b2b0 Fix potential NullReferenceException in TypeSystemAstBuilder.ConvertConstructor
b92cbff Fix potential InvalidCastException in AccessToClosureIssue.
5a31546 Fix NullReferenceException when calling GetBaseMembers() on global method.
b31436e Merge pull request icsharpcode/NRefactory#384 from DavidKarlas/master
93ab8b3 Fixing Constructor Initializer placement and new adding policies NewLineBeforeConstructorInitializerColon and NewLineAfterConstructorInitializerColon
a219cff Fixed a bug in constant value type system conversion.
5056b18 Fixed unit tests.
a31d543 Improved GetTypeForQueryVariable
f5d76b8 Removed resolveinvocationongiventarget call.
0dcf0a3 Added another work around for the query variable issue.
cdd1892 Revert "Try to use a syntactical approach for resolving lambda expressions."
ffdb464 Try to use a syntactical approach for resolving lambda expressions.
1bd7434 Added failing unit test.
be4d1c0 Improved CS0618UsageOfObsoleteMemberIssue
d20744e Set XmlResolver=null to avoid looking up external DTDs.
ff9fee2 Fix bug in AstNode.GetNodesBetween().
pull/387/merge
Daniel Grunwald 12 years ago
parent
commit
0f62dccb01
  1. 1
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  2. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CallToObjectEqualsViaBaseIssue.cs
  3. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CastExpressionOfIncompatibleTypeIssue.cs
  4. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CheckNamespaceIssue.cs
  5. 83
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0618UsageOfObsoleteMemberIssue.cs
  6. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs
  7. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs
  8. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/ExpressionIsNeverOfProvidedTypeIssue.cs
  9. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ConstantConditionIssue.cs
  10. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ParameterOnlyAssignedIssue.cs
  11. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/RedundantAssignmentIssue.cs
  12. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/UnreachableCodeIssue.cs
  13. 0
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/VariableOnlyAssignedIssue.cs
  14. 25
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/XmlDocIssue.cs
  15. 12
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/NotWorking/AccessToClosureIssues/AccessToClosureIssue.cs
  16. 14
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/CodeQuality/DelegateSubtractionIssue.cs
  17. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/CompilerWarnings/CS1573ParameterHasNoMatchingParamTagIssue.cs
  18. 5
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/Opportunities/ConvertToLambdaExpressionIssue.cs
  19. 141
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs
  20. 35
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantCastIssue.cs
  21. 5
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/DontUseLinqWhenItsVerboseAndInefficientIssue.cs
  22. 175
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/OptionalParameterCouldBeSkippedIssue.cs
  23. 23
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj
  24. 7
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/SemanticHighlightingVisitor.cs
  25. 10
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
  26. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  27. 10
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs
  28. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs
  29. 13
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_TypeMembers.cs
  30. 6
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
  31. 6
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
  32. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs
  33. 31
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
  34. 39
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
  35. 53
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  36. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/TypeSystemTests.cs
  37. 27
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Analysis/SemanticHighlightingTests.cs
  38. 9
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/AstTests.cs
  39. 32
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0029InvalidConversionIssueTests.cs
  40. 27
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0618UsageOfObsoleteMemberIssueTests.cs
  41. 20
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ConvertToLambdaExpressionIssueTests.cs
  42. 21
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/DelegateSubtractionIssueTests.cs
  43. 305
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/OptionalParameterCouldBeSkippedTests.cs
  44. 223
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantArgumentDefaultValueIssueTests.cs
  45. 44
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantCastIssueTests.cs
  46. 39
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/XmlDocIssueIssueTests.cs
  47. 33
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/MemberLookupTests.cs
  48. 18
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  49. 121
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs
  50. 3
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  51. 14
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs
  52. 31
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  53. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Documentation/XmlDocumentationProvider.cs
  54. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs
  55. 5
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/InheritanceHelper.cs
  56. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs

1
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

@ -253,7 +253,6 @@ @@ -253,7 +253,6 @@
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.NotResolvedInTextIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.ObjectCreationAsStatementIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.OperatorIsCanBeUsedIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.OptionalParameterCouldBeSkippedIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.OptionalParameterHierarchyMismatchIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.OptionalParameterRefOutIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.ParameterCanBeDeclaredWithBaseTypeIssue" />

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CallToObjectEqualsViaBaseIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CallToObjectEqualsViaBaseIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CastExpressionOfIncompatibleTypeIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CastExpressionOfIncompatibleTypeIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CheckNamespaceIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CheckNamespaceIssue.cs

83
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0618UsageOfObsoleteMemberIssue.cs

@ -104,7 +104,88 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -104,7 +104,88 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
base.VisitBinaryOperatorExpression(binaryOperatorExpression);
Check(ctx.Resolve(binaryOperatorExpression), binaryOperatorExpression.OperatorToken);
}
bool IsObsolete(EntityDeclaration entity)
{
foreach (var section in entity.Attributes) {
foreach (var attr in section.Attributes) {
var rr = ctx.Resolve(attr);
if (rr.Type.Name == "ObsoleteAttribute" && rr.Type.Namespace == "System")
return true;
}
}
return false;
}
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
if (IsObsolete(typeDeclaration))
return;
base.VisitTypeDeclaration(typeDeclaration);
}
public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
{
if (IsObsolete(methodDeclaration))
return;
base.VisitMethodDeclaration(methodDeclaration);
}
public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
{
if (IsObsolete(propertyDeclaration))
return;
base.VisitPropertyDeclaration(propertyDeclaration);
}
public override void VisitAccessor(Accessor accessor)
{
if (IsObsolete(accessor))
return;
base.VisitAccessor(accessor);
}
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
{
if (IsObsolete(indexerDeclaration))
return;
base.VisitIndexerDeclaration(indexerDeclaration);
}
public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
{
if (IsObsolete(eventDeclaration))
return;
base.VisitCustomEventDeclaration(eventDeclaration);
}
public override void VisitFieldDeclaration(FieldDeclaration fieldDeclaration)
{
if (IsObsolete(fieldDeclaration))
return;
base.VisitFieldDeclaration(fieldDeclaration);
}
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
{
if (IsObsolete(constructorDeclaration))
return;
base.VisitConstructorDeclaration(constructorDeclaration);
}
public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
{
if (IsObsolete(destructorDeclaration))
return;
base.VisitDestructorDeclaration(destructorDeclaration);
}
public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration)
{
if (IsObsolete(operatorDeclaration))
return;
base.VisitOperatorDeclaration(operatorDeclaration);
}
}
}
}

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ExpressionIsNeverOfProvidedTypeIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/ExpressionIsNeverOfProvidedTypeIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ConstantConditionIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ConstantConditionIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/ParameterOnlyAssignedIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ParameterOnlyAssignedIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/RedundantAssignmentIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/RedundantAssignmentIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/UnreachableCodeIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/UnreachableCodeIssue.cs

0
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/VariableOnlyAssignedIssue.cs → src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/VariableOnlyAssignedIssue.cs

25
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/XmlDocIssue.cs

@ -193,18 +193,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -193,18 +193,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var cref = el.Attributes.FirstOrDefault(attr => attr.Name == "cref");
if (cref == null)
break;
try {
var trctx = ctx.Resolver.TypeResolveContext;
if (member is IMember)
trctx = trctx.WithCurrentTypeDefinition(member.DeclaringTypeDefinition).WithCurrentMember((IMember)member);
if (member is ITypeDefinition)
trctx = trctx.WithCurrentTypeDefinition((ITypeDefinition)member);
var state = ctx.Resolver.GetResolverStateBefore(node);
if (state.CurrentUsingScope != null)
trctx = trctx.WithUsingScope(state.CurrentUsingScope);
var cdc = new CSharpDocumentationComment (emptySource, trctx);
var entity = cdc.ResolveCref(cref.Value);
@ -224,7 +221,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -224,7 +221,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
storedXmlComment.Clear();
}
protected virtual void VisitXmlChildren(AstNode node)
protected virtual void VisitXmlChildren(AstNode node, Action checkDocumentationAction)
{
AstNode next;
var child = node.FirstChild;
@ -233,8 +230,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -233,8 +230,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
child.AcceptVisitor(this);
child = next;
}
CheckXmlDoc(node);
checkDocumentationAction();
for (; child != null; child = next) {
// Store next to allow the loop to continue
@ -245,6 +241,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -245,6 +241,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
InvalideXmlComments();
}
protected virtual void VisitXmlChildren(AstNode node)
{
VisitXmlChildren(node, () => CheckXmlDoc(node));
}
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
VisitXmlChildren(typeDeclaration);
@ -282,12 +283,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -282,12 +283,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
public override void VisitEventDeclaration(EventDeclaration eventDeclaration)
{
VisitXmlChildren(eventDeclaration);
VisitXmlChildren(eventDeclaration, () => {
foreach (var e in eventDeclaration.Variables) {
CheckXmlDoc(e);
}
});
}
public override void VisitFieldDeclaration(FieldDeclaration fieldDeclaration)
{
VisitXmlChildren(fieldDeclaration);
VisitXmlChildren(fieldDeclaration, () => {
foreach (var e in fieldDeclaration.Variables) {
CheckXmlDoc(e);
}
});
}
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)

12
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/NotWorking/AccessToClosureIssues/AccessToClosureIssue.cs

@ -87,14 +87,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -87,14 +87,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
var variableDecl = variableInitializer.Parent as VariableDeclarationStatement;
if (variableDecl != null)
CheckVariable (((LocalResolveResult)ctx.Resolve (variableInitializer)).Variable,
CheckVariable (GetVariable(ctx.Resolve (variableInitializer)),
variableDecl.GetParent<Statement> ());
base.VisitVariableInitializer (variableInitializer);
}
public override void VisitForeachStatement (ForeachStatement foreachStatement)
{
CheckVariable (((LocalResolveResult)ctx.Resolve (foreachStatement.VariableNameToken)).Variable,
CheckVariable (GetVariable(ctx.Resolve (foreachStatement.VariableNameToken)),
foreachStatement);
base.VisitForeachStatement (foreachStatement);
}
@ -121,9 +121,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -121,9 +121,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
base.VisitParameterDeclaration (parameterDeclaration);
}
IVariable GetVariable(ResolveResult rr)
{
var lrr = rr as LocalResolveResult;
return lrr != null ? lrr.Variable : null;
}
void CheckVariable(IVariable variable, Statement env)
{
if (variable == null)
return;
if (!issueProvider.IsTargetVariable(variable))
return;

14
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/CodeQuality/DelegateSubtractionIssue.cs

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
using System.Collections.Generic;
using ICSharpCode.NRefactory.PatternMatching;
using ICSharpCode.NRefactory.Refactoring;
using ICSharpCode.NRefactory.Semantics;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -52,9 +53,16 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -52,9 +53,16 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
base.VisitBinaryOperatorExpression(binaryOperatorExpression);
if (binaryOperatorExpression.Operator != BinaryOperatorType.Subtract)
return;
var rr = ctx.Resolve(binaryOperatorExpression);
if (rr.Type.Kind == ICSharpCode.NRefactory.TypeSystem.TypeKind.Delegate)
var rr = ctx.Resolve(binaryOperatorExpression.Right);
if (rr.Type.Kind == ICSharpCode.NRefactory.TypeSystem.TypeKind.Delegate && !IsEvent (binaryOperatorExpression.Left)) {
AddIssue(new CodeIssue(binaryOperatorExpression, ctx.TranslateString("Delegate subtraction has unpredictable result")));
}
}
bool IsEvent(AstNode node)
{
var rr = ctx.Resolve(node) as MemberResolveResult;
return rr != null && rr.Member.SymbolKind == ICSharpCode.NRefactory.TypeSystem.SymbolKind.Event;
}
public override void VisitAssignmentExpression(AssignmentExpression assignmentExpression)
@ -63,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -63,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (assignmentExpression.Operator != AssignmentOperatorType.Subtract)
return;
var rr = ctx.Resolve(assignmentExpression.Right);
if (rr.Type.Kind == ICSharpCode.NRefactory.TypeSystem.TypeKind.Delegate)
if (rr.Type.Kind == ICSharpCode.NRefactory.TypeSystem.TypeKind.Delegate && !IsEvent (assignmentExpression.Left))
AddIssue(new CodeIssue(assignmentExpression, ctx.TranslateString("Delegate subtraction has unpredictable result")));
}
}

1
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/CompilerWarnings/CS1573ParameterHasNoMatchingParamTagIssue.cs

@ -128,6 +128,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -128,6 +128,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
List<Tuple<string, int>> parameters = new List<Tuple<string, int>>();
using (var reader = new XmlTextReader(new StringReader(xml.ToString()))) {
reader.XmlResolver = null;
try {
while (reader.Read()) {
if (member == null)

5
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/Opportunities/ConvertToLambdaExpressionIssue.cs

@ -57,6 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,6 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (!ConvertLambdaBodyStatementToExpressionAction.TryGetConvertableExpression(lambdaExpression.Body, out block, out expr))
return;
var node = block.Statements.FirstOrDefault() ?? block;
var expressionStatement = node as ExpressionStatement;
if (expressionStatement != null) {
if (expressionStatement.Expression is AssignmentExpression)
return;
}
var returnTypes = new List<IType>();
foreach (var type in TypeGuessing.GetValidTypes(ctx.Resolver, lambdaExpression)) {
if (type.Kind != TypeKind.Delegate)

141
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs

@ -127,4 +127,145 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -127,4 +127,145 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
}
/* TODO: Merge:
[IssueDescription("Optional argument has default value and can be skipped",
Description = "Finds calls to functions where optional parameters are used and the passed argument is the same as the default.",
Category = IssueCategories.RedundanciesInCode,
Severity = Severity.Hint)]
public class OptionalParameterCouldBeSkippedIssue : GatherVisitorCodeIssueProvider
{
protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context)
{
return new GatherVisitor(context);
}
class GatherVisitor : GatherVisitorBase<OptionalParameterCouldBeSkippedIssue>
{
static readonly object removeAllRedundantArgumentsKey = new object ();
public GatherVisitor(BaseRefactoringContext context) : base (context)
{
}
public override void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
{
base.VisitObjectCreateExpression(objectCreateExpression);
CheckMethodCall(objectCreateExpression, objectCreateExpression.Arguments,
(objectCreation, args) => new ObjectCreateExpression(objectCreation.Type.Clone(), args));
}
public override void VisitInvocationExpression(InvocationExpression invocationExpression)
{
base.VisitInvocationExpression(invocationExpression);
CheckMethodCall(invocationExpression, invocationExpression.Arguments,
(invocation, args) => new InvocationExpression(invocation.Target.Clone(), args));
}
void CheckMethodCall<T> (T node, IEnumerable<Expression> args, Func<T, IEnumerable<Expression>, T> generateReplacement) where T: AstNode
{
// The first two checks are unnecessary, but eliminates the majority of calls early,
// improving performance.
var arguments = args.ToArray();
if (arguments.Length == 0)
return;
var lastArg = arguments[arguments.Length - 1];
if (!(lastArg is PrimitiveExpression || lastArg is NamedArgumentExpression))
return;
var invocationResolveResult = ctx.Resolve(node) as CSharpInvocationResolveResult;
if (invocationResolveResult == null)
return;
string actionMessage = ctx.TranslateString("Remove redundant arguments");
var redundantArguments = GetRedundantArguments(arguments, invocationResolveResult);
var action = new CodeAction(actionMessage, script => {
var newArgumentList = arguments
.Where(arg => !redundantArguments.Contains(arg))
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}, node, removeAllRedundantArgumentsKey);
var issueMessage = ctx.TranslateString("Argument is identical to the default value");
var lastPositionalArgument = redundantArguments.FirstOrDefault(expression => !(expression is NamedArgumentExpression));
foreach (var argument in redundantArguments) {
var localArgument = argument;
var actions = new List<CodeAction>();
actions.Add(action);
if (localArgument is NamedArgumentExpression || localArgument == lastPositionalArgument) {
var title = ctx.TranslateString("Remove this argument");
actions.Add(new CodeAction(title, script => {
var newArgumentList = arguments
.Where(arg => arg != localArgument)
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}, node, null));
} else {
var title = ctx.TranslateString("Remove this and the following positional arguments");
actions.Add(new CodeAction(title, script => {
var newArgumentList = arguments
.Where(arg => arg.StartLocation < localArgument.StartLocation && !(arg is NamedArgumentExpression))
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}, node, null));
}
AddIssue(new CodeIssue(localArgument, issueMessage, actions) { IssueMarker = IssueMarker.GrayOut });
}
}
IList<Expression> GetRedundantArguments(Expression[] arguments, CSharpInvocationResolveResult invocationResolveResult)
{
var argumentToParameterMap = invocationResolveResult.GetArgumentToParameterMap();
var resolvedParameters = invocationResolveResult.Member.Parameters;
IList<Expression> redundantArguments = new List<Expression>();
for (int i = arguments.Length - 1; i >= 0; i--) {
var parameterIndex = argumentToParameterMap[i];
if (parameterIndex == -1)
// This particular parameter is an error, but keep trying the other ones
continue;
var parameter = resolvedParameters[parameterIndex];
var argument = arguments[i];
if (argument is PrimitiveExpression) {
if (parameter.IsParams)
// before positional params arguments all optional arguments are needed, otherwise some of the
// param arguments will be shifted out of the params into the fixed parameters
break;
if (!parameter.IsOptional)
// There can be no optional parameters preceding a required one
break;
var argumentResolveResult = ctx.Resolve(argument) as ConstantResolveResult;
if (argumentResolveResult == null || parameter.ConstantValue != argumentResolveResult.ConstantValue)
// Stop here since any arguments before this one has to be there
// to enable the passing of this argument
break;
redundantArguments.Add(argument);
} else if (argument is NamedArgumentExpression) {
var expression = ((NamedArgumentExpression)argument).Expression as PrimitiveExpression;
if (expression == null)
continue;
var expressionResolveResult = ctx.Resolve(expression) as ConstantResolveResult;
if (expressionResolveResult == null || parameter.ConstantValue != expressionResolveResult.ConstantValue)
// continue, since there can still be more arguments that are redundant
continue;
redundantArguments.Add(argument);
} else {
// This is a non-constant positional argument => no more redundancies are possible
break;
}
}
return redundantArguments;
}
}
}
*/
}

35
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantCastIssue.cs

@ -156,6 +156,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -156,6 +156,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return false;
}
bool IsRequiredToSelectOverload(IEnumerable<IMethod> methods, IType expectedType, int nArg)
{
// TODO: Check method accessibility & other parameter match.
int count = 0;
foreach (var method in methods) {
if (method.Parameters.Count < nArg)
continue;
var baseTypes = method.Parameters[nArg].Type.GetAllBaseTypes();
if (expectedType == method.Parameters[nArg].Type || baseTypes.Any(t => t.Equals(expectedType)))
count++;
}
return count > 1;
}
void CheckTypeCast(Expression typeCastNode, Expression expr, TextLocation castStart, TextLocation castEnd)
{
var outerTypeCastNode = typeCastNode;
@ -197,6 +211,27 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -197,6 +211,27 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
}
var mrr = ctx.Resolve(typeCastNode.Parent) as CSharpInvocationResolveResult;
if (mrr != null) {
if (mrr.Member.SymbolKind == SymbolKind.Constructor) {
int nArg = typeCastNode.Parent.Children
.Where(n => n.Role == Roles.Argument)
.TakeWhile(n => n.DescendantNodesAndSelf().All(c => c != typeCastNode))
.Count();
if (IsRequiredToSelectOverload(mrr.Member.DeclaringTypeDefinition.GetConstructors(), expectedType, nArg))
return;
} else if (mrr.Member.SymbolKind == SymbolKind.Method) {
int nArg = typeCastNode.Parent.Children
.Where(n => n.Role == Roles.Argument)
.TakeWhile(n => n.DescendantNodesAndSelf().All(c => c != typeCastNode))
.Count();
if (IsRequiredToSelectOverload(mrr.Member.DeclaringTypeDefinition.GetMethods(m => m.Name == mrr.Member.Name), expectedType, nArg))
return;
}
}
AddIssue(outerTypeCastNode, typeCastNode, expr, castStart, castEnd);
}
}

5
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/DontUseLinqWhenItsVerboseAndInefficientIssue.cs

@ -261,13 +261,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -261,13 +261,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
bool CanIndex(ITypeDefinition currentTypeDefinition, ResolveResult targetResolveResult)
{
var type = targetResolveResult.Type;
if (type is ArrayType) {
if (targetResolveResult.Type is ArrayType) {
return true;
}
var memberLookup = new MemberLookup(currentTypeDefinition, ctx.Compilation.MainAssembly);
var indexers = memberLookup.LookupIndexers(type).ToList();
var indexers = memberLookup.LookupIndexers(targetResolveResult).ToList();
return indexers.SelectMany(methodList => methodList).Any(
member => ((IProperty)member).CanGet && ((IProperty)member).Getter.Parameters.Count == 1);

175
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/OptionalParameterCouldBeSkippedIssue.cs

@ -1,175 +0,0 @@ @@ -1,175 +0,0 @@
//
// OptionalParameterCouldBeSkippedIssue.cs
//
// Author:
// Simon Lindgren <simon.n.lindgren@gmail.com>
//
// Copyright (c) 2012 Simon Lindgren
//
// 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.Collections.Generic;
using ICSharpCode.NRefactory.CSharp.Resolver;
using System.Linq;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using System;
using ICSharpCode.NRefactory.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[IssueDescription("Optional argument has default value and can be skipped",
Description = "Finds calls to functions where optional parameters are used and the passed argument is the same as the default.",
Category = IssueCategories.RedundanciesInCode,
Severity = Severity.Hint)]
public class OptionalParameterCouldBeSkippedIssue : GatherVisitorCodeIssueProvider
{
protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context)
{
return new GatherVisitor(context);
}
class GatherVisitor : GatherVisitorBase<OptionalParameterCouldBeSkippedIssue>
{
static readonly object removeAllRedundantArgumentsKey = new object ();
public GatherVisitor(BaseRefactoringContext context) : base (context)
{
}
public override void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
{
base.VisitObjectCreateExpression(objectCreateExpression);
CheckMethodCall(objectCreateExpression, objectCreateExpression.Arguments,
(objectCreation, args) => new ObjectCreateExpression(objectCreation.Type.Clone(), args));
}
public override void VisitInvocationExpression(InvocationExpression invocationExpression)
{
base.VisitInvocationExpression(invocationExpression);
CheckMethodCall(invocationExpression, invocationExpression.Arguments,
(invocation, args) => new InvocationExpression(invocation.Target.Clone(), args));
}
void CheckMethodCall<T> (T node, IEnumerable<Expression> args, Func<T, IEnumerable<Expression>, T> generateReplacement) where T: AstNode
{
// The first two checks are unnecessary, but eliminates the majority of calls early,
// improving performance.
var arguments = args.ToArray();
if (arguments.Length == 0)
return;
var lastArg = arguments[arguments.Length - 1];
if (!(lastArg is PrimitiveExpression || lastArg is NamedArgumentExpression))
return;
var invocationResolveResult = ctx.Resolve(node) as CSharpInvocationResolveResult;
if (invocationResolveResult == null)
return;
string actionMessage = ctx.TranslateString("Remove redundant arguments");
var redundantArguments = GetRedundantArguments(arguments, invocationResolveResult);
var action = new CodeAction(actionMessage, script => {
var newArgumentList = arguments
.Where(arg => !redundantArguments.Contains(arg))
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}, node, removeAllRedundantArgumentsKey);
var issueMessage = ctx.TranslateString("Argument is identical to the default value");
var lastPositionalArgument = redundantArguments.FirstOrDefault(expression => !(expression is NamedArgumentExpression));
foreach (var argument in redundantArguments) {
var localArgument = argument;
var actions = new List<CodeAction>();
actions.Add(action);
if (localArgument is NamedArgumentExpression || localArgument == lastPositionalArgument) {
var title = ctx.TranslateString("Remove this argument");
actions.Add(new CodeAction(title, script => {
var newArgumentList = arguments
.Where(arg => arg != localArgument)
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}, node, null));
} else {
var title = ctx.TranslateString("Remove this and the following positional arguments");
actions.Add(new CodeAction(title, script => {
var newArgumentList = arguments
.Where(arg => arg.StartLocation < localArgument.StartLocation && !(arg is NamedArgumentExpression))
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}, node, null));
}
AddIssue(new CodeIssue(localArgument, issueMessage, actions) { IssueMarker = IssueMarker.GrayOut });
}
}
IList<Expression> GetRedundantArguments(Expression[] arguments, CSharpInvocationResolveResult invocationResolveResult)
{
var argumentToParameterMap = invocationResolveResult.GetArgumentToParameterMap();
var resolvedParameters = invocationResolveResult.Member.Parameters;
IList<Expression> redundantArguments = new List<Expression>();
for (int i = arguments.Length - 1; i >= 0; i--) {
var parameterIndex = argumentToParameterMap[i];
if (parameterIndex == -1)
// This particular parameter is an error, but keep trying the other ones
continue;
var parameter = resolvedParameters[parameterIndex];
var argument = arguments[i];
if (argument is PrimitiveExpression) {
if (parameter.IsParams)
// before positional params arguments all optional arguments are needed, otherwise some of the
// param arguments will be shifted out of the params into the fixed parameters
break;
if (!parameter.IsOptional)
// There can be no optional parameters preceding a required one
break;
var argumentResolveResult = ctx.Resolve(argument) as ConstantResolveResult;
if (argumentResolveResult == null || parameter.ConstantValue != argumentResolveResult.ConstantValue)
// Stop here since any arguments before this one has to be there
// to enable the passing of this argument
break;
redundantArguments.Add(argument);
} else if (argument is NamedArgumentExpression) {
var expression = ((NamedArgumentExpression)argument).Expression as PrimitiveExpression;
if (expression == null)
continue;
var expressionResolveResult = ctx.Resolve(expression) as ConstantResolveResult;
if (expressionResolveResult == null || parameter.ConstantValue != expressionResolveResult.ConstantValue)
// continue, since there can still be more arguments that are redundant
continue;
redundantArguments.Add(argument);
} else {
// This is a non-constant positional argument => no more redundancies are possible
break;
}
}
return redundantArguments;
}
}
}
}

23
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj

@ -303,24 +303,13 @@ @@ -303,24 +303,13 @@
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\RedundantDefaultFieldInitializerIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\RedundantOverridenMemberIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\UnusedTypeParameterIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\CallToObjectEqualsViaBaseIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\CastExpressionOfIncompatibleTypeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\CompilerErrors\CS0659OverrideEqualWithoutGetHashCode.cs" />
<Compile Include="CodeIssues\Uncategorized\CompilerErrors\CS1729TypeHasNoConstructorWithNArgumentsIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ConstantConditionIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\DisposeMethodInNonIDisposableTypeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\DuplicatedLinqToListOrArrayIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ExceptionRethrowIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ExplicitConversionInForEachIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ExpressionIsNeverOfProvidedTypeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\IncorrectCallToObjectGetHashCodeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\OptionalParameterCouldBeSkippedIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\RedundantAssignmentIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ResultOfAsyncCallShouldNotBeIgnoredIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\UnreachableCodeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\UseOfMemberOfNullReference.cs" />
<Compile Include="CodeIssues\Uncategorized\VariableOnlyAssignedIssues\ParameterOnlyAssignedIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\VariableOnlyAssignedIssues\VariableOnlyAssignedIssue.cs" />
<Compile Include="CodeActions\AddExceptionDescriptionAction.cs" />
<Compile Include="CodeIssues\Uncategorized\DontUseLinqWhenItsVerboseAndInefficientIssue.cs" />
<Compile Include="CodeActions\ConvertIfStatementToConditionalTernaryExpressionAction.cs" />
@ -384,7 +373,6 @@ @@ -384,7 +373,6 @@
<Compile Include="CodeIssues\Synced\PracticesAndImprovements\UseIsOperatorIssue.cs" />
<Compile Include="CodeIssues\Synced\CodeQuality\FormatStringProblemIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInCode\RedundantCatchClauseIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\CheckNamespaceIssue.cs" />
<Compile Include="CodeIssues\Synced\CodeQuality\PossibleMultipleEnumerationIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInCode\ConditionIsAlwaysTrueOrFalseIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\UnusedLabelIssue.cs" />
@ -428,6 +416,17 @@ @@ -428,6 +416,17 @@
<Compile Include="CodeIssues\Custom\CompilerErrors\CS0169FieldIsNeverUsedIssue.cs" />
<Compile Include="CodeIssues\Custom\StaticEventSubscriptionIssue.cs" />
<Compile Include="CodeActions\CS1105ExtensionMethodMustBeDeclaredStaticAction.cs" />
<Compile Include="CodeIssues\Custom\CompilerErrors\CS0659OverrideEqualWithoutGetHashCode.cs" />
<Compile Include="CodeIssues\Custom\CompilerErrors\CS1729TypeHasNoConstructorWithNArgumentsIssue.cs" />
<Compile Include="CodeIssues\Custom\ParameterOnlyAssignedIssue.cs" />
<Compile Include="CodeIssues\Custom\VariableOnlyAssignedIssue.cs" />
<Compile Include="CodeIssues\Custom\CallToObjectEqualsViaBaseIssue.cs" />
<Compile Include="CodeIssues\Custom\ConstantConditionIssue.cs" />
<Compile Include="CodeIssues\Custom\CheckNamespaceIssue.cs" />
<Compile Include="CodeIssues\Custom\CastExpressionOfIncompatibleTypeIssue.cs" />
<Compile Include="CodeIssues\Custom\CompilerErrors\ExpressionIsNeverOfProvidedTypeIssue.cs" />
<Compile Include="CodeIssues\Custom\RedundantAssignmentIssue.cs" />
<Compile Include="CodeIssues\Custom\UnreachableCodeIssue.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

7
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/SemanticHighlightingVisitor.cs

@ -351,10 +351,9 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -351,10 +351,9 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
{
if (member.SymbolKind != SymbolKind.Method || member.ReturnType.Kind != TypeKind.Void)
return false;
while (member.IsOverride) {
member = (IParameterizedMember)InheritanceHelper.GetBaseMember(member);
if (member == null)
return false;
foreach (var baseMember in InheritanceHelper.GetBaseMembers(member, false)) {
if (IsInactiveConditional (baseMember.Attributes))
return true;
}
return IsInactiveConditional(member.Attributes);
}

10
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -916,11 +916,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -916,11 +916,17 @@ namespace ICSharpCode.NRefactory.CSharp
return this;
}
/// <summary>
/// Returns the root nodes of all subtrees that are fully contained in the specified region.
/// </summary>
public IEnumerable<AstNode> GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn)
{
return GetNodesBetween (new TextLocation (startLine, startColumn), new TextLocation (endLine, endColumn));
}
/// <summary>
/// Returns the root nodes of all subtrees that are fully contained between <paramref name="start"/> and <paramref name="end"/> (inclusive).
/// </summary>
public IEnumerable<AstNode> GetNodesBetween (TextLocation start, TextLocation end)
{
AstNode node = this;
@ -929,11 +935,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -929,11 +935,11 @@ namespace ICSharpCode.NRefactory.CSharp
if (start <= node.StartLocation && node.EndLocation <= end) {
// Remember next before yielding node.
// This allows iteration to continue when the caller removes/replaces the node.
next = node.NextSibling;
next = node.GetNextNode();
yield return node;
} else {
if (node.EndLocation <= start) {
next = node.NextSibling;
next = node.GetNextNode();
} else {
next = node.FirstChild;
}

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -3016,7 +3016,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -3016,7 +3016,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return result.Result;
}
bool isProtectedAllowed = resolveResult is ThisResolveResult ? true : lookup.IsProtectedAccessAllowed(type);
bool isProtectedAllowed = lookup.IsProtectedAccessAllowed(resolveResult);
bool skipNonStaticMembers = (resolveResult is TypeResolveResult);
if (resolveResult is MemberResolveResult && resolvedNode is IdentifierExpression) {

10
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs

@ -450,6 +450,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -450,6 +450,16 @@ namespace ICSharpCode.NRefactory.CSharp
get;
set;
}
public NewLinePlacement NewLineBeforeConstructorInitializerColon {
get;
set;
}
public NewLinePlacement NewLineAfterConstructorInitializerColon {
get;
set;
}
// indexer
public bool SpaceBeforeIndexerDeclarationBracket { // tested

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs

@ -266,6 +266,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -266,6 +266,8 @@ namespace ICSharpCode.NRefactory.CSharp
SpaceBeforeIndexerDeclarationBracket = false,
SpaceAfterMethodCallParameterComma = true,
SpaceAfterConstructorDeclarationParameterComma = true,
NewLineBeforeConstructorInitializerColon = NewLinePlacement.NewLine,
NewLineAfterConstructorInitializerColon = NewLinePlacement.SameLine,
SpaceBeforeNewParentheses = false,
SpacesWithinNewParentheses = false,

13
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_TypeMembers.cs

@ -434,16 +434,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -434,16 +434,11 @@ namespace ICSharpCode.NRefactory.CSharp
var initializer = constructorDeclaration.Initializer;
if (!initializer.IsNull) {
ForceSpacesBefore(constructorDeclaration.ColonToken, true);
ForceSpacesAfter(constructorDeclaration.ColonToken, true);
bool popIndent = initializer.StartLocation.Line != constructorDeclaration.ColonToken.StartLocation.Line;
if (popIndent) {
curIndent.Push(IndentType.Block);
FixIndentation(initializer);
}
curIndent.Push(IndentType.Block);
PlaceOnNewLine(policy.NewLineBeforeConstructorInitializerColon, constructorDeclaration.ColonToken);
PlaceOnNewLine(policy.NewLineAfterConstructorInitializerColon, initializer);
initializer.AcceptVisitor(this);
if (popIndent)
curIndent.Pop();
curIndent.Pop();
}
if (!constructorDeclaration.Body.IsNull) {
FixOpenBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken);

6
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs

@ -187,8 +187,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -187,8 +187,10 @@ namespace ICSharpCode.NRefactory.CSharp
WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, writer, formattingPolicy);
writer.WriteToken(Roles.Dot, ".");
} else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) == ConversionFlags.UseFullyQualifiedEntityNames) {
WriteQualifiedName(typeDef.Namespace, writer, formattingPolicy);
writer.WriteToken(Roles.Dot, ".");
if (!string.IsNullOrEmpty(typeDef.Namespace)) {
WriteQualifiedName(typeDef.Namespace, writer, formattingPolicy);
writer.WriteToken(Roles.Dot, ".");
}
}
writer.WriteIdentifier(node.NameToken);
if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList) {

6
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs

@ -855,7 +855,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -855,7 +855,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
ConstructorDeclaration decl = new ConstructorDeclaration();
decl.Modifiers = GetMemberModifiers(ctor);
decl.Name = ctor.DeclaringTypeDefinition.Name;
if (ctor.DeclaringTypeDefinition != null)
decl.Name = ctor.DeclaringTypeDefinition.Name;
foreach (IParameter p in ctor.Parameters) {
decl.Parameters.Add(ConvertParameter(p));
}
@ -866,7 +867,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -866,7 +867,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
DestructorDeclaration ConvertDestructor(IMethod dtor)
{
DestructorDeclaration decl = new DestructorDeclaration();
decl.Name = dtor.DeclaringTypeDefinition.Name;
if (dtor.DeclaringTypeDefinition != null)
decl.Name = dtor.DeclaringTypeDefinition.Name;
decl.Body = GenerateBodyBlock();
return decl;
}

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs

@ -2196,7 +2196,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -2196,7 +2196,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
// §7.6.6.2 Indexer access
MemberLookup lookup = CreateMemberLookup();
var indexers = lookup.LookupIndexers(target.Type);
var indexers = lookup.LookupIndexers(target);
if (arguments.Any(a => a.Type.Kind == TypeKind.Dynamic)) {
// If we have dynamic arguments, we need to represent the invocation as a dynamic invocation if there is more than one applicable indexer.

31
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs

@ -47,9 +47,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -47,9 +47,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
#endregion
ITypeDefinition currentTypeDefinition;
IAssembly currentAssembly;
bool isInEnumMemberInitializer;
readonly ITypeDefinition currentTypeDefinition;
readonly IAssembly currentAssembly;
readonly bool isInEnumMemberInitializer;
public MemberLookup(ITypeDefinition currentTypeDefinition, IAssembly currentAssembly, bool isInEnumMemberInitializer = false)
{
@ -59,9 +59,21 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -59,9 +59,21 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
#region IsAccessible
/// <summary>
/// Gets whether access to protected instance members of the target expression is possible.
/// </summary>
public bool IsProtectedAccessAllowed(ResolveResult targetResolveResult)
{
return targetResolveResult is ThisResolveResult || IsProtectedAccessAllowed(targetResolveResult.Type);
}
/// <summary>
/// Gets whether access to protected instance members of the target type is possible.
/// </summary>
/// <remarks>
/// This method does not consider the special case of the 'base' reference. If possible, use the
/// <c>IsProtectedAccessAllowed(ResolveResult)</c> overload instead.
/// </remarks>
public bool IsProtectedAccessAllowed(IType targetType)
{
if (targetType.Kind == TypeKind.TypeParameter)
@ -151,7 +163,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -151,7 +163,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
throw new ArgumentNullException("targetResolveResult");
bool targetIsTypeParameter = targetResolveResult.Type.Kind == TypeKind.TypeParameter;
bool allowProtectedAccess = (targetResolveResult is ThisResolveResult || IsProtectedAccessAllowed(targetResolveResult.Type));
bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult);
// maps the member name to the list of lookup groups
var lookupGroupDict = new Dictionary<string, List<LookupGroup>>();
@ -332,7 +344,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -332,7 +344,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
bool targetIsTypeParameter = targetResolveResult.Type.Kind == TypeKind.TypeParameter;
bool allowProtectedAccess = (targetResolveResult is ThisResolveResult || IsProtectedAccessAllowed(targetResolveResult.Type));
bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult);
Predicate<ITypeDefinition> nestedTypeFilter = delegate(ITypeDefinition entity) {
return entity.Name == name && IsAccessible(entity, allowProtectedAccess);
};
@ -399,12 +411,13 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -399,12 +411,13 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// <summary>
/// Looks up the indexers on the target type.
/// </summary>
public IList<MethodListWithDeclaringType> LookupIndexers(IType targetType)
public IList<MethodListWithDeclaringType> LookupIndexers(ResolveResult targetResolveResult)
{
if (targetType == null)
throw new ArgumentNullException("targetType");
if (targetResolveResult == null)
throw new ArgumentNullException("targetResolveResult");
bool allowProtectedAccess = IsProtectedAccessAllowed(targetType);
IType targetType = targetResolveResult.Type;
bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult);
Predicate<IUnresolvedProperty> filter = p => p.IsIndexer;
List<LookupGroup> lookupGroups = new List<LookupGroup>();

39
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

@ -573,8 +573,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -573,8 +573,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
CSharpResolver previousResolver = resolver;
try {
var nsName = namespaceDeclaration.NamespaceName;
AstNode child = namespaceDeclaration.FirstChild;
for (; child != null && child.Role != Roles.LBrace; child = child.NextSibling) {
Scan(child);
}
if (unresolvedFile != null) {
resolver = resolver.WithCurrentUsingScope(unresolvedFile.GetUsingScope(namespaceDeclaration.StartLocation).Resolve(resolver.Compilation));
} else {
// string fileName = namespaceDeclaration.GetRegion().FileName ?? string.Empty;
// Fetch parent using scope
@ -599,7 +607,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -599,7 +607,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
ApplyVisitorToUsings(cv, namespaceDeclaration.Children);
PushUsingScope(usingScope);
}
ScanChildren(namespaceDeclaration);
for (; child != null; child = child.NextSibling) {
Scan(child);
}
// merge undecided lambdas before leaving the using scope so that
// the resolver can make better use of its cache
MergeUndecidedLambdas();
@ -1790,7 +1801,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1790,7 +1801,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
return false;
}
static NameLookupMode GetNameLookupMode(Expression expr)
{
InvocationExpression ie = expr.Parent as InvocationExpression;
@ -3323,6 +3334,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -3323,6 +3334,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
ResolveResult IAstVisitor<ResolveResult>.VisitMemberType(MemberType memberType)
{
ResolveResult target;
NameLookupMode lookupMode = memberType.GetNameLookupMode();
if (memberType.IsDoubleColon && memberType.Target is SimpleType) {
SimpleType t = (SimpleType)memberType.Target;
StoreCurrentState(t);
@ -3335,8 +3347,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -3335,8 +3347,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
target = Resolve(memberType.Target);
}
NameLookupMode lookupMode = memberType.GetNameLookupMode();
var typeArguments = ResolveTypeArguments(memberType.TypeArguments);
Identifier identifier = memberType.MemberNameToken;
ResolveResult rr = resolver.ResolveMemberAccess(target, identifier.Name, typeArguments, lookupMode);
@ -3393,10 +3403,25 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -3393,10 +3403,25 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
IType GetTypeForQueryVariable(IType type)
{
// This assumes queries are only used on IEnumerable.
// We might want to look at the signature of a LINQ method (e.g. Select) instead.
bool? isGeneric;
return GetElementTypeFromIEnumerable(type, resolver.Compilation, false, out isGeneric);
// This assumes queries are only used on IEnumerable.
var result = GetElementTypeFromIEnumerable(type, resolver.Compilation, false, out isGeneric);
// If that fails try to resolve the Select method and resolve the projection.
if (result.Kind == TypeKind.Unknown) {
var selectAccess = resolver.ResolveMemberAccess(new ResolveResult (type), "Select", EmptyList<IType>.Instance);
ResolveResult[] arguments = {
new QueryExpressionLambda(1, voidResult)
};
var rr = resolver.ResolveInvocation(selectAccess, arguments) as CSharpInvocationResolveResult;
if (rr != null && rr.Arguments.Count == 2) {
var invokeMethod = rr.Arguments[1].Type.GetDelegateInvokeMethod();
if (invokeMethod != null && invokeMethod.Parameters.Count > 0)
return invokeMethod.Parameters[0].Type;
}
}
return result;
}
ResolveResult MakeTransparentIdentifierResolveResult()

53
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -1126,7 +1126,58 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -1126,7 +1126,58 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
return null;
}
}
public override ConstantExpression VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
{
if (!objectCreateExpression.Arguments.Any()) {
// built in primitive type constants can be created with new
// Todo: correctly resolve the type instead of doing the string approach
switch (objectCreateExpression.Type.ToString()) {
case "System.Boolean":
case "bool":
return new PrimitiveConstantExpression(KnownTypeReference.Boolean, new bool());
case "System.Char":
case "char":
return new PrimitiveConstantExpression(KnownTypeReference.Char, new char());
case "System.SByte":
case "sbyte":
return new PrimitiveConstantExpression(KnownTypeReference.SByte, new sbyte());
case "System.Byte":
case "byte":
return new PrimitiveConstantExpression(KnownTypeReference.Byte, new byte());
case "System.Int16":
case "short":
return new PrimitiveConstantExpression(KnownTypeReference.Int16, new short());
case "System.UInt16":
case "ushort":
return new PrimitiveConstantExpression(KnownTypeReference.UInt16, new ushort());
case "System.Int32":
case "int":
return new PrimitiveConstantExpression(KnownTypeReference.Int32, new int());
case "System.UInt32":
case "uint":
return new PrimitiveConstantExpression(KnownTypeReference.UInt32, new uint());
case "System.Int64":
case "long":
return new PrimitiveConstantExpression(KnownTypeReference.Int64, new long());
case "System.UInt64":
case "ulong":
return new PrimitiveConstantExpression(KnownTypeReference.UInt64, new ulong());
case "System.Single":
case "float":
return new PrimitiveConstantExpression(KnownTypeReference.Single, new float());
case "System.Double":
case "double":
return new PrimitiveConstantExpression(KnownTypeReference.Double, new double());
case "System.Decimal":
case "decimal":
return new PrimitiveConstantExpression(KnownTypeReference.Decimal, new decimal());
}
}
return null;
}
public override ConstantExpression VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression)
{
var initializer = arrayCreateExpression.Initializer;

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/TypeSystemTests.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck @@ -75,7 +75,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
context = compilation.TypeResolveContext;
// Include (potentially specialized) inherited members when testing ToMemberReference()
foreach (var member in IncludeAccessors(typeDef.GetMembers())) {
var resolvedMember = member.ToMemberReference().Resolve(context);
var resolvedMember = member.ToReference().Resolve(context);
if (!member.Equals(resolvedMember))
throw new InvalidOperationException();
}

27
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Analysis/SemanticHighlightingTests.cs

@ -401,6 +401,33 @@ class Test @@ -401,6 +401,33 @@ class Test
", inactiveCodeColor);
}
[Test]
public void TestInactiveConditionalCallOverrideTest()
{
TestColor (@"using System.Diagnostics;
class TestBase
{
[Conditional(""FOO"")]
public virtual void Test22()
{
}
}
class Test : TestBase
{
public override void Test22()
{
}
public void Foo()
{
$Test22();
}
}
", inactiveCodeColor);
}
[Test]
public void TestInactivePartialCall()
{

9
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/AstTests.cs

@ -72,6 +72,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,6 +72,15 @@ namespace ICSharpCode.NRefactory.CSharp
var childs = method.DescendantNodes(child => !(child is BlockStatement) || (((BlockStatement)child).Parent is MethodDeclaration)).Where(n => n is Statement).ToList();
Assert.AreEqual(4, childs.Count);
}
[Test]
public void GetNodesBetween()
{
var parser = new CSharpParser();
var expr = parser.ParseExpression("a*b+c*d");
var nodes = expr.GetNodesBetween(1, 3, 1, 6).ToList();
Assert.AreEqual(new[] { "b", "+", "c" }, nodes.Select(n => n.ToString()).ToList());
}
}
}

32
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0029InvalidConversionIssueTests.cs

@ -2,6 +2,7 @@ using System.Linq; @@ -2,6 +2,7 @@ using System.Linq;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeActions;
using System;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
{
@ -531,5 +532,36 @@ class TestClass @@ -531,5 +532,36 @@ class TestClass
}");
}
[Test]
public void LinqQueryBug()
{
var input = @"
using System;
public static class FooExt
{
public static May<TOut> Select<TIn, TOut>(this May<TIn> value, Func<TIn, TOut> projection)
{
return new May<TOut> ();
}
}
public class May<T>
{
public T Property { get; set; }
}
public class EmptyClass
{
public May<EmptyClass> Foo ()
{
return
from foo in new May<EmptyClass> ()
select foo;
}
}
";
TestWrongContext<CS0029InvalidConversionIssue> (input);
}
}
}

27
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0618UsageOfObsoleteMemberIssueTests.cs

@ -213,6 +213,33 @@ class MyClass @@ -213,6 +213,33 @@ class MyClass
#pragma warning restore 618
}
}
";
TestWrongContext<CS0618UsageOfObsoleteMemberIssue>(input);
}
/// <summary>
/// Bug 17859 - Source analysis should not warn when obsolete member is used by obsolete member
/// </summary>
[Test]
public void TestBug17859()
{
var input = @"
using System;
public class Foo
{
[Obsolete]
public static void OldBar ()
{
}
[Obsolete]
public static void OldBar2 ()
{
OldBar ();
}
}
";
TestWrongContext<CS0618UsageOfObsoleteMemberIssue>(input);
}

20
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ConvertToLambdaExpressionIssueTests.cs

@ -92,6 +92,26 @@ class TestClass @@ -92,6 +92,26 @@ class TestClass
}
[Test]
public void TestAssignmentExpression ()
{
TestWrongContext<ConvertToLambdaExpressionIssue>(@"
using System;
public class Test
{
void Foo ()
{
int i;
Action<int> foo = x => {
i = x + x;
};
foo(5);
}
}
");
}
/// <summary>
/// Bug 14840 - Incorrect "can be converted to expression" suggestion
/// </summary>

21
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/DelegateSubtractionIssueTests.cs

@ -77,6 +77,27 @@ class Foo @@ -77,6 +77,27 @@ class Foo
}
");
}
/// <summary>
/// Bug 18061 - Incorrect "delegate subtraction has unpredictable result" warning
/// </summary>
[Test]
public void TestBug18061()
{
TestWrongContext<DelegateSubtractionIssue>(@"
using System;
class Test
{
public event EventHandler Foo;
void Bar (EventHandler bar)
{
Foo -= bar;
}
}
");
}
}
}

305
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/OptionalParameterCouldBeSkippedTests.cs

@ -1,305 +0,0 @@ @@ -1,305 +0,0 @@
//
// OptionalParameterCouldBeSkippedTests.cs
//
// Author:
// Simon Lindgren <simon.n.lindgren@gmail.com>
//
// Copyright (c) 2012 Simon Lindgren
//
// 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.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
{
[TestFixture]
public class OptionalParameterCouldBeSkippedTests : InspectionActionTestBase
{
[Test]
public void SimpleCase()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"")
{
}
void Bar()
{
Foo (""a1"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(1, issues.Count);
var issue = issues [0];
Assert.AreEqual(2, issue.Actions.Count);
CheckFix(context, issues [0], @"
class TestClass
{
void Foo(string a1 = ""a1"")
{
}
void Bar()
{
Foo ();
}
}");
}
[Test]
public void ChecksConstructors()
{
var input = @"
class TestClass
{
public TestClass(string a1 = ""a1"")
{
}
void Bar()
{
var foo = new TestClass (""a1"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(1, issues.Count);
var issue = issues [0];
Assert.AreEqual(2, issue.Actions.Count);
CheckFix(context, issues [0], @"
class TestClass
{
public TestClass(string a1 = ""a1"")
{
}
void Bar()
{
var foo = new TestClass ();
}
}");
}
[Test]
public void IgnoresAllParametersPreceedingANeededOne()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (""a1"", ""Another string"", ""a3"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(1, issues.Count);
var issue = issues [0];
Assert.AreEqual(2, issue.Actions.Count);
CheckFix(context, issues [0], @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (""a1"", ""Another string"");
}
}");
}
[Test]
public void ChecksParametersIfParamsAreUnused()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"", params string[] extraStrings)
{
}
void Bar()
{
Foo (""a1"", ""a2"", ""a3"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(3, issues.Count);
Assert.AreEqual(2, issues[0].Actions.Count);
Assert.AreEqual(2, issues[1].Actions.Count);
Assert.AreEqual(2, issues[2].Actions.Count);
CheckFix(context, issues [2], @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"", params string[] extraStrings)
{
}
void Bar()
{
Foo ();
}
}");
}
[Test]
public void IgnoresIfParamsAreUsed()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"", params string[] extraStrings)
{
}
void Bar()
{
Foo (""a1"", ""a2"", ""a3"", ""extraString"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(0, issues.Count);
}
[Test]
public void NamedArgument()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"")
{
}
void Bar()
{
Foo (a2: ""a2"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(1, issues.Count);
Assert.AreEqual(2, issues[0].Actions.Count);
CheckFix(context, issues [0], @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"")
{
}
void Bar()
{
Foo ();
}
}");
}
[Test]
public void DoesNotStopAtDifferingNamedParameters()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (""a1"", ""a2"", a3: ""non-default"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(2, issues.Count);
Assert.AreEqual(2, issues[0].Actions.Count);
Assert.AreEqual(2, issues[1].Actions.Count);
CheckFix(context, issues [1], @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (a3: ""non-default"");
}
}");
}
[Test]
public void DoesNotStopAtNamedParamsArray()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", params string[] extras)
{
}
void Bar()
{
Foo (""a1"", ""a2"", extras: new [] { ""extra1"" });
}
}";
TestRefactoringContext context;
var issues = GetIssues(new OptionalParameterCouldBeSkippedIssue(), input, out context);
Assert.AreEqual(2, issues.Count);
Assert.AreEqual(2, issues[0].Actions.Count);
Assert.AreEqual(2, issues[1].Actions.Count);
// TODO: Fix formatting
CheckFix(context, issues [1], @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", params string[] extras)
{
}
void Bar()
{
Foo (extras: new[] {
""extra1""
});
}
}");
}
}
}

223
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantArgumentDefaultValueIssueTests.cs

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
// THE SOFTWARE.
using ICSharpCode.NRefactory.CSharp.Refactoring;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeActions;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
{
@ -213,6 +214,228 @@ class Test @@ -213,6 +214,228 @@ class Test
}
");
}
[Test]
public void SimpleCase()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
void Foo(string a1 = ""a1"")
{
}
void Bar()
{
Foo (""a1"");
}
}", @"
class TestClass
{
void Foo(string a1 = ""a1"")
{
}
void Bar()
{
Foo ();
}
}");
}
[Test]
public void ChecksConstructors()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
public TestClass(string a1 = ""a1"")
{
}
void Bar()
{
var foo = new TestClass (""a1"");
}
}", @"
class TestClass
{
public TestClass(string a1 = ""a1"")
{
}
void Bar()
{
var foo = new TestClass ();
}
}");
}
[Test]
public void IgnoresAllParametersPreceedingANeededOne()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (""a1"", ""Another string"", ""a3"");
}
}", @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (""a1"", ""Another string"");
}
}");
}
[Test]
public void ChecksParametersIfParamsAreUnused()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"", params string[] extraStrings)
{
}
void Bar()
{
Foo (""a1"", ""a2"", ""a3"");
}
}", 3, @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"", params string[] extraStrings)
{
}
void Bar()
{
Foo ();
}
}", 0);
}
[Test]
public void IgnoresIfParamsAreUsed()
{
var input = @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"", params string[] extraStrings)
{
}
void Bar()
{
Foo (""a1"", ""a2"", ""a3"", ""extraString"");
}
}";
TestRefactoringContext context;
var issues = GetIssues(new RedundantArgumentDefaultValueIssue(), input, out context);
Assert.AreEqual(0, issues.Count);
}
[Ignore("Fixme")]
[Test]
public void NamedArgument()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"")
{
}
void Bar()
{
Foo (a2: ""a2"");
}
}", @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"")
{
}
void Bar()
{
Foo ();
}
}");
}
[Ignore("Fixme")]
[Test]
public void DoesNotStopAtDifferingNamedParameters()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (""a1"", ""a2"", a3: ""non-default"");
}
}", @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", string a3 = ""a3"")
{
}
void Bar()
{
Foo (a3: ""non-default"");
}
}");
}
[Ignore("Fixme")]
[Test]
public void DoesNotStopAtNamedParamsArray()
{
Test<RedundantArgumentDefaultValueIssue>(@"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", params string[] extras)
{
}
void Bar()
{
Foo (""a1"", ""a2"", extras: new [] { ""extra1"" });
}
}", @"
class TestClass
{
void Foo(string a1 = ""a1"", string a2 = ""a2"", params string[] extras)
{
}
void Bar()
{
Foo (extras: new[] {
""extra1""
});
}
}");
}
}
}

44
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantCastIssueTests.cs

@ -319,5 +319,49 @@ class Foo @@ -319,5 +319,49 @@ class Foo
}
}");
}
/// <summary>
/// Bug 17945 - Bad 'unnecessary cast' warning
/// </summary>
[Test]
public void TestBug17945 ()
{
TestWrongContext<RedundantCastIssue> (@"
namespace Bug
{
public class C
{
public C (object o)
{
}
public C (string o)
: this (o as object)
{
}
}
}
");
}
[Test]
public void TestOverloadSelector ()
{
TestWrongContext<RedundantCastIssue> (@"
public class Foo
{
public void Bar (object o)
{
}
public void Bar (string o)
{
Bar ((object)o);
}
}
");
}
}
}

39
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/XmlDocIssueIssueTests.cs

@ -168,6 +168,45 @@ class Foo { @@ -168,6 +168,45 @@ class Foo {
}
");
}
[Test]
public void TestSeeCRefMember ()
{
TestWrongContext<XmlDocIssue>(@"
using System;
namespace Foo
{
public interface IGroupingProvider
{
IGroupingProvider Next { get; set; }
/// <summary>
/// Occurs when <see cref=""Next""/> changes.
/// </summary>
event EventHandler<EventArgs> NextChanged;
}
}
");
}
[Test]
public void TestEventComment ()
{
TestIssue<XmlDocIssue>(@"
using System;
namespace Foo
{
public interface IGroupingProvider
{
/// <summa
event EventHandler<EventArgs> NextChanged;
}
}
", 1);
}
}

33
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/MemberLookupTests.cs

@ -327,6 +327,39 @@ public class Test : Base { @@ -327,6 +327,39 @@ public class Test : Base {
Assert.AreEqual("Base.Field", rr.Member.FullName);
}
[Test]
public void ProtectedBaseIndexer()
{
string program = @"using System;
class X {
protected int this[int index] { get; }
}
class Y : X {
int M() {
return $base[0]$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.AreEqual(OverloadResolutionErrors.None, rr.OverloadResolutionErrors);
Assert.AreEqual("X.Item", rr.Member.FullName);
}
[Test]
public void ProtectedBaseIndexerError()
{
string program = @"using System;
class X {
protected int this[int index] { get; }
}
class Y : X {
int M(X x) {
return $x[0]$;
}
}";
var rr = Resolve(program);
Assert.IsTrue(rr.IsError);
}
[Test]
public void ThisHasSameTypeAsFieldInGenericClass()
{

18
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs

@ -399,7 +399,23 @@ class Activator { @@ -399,7 +399,23 @@ class Activator {
var result = Resolve<TypeResolveResult>(program);
Assert.AreEqual("Testnamespace.Activator", result.Type.FullName);
}
[Test]
public void NamespaceDefinitionOverwritesTypeName ()
{
// Classes in the current namespace are preferred over classes from
// imported namespaces
string program = @"using System;
namespace $Auto.Test$ {
class Auto
{
}
}
";
var result = Resolve<NamespaceResolveResult>(program);
Assert.AreEqual("Auto.Test", result.NamespaceName);
}
[Test]
public void ParentNamespaceTypeLookup()
{

121
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

@ -939,6 +939,127 @@ class Foo @@ -939,6 +939,127 @@ class Foo
");
}
[Test]
public void TestConstructorInitializerColonDontCare()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
policy.NewLineAfterConstructorInitializerColon = NewLinePlacement.DoNotCare;
policy.NewLineBeforeConstructorInitializerColon = NewLinePlacement.DoNotCare;
Test(policy, @"class A
{
public A () : base ()
{
}
public A () :
base ()
{
}
public A ()
: base ()
{
}
public A ()
:
base ()
{
}
}",
@"class A
{
public A () : base ()
{
}
public A () :
base ()
{
}
public A ()
: base ()
{
}
public A ()
:
base ()
{
}
}");
}
[Test]
public void TestConstructorInitializerColonNewLineBeforeSameLineAfter()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
policy.NewLineBeforeConstructorInitializerColon = NewLinePlacement.NewLine;
policy.NewLineAfterConstructorInitializerColon = NewLinePlacement.SameLine;
Test(policy, @"class A
{
public A () : base ()
{
}
public A () :
base ()
{
}
public A ()
: base ()
{
}
public A ()
:
base ()
{
}
}",
@"class A
{
public A ()
: base ()
{
}
public A ()
: base ()
{
}
public A ()
: base ()
{
}
public A ()
: base ()
{
}
}");
}
[Test]
public void TestIndentPreprocessorStatementsAdd()
{

3
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -374,7 +374,6 @@ @@ -374,7 +374,6 @@
<Compile Include="CSharp\CodeIssues\AccessToStaticMemberViaDerivedTypeIssueTests.cs" />
<Compile Include="CSharp\CodeIssues\ParameterCanBeDemotedIssue\IsTypeCriterionTests.cs" />
<Compile Include="Utils\CompositeFormatStringParser\CompositeFormatStringParserTests.cs" />
<Compile Include="CSharp\CodeIssues\OptionalParameterCouldBeSkippedTests.cs" />
<Compile Include="CSharp\CodeIssues\RedundantToStringCallIssueTests.cs" />
<Compile Include="CSharp\CodeIssues\CallToObjectEqualsViaBaseTests.cs" />
<Compile Include="CSharp\CodeIssues\IncorrectCallToGetHashCodeTests.cs" />
@ -585,7 +584,6 @@ @@ -585,7 +584,6 @@
<Compile Include="CSharp\CodeIssues\RedundantDelegateCreationIssueTests.cs" />
<Compile Include="CSharp\CodeIssues\RedundantEnumerableCastCallIssueTests.cs" />
<Compile Include="CSharp\CodeIssues\MissingInterfaceMemberImplementationIssueTests.cs" />
<Compile Include="CSharp\CodeIssues\UnmatchedSizeSpeicificationInArrayCreationTests.cs" />
<Compile Include="FormattingTests\TestLinq.cs" />
<Compile Include="CSharp\CodeIssues\RedundantBlockInDifferentBranchesTests.cs" />
<Compile Include="CSharp\CodeIssues\ParameterCanBeDemotedIssue\ParameterCanBeDeclaredWithBaseTypeIssueTests.cs" />
@ -619,6 +617,7 @@ @@ -619,6 +617,7 @@
<Compile Include="FormattingTests\ConstructFixerTests.cs" />
<Compile Include="CSharp\CodeIssues\StaticEventSubscriptionIssueTests.cs" />
<Compile Include="CSharp\CodeActions\CS1105ExtensionMethodMustBeDeclaredStaticActionTests.cs" />
<Compile Include="CSharp\CodeIssues\UnmatchedSizeSpeicificationInArrayCreationTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\cecil\Mono.Cecil.csproj">

14
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

@ -378,6 +378,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase @@ -378,6 +378,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase
public const int SOd = sizeof(double);
public const int SObl = sizeof(bool);
public const int SOe = sizeof(MyEnum);
public const byte CNewb = new byte();
public const sbyte CNewsb = new sbyte();
public const char CNewc = new char();
public const short CNews = new short();
public const ushort CNewus = new ushort();
public const int CNewi = new int();
public const uint CNewui = new uint();
public const long CNewl = new long();
public const ulong CNewul = new ulong();
public const double CNewd = new double();
public const float CNewf = new float();
public const decimal CNewm = new decimal();
}
public interface IExplicitImplementationTests

31
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -1310,25 +1310,24 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1310,25 +1310,24 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
[Test]
public unsafe void ConstantFields()
public unsafe void ConstantFieldsCreatedWithNew()
{
ITypeDefinition type = GetTypeDefinition(typeof(ConstantFieldTest));
AssertConstantField<byte>(type, "Cb", 42);
AssertConstantField<sbyte>(type, "Csb", 42);
AssertConstantField<char>(type, "Cc", '\x42');
AssertConstantField<short>(type, "Cs", 42);
AssertConstantField<ushort>(type, "Cus", 42);
AssertConstantField<int>(type, "Ci", 42);
AssertConstantField<uint>(type, "Cui", 42);
AssertConstantField<long>(type, "Cl", 42);
AssertConstantField<ulong>(type, "Cul", 42);
AssertConstantField<double>(type, "Cd", 42);
AssertConstantField<float>(type, "Cf", 42);
AssertConstantField<decimal>(type, "Cm", 42);
AssertConstantField<string>(type, "S", "hello, world");
AssertConstantField<string>(type, "NullString", null);
AssertConstantField<byte>(type, "CNewb", new byte());
AssertConstantField<sbyte>(type, "CNewsb", new sbyte());
AssertConstantField<char>(type, "CNewc", new char());
AssertConstantField<short>(type, "CNews", new short());
AssertConstantField<ushort>(type, "CNewus", new ushort());
AssertConstantField<int>(type, "CNewi", new int());
AssertConstantField<uint>(type, "CNewui", new uint());
AssertConstantField<long>(type, "CNewl", new long());
AssertConstantField<ulong>(type, "CNewul", new ulong());
AssertConstantField<double>(type, "CNewd", new double());
AssertConstantField<float>(type, "CNewf", new float());
AssertConstantField<decimal>(type, "CNewm", new decimal());
}
[Test]
public void ConstantFieldsSizeOf()
{

1
src/Libraries/NRefactory/ICSharpCode.NRefactory/Documentation/XmlDocumentationProvider.cs

@ -129,6 +129,7 @@ namespace ICSharpCode.NRefactory.Documentation @@ -129,6 +129,7 @@ namespace ICSharpCode.NRefactory.Documentation
Debug.WriteLine("XmlDoc " + fileName + " is redirecting to " + redirectionTarget);
using (FileStream redirectedFs = new FileStream(redirectionTarget, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) {
using (XmlTextReader redirectedXmlReader = new XmlTextReader(redirectedFs)) {
redirectedXmlReader.XmlResolver = null; // no DTD resolving
this.fileName = redirectionTarget;
ReadXmlDoc(redirectedXmlReader);
}

2
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs

@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
.Concat(GetEvents(filter, options));
}
public virtual IEnumerable<IMethod> GetAccessors(Predicate<IUnresolvedMethod> filter, GetMemberOptions options = GetMemberOptions.None)
public virtual IEnumerable<IMethod> GetAccessors(Predicate<IUnresolvedMethod> filter = null, GetMemberOptions options = GetMemberOptions.None)
{
return EmptyList<IMethod>.Instance;
}

5
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/InheritanceHelper.cs

@ -61,6 +61,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -61,6 +61,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
var substitution = member.Substitution;
member = member.MemberDefinition;
if (member.DeclaringTypeDefinition == null) {
// For global methods, return empty list. (prevent SharpDevelop UDC crash 4524)
yield break;
}
IEnumerable<IType> allBaseTypes;
if (includeImplementedInterfaces) {
allBaseTypes = member.DeclaringTypeDefinition.GetAllBaseTypes();

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs

@ -42,6 +42,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -42,6 +42,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </remarks>
public static IEnumerable<IType> GetAllBaseTypes(this IType type)
{
if (type == null)
throw new ArgumentNullException("type");
BaseTypeCollector collector = new BaseTypeCollector();
collector.CollectBaseTypes(type);
return collector;
@ -57,6 +59,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -57,6 +59,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </remarks>
public static IEnumerable<IType> GetNonInterfaceBaseTypes(this IType type)
{
if (type == null)
throw new ArgumentNullException("type");
BaseTypeCollector collector = new BaseTypeCollector();
collector.SkipImplementedInterfaces = true;
collector.CollectBaseTypes(type);

Loading…
Cancel
Save