protected override void OnParsedDocumentUpdated() { base.OnParsedDocumentUpdated(); aspDoc = CU as WebFormsParsedDocument; if (HasDoc) { refman.Doc = aspDoc; } var newProj = base.DocumentContext.Project as DotNetProject; if (newProj != null) { project = newProj; refman.Project = newProj; } if (HasDoc) { documentInfo = new DocumentInfo(aspDoc, refman.GetUsings()); // localDocumentProjection = new MonoDevelop.AspNet.WebForms.CSharp.CSharpProjector ().CreateProjection (documentInfo, Editor, true).Result; // projectedEditor = localDocumentProjection.CreateProjectedEditor (DocumentContext); // Editor.SetOrUpdateProjections (DocumentContext, new [] { localDocumentProjection }); } }
protected override void OnParsedDocumentUpdated() { base.OnParsedDocumentUpdated(); aspDoc = CU as WebFormsParsedDocument; if (HasDoc) { refman.Doc = aspDoc; } var newProj = Document.Project as AspNetAppProject; if (newProj != null) { project = newProj; refman.Project = newProj; } documentBuilder = HasDoc ? LanguageCompletionBuilderService.GetBuilder(aspDoc.Info.Language) : null; if (documentBuilder != null) { documentInfo = new DocumentInfo(refman.Compilation, aspDoc, refman.GetUsings()); documentInfo.ParsedDocument = documentBuilder.BuildDocument(documentInfo, Editor); documentInfo.CodeBesideClass = CreateCodeBesideClass(documentInfo, refman); } }
public DocumentInfo(ICompilation dom, WebFormsParsedDocument aspNetParsedDocument, IEnumerable <string> imports) { this.Dom = dom; this.AspNetDocument = aspNetParsedDocument; this.Imports = imports; BuildExpressionAndScriptsLists(); }
public override System.Threading.Tasks.Task <ParsedDocument> Parse(ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var info = new WebFormsPageInfo(); var errors = new List <Error> (); var parser = new XmlParser( new WebFormsRootState(), true ); try { parser.Parse(parseOptions.Content.CreateReader()); } catch (Exception ex) { LoggingService.LogError("Unhandled error parsing ASP.NET document '" + (parseOptions.FileName ?? "") + "'", ex); errors.Add(new Error(ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message)); } // get the errors from the StateEngine parser errors.AddRange(parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot(); info.Populate(xDoc, errors); var type = AspNetAppProjectFlavor.DetermineWebSubtype(parseOptions.FileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add(new Error(ErrorType.Error, "File directive is missing", new DocumentLocation(1, 1))); } else { type = info.Subtype; errors.Add(new Error(ErrorType.Warning, "File directive does not match page extension", new DocumentLocation(1, 1))); } } var result = new WebFormsParsedDocument(parseOptions.FileName, type, info, xDoc); result.AddRange(errors); return(System.Threading.Tasks.Task.FromResult((ParsedDocument)result)); }
public override ParsedDocument Parse(bool storeAst, string fileName, TextReader tr, Project project = null) { var info = new WebFormsPageInfo(); var errors = new List <Error> (); var parser = new XmlParser( new WebFormsRootState(), true ); try { parser.Parse(tr); } catch (Exception ex) { LoggingService.LogError("Unhandled error parsing ASP.NET document '" + (fileName ?? "") + "'", ex); errors.Add(new Error(ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message)); } // get the errors from the StateEngine parser errors.AddRange(parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot(); info.Populate(xDoc, errors); var type = AspNetAppProject.DetermineWebSubtype(fileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add(new Error(ErrorType.Error, "File directive is missing", 1, 1)); } else { type = info.Subtype; errors.Add(new Error(ErrorType.Warning, "File directive does not match page extension", 1, 1)); } } var result = new WebFormsParsedDocument(fileName, type, info, xDoc); result.Add(errors); return(result); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var info = new WebFormsPageInfo (); var errors = new List<Error> (); var parser = new XmlParser ( new WebFormsRootState (), true ); try { parser.Parse (parseOptions.Content.CreateReader ()); } catch (Exception ex) { LoggingService.LogError ("Unhandled error parsing ASP.NET document '" + (parseOptions.FileName ?? "") + "'", ex); errors.Add (new Error (ErrorType.Error, GettextCatalog.GetString ("Unhandled error parsing ASP.NET document: {0}", ex.Message))); } // get the errors from the StateEngine parser errors.AddRange (parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot (); info.Populate (xDoc, errors); var type = AspNetAppProjectFlavor.DetermineWebSubtype (parseOptions.FileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add (new Error (ErrorType.Error, GettextCatalog.GetString ("File directive is missing"), new DocumentLocation (1, 1))); } else { type = info.Subtype; errors.Add (new Error (ErrorType.Warning, GettextCatalog.GetString ("File directive does not match page extension"), new DocumentLocation (1, 1))); } } var result = new WebFormsParsedDocument (parseOptions.FileName, type, info, xDoc); result.AddRange (errors); return System.Threading.Tasks.Task.FromResult((ParsedDocument)result); }
public override ParsedDocument Parse (bool storeAst, string fileName, TextReader tr, Project project = null) { var info = new WebFormsPageInfo (); var errors = new List<Error> (); var parser = new XmlParser ( new WebFormsRootState (), true ); try { parser.Parse (tr); } catch (Exception ex) { LoggingService.LogError ("Unhandled error parsing ASP.NET document '" + (fileName ?? "") + "'", ex); errors.Add (new Error (ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message)); } // get the errors from the StateEngine parser errors.AddRange (parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot (); info.Populate (xDoc, errors); var type = AspNetAppProject.DetermineWebSubtype (fileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add (new Error (ErrorType.Error, "File directive is missing", 1, 1)); } else { type = info.Subtype; errors.Add (new Error (ErrorType.Warning, "File directive does not match page extension", 1, 1)); } } var result = new WebFormsParsedDocument (fileName, type, info, xDoc); result.Add (errors); return result; }
public static BuildResult GenerateCodeBehind( DotNetProject project, string filename, WebFormsParsedDocument document, out CodeCompileUnit ccu) { ccu = null; var result = new BuildResult(); string className = document.Info.InheritedClass; AddErrorsToResult(result, filename, document.GetErrorsAsync().Result); if (result.ErrorCount > 0) { return(result); } if (string.IsNullOrEmpty(className)) { return(result); } var refman = new WebFormsTypeContext { Project = project, Doc = document }; refman.CreateCompilation(default(CancellationToken)).Wait(); var memberList = new WebFormsMemberListBuilder(refman, document.XDocument); memberList.Build(); AddErrorsToResult(result, filename, memberList.Errors); if (result.ErrorCount > 0) { return(result); } //initialise the generated type ccu = new CodeCompileUnit(); var namespac = new CodeNamespace(); ccu.Namespaces.Add(namespac); var typeDecl = new CodeTypeDeclaration { IsClass = true, IsPartial = true, }; namespac.Types.Add(typeDecl); //name the class and namespace int namespaceSplit = className.LastIndexOf('.'); if (namespaceSplit > -1) { namespac.Name = project.StripImplicitNamespace(className.Substring(0, namespaceSplit)); typeDecl.Name = className.Substring(namespaceSplit + 1); } else { typeDecl.Name = className; } string masterTypeName = null; if (!String.IsNullOrEmpty(document.Info.MasterPageTypeName)) { masterTypeName = document.Info.MasterPageTypeName; } else if (!String.IsNullOrEmpty(document.Info.MasterPageTypeVPath)) { try { var ext = project.GetService <AspNetAppProjectFlavor> (); ProjectFile resolvedMaster = ext.ResolveVirtualPath(document.Info.MasterPageTypeVPath, document.FileName); WebFormsParsedDocument masterParsedDocument = null; if (resolvedMaster != null) { masterParsedDocument = IdeApp.TypeSystemService.ParseFile(project, resolvedMaster.FilePath).Result as WebFormsParsedDocument; } if (masterParsedDocument != null && !String.IsNullOrEmpty(masterParsedDocument.Info.InheritedClass)) { masterTypeName = masterParsedDocument.Info.InheritedClass; } } catch (Exception ex) { LoggingService.LogWarning("Error resolving master page type", ex); } if (string.IsNullOrEmpty(masterTypeName)) { var msg = GettextCatalog.GetString("Could not find type for master '{0}'", document.Info.MasterPageTypeVPath); result.AddError(filename, msg); return(result); } } if (masterTypeName != null) { var masterProp = new CodeMemberProperty { Name = "Master", Type = new CodeTypeReference(masterTypeName), HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.New | MemberAttributes.Final, }; masterProp.GetStatements.Add(new CodeMethodReturnStatement( new CodeCastExpression(masterTypeName, new CodePropertyReferenceExpression( new CodeBaseReferenceExpression(), "Master")))); typeDecl.Members.Add(masterProp); } //shortcut building the existing members type map if (memberList.Members.Count == 0) { return(result); } var cls = refman.GetTypeByMetadataName(className); var members = GetDesignerMembers(memberList.Members.Values, cls, filename); //add fields for each control in the page foreach (var member in members) { var type = new CodeTypeReference(member.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)); typeDecl.Members.Add(new CodeMemberField(type, member.Name) { Attributes = MemberAttributes.Family }); } return(result); }
public static BuildResult GenerateCodeBehind ( DotNetProject project, string filename, WebFormsParsedDocument document, out CodeCompileUnit ccu) { ccu = null; var result = new BuildResult (); string className = document.Info.InheritedClass; AddErrorsToResult (result, filename, document.GetErrorsAsync().Result); if (result.ErrorCount > 0) return result; if (string.IsNullOrEmpty (className)) return result; var refman = new WebFormsTypeContext { Project = project, Doc = document }; refman.CreateCompilation (default(CancellationToken)).Wait (); var memberList = new WebFormsMemberListBuilder (refman, document.XDocument); memberList.Build (); AddErrorsToResult (result, filename, memberList.Errors); if (result.ErrorCount > 0) return result; //initialise the generated type ccu = new CodeCompileUnit (); var namespac = new CodeNamespace (); ccu.Namespaces.Add (namespac); var typeDecl = new CodeTypeDeclaration { IsClass = true, IsPartial = true, }; namespac.Types.Add (typeDecl); //name the class and namespace int namespaceSplit = className.LastIndexOf ('.'); if (namespaceSplit > -1) { namespac.Name = project.StripImplicitNamespace (className.Substring (0, namespaceSplit)); typeDecl.Name = className.Substring (namespaceSplit + 1); } else { typeDecl.Name = className; } string masterTypeName = null; if (!String.IsNullOrEmpty (document.Info.MasterPageTypeName)) { masterTypeName = document.Info.MasterPageTypeName; } else if (!String.IsNullOrEmpty (document.Info.MasterPageTypeVPath)) { try { var ext = project.GetService<AspNetAppProjectFlavor> (); ProjectFile resolvedMaster = ext.ResolveVirtualPath (document.Info.MasterPageTypeVPath, document.FileName); WebFormsParsedDocument masterParsedDocument = null; if (resolvedMaster != null) masterParsedDocument = TypeSystemService.ParseFile (project, resolvedMaster.FilePath).Result as WebFormsParsedDocument; if (masterParsedDocument != null && !String.IsNullOrEmpty (masterParsedDocument.Info.InheritedClass)) masterTypeName = masterParsedDocument.Info.InheritedClass; } catch (Exception ex) { LoggingService.LogWarning ("Error resolving master page type", ex); } if (string.IsNullOrEmpty (masterTypeName)) { var msg = string.Format ("Could not find type for master '{0}'", document.Info.MasterPageTypeVPath); result.AddError (filename, msg); return result; } } if (masterTypeName != null) { var masterProp = new CodeMemberProperty { Name = "Master", Type = new CodeTypeReference (masterTypeName), HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.New | MemberAttributes.Final, }; masterProp.GetStatements.Add (new CodeMethodReturnStatement ( new CodeCastExpression (masterTypeName, new CodePropertyReferenceExpression ( new CodeBaseReferenceExpression (), "Master")))); typeDecl.Members.Add (masterProp); } //shortcut building the existing members type map if (memberList.Members.Count == 0) return result; var cls = refman.GetTypeByMetadataName (className); var members = GetDesignerMembers (memberList.Members.Values, cls, filename); //add fields for each control in the page foreach (var member in members) { var type = new CodeTypeReference (member.Type.ToDisplayString (SymbolDisplayFormat.CSharpErrorMessageFormat)); typeDecl.Members.Add (new CodeMemberField (type, member.Name) { Attributes = MemberAttributes.Family }); } return result; }
public DocumentInfo (WebFormsParsedDocument aspNetParsedDocument, IEnumerable<string> imports) { this.AspNetDocument = aspNetParsedDocument; this.Imports = imports; BuildExpressionAndScriptsLists (); }