Browse Source

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

newNRvisualizers
Mansheng Yang 14 years ago
parent
commit
4ff155eac0
  1. 18
      ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
  2. 22
      ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs
  3. 1
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  4. 17
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  5. 151
      ICSharpCode.NRefactory.CSharp/Parser/CompilerSettings.cs
  6. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs
  7. 5
      ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs
  8. 24
      ICSharpCode.NRefactory.ConsistencyCheck/CSharpProject.cs
  9. 4
      ICSharpCode.NRefactory.ConsistencyCheck/RoundtripTest.cs
  10. 2
      ICSharpCode.NRefactory.Demo/CSDemo.Designer.cs
  11. 8
      ICSharpCode.NRefactory.Demo/CSDemo.cs
  12. 7
      ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj
  13. 80
      ICSharpCode.NRefactory.Demo/SemanticTreeDialog.Designer.cs
  14. 92
      ICSharpCode.NRefactory.Demo/SemanticTreeDialog.cs
  15. 120
      ICSharpCode.NRefactory.Demo/SemanticTreeDialog.resx
  16. 13
      ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs

18
ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// This is the only way to get an expression that isn't part of a statment. /// This is the only way to get an expression that isn't part of a statment.
/// (eg. when an error follows an expression). /// (eg. when an error follows an expression).
/// ///
/// This is used for code completion to 'get the expression before a token - like ., <, ('. /// This is used for code completion to 'get the expression before a token - like ., &lt;, ('.
/// </summary> /// </summary>
public AstNode TopExpression { public AstNode TopExpression {
get; get;
@ -136,33 +136,25 @@ namespace ICSharpCode.NRefactory.CSharp
public static CompilationUnit Parse (string text, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken)) public static CompilationUnit Parse (string text, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{ {
var parser = new CSharpParser (); var parser = new CSharpParser (settings);
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (text, fileName); return parser.Parse (text, fileName);
} }
public static CompilationUnit Parse (TextReader reader, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken)) public static CompilationUnit Parse (TextReader reader, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{ {
var parser = new CSharpParser (); var parser = new CSharpParser (settings);
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (reader, fileName, 0); return parser.Parse (reader, fileName, 0);
} }
public static CompilationUnit Parse (Stream stream, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken)) public static CompilationUnit Parse (Stream stream, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{ {
var parser = new CSharpParser (); var parser = new CSharpParser (settings);
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (stream, fileName, 0); return parser.Parse (stream, fileName, 0);
} }
public static CompilationUnit Parse (ITextSource textSource, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken)) public static CompilationUnit Parse (ITextSource textSource, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{ {
var parser = new CSharpParser (); var parser = new CSharpParser (settings);
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (textSource, fileName, 0); return parser.Parse (textSource, fileName, 0);
} }
} }

22
ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs

