Browse Source

Merge remote-tracking branch 'upstream/master' into mansheng

newNRvisualizers
Mansheng Yang 14 years ago
parent
commit
611cc25660
  1. 2
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  2. 15
      ICSharpCode.NRefactory.CSharp/Completion/ICompletionContextProvider.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  4. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateBackingStoreAction.cs
  5. 1
      ICSharpCode.NRefactory.CSharp/Resolver/OverloadResolution.cs
  6. 2
      ICSharpCode.NRefactory.Demo/CSDemo.cs
  7. 77
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateBackingStoreTests.cs
  8. 40
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
  9. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  10. 2
      ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs
  11. 20
      Packages/ICSharpCode.NRefactory.nuspec
  12. 24
      README

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;

15
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)
{
@ -57,6 +68,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -57,6 +68,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
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/Parser/CSharpParser.cs

@ -3765,7 +3765,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -3765,7 +3765,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);

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.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;
}
}
}");
}
}
}

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

@ -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"));
});
}
}
}

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -327,6 +327,7 @@ @@ -327,6 +327,7 @@
<Compile Include="CSharp\CodeActions\ExtractFieldTests.cs" />
<Compile Include="CSharp\CodeCompletion\DocumentationContextTests.cs" />
<Compile Include="CSharp\CodeCompletion\BrowsableAttributeTests.cs" />
<Compile Include="CSharp\CodeActions\CreateBackingStoreTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

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")]

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