2 // Document.cs: Parses an ASP.NET file, and provides a range of services for
3 // gathering information from it.
6 // Michael Hutchinson <m.j.hutchinson@gmail.com>
8 // Copyright (C) 2006 Michael Hutchinson
11 // This source code is licenced under The MIT License:
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System
.Collections
.Generic
;
37 using MonoDevelop
.AspNet
;
38 using MonoDevelop
.AspNet
.Parser
.Dom
;
39 using MonoDevelop
.Projects
;
40 using MonoDevelop
.Ide
.Gui
.Content
;
42 namespace MonoDevelop
.AspNet
.Parser
47 AspNetAppProject project
;
49 DocumentReferenceManager refMan
;
50 MemberListVisitor memberList
;
51 List
<ParserException
> errors
= new List
<ParserException
> ();
53 Document (Project project
, string filePath
)
55 this.filePath
= filePath
;
56 this.project
= project
as AspNetAppProject
;
59 public Document (ITextBuffer buffer
, Project project
, string filePath
) : this (project
, filePath
)
61 using (TextReader sr
= new StreamReader (new MemoryStream (new System
.Text
.UTF8Encoding().GetBytes (buffer
.Text
)))) {
66 public Document (TextReader sr
, Project project
, string filePath
) : this (project
, filePath
)
68 this.filePath
= filePath
;
69 this.project
= project
as AspNetAppProject
;
73 public Document (ProjectFile file
) : this (file
.Project
, file
.FilePath
)
77 sr
= new StreamReader (file
.FilePath
);
79 } catch (Exception ex
) {
80 MonoDevelop
.Core
.LoggingService
.LogError ("Unhandled error parsing ASP.NET document", ex
);
81 errors
.Add (new ParserException (null, "Unhandled error parsing ASP.NET document: " + ex
.ToString ()));
88 void Init (TextReader sr
)
90 rootNode
= new RootNode ();
91 rootNode
.Parse (filePath
, sr
);
93 foreach (MonoDevelop
.AspNet
.Parser
.Internal
.ParseException ex
in rootNode
.ParseErrors
)
94 errors
.Add (new ParserException (ex
.Location
, ex
.Message
));
96 if (MonoDevelop.Core.LoggingService.IsLevelEnabled (MonoDevelop.Core.Logging.LogLevel.Debug)) {
97 DebugStringVisitor dbg = new DebugStringVisitor ();
98 rootNode.AcceptVisit (dbg);
99 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
100 sb.AppendLine ("Parsed AspNet file:");
101 sb.AppendLine (dbg.DebugString);
102 if (errors.Count > 0) {
103 sb.AppendLine ("Errors:");
104 foreach (ParserException ex in errors)
105 sb.AppendLine (ex.ToString ());
107 MonoDevelop.Core.LoggingService.LogDebug (sb.ToString ());
111 public bool IsValid
{
112 get { return errors.Count == 0; }
115 public IList
<ParserException
> ParseErrors
{
116 get { return errors; }
119 public RootNode RootNode
{
120 get { return rootNode; }
123 public DocumentReferenceManager ReferenceManager
{
126 refMan
= new DocumentReferenceManager (this);
131 public AspNetAppProject Project
{
134 project
= MonoDevelop
.Ide
.Gui
.IdeApp
.Workspace
.GetProjectContainingFile (filePath
)
140 public string FilePath
{
141 get { return filePath; }
144 public MemberListVisitor MemberList
{
146 if (memberList
== null) {
147 memberList
= new MemberListVisitor (this);
148 rootNode
.AcceptVisit (memberList
);