@ -33,12 +33,15 @@ namespace ICSharpCode.NRefactory.CSharp
string assemblyName; string assemblyName;
Dictionary<string, IParsedFile> parsedFiles; Dictionary<string, IParsedFile> parsedFiles;
List<IAssemblyReference> assemblyReferences; List<IAssemblyReference> assemblyReferences;
CompilerSettings compilerSettings;
public CSharpProjectContent() public CSharpProjectContent()
{ {
this.assemblyName = string.Empty; this.assemblyName = string.Empty;
this.parsedFiles = new Dictionary<string, IParsedFile>(Platform.FileNameComparer); this.parsedFiles = new Dictionary<string, IParsedFile>(Platform.FileNameComparer);
this.assemblyReferences = new List<IAssemblyReference>(); this.assemblyReferences = new List<IAssemblyReference>();
this.compilerSettings = new CompilerSettings();
compilerSettings.Freeze();
} }
protected CSharpProjectContent(CSharpProjectContent pc) protected CSharpProjectContent(CSharpProjectContent pc)
@ -46,6 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp
this.assemblyName = pc.assemblyName; this.assemblyName = pc.assemblyName;
this.parsedFiles = new Dictionary<string, IParsedFile>(pc.parsedFiles, Platform.FileNameComparer); this.parsedFiles = new Dictionary<string, IParsedFile>(pc.parsedFiles, Platform.FileNameComparer);
this.assemblyReferences = new List<IAssemblyReference>(pc.assemblyReferences); this.assemblyReferences = new List<IAssemblyReference>(pc.assemblyReferences);
this.compilerSettings = pc.compilerSettings;
} }
public IEnumerable<IParsedFile> Files { public IEnumerable<IParsedFile> Files {
@ -60,6 +64,14 @@ namespace ICSharpCode.NRefactory.CSharp
get { return assemblyName; } get { return assemblyName; }
} }
public CompilerSettings CompilerSettings {
get { return compilerSettings; }
}
object IProjectContent.CompilerSettings {
get { return compilerSettings; }
}
public IEnumerable<IUnresolvedAttribute> AssemblyAttributes { public IEnumerable<IUnresolvedAttribute> AssemblyAttributes {
get { get {
return this.Files.SelectMany(f => f.AssemblyAttributes); return this.Files.SelectMany(f => f.AssemblyAttributes);
@ -112,6 +124,16 @@ namespace ICSharpCode.NRefactory.CSharp
return pc; return pc;
} }
public IProjectContent SetCompilerSettings(object compilerSettings)
{
if (!(compilerSettings is CompilerSettings))
throw new ArgumentException("Settings must be an instance of " + typeof(CompilerSettings).FullName, "compilerSettings");
CSharpProjectContent pc = Clone();
pc.compilerSettings = (CompilerSettings)compilerSettings;
pc.compilerSettings.Freeze();
return pc;
}
public IProjectContent AddAssemblyReferences(IEnumerable<IAssemblyReference> references) public IProjectContent AddAssemblyReferences(IEnumerable<IAssemblyReference> references)
{ {
CSharpProjectContent pc = Clone(); CSharpProjectContent pc = Clone();

1
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -183,6 +183,7 @@
<Compile Include="OutputVisitor\IOutputFormatter.cs" /> <Compile Include="OutputVisitor\IOutputFormatter.cs" />
<Compile Include="OutputVisitor\CSharpOutputVisitor.cs" /> <Compile Include="OutputVisitor\CSharpOutputVisitor.cs" />
<Compile Include="OutputVisitor\TextWriterOutputFormatter.cs" /> <Compile Include="OutputVisitor\TextWriterOutputFormatter.cs" />
<Compile Include="Parser\CompilerSettings.cs" />
<Compile Include="Parser\CSharpParser.cs" /> <Compile Include="Parser\CSharpParser.cs" />
<Compile Include="Parser\mcs\anonymous.cs" /> <Compile Include="Parser\mcs\anonymous.cs" />
<Compile Include="Parser\mcs\argument.cs" /> <Compile Include="Parser\mcs\argument.cs" />

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

@ -36,6 +36,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public class CSharpParser public class CSharpParser
{ {
CompilerSettings compilerSettings;
class ConversionVisitor : StructuralVisitor class ConversionVisitor : StructuralVisitor
{ {
CompilationUnit unit = new CompilationUnit (); CompilationUnit unit = new CompilationUnit ();
@ -3471,13 +3473,12 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpParser () public CSharpParser ()
{ {
CompilerSettings = new CompilerSettings (); compilerSettings = new CompilerSettings();
CompilerSettings.Unsafe = true;
} }
public CSharpParser (CompilerSettings args) public CSharpParser (CompilerSettings args)
{ {
CompilerSettings = args; compilerSettings = args ?? new CompilerSettings();
} }
static AstNode GetOuterLeft (AstNode node) static AstNode GetOuterLeft (AstNode node)
@ -3673,8 +3674,12 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public CompilerSettings CompilerSettings { public CompilerSettings CompilerSettings {
get; get { return compilerSettings; }
internal set; set {
if (value == null)
throw new ArgumentNullException();
compilerSettings = value;
}
} }
public Action<CompilerCompilationUnit> CompilationUnitCallback { public Action<CompilerCompilationUnit> CompilationUnitCallback {
@ -3698,7 +3703,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
lock (parseLock) { lock (parseLock) {
errorReportPrinter = new ErrorReportPrinter (""); errorReportPrinter = new ErrorReportPrinter ("");
var ctx = new CompilerContext (CompilerSettings, errorReportPrinter); var ctx = new CompilerContext (compilerSettings.ToMono(), errorReportPrinter);
ctx.Settings.TabSize = 1; ctx.Settings.TabSize = 1;
var reader = new SeekableStreamReader (stream, Encoding.UTF8); var reader = new SeekableStreamReader (stream, Encoding.UTF8);
var file = new SourceFile (fileName, fileName, 0); var file = new SourceFile (fileName, fileName, 0);

151
ICSharpCode.NRefactory.CSharp/Parser/CompilerSettings.cs

@ -0,0 +1,151 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// 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 System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// C# compiler settings.
/// </summary>
[Serializable]
public class CompilerSettings : AbstractFreezable
{
protected override void FreezeInternal()
{
conditionalSymbols = FreezableHelper.FreezeList(conditionalSymbols);
specificWarningsAsErrors = FreezableHelper.FreezeList(specificWarningsAsErrors);
disabledWarnings = FreezableHelper.FreezeList(disabledWarnings);
base.FreezeInternal();
}
/// <summary>
/// Creates a new CompilerSettings instance.
/// </summary>
public CompilerSettings()
{
}
bool allowUnsafeBlocks = true;
/// <summary>
/// Gets/Sets whether <c>unsafe</c> code is allowed.
/// The default is <c>true</c>. If set to false, parsing unsafe code will result in parser errors.
/// </summary>
public bool AllowUnsafeBlocks {
get { return allowUnsafeBlocks; }
set {
FreezableHelper.ThrowIfFrozen(this);
allowUnsafeBlocks = value;
}
}
bool checkForOverflow;
/// <summary>
/// Gets/Sets whether overflow checking is enabled.
/// The default is <c>false</c>. This setting effects semantic analysis.
/// </summary>
public bool CheckForOverflow {
get { return checkForOverflow; }
set { checkForOverflow = value; }
}
Version languageVersion = new Version((int)Mono.CSharp.LanguageVersion.Default, 0);
/// <summary>
/// Gets/Sets the language version used by the parser.
/// Using language constructs newer than the supplied version will result in parser errors.
/// </summary>
public Version LanguageVersion {
get { return languageVersion; }
set {
FreezableHelper.ThrowIfFrozen(this);
if (value == null)
throw new ArgumentNullException();
languageVersion = value;
}
}
IList<string> conditionalSymbols = new List<string>();
/// <summary>
/// Gets/Sets the list of conditional symbols that are defined project-wide.
/// </summary>
public IList<string> ConditionalSymbols {
get { return conditionalSymbols; }
}
bool treatWarningsAsErrors;
public bool TreatWarningsAsErrors {
get { return treatWarningsAsErrors; }
set {
FreezableHelper.ThrowIfFrozen(this);
treatWarningsAsErrors = value;
}
}
IList<int> specificWarningsAsErrors = new List<int>();
/// <summary>
/// Allows treating specific warnings as errors without setting <see cref="TreatWarningsAsErrors"/> to true.
/// </summary>
public IList<int> SpecificWarningsAsErrors {
get { return specificWarningsAsErrors; }
}
int warningLevel = 4;
public int WarningLevel {
get { return warningLevel; }
set {
FreezableHelper.ThrowIfFrozen(this);
warningLevel = value;
}
}
IList<int> disabledWarnings = new List<int>();
/// <summary>
/// Allows treating specific warnings as errors without setting <see cref="TreatWarningsAsErrors"/> to true.
/// </summary>
public IList<int> DisabledWarnings {
get { return disabledWarnings; }
}
internal Mono.CSharp.CompilerSettings ToMono()
{
var s = new Mono.CSharp.CompilerSettings();
s.Unsafe = allowUnsafeBlocks;
s.Checked = checkForOverflow;
s.Version = (Mono.CSharp.LanguageVersion)languageVersion.Major;
s.WarningsAreErrors = treatWarningsAsErrors;
s.WarningLevel = warningLevel;
foreach (int code in disabledWarnings)
s.SetIgnoreWarning(code);
foreach (int code in specificWarningsAsErrors)
s.AddWarningAsError(code);
foreach (string sym in conditionalSymbols)
s.AddConditionalSymbol(sym);
return s;
}
}
}

4
ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs

@ -225,6 +225,10 @@ namespace Mono.CSharp {
} }
} }
public IList<string> ConditionalSymbols {
get { return conditional_symbols; }
}
#endregion #endregion
public void AddConditionalSymbol (string symbol) public void AddConditionalSymbol (string symbol)

5
ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs

@ -56,6 +56,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
this.compilation = compilation; this.compilation = compilation;
this.conversions = CSharpConversions.Get(compilation); this.conversions = CSharpConversions.Get(compilation);
this.context = new CSharpTypeResolveContext(compilation.MainAssembly); this.context = new CSharpTypeResolveContext(compilation.MainAssembly);
var pc = compilation.MainAssembly.UnresolvedAssembly as CSharpProjectContent;
if (pc != null) {
this.checkForOverflow = pc.CompilerSettings.CheckForOverflow;
}
} }
public CSharpResolver(CSharpTypeResolveContext context) public CSharpResolver(CSharpTypeResolveContext context)

24
ICSharpCode.NRefactory.ConsistencyCheck/CSharpProject.cs

@ -36,9 +36,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
public readonly List<CSharpFile> Files = new List<CSharpFile>(); public readonly List<CSharpFile> Files = new List<CSharpFile>();
public readonly bool AllowUnsafeBlocks; public readonly CompilerSettings CompilerSettings = new CompilerSettings();
public readonly bool CheckForOverflowUnderflow;
public readonly string[] PreprocessorDefines;
public IProjectContent ProjectContent; public IProjectContent ProjectContent;
@ -56,9 +54,11 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
var p = new Microsoft.Build.Evaluation.Project(fileName); var p = new Microsoft.Build.Evaluation.Project(fileName);
this.AssemblyName = p.GetPropertyValue("AssemblyName"); this.AssemblyName = p.GetPropertyValue("AssemblyName");
this.AllowUnsafeBlocks = GetBoolProperty(p, "AllowUnsafeBlocks") ?? false; this.CompilerSettings.AllowUnsafeBlocks = GetBoolProperty(p, "AllowUnsafeBlocks") ?? false;
this.CheckForOverflowUnderflow = GetBoolProperty(p, "CheckForOverflowUnderflow") ?? false; this.CompilerSettings.CheckForOverflow = GetBoolProperty(p, "CheckForOverflowUnderflow") ?? false;
this.PreprocessorDefines = p.GetPropertyValue("DefineConstants").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string symbol in p.GetPropertyValue("DefineConstants").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) {
this.CompilerSettings.ConditionalSymbols.Add(symbol.Trim());
}
foreach (var item in p.GetItems("Compile")) { foreach (var item in p.GetItems("Compile")) {
Files.Add(new CSharpFile(this, Path.Combine(p.DirectoryPath, item.EvaluatedInclude))); Files.Add(new CSharpFile(this, Path.Combine(p.DirectoryPath, item.EvaluatedInclude)));
} }
@ -95,6 +95,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
} }
this.ProjectContent = new CSharpProjectContent() this.ProjectContent = new CSharpProjectContent()
.SetAssemblyName(this.AssemblyName) .SetAssemblyName(this.AssemblyName)
.SetCompilerSettings(this.CompilerSettings)
.AddAssemblyReferences(references) .AddAssemblyReferences(references)
.UpdateProjectContent(null, Files.Select(f => f.ParsedFile)); .UpdateProjectContent(null, Files.Select(f => f.ParsedFile));
} }
@ -121,15 +122,6 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
return null; return null;
} }
public CSharpParser CreateParser()
{
var settings = new Mono.CSharp.CompilerSettings();
settings.Unsafe = AllowUnsafeBlocks;
foreach (string define in PreprocessorDefines)
settings.AddConditionalSymbol(define);
return new CSharpParser(settings);
}
public override string ToString() public override string ToString()
{ {
return string.Format("[CSharpProject AssemblyName={0}]", AssemblyName); return string.Format("[CSharpProject AssemblyName={0}]", AssemblyName);
@ -176,7 +168,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
this.Content = new StringTextSource(File.ReadAllText(FileName)); this.Content = new StringTextSource(File.ReadAllText(FileName));
this.LinesOfCode = 1 + this.Content.Text.Count(c => c == '\n'); this.LinesOfCode = 1 + this.Content.Text.Count(c => c == '\n');
CSharpParser p = project.CreateParser(); CSharpParser p = new CSharpParser(project.CompilerSettings);
this.CompilationUnit = p.Parse(Content.CreateReader(), fileName); this.CompilationUnit = p.Parse(Content.CreateReader(), fileName);
if (p.HasErrors) { if (p.HasErrors) {
Console.WriteLine("Error parsing " + fileName + ":"); Console.WriteLine("Error parsing " + fileName + ":");

4
ICSharpCode.NRefactory.ConsistencyCheck/RoundtripTest.cs

@ -55,9 +55,9 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
if (file.FileName.EndsWith("DefaultResolvedTypeDefinition.cs")) if (file.FileName.EndsWith("DefaultResolvedTypeDefinition.cs"))
return; // skip due to MethodDeclarationTests.GenericMethodWithMultipleConstraints return; // skip due to MethodDeclarationTests.GenericMethodWithMultipleConstraints
Roundtrip(file.Project.CreateParser(), file.FileName, code); Roundtrip(new CSharpParser(file.Project.CompilerSettings), file.FileName, code);
// After trying unix-style newlines, also try windows-style newlines: // After trying unix-style newlines, also try windows-style newlines:
Roundtrip(file.Project.CreateParser(), file.FileName, code.Replace("\n", "\r\n")); Roundtrip(new CSharpParser(file.Project.CompilerSettings), file.FileName, code.Replace("\n", "\r\n"));
} }
public static void Roundtrip(CSharpParser parser, string fileName, string code) public static void Roundtrip(CSharpParser parser, string fileName, string code)

2
ICSharpCode.NRefactory.Demo/CSDemo.Designer.cs generated

@ -153,7 +153,7 @@ namespace ICSharpCode.NRefactory.Demo
this.csharpParseButton.Name = "csharpParseButton"; this.csharpParseButton.Name = "csharpParseButton";
this.csharpParseButton.Size = new System.Drawing.Size(100, 23); this.csharpParseButton.Size = new System.Drawing.Size(100, 23);
this.csharpParseButton.TabIndex = 0; this.csharpParseButton.TabIndex = 0;
this.csharpParseButton.Text = "Parse"; this.csharpParseButton.Text = "\u2193 Parse \u2193";
this.csharpParseButton.UseVisualStyleBackColor = true; this.csharpParseButton.UseVisualStyleBackColor = true;
this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick); this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick);
// //

