コード例 #1
0
        }        // CanParse

        public override ParsedDocument Parse(ProjectDom dom, string fileName, string content)
        {
            ParsedDocument doc = new ParsedDocument(fileName);

            doc.Flags |= ParsedDocumentFlags.NonSerializable;
            Project p = (null == dom || null == dom.Project)?
                        IdeApp.Workspace.GetProjectContainingFile(fileName):
                        dom.Project;
            ProjectInformation pi = ProjectInformationManager.Instance.Get(p);
            CompilationUnit    cu;

            doc.CompilationUnit = cu = new CompilationUnit(fileName);
            IType   tmp;
            IMember member;

            string[] contentLines = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            DomType  globals      = new DomType(cu, ClassType.Unknown, GettextCatalog.GetString("(Global Scope)"), new DomLocation(1, 1), string.Empty, new DomRegion(1, int.MaxValue), new List <IMember> ());

            lock (pi) {
                // Add containers to type list
                foreach (LanguageItem li in pi.Containers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        tmp = LanguageItemToIMember(pi, li, contentLines) as IType;
                        if (null != tmp)
                        {
                            cu.Add(tmp);
                        }
                    }
                }

                // Add global category for unscoped symbols
                foreach (LanguageItem li in pi.InstanceMembers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        member = LanguageItemToIMember(pi, li, contentLines);
                        if (null != member)
                        {
                            globals.Add(member);
                        }
                    }
                }
            }

            cu.Add(globals);

            return(doc);
        }
コード例 #2
0
        public static void Unpack(Dictionary <string, MemoryStream> source, string workingDirectory, out CompilationUnit unit)
        {
            unit = new CompilationUnit();
            foreach (var(key, value) in source)
            {
                if (!key.EndsWith(".java"))
                {
                    continue;
                }

                var split                     = key.Split("/");
                var packageAndFile            = string.Join("\\", split);
                var packageDirectory          = Path.GetDirectoryName(packageAndFile);
                var fullyQualifiedPackageName = packageDirectory.Replace(@"\", ".");
                var fileName                  = Path.GetFileName(packageAndFile);
                var fullUri                   = Path.Combine(workingDirectory, packageAndFile);

                if (fileName.Contains("Test", StringComparison.CurrentCultureIgnoreCase))
                {
                    var javaFile = GetJavaTestClass(workingDirectory, fullUri, packageDirectory, fullyQualifiedPackageName, fileName);
                    unit.Add(javaFile);
                }

                unit.SourceFiles.Add(fullUri);

                CreateDirectoryPath(Path.GetDirectoryName(fullUri));
                File.WriteAllText(fullUri, Encoding.ASCII.GetString(value.ToArray()), Encoding.ASCII);
            }
        }
コード例 #3
0
        public void TestGetNamespaceContentsCase3()
        {
            CompilationUnit unit = new CompilationUnit("file.cs");

            unit.Add(new DomType("ANamespace.AnotherNamespace.AClass"));
            unit.Add(new DomType("ANamespace.AnotherNamespace.BClass"));
            unit.Add(new DomType("ANamespace.AnotherNamespace.CClass"));
            unit.Add(new DomType("ANamespace.AClass2"));
            unit.Add(new DomType("ANamespace.BClass2"));
            unit.Add(new DomType("CClass3"));

            List <IMember> member = new List <IMember> ();

            unit.GetNamespaceContents(member, "ANamespace.AnotherNamespace", true);
            Assert.AreEqual(3, member.Count);

            IType type = member[0] as IType;

            Assert.IsNotNull(type);
            Assert.AreEqual("AClass", type.Name);

            type = member[1] as IType;
            Assert.IsNotNull(type);
            Assert.AreEqual("BClass", type.Name);

            type = member[2] as IType;
            Assert.IsNotNull(type);
            Assert.AreEqual("CClass", type.Name);
        }
コード例 #4
0
		public void TestGetNamespaceContentsCase2 ()
		{
			CompilationUnit unit = new CompilationUnit ("file.cs");
			unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
			unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
			unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
			unit.Add (new DomType ("ANamespace.AClass2"));
			unit.Add (new DomType ("ANamespace.BClass2"));
			unit.Add (new DomType ("CClass3"));
			
			List<IMember> member = new List<IMember> ();
			unit.GetNamespaceContents (member, "ANamespace", true);
			
			Assert.AreEqual (3, member.Count);
			Namespace ns = member[0] as Namespace;
			Assert.IsNotNull (ns);
			Assert.AreEqual ("AnotherNamespace", ns.Name);
			
			IType type = member[1] as IType;
			Assert.IsNotNull (type);
			Assert.AreEqual ("AClass2", type.Name);
			
			type = member[2] as IType;
			Assert.IsNotNull (type);
			Assert.AreEqual ("BClass2", type.Name);
		}
コード例 #5
0
		public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			ParsedDocument doc = new ParsedDocument (fileName);
			doc.Flags |= ParsedDocumentFlags.NonSerializable;
			Project p = (null == dom || null == dom.Project)? 
				IdeApp.Workspace.GetProjectContainingFile (fileName):
				dom.Project;
			ProjectInformation pi = ProjectInformationManager.Instance.Get (p);
			CompilationUnit cu;
			doc.CompilationUnit = cu = new CompilationUnit (fileName);
			IType tmp;
			IMember member;
			string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);
			DomType globals = new DomType (cu, ClassType.Unknown, GettextCatalog.GetString ("(Global Scope)"), new DomLocation (1, 1), string.Empty, new DomRegion (1, int.MaxValue), new List<IMember> ());
			
			lock (pi) {
				// Add containers to type list
				foreach (LanguageItem li in pi.Containers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						tmp = LanguageItemToIMember (pi, li, contentLines) as IType;
						if (null != tmp){ cu.Add (tmp); }
					}
				}
				
				// Add global category for unscoped symbols
				foreach (LanguageItem li in pi.InstanceMembers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						member = LanguageItemToIMember (pi, li, contentLines);
						if (null != member) { 
							globals.Add (member); 
						}
					}
				}
			}
			
			cu.Add (globals);
			
			return doc;
		}
