Permalink
Browse files

Started type system conversion. (still some todos left)

  • Loading branch information...
mkrueger committed Jun 16, 2011
1 parent 74a5706 commit 59ba94055eaf9dd53a26b5f4ca1c20cfe8cb3b5e
@@ -6,6 +6,7 @@ DEPS = \
$(top_builddir)/build/AddIns/MonoDevelop.Deployment/MonoDevelop.Deployment.dll \
$(top_builddir)/build/AddIns/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.dll \
$(top_builddir)/build/AddIns/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor.dll \
$(top_builddir)/build/bin/ICSharpCode.NRefactory.dll \
$(top_builddir)/build/bin/MonoDevelop.Core.dll \
$(top_builddir)/build/bin/MonoDevelop.Ide.dll
@@ -27,8 +27,8 @@
//
using System;
using MonoDevelop.Projects.Dom;
using MonoDevelop.Projects.Dom.Parser;
using ICSharpCode.NRefactory.TypeSystem;
using MonoDevelop.TypeSystem;
namespace MonoDevelop.Moonlight.Gui
{
@@ -94,11 +94,11 @@ void FillClasses (MoonlightProject project)
return;
classesFilled = true;
try {
ProjectDom dom = ProjectDomService.GetProjectDom (project);
IType appType = dom.GetType ("System.Windows.Application", true);
var dom = TypeSystemService.GetContext (project);
IType appType = dom.GetClass ("System.Windows", "Application", 0, StringComparer.Ordinal);
if (appType == null)
return;
foreach (IType type in dom.GetSubclasses (appType, false))
foreach (IType type in appType.GetAllBaseTypes (dom))
classListStore.AppendValues (type.FullName);
} catch (InvalidOperationException) {
// Project not found in parser database
@@ -90,6 +90,10 @@
<Name>MonoDevelop.Deployment</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\contrib\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
@@ -29,10 +29,10 @@
using System;
using System.Collections.Generic;
using MonoDevelop.Projects.Dom;
using MonoDevelop.Projects.Dom.Parser;
using MonoDevelop.Ide.CodeCompletion;
using MonoDevelop.Xml.StateEngine;
using MonoDevelop.Xml.StateEngine;
using ICSharpCode.NRefactory.TypeSystem;
using MonoDevelop.TypeSystem;
namespace MonoDevelop.Moonlight
{
@@ -47,47 +47,42 @@ public MoonlightEditorExtension ()
#region Code completion
// static ProjectDom GetMLDom (MoonlightProject project)
// static ITypeResolveContext GetMLDom (MoonlightProject project)
// {
// return ProjectDomService.GetAssemblyDom (
// return TypeSystemService.GetAssemblyDom (
// MonoDevelop.Core.Runtime.SystemAssemblyService.GetAssemblyNameForVersion (
// "System.Windows", GetProjectTargetFramework (project)));
// }
public static IEnumerable<IType> ListControlClasses (ProjectDom database, string namespac)
public static IEnumerable<IType> ListControlClasses (ITypeResolveContext database, string namespac)
{
if (database == null)
yield break;
DomReturnType swd = new DomReturnType ("System.Windows.DependencyObject");
var swd = database.GetClass ("System.Windows", "DependencyObject", 0, StringComparer.Ordinal);
//return classes if they derive from system.web.ui.control
foreach (IMember mem in database.GetNamespaceContents (namespac, true, true)) {
IType cls = mem as IType;
if (cls != null && !cls.IsAbstract && cls.IsPublic && cls.IsBaseType (swd))
foreach (IType cls in database.GetClasses (namespac, StringComparer.Ordinal)) {
if (cls != null && !cls.GetDefinition ().IsAbstract && cls.GetDefinition ().IsPublic && cls.IsBaseType (database, swd))
yield return cls;
}
}
static IEnumerable<MonoDevelop.Projects.Dom.IProperty> GetAllProperties (
MonoDevelop.Projects.Dom.Parser.ProjectDom projectDatabase,
MonoDevelop.Projects.Dom.IType cls)
static IEnumerable<IProperty> GetAllProperties (
ITypeResolveContext projectDatabase,
IType cls)
{
foreach (MonoDevelop.Projects.Dom.IType type in projectDatabase.GetInheritanceTree (cls))
foreach (MonoDevelop.Projects.Dom.IProperty prop in type.Properties)
yield return prop;
return cls.GetProperties (projectDatabase);
}
static IEnumerable<MonoDevelop.Projects.Dom.IEvent> GetAllEvents (
MonoDevelop.Projects.Dom.Parser.ProjectDom projectDatabase,
MonoDevelop.Projects.Dom.IType cls)
static IEnumerable<IEvent> GetAllEvents (
ITypeResolveContext projectDatabase,
IType cls)
{
foreach (MonoDevelop.Projects.Dom.IType type in projectDatabase.GetInheritanceTree (cls))
foreach (MonoDevelop.Projects.Dom.IEvent ev in type.Events)
yield return ev;
return cls.GetEvents (projectDatabase);
}
static IEnumerable<T> GetUniqueMembers<T> (IEnumerable<T> members) where T : MonoDevelop.Projects.Dom.IMember
static IEnumerable<T> GetUniqueMembers<T> (IEnumerable<T> members) where T : IMember
{
Dictionary <string, bool> existingItems = new Dictionary<string,bool> ();
foreach (T item in members) {
@@ -98,35 +93,35 @@ public static IEnumerable<IType> ListControlClasses (ProjectDom database, string
}
}
static void AddControlMembers (CompletionDataList list, ProjectDom database, IType controlClass,
static void AddControlMembers (CompletionDataList list, ITypeResolveContext database, IType controlClass,
Dictionary<string, string> existingAtts)
{
//add atts only if they're not already in the tag
foreach (IProperty prop in GetUniqueMembers<MonoDevelop.Projects.Dom.IProperty> (GetAllProperties (database, controlClass)))
foreach (IProperty prop in GetUniqueMembers<IProperty> (GetAllProperties (database, controlClass)))
if (prop.IsPublic && (existingAtts == null || !existingAtts.ContainsKey (prop.Name)))
list.Add (prop.Name, prop.StockIcon, prop.Documentation);
list.Add (prop.Name, prop.GetStockIcon (), prop.Documentation);
//similarly add events
foreach (MonoDevelop.Projects.Dom.IEvent eve
in GetUniqueMembers<MonoDevelop.Projects.Dom.IEvent> (GetAllEvents (database, controlClass))) {
foreach (var eve
in GetUniqueMembers<IEvent> (GetAllEvents (database, controlClass))) {
string eveName = eve.Name;
if (eve.IsPublic && (existingAtts == null || !existingAtts.ContainsKey (eveName)))
list.Add (eveName, eve.StockIcon, eve.Documentation);
list.Add (eveName, eve.GetStockIcon (), eve.Documentation);
}
}
ProjectDom GetDb ()
ITypeResolveContext GetDb ()
{
return Document.Dom;
return Document.TypeResolveContext;
}
void GetType (IAttributedXObject attributedOb, Action<IType, ProjectDom> action)
void GetType (IAttributedXObject attributedOb, Action<IType, ITypeResolveContext> action)
{
ProjectDom database = GetDb ();
ITypeResolveContext database = GetDb ();
if (database == null)
return;
foreach (string namespc in namespaces) {
IType controlType = database.GetType (namespc + "." + attributedOb.Name.Name);
IType controlType = database.GetClass (namespc, attributedOb.Name.Name, 0, StringComparer.Ordinal);
if (controlType != null) {
action (controlType, database);
break;
@@ -140,17 +135,17 @@ void GetType (IAttributedXObject attributedOb, Action<IType, ProjectDom> action)
protected override void GetElementCompletions(CompletionDataList list)
{
base.GetElementCompletions (list);
ProjectDom database = GetDb ();
ITypeResolveContext database = GetDb ();
if (database == null)
return;
IType type = database.GetType ("System.Windows.DependencyObject");
IType type = database.GetClass ("System.Windows", "DependencyObject", 0, StringComparer.Ordinal);
if (type == null)
return;
foreach (string namespc in namespaces)
foreach (IType t in ListControlClasses (database, namespc))
list.Add (t.Name, Gtk.Stock.GoForward, t.Documentation);
list.Add (t.Name, Gtk.Stock.GoForward, t.GetDocumentation ());
}
// static MonoDevelop.Core.TargetFramework GetProjectTargetFramework (MoonlightProject project)
@@ -165,7 +160,7 @@ protected override void GetElementCompletions(CompletionDataList list)
if (!existingAtts.ContainsKey ("x:Name"))
list.Add ("x:Name");
GetType (attributedOb, delegate (IType type, ProjectDom dom) {
GetType (attributedOb, delegate (IType type, ITypeResolveContext dom) {
AddControlMembers (list, dom, type, existingAtts);
});
return list.Count > 0? list : null;
@@ -174,21 +169,21 @@ protected override void GetElementCompletions(CompletionDataList list)
protected override CompletionDataList GetAttributeValueCompletions (IAttributedXObject attributedOb, XAttribute att)
{
var list = base.GetAttributeValueCompletions (attributedOb, att) ?? new CompletionDataList ();
GetType (attributedOb, delegate (IType type, ProjectDom dom) {
ITypeResolveContext ctx = document.TypeResolveContext;
GetType (attributedOb, delegate (IType type, ITypeResolveContext dom) {
foreach (IProperty prop in GetAllProperties (dom, type)) {
if (prop.Name != att.Name.FullName)
continue;
//boolean completion
if (prop.ReturnType.FullName == "System.Boolean") {
if (prop.ReturnType.Resolve (ctx).Equals (ctx.GetClass (typeof (bool)))) {
list.Add ("true", "md-literal");
list.Add ("false", "md-literal");
return;
}
//color completion
if (prop.ReturnType.FullName == "System.Windows.Media.Color") {
if (prop.ReturnType.Resolve (ctx).ReflectionName == "System.Windows.Media.Color") {
System.Drawing.ColorConverter conv = new System.Drawing.ColorConverter ();
foreach (System.Drawing.Color c in conv.GetStandardValues (null)) {
if (c.IsSystemColor)
@@ -200,9 +195,9 @@ protected override CompletionDataList GetAttributeValueCompletions (IAttributedX
}
//enum completion
MonoDevelop.Projects.Dom.IType retCls = dom.GetType (prop.ReturnType);
if (retCls != null && retCls.ClassType == MonoDevelop.Projects.Dom.ClassType.Enum) {
foreach (MonoDevelop.Projects.Dom.IField enumVal in retCls.Fields)
var retCls = prop.ReturnType.Resolve (ctx);
if (retCls != null && retCls.IsEnum ()) {
foreach (var enumVal in retCls.GetFields (ctx))
if (enumVal.IsPublic && enumVal.IsStatic)
list.Add (enumVal.Name, "md-literal", enumVal.Documentation);
return;
@@ -33,17 +33,16 @@
using System.Xml;
using MonoDevelop.Xml.StateEngine;
using MonoDevelop.Projects.Dom;
using MonoDevelop.Projects.Dom.Parser;
using MonoDevelop.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem;
namespace MonoDevelop.Moonlight
{
public class MoonlightParser : AbstractParser
public class MoonlightParser : AbstractTypeSystemProvider
{
public override ParsedDocument Parse (ProjectDom dom, string fileName, string fileContent)
public override ParsedDocument Parse (ICSharpCode.NRefactory.TypeSystem.IProjectContent projectContent, bool storeAst, string fileName, TextReader tr)
{
XmlParsedDocument doc = new XmlParsedDocument (fileName);
TextReader tr = new StringReader (fileContent);
try {
Parser xmlParser = new Parser (new XmlFreeState (), true);
xmlParser.Parse (tr);
@@ -59,10 +58,6 @@ public override ParsedDocument Parse (ProjectDom dom, string fileName, string fi
catch (Exception ex) {
MonoDevelop.Core.LoggingService.LogError ("Unhandled error parsing xaml document", ex);
}
finally {
if (tr != null)
tr.Dispose ();
}
return doc;
}
@@ -83,55 +78,56 @@ static void GenerateCU (XmlParsedDocument doc)
string rootNamespace, rootType, rootAssembly;
XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly);
CompilationUnit cu = new CompilationUnit (doc.FileName);
doc.CompilationUnit = cu;
DomRegion rootRegion = doc.XDocument.RootElement.Region;
if (doc.XDocument.RootElement.IsClosed)
rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End;
DomType declType = new DomType (cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType,
doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion);
cu.Add (declType);
DomMethod initcomp = new DomMethod ();
initcomp.Name = "InitializeComponent";
initcomp.Modifiers = Modifiers.Public;
initcomp.ReturnType = DomReturnType.Void;
declType.Add (initcomp);
DomField _contentLoaded = new DomField ("_contentLoaded");
_contentLoaded.ReturnType = new DomReturnType ("System.Boolean");
if (isApplication)
return;
cu.Add (new DomUsing (DomRegion.Empty, "System"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
// Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
// namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
// TODO: Type system conversion.
// var cu = new ParsedDocument (doc.FileName);
// doc.CompilationUnit = cu;
//
// DomRegion rootRegion = doc.XDocument.RootElement.Region;
// if (doc.XDocument.RootElement.IsClosed)
// rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End;
//
// DomType declType = new DomType (cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType,
// doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion);
// cu.Add (declType);
//
// DomMethod initcomp = new DomMethod ();
// initcomp.Name = "InitializeComponent";
// initcomp.Modifiers = Modifiers.Public;
// initcomp.ReturnType = DomReturnType.Void;
// declType.Add (initcomp);
//
// DomField _contentLoaded = new DomField ("_contentLoaded");
// _contentLoaded.ReturnType = new DomReturnType ("System.Boolean");
//
// if (isApplication)
// return;
//
// cu.Add (new DomUsing (DomRegion.Empty, "System"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
// cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
XName nameAtt = new XName ("x", "Name");
// Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
// namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
XAttribute name = el.Attributes [nameAtt];
if (name != null && name.IsComplete) {
string type = ResolveType (el);
if (type == null || type.Length == 0)
doc.Add (new Error (ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
else
declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType (type)));
}
}
// XName nameAtt = new XName ("x", "Name");
//
// foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
// XAttribute name = el.Attributes [nameAtt];
// if (name != null && name.IsComplete) {
// string type = ResolveType (el);
// if (type == null || type.Length == 0)
// doc.Add (new Error (ErrorType.Error, el.Region.Begin, "Could not find namespace for '" + el.Name.FullName + "'."));
// else
// declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Begin, new DomReturnType (type)));
// }
// }
}
static string GetNamespace (XElement el)
@@ -34,7 +34,6 @@
using System.Xml;
using MonoDevelop.Projects;
using MonoDevelop.Projects.Dom;
namespace MonoDevelop.Moonlight
{

0 comments on commit 59ba940

Please sign in to comment.