Browse Source

Add NRefactory.Demo (TreeView for visualization of C# DOM)

newNRvisualizers
Daniel Grunwald 16 years ago
parent
commit
716a5f51fe
  1. 61
      ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj
  2. 177
      ICSharpCode.NRefactory.Demo/MainForm.Designer.cs
  3. 106
      ICSharpCode.NRefactory.Demo/MainForm.cs
  4. 120
      ICSharpCode.NRefactory.Demo/MainForm.resx
  5. 25
      ICSharpCode.NRefactory.Demo/Program.cs
  6. 31
      ICSharpCode.NRefactory.Demo/Properties/AssemblyInfo.cs
  7. 33
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/SimpleNameLookupTests.cs
  8. 3
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/TypeDeclaration.cs
  9. 7
      ICSharpCode.NRefactory/CSharp/Dom/INode.cs
  10. 10
      ICSharpCode.NRefactory/CSharp/Dom/QualifiedIdentifier.cs
  11. 96
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  12. 12
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-tokenizer.cs
  13. 2
      ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
  14. 26
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  15. 7
      ICSharpCode.NRefactory/TypeSystem/IEntity.cs
  16. 12
      NRefactory.sln

61
ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>ICSharpCode.NRefactory.Demo</RootNamespace>
<AssemblyName>ICSharpCode.NRefactory.Demo</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs" />
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

177
ICSharpCode.NRefactory.Demo/MainForm.Designer.cs generated

@ -0,0 +1,177 @@ @@ -0,0 +1,177 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
namespace ICSharpCode.NRefactory.Demo
{
partial class MainForm
{
/// <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.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.csharpCodeTextBox = new System.Windows.Forms.TextBox();
this.csharpTreeView = new System.Windows.Forms.TreeView();
this.csharpGenerateCodeButton = new System.Windows.Forms.Button();
this.csharpParseButton = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(515, 484);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.splitContainer1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(507, 458);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "C#";
this.tabPage1.UseVisualStyleBackColor = true;
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(3, 3);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.csharpCodeTextBox);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.csharpTreeView);
this.splitContainer1.Panel2.Controls.Add(this.csharpGenerateCodeButton);
this.splitContainer1.Panel2.Controls.Add(this.csharpParseButton);
this.splitContainer1.Size = new System.Drawing.Size(501, 452);
this.splitContainer1.SplitterDistance = 201;
this.splitContainer1.TabIndex = 0;
//
// csharpCodeTextBox
//
this.csharpCodeTextBox.AcceptsReturn = true;
this.csharpCodeTextBox.AcceptsTab = true;
this.csharpCodeTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.csharpCodeTextBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.csharpCodeTextBox.HideSelection = false;
this.csharpCodeTextBox.Location = new System.Drawing.Point(0, 0);
this.csharpCodeTextBox.Multiline = true;
this.csharpCodeTextBox.Name = "csharpCodeTextBox";
this.csharpCodeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.csharpCodeTextBox.Size = new System.Drawing.Size(501, 201);
this.csharpCodeTextBox.TabIndex = 0;
this.csharpCodeTextBox.Text = "using System;\r\nclass Test\r\n{\r\n public void Main(string[] args)\r\n {\r\n " +
" System.Console.WriteLine(\"Hello, World\");\r\n }\r\n}";
this.csharpCodeTextBox.WordWrap = false;
//
// csharpTreeView
//
this.csharpTreeView.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.csharpTreeView.Location = new System.Drawing.Point(3, 28);
this.csharpTreeView.Name = "csharpTreeView";
this.csharpTreeView.Size = new System.Drawing.Size(493, 216);
this.csharpTreeView.TabIndex = 2;
this.csharpTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.CSharpTreeViewAfterSelect);
//
// csharpGenerateCodeButton
//
this.csharpGenerateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.csharpGenerateCodeButton.Location = new System.Drawing.Point(249, 3);
this.csharpGenerateCodeButton.Name = "csharpGenerateCodeButton";
this.csharpGenerateCodeButton.Size = new System.Drawing.Size(118, 23);
this.csharpGenerateCodeButton.TabIndex = 1;
this.csharpGenerateCodeButton.Text = "Generate Code";
this.csharpGenerateCodeButton.UseVisualStyleBackColor = true;
this.csharpGenerateCodeButton.Click += new System.EventHandler(this.CSharpGenerateCodeButtonClick);
//
// csharpParseButton
//
this.csharpParseButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.csharpParseButton.Location = new System.Drawing.Point(133, 3);
this.csharpParseButton.Name = "csharpParseButton";
this.csharpParseButton.Size = new System.Drawing.Size(110, 23);
this.csharpParseButton.TabIndex = 0;
this.csharpParseButton.Text = "Parse Code";
this.csharpParseButton.UseVisualStyleBackColor = true;
this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick);
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(507, 458);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "VB";
this.tabPage2.UseVisualStyleBackColor = true;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(515, 484);
this.Controls.Add(this.tabControl1);
this.Name = "MainForm";
this.Text = "NRefactory Demo";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
private System.Windows.Forms.TreeView csharpTreeView;
private System.Windows.Forms.Button csharpParseButton;
private System.Windows.Forms.Button csharpGenerateCodeButton;
private System.Windows.Forms.TextBox csharpCodeTextBox;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabControl tabControl1;
}
}