コード例 #6
0
        public void TestGetNamespaceContentsCase4()
        {
            CompilationUnit unit = new CompilationUnit("file.cs");

            unit.Add(new DomType("ANamespace.AnotherNamespace.AClass"));
            unit.Add(new DomType("ANamespace.AnotherNamespace.BClass"));
            unit.Add(new DomType("ANamespace.AnotherNamespace.CClass"));
            unit.Add(new DomType("ANamespace.AClass2"));
            unit.Add(new DomType("ANamespace.BClass2"));
            unit.Add(new DomType("CClass3"));

            List <IMember> member = new List <IMember> ();

            unit.GetNamespaceContents(member, "ANamespace.NotExist", true);
            Assert.AreEqual(0, member.Count);
        }
コード例 #7
0
        public override ParsedDocument Parse(ProjectDom dom, string fileName, string content)
        {
            ParsedDocument     doc = new ParsedDocument(fileName);
            ProjectInformation pi  = ProjectInformationManager.Instance.Get((null == dom)? null: dom.Project);

            if (null == doc.CompilationUnit)
            {
                doc.CompilationUnit = new CompilationUnit(fileName);
            }
            CompilationUnit      cu       = (CompilationUnit)doc.CompilationUnit;
            int                  lastLine = 0;
            ICollection <Symbol> classes  = pi.GetClassesForFile(fileName);

            if (null == classes || 0 == classes.Count)
            {
                return(lastGood);
            }

            foreach (Symbol node in classes)
            {
                if (null == node)
                {
                    continue;
                }
                List <IMember> members = new List <IMember> ();
                lastLine = node.SourceReferences[0].LastLine;

                foreach (Symbol child in node.Children)
                {
                    if (1 > child.SourceReferences.Count ||
                        child.SourceReferences[0].File != node.SourceReferences[0].File)
                    {
                        continue;
                    }
                    lastLine = Math.Max(lastLine, child.SourceReferences[0].LastLine + 1);

                    switch (child.MemberType.ToLower())
                    {
                    case "class":
                        members.Add(new DomType(new CompilationUnit(fileName), ClassType.Class, child.Name, new DomLocation(child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List <IMember> ()));
                        break;

                    case "interface":
                        members.Add(new DomType(new CompilationUnit(fileName), ClassType.Interface, child.Name, new DomLocation(child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List <IMember> ()));
                        break;

                    case "delegate":
                        members.Add(new DomType(new CompilationUnit(fileName), ClassType.Delegate, child.Name, new DomLocation(child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List <IMember> ()));
                        break;

                    case "struct":
                        members.Add(new DomType(new CompilationUnit(fileName), ClassType.Struct, child.Name, new DomLocation(child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List <IMember> ()));
                        break;

                    case "enum":
                        members.Add(new DomType(new CompilationUnit(fileName), ClassType.Enum, child.Name, new DomLocation(child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List <IMember> ()));
                        break;

                    case "method":
                    case "creationmethod":
                    case "constructor":
                        DomMethod method = new DomMethod(child.Name, Modifiers.None, MethodModifier.None, new DomLocation(child.SourceReferences[0].FirstLine, 1), new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new DomReturnType(child.ReturnType.TypeName));
                        foreach (DataType param in child.Parameters)
                        {
                            method.Add(new DomParameter(method, param.Name, new DomReturnType(param.TypeName)));
                        }
                        members.Add(method);
                        break;

                    case "property":
                        members.Add(new DomProperty(child.Name, Modifiers.None, new DomLocation(child.SourceReferences[0].FirstLine, 1), new DomRegion(child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new DomReturnType()));
                        break;

                    case "field":
                    case "constant":
                    case "errorcode":
                        members.Add(new DomField(child.Name, Modifiers.None, new DomLocation(child.SourceReferences[0].FirstLine, 1), new DomReturnType()));
                        break;

                    case "signal":
                        members.Add(new DomEvent(child.Name, Modifiers.None, new DomLocation(child.SourceReferences[0].FirstLine, 1), new DomReturnType()));
                        break;

                    default:
                        MonoDevelop.Core.LoggingService.LogDebug("ValaDocumentParser: Unsupported member type: {0}", child.MemberType);
                        break;
                    }            // Switch on node type
                }                // Collect members

                cu.Add(new DomType(new CompilationUnit(fileName), ClassType.Class, node.Name, new DomLocation(node.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion(node.SourceReferences[0].FirstLine, int.MaxValue, lastLine, int.MaxValue), members));
            }            // Add each class in file

            return(lastGood = doc);
        } // Parse
コード例 #8
0
ファイル: DiffParser.cs プロジェクト: yayanyang/monodevelop
        public override ParsedDocument Parse(ProjectDom dom, string fileName, string content)
        {
            ParsedDocument doc = new ParsedDocument(fileName);

            if (null == doc.CompilationUnit)
            {
                doc.CompilationUnit = new CompilationUnit(fileName);
            }
            CompilationUnit cu            = (CompilationUnit)doc.CompilationUnit;
            DomType         currentFile   = null;
            DomProperty     currentRegion = null;

            string eol      = Environment.NewLine;
            Match  eolMatch = eolExpression.Match(content);

            if (eolMatch != null && eolMatch.Success)
            {
                eol = eolMatch.Groups["eol"].Value;
            }

            string[] lines   = content.Split(new string[] { eol }, StringSplitOptions.None);
            int      linenum = 1;
            Match    lineMatch;

            foreach (string line in lines)
            {
                lineMatch = fileHeaderExpression.Match(line.Trim());
                if (lineMatch != null && lineMatch.Success)
                {
                    if (currentFile != null)                     // Close out previous file region
                    {
                        currentFile.BodyRegion = new DomRegion(currentFile.BodyRegion.Start.Line,
                                                               currentFile.BodyRegion.Start.Column,
                                                               linenum - 1, int.MaxValue);
                    }
                    if (currentRegion != null)                     // Close out previous chunk region
                    {
                        currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.Start.Line,
                                                                 currentRegion.BodyRegion.Start.Column,
                                                                 linenum - 1, int.MaxValue);
                    }

                    // Create new file region
                    currentFile = new DomType(cu, ClassType.Unknown, Modifiers.None,
                                              lastToken(lineMatch.Groups["filepath"].Value),
                                              new DomLocation(linenum, 1),
                                              string.Empty,
                                              new DomRegion(linenum, line.Length + 1, linenum, int.MaxValue));
                    cu.Add(currentFile);
                }
                else
                {
                    lineMatch = chunkExpression.Match(line);
                    if (lineMatch != null && lineMatch.Success && currentFile != null)
                    {
                        if (currentRegion != null)                         // Close out previous chunk region
                        {
                            currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.Start.Line,
                                                                     currentRegion.BodyRegion.Start.Column,
                                                                     linenum - 1, int.MaxValue);
                        }

                        // Create new chunk region
                        currentRegion = new DomProperty(lineMatch.Groups["chunk"].Value, Modifiers.None,
                                                        new DomLocation(linenum, 1),
                                                        new DomRegion(linenum, line.Length + 1, linenum, int.MaxValue), null);
                        currentFile.Add(currentRegion);
                    }
                }
                ++linenum;
            }

            // Close out trailing regions
            if (currentFile != null)
            {
                currentFile.BodyRegion = new DomRegion(currentFile.BodyRegion.Start.Line,
                                                       currentFile.BodyRegion.Start.Column,
                                                       Math.Max(1, linenum - 2), int.MaxValue);
            }
            if (currentRegion != null)
            {
                currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.Start.Line,
                                                         currentRegion.BodyRegion.Start.Column,
                                                         Math.Max(1, linenum - 2), int.MaxValue);
            }

            return(doc);
        }
コード例 #9
0
        static void GenerateCU(XmlParsedDocument doc)
        {
            if (doc.XDocument == null || doc.XDocument.RootElement == null)
            {
                doc.Add(new Error(ErrorType.Error, 1, 1, "No root node found."));
                return;
            }

            XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName("x", "Class")];

            if (rootClass == null)
            {
                doc.Add(new Error(ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute."));
                return;
            }

            bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";

            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";

            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.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
                    }
                    else
                    {
                        declType.Add(new DomField(name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType(type)));
                    }
                }
            }
        }
コード例 #10
0
		public void TestGetNamespaceContentsCase4 ()
		{
			CompilationUnit unit = new CompilationUnit ("file.cs");
			unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
			unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
			unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
			unit.Add (new DomType ("ANamespace.AClass2"));
			unit.Add (new DomType ("ANamespace.BClass2"));
			unit.Add (new DomType ("CClass3"));
			
			List<IMember> member = new List<IMember> ();
			unit.GetNamespaceContents (member, "ANamespace.NotExist", true);
			Assert.AreEqual (0, member.Count);
		}
コード例 #11
0
		static void GenerateCU (XmlParsedDocument doc)
		{
			if (doc.XDocument == null || doc.XDocument.RootElement == null) {
				doc.Add (new Error (ErrorType.Error, 1, 1, "No root node found."));
				return;
			}

			XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")];
			if (rootClass == null) {
				doc.Add (new Error (ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute."));
				return;
			}

			bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";
			
			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";
			
			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.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
					else
						declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType (type)));
				}
			}
		}