8
ICSharpCode.NRefactory.Demo/CSDemo.cs

@ -203,9 +203,11 @@ namespace ICSharpCode.NRefactory.Demo
ICompilation compilation = project.CreateCompilation(); ICompilation compilation = project.CreateCompilation();
AstNode selectedNode = null;
StoreInDictionaryNavigator navigator; StoreInDictionaryNavigator navigator;
if (csharpTreeView.SelectedNode != null) { if (csharpTreeView.SelectedNode != null) {
navigator = new StoreInDictionaryNavigator((AstNode)csharpTreeView.SelectedNode.Tag); selectedNode = (AstNode)csharpTreeView.SelectedNode.Tag;
navigator = new StoreInDictionaryNavigator(selectedNode);
} else { } else {
navigator = new StoreInDictionaryNavigator(); navigator = new StoreInDictionaryNavigator();
} }
@ -214,6 +216,10 @@ namespace ICSharpCode.NRefactory.Demo
csharpTreeView.BeginUpdate(); csharpTreeView.BeginUpdate();
ShowResolveResultsInTree(csharpTreeView.Nodes, navigator); ShowResolveResultsInTree(csharpTreeView.Nodes, navigator);
csharpTreeView.EndUpdate(); csharpTreeView.EndUpdate();
if (csharpTreeView.SelectedNode != null) {
using (var dlg = new SemanticTreeDialog(resolver.Resolve(selectedNode)))
dlg.ShowDialog();
}
} }
sealed class StoreInDictionaryNavigator : NodeListResolveVisitorNavigator sealed class StoreInDictionaryNavigator : NodeListResolveVisitorNavigator