106
ICSharpCode.NRefactory.Demo/MainForm.cs

@ -0,0 +1,106 @@ @@ -0,0 +1,106 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.Demo
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
CSharpParseButtonClick(null, null);
}
void CSharpParseButtonClick(object sender, EventArgs e)
{
CSharpParser parser = new CSharpParser();
CompilationUnit cu = parser.Parse(new StringReader(csharpCodeTextBox.Text));
csharpTreeView.Nodes.Clear();
foreach (var element in cu.Children) {
csharpTreeView.Nodes.Add(MakeTreeNode(element));
}
}
TreeNode MakeTreeNode(INode node)
{
StringBuilder b = new StringBuilder();
b.Append(DecodeRole(node.Role, node.Parent != null ? node.Parent.GetType() : null));
b.Append(": ");
b.Append(node.GetType().Name);
bool hasProperties = false;
foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum) {
if (!hasProperties) {
hasProperties = true;
b.Append(" (");
} else {
b.Append(", ");
}
b.Append(p.Name);
b.Append(" = ");
try {
object val = p.GetValue(node, null);
b.Append(val != null ? val.ToString() : "**null**");
} catch (TargetInvocationException ex) {
b.Append("**" + ex.InnerException.GetType().Name + "**");
}
}
}
if (hasProperties)
b.Append(")");
TreeNode t = new TreeNode(b.ToString());
t.Tag = node;
foreach (INode child in node.Children) {
t.Nodes.Add(MakeTreeNode(child));
}
return t;
}
string DecodeRole(int role, Type type)
{
if (type != null) {
foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.Static)) {
if (field.FieldType == typeof(int) && (int)field.GetValue(null) == role)
return field.Name;
}
}
foreach (FieldInfo field in typeof(AbstractNode.Roles).GetFields(BindingFlags.Public | BindingFlags.Static)) {
if (field.FieldType == typeof(int) && (int)field.GetValue(null) == role)
return field.Name;
}
return role.ToString();
}
void CSharpGenerateCodeButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e)
{
INode node = e.Node.Tag as INode;
if (node != null) {
int startOffset = csharpCodeTextBox.GetFirstCharIndexFromLine(node.StartLocation.Line - 1) + node.StartLocation.Column - 1;
int endOffset = csharpCodeTextBox.GetFirstCharIndexFromLine(node.EndLocation.Line - 1) + node.EndLocation.Column - 1;
csharpCodeTextBox.Select(startOffset, endOffset - startOffset);
}
}
}
}

120
ICSharpCode.NRefactory.Demo/MainForm.resx

@ -0,0 +1,120 @@ @@ -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>