コード例 #12
0
 /// <summary>
 /// Populate a compilation unit with unparented classes
 /// </summary>
 void PopulateClasses(CompilationUnit cu)
 {
     foreach (KeyValuePair<int,RubyDeclaration> pair in classes) {
         DomType myclass = new DomType (cu, ClassType.Class, pair.Value.name, new DomLocation (pair.Value.beginLine, 1), string.Empty,
                                        new DomRegion (pair.Value.beginLine, pair.Value.beginColumn+1,
                                                       pair.Value.endLine, int.MaxValue), new List<IMember> ());
         PopulateMethods (myclass);
         cu.Add (myclass);
     }// Add classes and member methods
 }
コード例 #13
0
        /// <summary>
        /// Populate a module with classes
        /// </summary>
        void PopulateClasses(CompilationUnit cu, RubyDeclaration parent)
        {
            List<int> removal = new List<int> ();

            foreach (KeyValuePair<int,RubyDeclaration> mpair in classes) {
                if (mpair.Key >= parent.beginLine && mpair.Key <= parent.endLine) {
                    DomType myclass = new DomType (cu, ClassType.Class, mpair.Value.name, new DomLocation (mpair.Value.beginLine, 1),
                                                   parent.name, new DomRegion (mpair.Value.beginLine, mpair.Value.beginColumn+1,
                                                                               mpair.Value.endLine, int.MaxValue),
                                                                               new List<IMember> ());
                    PopulateMethods (myclass);
                    cu.Add (myclass);
                    removal.Add (mpair.Key);
                }// Add classes that are declared within the parent's scope
            }// Check detected classes

            // Remove used classes from map
            foreach (int key in removal){ classes.Remove (key); }
        }