7
ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj

@ -72,6 +72,10 @@
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SemanticTreeDialog.cs" />
<Compile Include="SemanticTreeDialog.Designer.cs">
<DependentUpon>SemanticTreeDialog.cs</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj"> <ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
@ -90,6 +94,9 @@
<EmbeddedResource Include="MainForm.resx"> <EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="SemanticTreeDialog.resx">
<DependentUpon>SemanticTreeDialog.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project> </Project>

80
ICSharpCode.NRefactory.Demo/SemanticTreeDialog.Designer.cs generated

@ -0,0 +1,80 @@
/*
* Created by SharpDevelop.
* User: Daniel
* Date: 6/22/2012
* Time: 17:08
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace ICSharpCode.NRefactory.Demo
{
partial class SemanticTreeDialog
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.cancelButton = new System.Windows.Forms.Button();
this.treeView = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(197, 236);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 0;
this.cancelButton.Text = "Close";
this.cancelButton.UseVisualStyleBackColor = true;
//
// treeView
//
this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView.Location = new System.Drawing.Point(12, 12);
this.treeView.Name = "treeView";
this.treeView.ShowRootLines = false;
this.treeView.Size = new System.Drawing.Size(260, 218);
this.treeView.TabIndex = 1;
//
// SemanticTreeDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.treeView);
this.Controls.Add(this.cancelButton);
this.Name = "SemanticTreeDialog";
this.Text = "Semantic Tree";
this.ResumeLayout(false);
}
private System.Windows.Forms.TreeView treeView;
private System.Windows.Forms.Button cancelButton;
}
}

92
ICSharpCode.NRefactory.Demo/SemanticTreeDialog.cs

@ -0,0 +1,92 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// 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 System.Collections;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.NRefactory.Semantics;
namespace ICSharpCode.NRefactory.Demo
{
/// <summary>
/// Description of SemanticTreeDialog.
/// </summary>
public partial class SemanticTreeDialog : Form
{
public SemanticTreeDialog(ResolveResult rr)
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
var rootNode = MakeObjectNode("Resolve() = ", rr);
rootNode.Expand();
treeView.Nodes.Add(rootNode);
}
TreeNode MakeObjectNode(string prefix, object obj)
{
if (obj == null)
return new TreeNode(prefix + "null");
if (obj is ResolveResult) {
TreeNode t = new TreeNode(prefix + obj.GetType().Name);
t.Tag = obj;
foreach (PropertyInfo p in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
if (p.Name == "ConstantValue" && !((ResolveResult)obj).IsCompileTimeConstant)
continue;
TreeNode child = MakePropertyNode(p.Name, p.PropertyType, p.GetValue(obj, null));
if (child != null)
t.Nodes.Add(child);
}
foreach (FieldInfo p in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)) {
TreeNode child = MakePropertyNode(p.Name, p.FieldType, p.GetValue(obj));
if (child != null)
t.Nodes.Add(child);
}
return t;
} else {
return new TreeNode(prefix + obj.ToString());
}
}
TreeNode MakePropertyNode(string propertyName, Type propertyType, object propertyValue)
{
if (propertyName == "IsError" && (propertyValue as bool?) == false)
return null;
if (propertyName == "IsCompileTimeConstant" && (propertyValue as bool?) == false)
return null;
if (propertyValue == null) {
return new TreeNode(propertyName + " = null");
}
if (propertyType.GetInterface("System.Collections.IEnumerable") != null && propertyType != typeof(string)) {
var collection = ((IEnumerable)propertyValue).Cast<object>().ToList();
var node = new TreeNode(propertyName + " = Collection with " + collection.Count + " elements");
foreach (object element in collection) {
node.Nodes.Add(MakeObjectNode("", element));
}
return node;
}
return MakeObjectNode(propertyName + " = ", propertyValue);
}
}
}

120
ICSharpCode.NRefactory.Demo/SemanticTreeDialog.resx

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

13
ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs

@ -42,6 +42,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary> /// </summary>
IEnumerable<IAssemblyReference> AssemblyReferences { get; } IEnumerable<IAssemblyReference> AssemblyReferences { get; }
/// <summary>
/// Gets the compiler settings object.
/// The concrete type of the settings object depends on the programming language used to implement this project.
/// </summary>
object CompilerSettings { get; }
/// <summary> /// <summary>
/// Creates a new <see cref="ICompilation"/> that allows resolving within this project. /// Creates a new <see cref="ICompilation"/> that allows resolving within this project.
/// </summary> /// </summary>
@ -83,5 +89,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Removes types and attributes from oldFiles from the project, and adds those from newFiles. /// Removes types and attributes from oldFiles from the project, and adds those from newFiles.
/// </summary> /// </summary>
IProjectContent UpdateProjectContent(IEnumerable<IParsedFile> oldFiles, IEnumerable<IParsedFile> newFiles); IProjectContent UpdateProjectContent(IEnumerable<IParsedFile> oldFiles, IEnumerable<IParsedFile> newFiles);
/// <summary>
/// Sets the compiler settings object.
/// The concrete type of the settings object depends on the programming language used to implement this project.
/// Using the incorrect type of settings object results in an <see cref="ArgumentException"/>.
/// </summary>
IProjectContent SetCompilerSettings(object compilerSettings);
} }
} }

Loading…
Cancel
Save