25
ICSharpCode.NRefactory.Demo/Program.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Windows.Forms;
namespace ICSharpCode.NRefactory.Demo
{
/// <summary>
/// Class with program entry point.
/// </summary>
internal sealed class Program
{
/// <summary>
/// Program entry point.
/// </summary>
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}

31
ICSharpCode.NRefactory.Demo/Properties/AssemblyInfo.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ICSharpCode.NRefactory.Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ICSharpCode.NRefactory.Demo")]
[assembly: AssemblyCopyright("Copyright 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

33
ICSharpCode.NRefactory.Tests/CSharp/Resolver/SimpleNameLookupTests.cs

@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ICSharpCode.NRefactory.TypeSystem;
@ -102,5 +104,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -102,5 +104,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
Assert.IsTrue(resolver.ResolveAlias("System").IsError);
}
[Test]
public void FindClassInCurrentNamespace()
{
resolver.UsingScope = MakeUsingScope("System.Collections");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("String", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
}
[Test]
public void FindNeighborNamespace()
{
resolver.UsingScope = MakeUsingScope("System.Collections");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
[Test]
public void FindTypeParameters()
{
resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentTypeDefinition = context.GetClass(typeof(List<>));
resolver.CurrentMember = resolver.CurrentTypeDefinition.Methods.Single(m => m.Name == "ConvertAll");
TypeResolveResult trr;
trr = (TypeResolveResult)resolver.ResolveSimpleName("TOutput", new IType[0]);
Assert.AreSame(((IMethod)resolver.CurrentMember).TypeParameters[0], trr.Type);
trr = (TypeResolveResult)resolver.ResolveSimpleName("T", new IType[0]);
Assert.AreSame(resolver.CurrentTypeDefinition.TypeParameters[0], trr.Type);
}
}
}

3
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/TypeDeclaration.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// TypeDeclaration.cs
//
// Author:
@ -47,6 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,6 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
// TODO: rename to TypeParameters, more specific return type
public IEnumerable<INode> TypeArguments {
get {
return GetChildrenByRole (Roles.TypeArgument).Cast<INode> ();

7
ICSharpCode.NRefactory/CSharp/Dom/INode.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// INode.cs
//
// Author:
@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
@ -35,6 +36,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -35,6 +36,10 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
IEnumerable<INode> Children {
get;
}
int Role {
get;
set;

10
ICSharpCode.NRefactory/CSharp/Dom/QualifiedIdentifier.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// QualifiedIdentifier.cs
//
// Author:
@ -25,6 +25,8 @@ @@ -25,6 +25,8 @@
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.NRefactory.CSharp
@ -43,6 +45,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,6 +45,12 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public IEnumerable<Identifier> NameParts {
get {
return GetChildrenByRole (Roles.Identifier).Cast<Identifier>();
}
}
public QualifiedIdentifier ()
{
}

96
ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// Produces type and member declarations.
/// </summary>
public class TypeSystemConvertVisitor : AbstractDomVisitor<object, IEntity>
{
readonly string fileName;
UsingScope usingScope;
DefaultTypeDefinition currentTypeDefinition;
public TypeSystemConvertVisitor(IProjectContent pc, string fileName)
{
this.usingScope = new UsingScope(pc);
this.fileName = fileName;
}
DomRegion MakeRegion(DomLocation start, DomLocation end)
{
return new DomRegion(fileName, start.Line, start.Column, end.Line, end.Column);
}
// TODO: extern aliases
public override IEntity VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
throw new NotImplementedException();
}
public override IEntity VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, object data)
{
throw new NotImplementedException();
}
public override IEntity VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
{
UsingScope previousUsingScope = usingScope;
foreach (Identifier ident in namespaceDeclaration.NameIdentifier.NameParts) {
usingScope = new UsingScope(usingScope, NamespaceDeclaration.BuildQualifiedName(usingScope.NamespaceName, ident.Name));
}
base.VisitNamespaceDeclaration(namespaceDeclaration, data);
usingScope = previousUsingScope;
return null;
}
// TODO: assembly attributes
DefaultTypeDefinition CreateTypeDefinition(string name)
{
if (currentTypeDefinition != null)
return new DefaultTypeDefinition(currentTypeDefinition, name);
else
return new DefaultTypeDefinition(usingScope.ProjectContent, usingScope.NamespaceName, name);
}
public override IEntity VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
var td = currentTypeDefinition = CreateTypeDefinition(typeDeclaration.Name);
td.ClassType = typeDeclaration.ClassType;
td.Region = MakeRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
td.BodyRegion = MakeRegion(typeDeclaration.LBrace.StartLocation, typeDeclaration.RBrace.EndLocation);
td.AddDefaultConstructorIfRequired = true;
ConvertAttributes(td.Attributes, typeDeclaration.Attributes);
// TODO: modifiers
//ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeArguments, typeDeclaration.Constraints, td);
// TODO: base type references?
// TODO: members
currentTypeDefinition = (DefaultTypeDefinition)currentTypeDefinition.DeclaringTypeDefinition;
return td;
}
public override IEntity VisitEnumDeclaration(EnumDeclaration enumDeclaration, object data)
{
return VisitTypeDeclaration(enumDeclaration, data);
}
void ConvertAttributes(IList<IAttribute> outputList, IEnumerable<AttributeSection> attributes)
{
throw new NotImplementedException();
}
}
}

12
ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-tokenizer.cs

@ -61,11 +61,13 @@ namespace Mono.CSharp @@ -61,11 +61,13 @@ namespace Mono.CSharp
public int GetHashCode (char[] obj)
{
int h = 0;
for (int i = 0; i < length; ++i)
h = (h << 5) - h + obj [i];
return h;
unchecked {
int h = 0;
for (int i = 0; i < length; ++i)
h = (h << 5) - h + obj [i];
return h;
}
}
}

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

