Browse Source

Merge branch 'master' into simonl

Conflicts:
	ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
newNRvisualizers
Simon Lindgren 14 years ago
parent
commit
2a45c1e68e
  1. 10
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  3. 19
      ICSharpCode.NRefactory.CSharp/Completion/CompletionDataWrapper.cs
  4. 17
      ICSharpCode.NRefactory.CSharp/Completion/ICompletionContextProvider.cs
  5. 2
      ICSharpCode.NRefactory.CSharp/Completion/ICompletionDataFactory.cs
  6. 4
      ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs
  7. 18
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  8. 2
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  9. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateBackingStoreAction.cs
  10. 11
      ICSharpCode.NRefactory.CSharp/Resolver/CSharpConversions.cs
  11. 2
      ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
  12. 1
      ICSharpCode.NRefactory.CSharp/Resolver/OverloadResolution.cs
  13. 2
      ICSharpCode.NRefactory.CSharp/TypeSystem/ResolvedUsingScope.cs
  14. 2
      ICSharpCode.NRefactory.Demo/CSDemo.cs
  15. 77
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateBackingStoreTests.cs
  16. 44
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
  17. 100
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/InvocationTests.cs
  18. 26
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  19. 10
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  20. 6
      ICSharpCode.NRefactory.Xml/ICSharpCode.NRefactory.Xml.csproj
  21. 9
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  22. 2
      ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs
  23. 5
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  24. 22
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedEntity.cs
  25. 24
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedMember.cs
  26. 12
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedMethod.cs
  27. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedProperty.cs
  28. 23
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs
  29. 2
      ICSharpCode.NRefactory/Utils/EmptyList.cs
  30. 2
      ICSharpCode.NRefactory/Utils/LazyInit.cs
  31. 2
      ICSharpCode.NRefactory/Utils/MultiDictionary.cs
  32. 20
      Packages/ICSharpCode.NRefactory.nuspec
  33. 24
      README

10
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -1384,7 +1384,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -1384,7 +1384,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
wrapper.AddNamespace(pair.Key);
wrapper.AddAlias(pair.Key);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
@ -1418,7 +1418,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -1418,7 +1418,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(curNs.Name);
wrapper.AddNamespace(curNs);
}
}
}
@ -2173,7 +2173,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2173,7 +2173,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
}
foreach (var ns in nr.Namespace.ChildNamespaces) {
result.AddNamespace(ns.Name);
result.AddNamespace(ns);
}
} else if (resolveResult is TypeResolveResult) {
var type = resolveResult.Type;
@ -2194,7 +2194,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2194,7 +2194,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
foreach (var ns in Compilation.RootNamespace.ChildNamespaces) {
yield return factory.CreateNamespaceCompletionData(ns.Name);
yield return factory.CreateNamespaceCompletionData(ns);
}
}
@ -2306,7 +2306,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2306,7 +2306,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
foreach (var ns in nr.Namespace.ChildNamespaces) {
namespaceContents.AddNamespace(ns.Name);
namespaceContents.AddNamespace(ns);
}
return namespaceContents.Result;
}

2
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -682,6 +682,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -682,6 +682,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
wrapper.Append(new string('}', closingBrackets));
}
var parser = new CSharpParser ();
foreach (var sym in CompletionContextProvider.ConditionalSymbols)
parser.CompilerSettings.ConditionalSymbols.Add (sym);
parser.InitialLocation = new TextLocation(memberLocation.Line - generatedLines, 1);
var result = parser.Parse(wrapper.ToString ());
return result;

19
ICSharpCode.NRefactory.CSharp/Completion/CompletionDataWrapper.cs