@ -1732,6 +1732,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1732,6 +1732,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
#endregion
#region ResolvePrimitive
public ResolveResult ResolvePrimitive(object value)
{
if (value == null) {
@ -1742,5 +1743,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1742,5 +1743,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return new ConstantResolveResult(type, value);
}
}
#endregion
}
}

26
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -11,37 +11,42 @@ @@ -11,37 +11,42 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>DEBUG;TRACE;FULL_AST</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;FULL_AST</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DebugType>Full</DebugType>
<Optimize>false</Optimize>
<WarningLevel>4</WarningLevel>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<DebugType>None</DebugType>
<Optimize>true</Optimize>
<WarningLevel>4</WarningLevel>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil">
@ -151,6 +156,7 @@ @@ -151,6 +156,7 @@
<Compile Include="CSharp\Parser\mcs\MonoSymbolWriter.cs" />
<Compile Include="CSharp\Parser\mcs\outline.cs" />
<Compile Include="CSharp\Parser\mcs\roottypes.cs" />
<Compile Include="CSharp\Parser\TypeSystemConvertVisitor.cs" />
<Compile Include="CSharp\Resolver\AliasNamespaceReference.cs" />
<Compile Include="CSharp\Resolver\AmbiguousResolveResult.cs" />
<Compile Include="CSharp\Resolver\ByReferenceResolveResult.cs" />

7
ICSharpCode.NRefactory/TypeSystem/IEntity.cs

@ -12,7 +12,14 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -12,7 +12,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
EntityType EntityType { get; }
/// <summary>
/// Gets the complete entity region (including header+body)
/// </summary>
DomRegion Region { get; }
/// <summary>
/// Gets the entity body region.
/// </summary>
DomRegion BodyRegion { get; }
/// <summary>

12
NRefactory.sln

@ -12,10 +12,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "I @@ -12,10 +12,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "I
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Tests", "ICSharpCode.NRefactory.Tests\ICSharpCode.NRefactory.Tests.csproj", "{63D3B27A-D966-4902-90B3-30290E1692F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Demo", "ICSharpCode.NRefactory.Demo\ICSharpCode.NRefactory.Demo.csproj", "{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@ -26,6 +30,14 @@ Global @@ -26,6 +30,14 @@ Global
{63D3B27A-D966-4902-90B3-30290E1692F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63D3B27A-D966-4902-90B3-30290E1692F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63D3B27A-D966-4902-90B3-30290E1692F1}.Release|Any CPU.Build.0 = Release|Any CPU
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Debug|Any CPU.Build.0 = Debug|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Debug|Any CPU.ActiveCfg = Debug|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Release|Any CPU.Build.0 = Release|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Release|Any CPU.ActiveCfg = Release|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Debug|x86.Build.0 = Debug|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Debug|x86.ActiveCfg = Debug|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Release|x86.Build.0 = Release|x86
{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj

Loading…
Cancel
Save