@ -58,7 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -58,7 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
{
result.Add (data);
}
public void AddCustom (string displayText, string description = null, string completionText = null)
{
result.Add (Factory.CreateLiteralCompletionData (displayText, description, completionText));
@ -66,14 +67,20 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -66,14 +67,20 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
HashSet<string> usedNamespaces = new HashSet<string> ();
public void AddNamespace (string name)
public void AddNamespace (INamespace ns)
{
if (string.IsNullOrEmpty (name) || usedNamespaces.Contains (name))
if (usedNamespaces.Contains (ns.Name))
return;
usedNamespaces.Add (name);
result.Add (Factory.CreateNamespaceCompletionData (name));
usedNamespaces.Add (ns.Name);
result.Add (Factory.CreateNamespaceCompletionData (ns));
}
public void AddAlias(string alias)
{
result.Add (Factory.CreateLiteralCompletionData (alias));
}
HashSet<string> usedTypes = new HashSet<string> ();
public ICompletionData AddType(IType type, string shortType)

17
ICSharpCode.NRefactory.CSharp/Completion/ICompletionContextProvider.cs

@ -35,6 +35,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -35,6 +35,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
{
public interface ICompletionContextProvider
{
IList<string> ConditionalSymbols {
get;
}
void GetCurrentMembers (int offset, out IUnresolvedTypeDefinition currentType, out IUnresolvedMember currentMember);
Tuple<string, TextLocation> GetMemberTextToCaret(int caretOffset, IUnresolvedTypeDefinition currentType, IUnresolvedMember currentMember);
@ -46,6 +50,13 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -46,6 +50,13 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
{
readonly IDocument document;
readonly CSharpUnresolvedFile unresolvedFile;
readonly List<string> symbols = new List<string> ();
public IList<string> ConditionalSymbols {
get {
return symbols;
}
}
public DefaultCompletionContextProvider (IDocument document, CSharpUnresolvedFile unresolvedFile)
{
@ -56,7 +67,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -56,7 +67,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
this.document = document;
this.unresolvedFile = unresolvedFile;
}
public void AddSymbol (string sym)
{
symbols.Add (sym);
}
public void GetCurrentMembers(int offset, out IUnresolvedTypeDefinition currentType, out IUnresolvedMember currentMember)
{
//var document = engine.document;

2
ICSharpCode.NRefactory.CSharp/Completion/ICompletionDataFactory.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
/// </param>
ICompletionData CreateLiteralCompletionData (string title, string description = null, string insertText = null);
ICompletionData CreateNamespaceCompletionData (string name);
ICompletionData CreateNamespaceCompletionData (INamespace name);
ICompletionData CreateVariableCompletionData (IVariable variable);

4
ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp
SpaceBeforeDelegateDeclarationParentheses = true,
SpaceAfterMethodCallParameterComma = true,
SpaceAfterConstructorDeclarationParameterComma = true,
SpaceBeforeNewParentheses = true,
SpacesWithinNewParentheses = false,
SpacesBetweenEmptyNewParentheses = false,
@ -152,6 +152,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -152,6 +152,7 @@ namespace ICSharpCode.NRefactory.CSharp
PropertyFormatting = PropertyFormatting.AllowOneLine,
SpaceBeforeMethodDeclarationParameterComma = false,
SpaceAfterMethodDeclarationParameterComma = true,
SpaceAfterDelegateDeclarationParameterComma = true,
SpaceBeforeFieldDeclarationComma = false,
SpaceAfterFieldDeclarationComma = true,
SpaceBeforeLocalVariableDeclarationComma = false,
@ -322,6 +323,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -322,6 +323,7 @@ namespace ICSharpCode.NRefactory.CSharp
PropertyFormatting = PropertyFormatting.AllowOneLine,
SpaceBeforeMethodDeclarationParameterComma = false,
SpaceAfterMethodDeclarationParameterComma = true,
SpaceAfterDelegateDeclarationParameterComma = true,
SpaceBeforeFieldDeclarationComma = false,
SpaceAfterFieldDeclarationComma = true,
SpaceBeforeLocalVariableDeclarationComma = false,

18
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -32,38 +32,40 @@ @@ -32,38 +32,40 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE;FULL_AST</DefineConstants>
<DefineConstants>DEBUG;TRACE;FULL_AST;NET_4_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE;FULL_AST</DefineConstants>
<DefineConstants>TRACE;FULL_AST;NET_4_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Debug' ">
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE;FULL_AST;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;FULL_AST;NET_4_0;NET_4_5</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Release' ">
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE;FULL_AST;NET45</DefineConstants>
<DefineConstants>TRACE;FULL_AST;NET_4_0;NET_4_5</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

2
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -3768,7 +3768,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -3768,7 +3768,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
conversionVisitor.Unit.FileName = fileName;
conversionVisitor.Unit.ConditionalSymbols = top.Conditionals.ToArray ();
conversionVisitor.Unit.ConditionalSymbols = top.Conditionals.Concat (compilerSettings.ConditionalSymbols).ToArray ();
return conversionVisitor.Unit;
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateBackingStoreAction.cs

@ -46,6 +46,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -46,6 +46,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// create field
var backingStore = new FieldDeclaration ();
if (property.Modifiers.HasFlag (Modifiers.Static))
backingStore.Modifiers |= Modifiers.Static;
backingStore.ReturnType = property.ReturnType.Clone ();
var initializer = new VariableInitializer (backingStoreName);

11
ICSharpCode.NRefactory.CSharp/Resolver/CSharpConversions.cs

@ -186,8 +186,15 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -186,8 +186,15 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return true;
if (ImplicitReferenceConversion(fromType, toType, 0))
return true;
if (IsBoxingConversion(fromType, toType) && !NullableType.IsNullable(fromType))
return true;
if (NullableType.IsNullable(fromType)) {
// An 'object' constraint still allows nullable value types
// (object constraints don't exist in C#, but are inserted by DefaultResolvedTypeParameter.DirectBaseTypes)
if (toType.IsKnownType(KnownTypeCode.Object))
return true;
} else {
if (IsBoxingConversion(fromType, toType))
return true;
}
if (ImplicitTypeParameterConversion(fromType, toType))
return true;
return false;

2
ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs

@ -505,7 +505,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -505,7 +505,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
} else if (!classLookupGroup.MethodsAreHidden) {
foreach (IMethod classMethod in classLookupGroup.Methods) {
foreach (var classMethod in classLookupGroup.Methods) {
// Hide all non-methods from interface types, and all methods with the same signature
// as a method in this class type.
foreach (var interfaceLookupGroup in lookupGroups) {

1
ICSharpCode.NRefactory.CSharp/Resolver/OverloadResolution.cs

@ -249,7 +249,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -249,7 +249,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
RunTypeInference(candidate);
CheckApplicability(candidate);
ConsiderIfNewCandidateIsBest(candidate);
ValidateMethodConstraints(candidate);
return true;
}

2
ICSharpCode.NRefactory.CSharp/TypeSystem/ResolvedUsingScope.cs

@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
CSharpResolver resolver = new CSharpResolver(parentContext.WithUsingScope(this));
foreach (var u in usingScope.Usings) {
INamespace ns = u.ResolveNamespace(resolver);
if (ns != null)
if (ns != null && !result.Contains(ns))
result.Add(ns);
}
return LazyInit.GetOrSet(ref this.usings, new ReadOnlyCollection<INamespace>(result));

2
ICSharpCode.NRefactory.Demo/CSDemo.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.Demo @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.Demo
void CSharpParseButtonClick(object sender, EventArgs e)
{
syntaxTree = SyntaxTree.Parse(csharpCodeTextBox.Text);
syntaxTree = new CSharpParser().Parse(csharpCodeTextBox.Text, "demo.cs");
csharpTreeView.Nodes.Clear();
foreach (var element in syntaxTree.Children) {
csharpTreeView.Nodes.Add(MakeTreeNode(element));

77
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateBackingStoreTests.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
//
// CreateBackingStoreTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Text;
namespace ICSharpCode.NRefactory.CSharp.CodeActions
{
[TestFixture]
public class CreateBackingStoreTests : ContextActionTestBase
{
[Test()]
public void TestSimpleStore ()
{
Test<CreateBackingStoreAction> (@"class TestClass
{
string $Test { get; set; }
}", @"class TestClass
{
string test;
string Test {
get {
return test;
}
set {
test = value;
}
}
}");
}
[Test()]
public void TestStaticStore ()
{
Test<CreateBackingStoreAction> (@"class TestClass
{
public static string $Test { get; set; }
}", @"class TestClass
{
static string test;
public static string Test {
get {
return test;
}
set {
test = value;
}
}
}");
}
}
}

44
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -147,9 +147,9 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion @@ -147,9 +147,9 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
return new CompletionData (title);
}
public ICompletionData CreateNamespaceCompletionData (string name)
public ICompletionData CreateNamespaceCompletionData (INamespace ns)
{
return new CompletionData (name);
return new CompletionData (ns.Name);
}
public ICompletionData CreateVariableCompletionData (ICSharpCode.NRefactory.TypeSystem.IVariable variable)
@ -244,6 +244,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion @@ -244,6 +244,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
}
}
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
mb.AddSymbol ("TEST");
var engine = new CSharpCompletionEngine(doc, mb, new TestFactory(), pctx, rctx);
engine.EolMarker = Environment.NewLine;
@ -5375,6 +5376,45 @@ public class FooBar @@ -5375,6 +5376,45 @@ public class FooBar
});
}
[Test()]
public void TestCompletionInPreprocessorIf()
{
CombinedProviderTest(
@"using System;
public class FooBar
{
public static void Main (string[] args)
{
#if TEST
$Console.$
#endif
}
}
", provider => {
Assert.IsNotNull(provider.Find("WriteLine"));
});
}
[Test()]
public void TestCompletionInUndefinedPreprocessorIf()
{
CombinedProviderTest(
@"using System;
public class FooBar
{
public static void Main (string[] args)
{
#if UNDEFINED
$Console.$
#endif
}
}
", provider => {
Assert.IsNull(provider.Find("WriteLine"));
});
}
}
}

100
ICSharpCode.NRefactory.Tests/CSharp/Resolver/InvocationTests.cs

@ -635,5 +635,105 @@ class Test @@ -635,5 +635,105 @@ class Test
Assert.AreEqual(OverloadResolutionErrors.MethodConstraintsNotSatisfied, rr.OverloadResolutionErrors);
Assert.IsTrue(rr.IsError);
}
[Test]
public void MethodCanBeInvokedWithNullableTypeArgument1() {
string program = @"
public class C {
static T F<T>() {
return default(T);
}
void M() {
$F<int?>()$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsFalse(rr.IsError);
}
[Test]
public void MethodCanBeInvokedWithNullableTypeArgument2() {
string program = @"
public class C {
static T F<T>(T t) {
return default(T);
}
void M() {
$F((int?)null)$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsFalse(rr.IsError);
}
[Test]
public void MethodCanBeInvokedWithNullableTypeArgument3() {
string program = @"
public class C {
static T F<T, U>() where T : U {
return default(T);
}
void M() {
$F<int?, object>()$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsFalse(rr.IsError);
}
[Test]
public void MethodWithStructContraintCanBeInvokedWithValueType() {
string program = @"
public class C {
static T F<T>() where T : struct {
return default(T);
}
void M() {
$F<int>()$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsFalse(rr.IsError);
}
[Test]
public void MethodWithStructContraintCannotBeInvokedWithNullableValueType() {
string program = @"
public class C {
static T F<T>() where T : struct {
return default(T);
}
void M() {
$F<int?>()$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsTrue(rr.IsError);
Assert.AreEqual(OverloadResolutionErrors.MethodConstraintsNotSatisfied, rr.OverloadResolutionErrors);
}
[Test]
public void CanConstructGenericTypeWithNullableTypeArgument() {
string program = @"
public class X<T> {}
public class C {
void M() {
$new X<int?>()$;
}
}";
var rr = Resolve<CSharpInvocationResolveResult>(program);
Assert.IsFalse(rr.IsError);
}
}
}

26
ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs

@ -989,5 +989,31 @@ class MainClass : Test @@ -989,5 +989,31 @@ class MainClass : Test
Assert.AreEqual("System.String", result.Type.FullName);
}
[Test]
public void DuplicateUsingDirective() {
string program = @"
using foo;
using foo;
namespace bar {
using foo;
using foo;
public class Bar {
public void M() {
new $Foo$();
}
}
}
namespace foo {
public class Foo {
}
}";
var result = Resolve<TypeResolveResult>(program);
Assert.IsFalse(result.IsError);
Assert.AreEqual("foo.Foo", result.Type.FullName);
}
}
}

10
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -17,11 +17,11 @@ @@ -17,11 +17,11 @@
<OutputPath>..\bin\$(Configuration)\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>PdbOnly</DebugType>
@ -44,19 +44,20 @@ @@ -44,19 +44,20 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET_4_5</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Release' ">
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET_4_5</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
@ -302,6 +303,7 @@ @@ -302,6 +303,7 @@
<Compile Include="CSharp\CodeActions\ConvertAnonymousDelegateToLambdaTests.cs" />
<Compile Include="CSharp\CodeActions\ConvertLamdaToAnonymousDelegateTests.cs" />
<Compile Include="CSharp\CodeIssues\ParameterCanBeDemotedIssue\SupportsIndexingCriterionTests.cs" />
<Compile Include="CSharp\CodeActions\CreateBackingStoreTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

6
ICSharpCode.NRefactory.Xml/ICSharpCode.NRefactory.Xml.csproj

@ -49,17 +49,17 @@ @@ -49,17 +49,17 @@
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Debug' ">
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET_4_5</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Release' ">
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET_4_5</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">

9
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -51,23 +51,24 @@ @@ -51,23 +51,24 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Debug' ">
<Optimize>False</Optimize>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET_4_5</DefineConstants>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<StartAction>Project</StartAction>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Release' ">
<Optimize>True</Optimize>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET_4_5</DefineConstants>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

2
ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs

@ -23,4 +23,4 @@ using System.Runtime.InteropServices; @@ -23,4 +23,4 @@ using System.Runtime.InteropServices;
// [AssemblyFileVersion] is the version of the NuGet package,
// should follow http://semver.org/ rules
[assembly: AssemblyFileVersion("5.1.0")]
[assembly: AssemblyFileVersion("5.2.0")]

5
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -1846,6 +1846,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1846,6 +1846,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
// FlagHasNoExtensionMethods is unused in LazyCecilTypeDefinition
}
public override object Clone()
{
throw new NotSupportedException();
}
public IType Resolve(ITypeResolveContext context)
{
if (context == null)

22
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedEntity.cs

@ -96,6 +96,23 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -96,6 +96,23 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
rareFields.ApplyInterningProvider(provider);
}
/// <summary>
/// Creates a shallow clone of this entity.
/// Collections (e.g. a type's member list) will be cloned as well, but the elements
/// of said list will not be.
/// If this instance is frozen, the clone will be unfrozen.
/// </summary>
public virtual object Clone()
{
var copy = (AbstractUnresolvedEntity)MemberwiseClone();
copy.flags[FlagFrozen] = false;
if (attributes != null)
copy.attributes = new List<IUnresolvedAttribute>(attributes);
if (rareFields != null)
copy.rareFields = (RareFields)rareFields.Clone();
return copy;
}
[Serializable]
internal class RareFields
{
@ -110,6 +127,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -110,6 +127,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public virtual void ApplyInterningProvider(IInterningProvider provider)
{
}
public virtual object Clone()
{
return MemberwiseClone();
}
}
protected void ThrowIfFrozen()

24
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractUnresolvedMember.cs

@ -39,6 +39,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -39,6 +39,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
interfaceImplementations = provider.InternList(interfaceImplementations);
}
protected override void FreezeInternal()
{
base.FreezeInternal();
interfaceImplementations = FreezableHelper.FreezeList(interfaceImplementations);
}
public override object Clone()
{
var copy = (AbstractUnresolvedMember)base.Clone();
if (interfaceImplementations != null)
copy.interfaceImplementations = new List<IMemberReference>(interfaceImplementations);
return copy;
}
/*
[Serializable]
internal new class RareFields : AbstractUnresolvedEntity.RareFields
@ -56,6 +70,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -56,6 +70,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
interfaceImplementations = FreezableHelper.FreezeListAndElements(interfaceImplementations);
base.FreezeInternal();
}
override Clone(){}
}
internal override AbstractUnresolvedEntity.RareFields WriteRareFields()
@ -83,20 +99,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -83,20 +99,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
/*
public IList<IMemberReference> ExplicitInterfaceImplementations {
get {
/*
RareFields rareFields = (RareFields)this.rareFields;
if (rareFields == null || rareFields.interfaceImplementations == null) {
rareFields = (RareFields)WriteRareFields();
return rareFields.interfaceImplementations = new List<IMemberReference>();
}
return rareFields.interfaceImplementations;
}
}*/
public IList<IMemberReference> ExplicitInterfaceImplementations {
get {
*/
if (interfaceImplementations == null)
interfaceImplementations = new List<IMemberReference>();
return interfaceImplementations;

12
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedMethod.cs

@ -42,6 +42,18 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -42,6 +42,18 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
base.FreezeInternal();
}
public override object Clone()
{
var copy = (DefaultUnresolvedMethod)base.Clone();
if (returnTypeAttributes != null)
copy.returnTypeAttributes = new List<IUnresolvedAttribute>(returnTypeAttributes);
if (typeParameters != null)
copy.typeParameters = new List<IUnresolvedTypeParameter>(typeParameters);
if (parameters != null)
copy.parameters = new List<IUnresolvedParameter>(parameters);
return copy;
}
public override void ApplyInterningProvider(IInterningProvider provider)
{
base.ApplyInterningProvider(provider);

8
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedProperty.cs

@ -39,6 +39,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -39,6 +39,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
base.FreezeInternal();
}
public override object Clone()
{
var copy = (DefaultUnresolvedProperty)base.Clone();
if (parameters != null)
copy.parameters = new List<IUnresolvedParameter>(parameters);
return copy;
}
public override void ApplyInterningProvider(IInterningProvider provider)
{
base.ApplyInterningProvider(provider);

23
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedTypeDefinition.cs

@ -75,6 +75,29 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -75,6 +75,29 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.UnresolvedFile = declaringTypeDefinition.UnresolvedFile;
}
protected override void FreezeInternal()
{
base.FreezeInternal();
baseTypes = FreezableHelper.FreezeList(baseTypes);
typeParameters = FreezableHelper.FreezeListAndElements(typeParameters);
nestedTypes = FreezableHelper.FreezeListAndElements(nestedTypes);
members = FreezableHelper.FreezeListAndElements(members);
}
public override object Clone()
{
var copy = (DefaultUnresolvedTypeDefinition)base.Clone();
if (baseTypes != null)
copy.baseTypes = new List<ITypeReference>(baseTypes);
if (typeParameters != null)
copy.typeParameters = new List<IUnresolvedTypeParameter>(typeParameters);
if (nestedTypes != null)
copy.nestedTypes = new List<IUnresolvedTypeDefinition>(nestedTypes);
if (members != null)
copy.members = new List<IUnresolvedMember>(members);
return copy;
}
public TypeKind Kind {
get { return kind; }
set {

2
ICSharpCode.NRefactory/Utils/EmptyList.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory
{
[Serializable]
public sealed class EmptyList<T> : IList<T>, IEnumerator<T>
#if NET45
#if NET_4_5
, IReadOnlyList<T>
#endif
{

2
ICSharpCode.NRefactory/Utils/LazyInit.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.Utils @@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.Utils
{
public static T VolatileRead<T>(ref T location) where T : class
{
#if NET45
#if NET_4_5
return Volatile.Read(ref location);
#else
T result = location;

2
ICSharpCode.NRefactory/Utils/MultiDictionary.cs

@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.Utils @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.Utils
dict.Clear();
}
#if NET45
#if NET_4_5
public IReadOnlyList<TValue> this[TKey key] {
#else
public IList<TValue> this[TKey key] {

20
Packages/ICSharpCode.NRefactory.nuspec

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>ICSharpCode.NRefactory</id>
<version>5.1.0</version>
<version>5.2.0</version>
<title>NRefactory</title>
<authors>Daniel Grunwald, Mike Krüger, Erik Källén</authors>
<owners>Daniel Grunwald</owners>
@ -19,15 +19,15 @@ @@ -19,15 +19,15 @@
</dependencies>
</metadata>
<files>
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.dll" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.pdb" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.xml" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.CSharp.dll" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.CSharp.pdb" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.CSharp.xml" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.Xml.dll" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.Xml.pdb" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\bin\Release\ICSharpCode.NRefactory.Xml.xml" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.xml" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.CSharp.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.CSharp.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.CSharp.xml" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Xml.dll" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Xml.pdb" target="lib\Net40" />
<file src="..\bin\Release\ICSharpCode.NRefactory.Xml.xml" target="lib\Net40" />
<file src="..\ICSharpCode.NRefactory\**\*.cs" target="src\ICSharpCode.NRefactory" />
<file src="..\ICSharpCode.NRefactory.CSharp\**\*.cs" target="src\ICSharpCode.NRefactory.CSharp" />
<file src="..\ICSharpCode.NRefactory.CSharp\**\*.jay" target="src\ICSharpCode.NRefactory.CSharp" />

24
README

@ -1,16 +1,7 @@ @@ -1,16 +1,7 @@
Overview of the NRefactory library:
Features:
- C# Parser
- Abstract Syntax Tree with pattern-matching support
- Semantic Analysis for C# (supports C# 4.0 + async/await)
- Code Completion for C#
- Pretty Printer for C#
- Lots of C# refactorings
Non-Features:
- VB support is not implemented yet.
- NRefactory cannot generate IL code
Introductory documentation:
http://www.codeproject.com/Articles/408663/Using-NRefactory-for-analyzing-Csharp-code
How to download:
- Binaries are provided as a NuGet package (http://nuget.org/packages/ICSharpCode.NRefactory)
@ -22,6 +13,17 @@ How to compile: @@ -22,6 +13,17 @@ How to compile:
next to the directory containing NRefactory.
2. Open NRefactory.sln in your favorite .NET IDE and compile.
Features:
- C# Parser
- Abstract Syntax Tree with pattern-matching support
- Semantic Analysis for C# (supports C# 4.0 + async/await)
- Code Completion for C#
- Pretty Printer for C#
- Lots of C# refactorings
Non-Features:
- VB support is not implemented yet.
- NRefactory cannot generate IL code
Dependencies:
.NET 4.0

Loading…
Cancel
Save