Ejemplo n.º 1
0
            bool ReadClasses()
            {
                int classCount        = reader.ReadInt32();
                int externalTypeCount = reader.ReadInt32();

                types = new IReturnType[classCount + externalTypeCount];
                DefaultClass[] classes = new DefaultClass[classCount];
                for (int i = 0; i < classes.Length; i++)
                {
                    DefaultClass c = new DefaultClass(pc.AssemblyCompilationUnit, reader.ReadString());
                    classes[i] = c;
                    types[i]   = c.DefaultReturnType;
                }
                for (int i = classCount; i < types.Length; i++)
                {
                    string name = reader.ReadString();
                    types[i] = new GetClassReturnType(pc, name, reader.ReadByte());
                }
                stringArray = new string[reader.ReadInt32()];
                for (int i = 0; i < stringArray.Length; i++)
                {
                    stringArray[i] = reader.ReadString();
                }
                ReadAttributes(pc.AssemblyCompilationUnit);
                for (int i = 0; i < classes.Length; i++)
                {
                    ReadClass(classes[i]);
                    pc.AddClassToNamespaceList(classes[i]);
                    if (reader.ReadByte() != 64)
                    {
                        return(false);
                    }
                }
                return(true);
            }
Ejemplo n.º 2
0
        public static DefaultClass GetDummyClassForTypeParameter(ITypeParameter p)
        {
            DefaultClass c = new DefaultClass(p.Class.CompilationUnit, p.Name);

            if (p.Method != null)
            {
                c.Region = new DomRegion(p.Method.Region.BeginLine, p.Method.Region.BeginColumn);
            }
            else
            {
                c.Region = new DomRegion(p.Class.Region.BeginLine, p.Class.Region.BeginColumn);
            }
            c.Modifiers = ModifierEnum.Public;
            if (p.HasValueTypeConstraint)
            {
                c.ClassType = ClassType.Struct;
            }
            else if (p.HasConstructableConstraint)
            {
                c.ClassType = ClassType.Class;
            }
            else
            {
                c.ClassType = ClassType.Interface;
            }
            return(c);
        }
Ejemplo n.º 3
0
		static IClass CreateMyApplication(ICompilationUnit cu, VBNetProject project, string ns)
		{
			DefaultClass c = new DefaultClass(cu, ns + ".MyApplication");
			c.ClassType = ClassType.Class;
			c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic;
			c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));
			switch (project.OutputType) {
				case OutputType.WinExe:
					c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase"));
					if (project.GetEvaluatedProperty("MyType") == "WindowsForms") {
						c.Methods.Add(
							new DefaultMethod(c, "Main") {
								Modifiers = ModifierEnum.Internal | ModifierEnum.Static,
								ReturnType = c.ProjectContent.SystemTypes.Void,
								Parameters = new[] {
									new DefaultParameter(
										"args",
										new ArrayReturnType(c.ProjectContent, c.ProjectContent.SystemTypes.String, 1),
										DomRegion.Empty
									)
								}
							});
					}
					break;
				case OutputType.Exe:
					c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase"));
					break;
				default:
					c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ApplicationBase"));
					break;
			}
			return c;
		}
Ejemplo n.º 4
0
		void AddWebViewPageBaseClass(DefaultClass webViewPageClass, IReturnType modelType)
		{
			IClass webViewPageBaseClass = webViewPageClass.ProjectContent.GetClass("System.Web.Mvc.WebViewPage", 1);
			if (webViewPageBaseClass != null) {
				IReturnType returnType = GetWebViewPageBaseClassReturnType(webViewPageBaseClass, modelType);
				webViewPageClass.BaseTypes.Add(returnType);
			}
		}
		public override IClass GetUnderlyingClass()
		{
			if (cachedClass != null) return cachedClass;
			DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ModifierEnum.None, DomRegion.Empty, null);
			c.BaseTypes.Add(cu.ProjectContent.SystemTypes.Delegate);
			AddDefaultDelegateMethod(c, returnType ?? cu.ProjectContent.SystemTypes.Object, parameters);
			cachedClass = c;
			return c;
		}
Ejemplo n.º 6
0
		DefaultClass CreateWebViewPageClass(RazorCompilationUnit compilationUnit)
		{
			var webViewPageClass = new DefaultClass(compilationUnit, "RazorWebViewPage") {
				Region = new DomRegion(1, 0, 3, 0)
			};
			IReturnType modelType = GetModelReturnType(compilationUnit);
			AddWebViewPageBaseClass(webViewPageClass, modelType);
			return webViewPageClass;
		}
		public void ExpressionResultContextShowItemReturnsTrueForIMethod()
		{
			MockProjectContent projectContent = new MockProjectContent();
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			DefaultClass c = new DefaultClass(unit, "MyClass");
			DefaultMethod method = new DefaultMethod(c, "Test");
			
			Assert.IsTrue(expressionResult.Context.ShowEntry(method));
		}
		protected override ExpressionResult GetExpressionResult()
		{
			List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>();
			DefaultClass consoleClass = new DefaultClass(compilationUnit, "System.Console");
			namespaceItems.Add(consoleClass);
			projectContent.AddExistingNamespaceContents("System", namespaceItems);
			
			return new ExpressionResult("MySystem", ExpressionContext.Default);
		}
		public void FindMethodFromArrayReturnsNullForUnknownMethod()
		{
			DefaultClass c = new DefaultClass(new DefaultCompilationUnit(new DefaultProjectContent()), "Test");
			DefaultMethod method = new DefaultMethod(c, "abc");
			
			ArrayList items = new ArrayList();
			items.Add(method);
			
			Assert.IsNull(PythonCompletionItemsHelper.FindMethodFromCollection("unknown", items));
		}
Ejemplo n.º 10
0
 public IClass GetInnermostClass(int caretLine, int caretColumn)
 {
     foreach (IClass c in Classes)
     {
         if (c != null && DefaultClass.IsInside(c, caretLine, caretColumn))
         {
             return(c.GetInnermostClass(caretLine, caretColumn));
         }
     }
     return(null);
 }
		public void Init()
		{
			projectContent = new MockProjectContent();
			completion = new PythonImportCompletion(projectContent);
			
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			ParseInformation parseInfo = new ParseInformation(unit);
			c = new DefaultClass(unit, "Class");
			List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>();
			namespaceItems.Add(c);
			projectContent.AddExistingNamespaceContents("System", namespaceItems);
		}
Ejemplo n.º 12
0
        public override IClass GetUnderlyingClass()
        {
            if (cachedClass != null)
            {
                return(cachedClass);
            }
            DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ModifierEnum.None, DomRegion.Empty, null);

            c.BaseTypes.Add(cu.ProjectContent.SystemTypes.Delegate);
            AddDefaultDelegateMethod(c, returnType ?? cu.ProjectContent.SystemTypes.Object, parameters ?? new IParameter[0]);
            cachedClass = c;
            return(c);
        }
		public void Init()
		{
			string code = "from System import Console";
			importExpression = new PythonImportExpression(code);
			resolveResult = new PythonImportModuleResolveResult(importExpression);
			
			projectContent = new MockProjectContent();
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			DefaultClass c = new DefaultClass(unit, "Test");
			List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>();
			namespaceItems.Add(c);
			projectContent.AddExistingNamespaceContents("System", namespaceItems);
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Builds Visual Basic's "My" namespace for the specified project.
		/// </summary>
		public static void BuildNamespace(VBNetProject project, IProjectContent pc)
		{
			if ("custom".Equals(project.GetEvaluatedProperty("MyType"), StringComparison.OrdinalIgnoreCase))
				return;
			
			ICompilationUnit cu = new DefaultCompilationUnit(pc);
			//cu.FileName = "GeneratedMyNamespace.vb"; // leave FileName null - fixes SD2-854
			string ns;
			if (project.RootNamespace == null || project.RootNamespace.Length == 0)
				ns = "My";
			else
				ns = project.RootNamespace + ".My";
			IClass myApp = CreateMyApplication(cu, project, ns);
			IClass myComp = CreateMyComputer(cu, ns);
			
			cu.Classes.Add(myApp);
			cu.Classes.Add(myComp);
			
			IClass myForms = null;
			if (project.OutputType == OutputType.WinExe) {
				myForms = CreateMyForms(cu, ns);
				cu.Classes.Add(myForms);
			}
			DefaultClass c = new DefaultClass(cu, ns + ".MyProject");
			c.ClassType = ClassType.Module;
			c.Modifiers = ModifierEnum.Internal | ModifierEnum.Partial | ModifierEnum.Sealed | ModifierEnum.Synthetic;
			c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));
			
			// we need to use GetClassReturnType instead of DefaultReturnType because we need
			// a reference to the compound class.
			c.Properties.Add(new DefaultProperty("Application",
			                                     new GetClassReturnType(pc, myApp.FullyQualifiedName, 0),
			                                     ModifierEnum.Public | ModifierEnum.Static,
			                                     DomRegion.Empty, DomRegion.Empty, c));
			c.Properties.Add(new DefaultProperty("Computer",
			                                     new GetClassReturnType(pc, myComp.FullyQualifiedName, 0),
			                                     ModifierEnum.Public | ModifierEnum.Static,
			                                     DomRegion.Empty, DomRegion.Empty, c));
			if (myForms != null) {
				c.Properties.Add(new DefaultProperty("Forms",
				                                     new GetClassReturnType(pc, myForms.FullyQualifiedName, 0),
				                                     ModifierEnum.Public | ModifierEnum.Static,
				                                     DomRegion.Empty, DomRegion.Empty, c));
			}
			c.Properties.Add(new DefaultProperty("User",
			                                     new GetClassReturnType(pc, "Microsoft.VisualBasic.ApplicationServices.User", 0),
			                                     ModifierEnum.Public | ModifierEnum.Static,
			                                     DomRegion.Empty, DomRegion.Empty, c));
			cu.Classes.Add(c);
			pc.UpdateCompilationUnit(null, cu, cu.FileName);
		}
Ejemplo n.º 15
0
		public void FixtureSetup()
		{
			ProjectContentRegistry r = new ProjectContentRegistry();
			msc = r.Mscorlib;
			swf = r.GetProjectContentForReference("System.Windows.Forms", typeof(System.Windows.Forms.Form).Module.FullyQualifiedName);
			
			DefaultProjectContent dpc = new DefaultProjectContent();
			dpc.ReferencedContents.Add(msc);
			DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc);
			dummyClass = new DefaultClass(cu, "DummyClass");
			cu.Classes.Add(dummyClass);
			methodForGenericCalls = new DefaultMethod(dummyClass, "DummyMethod");
			dummyClass.Methods.Add(methodForGenericCalls);
		}
        DefaultClass AddClass(NavigateToItem item, IDocument document)
        {
            var defaultClass = new DefaultClass(this, item.GetFullName());
            defaultClass.BodyRegion = item.ToRegion(document);
            defaultClass.Region = defaultClass.BodyRegion;

            if (item.HasContainer()) {
                IClass parentClass = FindParentClass(item);
                parentClass.InnerClasses.Add(defaultClass);
            } else {
                Classes.Add(defaultClass);
            }
            return defaultClass;
        }
		public void Init()
		{
			DefaultProjectContent projectContent = new DefaultProjectContent();
			unit = new DefaultCompilationUnit(projectContent);
			DefaultClass c = new DefaultClass(unit, "Foo");
			
			DefaultMethod buttonClickMethod = new DefaultMethod(c, "ButtonClick");
			AddSenderAndEventArgsParameters(buttonClickMethod);
			c.Methods.Add(buttonClickMethod);
			
			projectContent.AddClassToNamespaceList(c);
			
			parseInfo = new ParseInformation(unit);
		}
Ejemplo n.º 18
0
 static void AddTypeParametersForCtrlSpace(ArrayList result, IEnumerable <ITypeParameter> typeParameters)
 {
     foreach (ITypeParameter p in typeParameters)
     {
         DefaultClass c = DefaultTypeParameter.GetDummyClassForTypeParameter(p);
         if (p.Method != null)
         {
             c.Documentation = "Type parameter of " + p.Method.Name;
         }
         else
         {
             c.Documentation = "Type parameter of " + p.Class.Name;
         }
         result.Add(c);
     }
 }
Ejemplo n.º 19
0
		/// <summary>
		/// Walks a class definition.
		/// </summary>
		public override bool Walk(ClassDefinition node)
		{
			DefaultClass c = new DefaultClass(compilationUnit, GetFullyQualifiedClassName(node));
			c.Region = GetRegion(node);
			c.BodyRegion = GetBodyRegion(node.Body, node.Header);
			AddBaseTypes(c, node.Bases);
			
			// Save the class.
			compilationUnit.Classes.Add(c);
			
			// Walk through all the class items.
			currentClass = c;
			node.Body.Walk(this);
			currentClass = null;
			
			return false;
		}
		internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList<IParameter> parameters)
		{
			ModifierEnum modifiers = ModifierEnum.Public | ModifierEnum.Synthetic;
			DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c);
			foreach (IParameter par in parameters) {
				invokeMethod.Parameters.Add(par);
			}
			c.Methods.Add(invokeMethod);
			invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c);
			foreach (IParameter par in parameters) {
				invokeMethod.Parameters.Add(par);
			}
			invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
			invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
			c.Methods.Add(invokeMethod);
			invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c);
			invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
			c.Methods.Add(invokeMethod);
		}
Ejemplo n.º 21
0
        internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList <IParameter> parameters)
        {
            ModifierEnum  modifiers    = ModifierEnum.Public | ModifierEnum.Synthetic;
            DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c);

            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c);
            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
            invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c);
            invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
        }
Ejemplo n.º 22
0
		public override object VisitEventDeclaration(NRefactoryAST.EventDeclaration eventDeclaration, object data)
		{
			DomRegion region     = GetRegion(eventDeclaration.StartLocation, eventDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(eventDeclaration.BodyStart,     eventDeclaration.BodyEnd);
			DefaultClass c = GetCurrentClass();
			
			IReturnType type;
			if (eventDeclaration.TypeReference.IsNull) {
				DefaultClass del = new DefaultClass(cu, ClassType.Delegate,
				                                    ConvertModifier(eventDeclaration.Modifier),
				                                    region, c);
				del.Modifiers |= ModifierEnum.Synthetic;
				CreateDelegate(del, eventDeclaration.Name + "EventHandler",
				               new NRefactoryAST.TypeReference("System.Void", true),
				               new NRefactoryAST.TemplateDefinition[0],
				               eventDeclaration.Parameters);
				type = del.DefaultReturnType;
			} else {
				type = CreateReturnType(eventDeclaration.TypeReference);
			}
			DefaultEvent e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, c);
			ConvertAttributes(eventDeclaration, e);
			c.Events.Add(e);
			
			e.Documentation = GetDocumentation(region.BeginLine, eventDeclaration.Attributes);
			if (eventDeclaration.HasAddRegion) {
				e.AddMethod = new DefaultMethod(e.DeclaringType, "add_" + e.Name) {
					Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
					Region = GetRegion(eventDeclaration.AddRegion.StartLocation, eventDeclaration.AddRegion.EndLocation),
					BodyRegion = GetRegion(eventDeclaration.AddRegion.Block.StartLocation, eventDeclaration.AddRegion.Block.EndLocation)
				};
			}
			if (eventDeclaration.HasRemoveRegion) {
				e.RemoveMethod = new DefaultMethod(e.DeclaringType, "remove_" + e.Name) {
					Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
					Region = GetRegion(eventDeclaration.RemoveRegion.StartLocation, eventDeclaration.RemoveRegion.EndLocation),
					BodyRegion = GetRegion(eventDeclaration.RemoveRegion.Block.StartLocation, eventDeclaration.RemoveRegion.Block.EndLocation)
				};
			}
			return null;
		}
Ejemplo n.º 23
0
		void CreateDelegate(DefaultClass c, string name, NRefactoryAST.TypeReference returnType, IList<NRefactoryAST.TemplateDefinition> templates, IList<NRefactoryAST.ParameterDeclarationExpression> parameters)
		{
			c.BaseTypes.Add(c.ProjectContent.SystemTypes.MulticastDelegate);
			DefaultClass outerClass = GetCurrentClass();
			if (outerClass != null) {
				outerClass.InnerClasses.Add(c);
				c.FullyQualifiedName = outerClass.FullyQualifiedName + '.' + name;
			} else {
				c.FullyQualifiedName = PrependCurrentNamespace(name);
				cu.Classes.Add(c);
			}
			c.UsingScope = currentNamespace;
			currentClass.Push(c); // necessary for CreateReturnType
			ConvertTemplates(outerClass, templates, c);
			
			List<IParameter> p = new List<IParameter>();
			if (parameters != null) {
				foreach (NRefactoryAST.ParameterDeclarationExpression param in parameters) {
					p.Add(CreateParameter(param));
				}
			}
			AnonymousMethodReturnType.AddDefaultDelegateMethod(c, CreateReturnType(returnType), p);
			
			currentClass.Pop();
		}
Ejemplo n.º 24
0
		public override object VisitDelegateDeclaration(NRefactoryAST.DelegateDeclaration delegateDeclaration, object data)
		{
			DomRegion region = GetRegion(delegateDeclaration.StartLocation, delegateDeclaration.EndLocation);
			DefaultClass c = new DefaultClass(cu, ClassType.Delegate, ConvertTypeModifier(delegateDeclaration.Modifier), region, GetCurrentClass());
			c.Documentation = GetDocumentation(region.BeginLine, delegateDeclaration.Attributes);
			ConvertAttributes(delegateDeclaration, c);
			CreateDelegate(c, delegateDeclaration.Name, delegateDeclaration.ReturnType,
			               delegateDeclaration.Templates, delegateDeclaration.Parameters);
			return c;
		}
Ejemplo n.º 25
0
		void ConvertTemplates(DefaultClass outerClass, IList<NRefactoryAST.TemplateDefinition> templateList, DefaultClass c)
		{
			int outerClassTypeParameterCount = outerClass != null ? outerClass.TypeParameters.Count : 0;
			if (templateList.Count == 0 && outerClassTypeParameterCount == 0) {
				c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
			} else {
				Debug.Assert(c.TypeParameters.Count == 0);
				
				int index = 0;
				if (outerClassTypeParameterCount > 0) {
					foreach (DefaultTypeParameter outerTypeParamter in outerClass.TypeParameters) {
						DefaultTypeParameter p = new DefaultTypeParameter(c, outerTypeParamter.Name, index++);
						p.HasConstructableConstraint = outerTypeParamter.HasConstructableConstraint;
						p.HasReferenceTypeConstraint = outerTypeParamter.HasReferenceTypeConstraint;
						p.HasValueTypeConstraint = outerTypeParamter.HasValueTypeConstraint;
						p.Attributes.AddRange(outerTypeParamter.Attributes);
						p.Constraints.AddRange(outerTypeParamter.Constraints);
						c.TypeParameters.Add(p);
					}
				}
				
				foreach (NRefactoryAST.TemplateDefinition template in templateList) {
					c.TypeParameters.Add(new DefaultTypeParameter(c, template.Name, index++));
				}
				// converting the constraints requires that the type parameters are already present
				for (int i = 0; i < templateList.Count; i++) {
					ConvertConstraints(templateList[i], (DefaultTypeParameter)c.TypeParameters[i + outerClassTypeParameterCount]);
				}
			}
		}
Ejemplo n.º 26
0
		public override object VisitTypeDeclaration(NRefactoryAST.TypeDeclaration typeDeclaration, object data)
		{
			DomRegion region = GetRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);
			
			DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertTypeModifier(typeDeclaration.Modifier), region, GetCurrentClass());
			if (c.IsStatic) {
				// static classes are also abstract and sealed at the same time
				c.Modifiers |= ModifierEnum.Abstract | ModifierEnum.Sealed;
			}
			c.BodyRegion = bodyRegion;
			ConvertAttributes(typeDeclaration, c);
			c.Documentation = GetDocumentation(region.BeginLine, typeDeclaration.Attributes);
			
			DefaultClass outerClass = GetCurrentClass();
			if (outerClass != null) {
				outerClass.InnerClasses.Add(c);
				c.FullyQualifiedName = outerClass.FullyQualifiedName + '.' + typeDeclaration.Name;
			} else {
				c.FullyQualifiedName = PrependCurrentNamespace(typeDeclaration.Name);
				cu.Classes.Add(c);
			}
			c.UsingScope = currentNamespace;
			currentClass.Push(c);
			
			ConvertTemplates(outerClass, typeDeclaration.Templates, c); // resolve constrains in context of the class
			// templates must be converted before base types because base types may refer to generic types
			
			if (c.ClassType != ClassType.Enum && typeDeclaration.BaseTypes != null) {
				foreach (NRefactoryAST.TypeReference type in typeDeclaration.BaseTypes) {
					IReturnType rt = CreateReturnType(type, null, TypeVisitor.ReturnTypeOptions.BaseTypeReference);
					if (rt != null) {
						c.BaseTypes.Add(rt);
					}
				}
			}
			
			object ret = typeDeclaration.AcceptChildren(this, data);
			currentClass.Pop();
			
			if (c.ClassType == ClassType.Module) {
				foreach (DefaultField f in c.Fields) {
					f.Modifiers |= ModifierEnum.Static;
				}
				foreach (DefaultMethod m in c.Methods) {
					m.Modifiers |= ModifierEnum.Static;
				}
				foreach (DefaultProperty p in c.Properties) {
					p.Modifiers |= ModifierEnum.Static;
				}
				foreach (DefaultEvent e in c.Events) {
					e.Modifiers |= ModifierEnum.Static;
				}
			}

            mapType(typeDeclaration, c);

			return ret;
		}
Ejemplo n.º 27
0
        public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent)
        {
            Init(fileContent.Text);

            SimpleCocoParser parser = new SimpleCocoParser(new Scanner(new StringStream(fileContent.Text)));

            parser.Parse();

            DefaultCompilationUnit cu = new DefaultCompilationUnit(projectContent);

            Location start, end;

            if (parser.CopySection != null) {
                start = OffsetToLocation(parser.CopySection.StartOffset);
                end = OffsetToLocation(parser.CopySection.EndOffset);

                cu.FoldingRegions.Add(new FoldingRegion("[copy]", new DomRegion(start.Line, start.Column, end.Line, end.Column)));
            }

            if (parser.UsingSection != null) {
                start = OffsetToLocation(parser.UsingSection.StartOffset);
                end = OffsetToLocation(parser.UsingSection.EndOffset);

                cu.FoldingRegions.Add(new FoldingRegion("[...]", new DomRegion(start.Line, start.Column, end.Line, end.Column)));
            }

            DefaultClass parserClass = null;

            if (parser.ParserSection != null) {
                start = OffsetToLocation(parser.ParserSection.StartOffset);
                end = OffsetToLocation(parser.ParserSection.EndOffset);

                parserClass = new DefaultClass(cu, parser.ParserName);

                parserClass.ClassType = ClassType.Class;
                parserClass.Modifiers = ModifierEnum.None;
                parserClass.Region = new DomRegion(start.Line, start.Column, end.Line, end.Column);

                cu.Classes.Add(parserClass);

                foreach (var info in parser.Lists) {
                    start = OffsetToLocation(info.segment.StartOffset);
                    end = OffsetToLocation(info.segment.EndOffset);

                    var region = new DomRegion(start.Line, start.Column, start.Line, start.Column + info.name.Length);
                    var body = new DomRegion(start.Line, start.Column, end.Line, end.Column);

                    var prop = new DefaultProperty(parserClass, info.name) {
                        Region = region, BodyRegion = body, Modifiers = ModifierEnum.Public
                    };

                    parserClass.Properties.Add(prop);
                }

                foreach (var info in parser.Productions) {
                    start = OffsetToLocation(info.segment.StartOffset);
                    end = OffsetToLocation(info.segment.EndOffset);

                    var region = new DomRegion(start.Line, start.Column, start.Line, start.Column + info.name.Length);
                    var body = new DomRegion(start.Line, start.Column, end.Line, end.Column);

                    var method = new DefaultMethod(parserClass, info.name) {
                        Region = region, BodyRegion = body, Modifiers = ModifierEnum.Public
                    };

                    parserClass.Methods.Add(method);
                }
            }
            return cu;
        }
Ejemplo n.º 28
0
		private void EnterTypeDefinition(AST.TypeDefinition node, ClassType classType)
		{
			//LoggingService.Debug("Enter " + node.GetType().Name + " (" + node.FullName + ")");
			foreach (AST.Attribute att in node.Attributes) {
				if (att.Name == "Boo.Lang.ModuleAttribute")
					classType = ClassType.Module;
			}
			DomRegion region = GetClientRegion(node);
			DefaultClass c = new DefaultClass(_cu, classType, GetModifier(node), region, OuterClass);
			c.FullyQualifiedName = node.FullName;
			if (_currentClass.Count > 0)
				_currentClass.Peek().InnerClasses.Add(c);
			else
				_cu.Classes.Add(c);
			_currentClass.Push(c);
			ConvertAttributes(node, c);
			ConvertTemplates(node, c);
			if (node.BaseTypes != null) {
				foreach (AST.TypeReference r in node.BaseTypes) {
					c.BaseTypes.Add(CreateReturnType(r));
				}
			}
		}
			bool ReadClasses()
			{
				int classCount = reader.ReadInt32();
				int externalTypeCount = reader.ReadInt32();
				types = new IReturnType[classCount + externalTypeCount];
				DefaultClass[] classes = new DefaultClass[classCount];
				for (int i = 0; i < classes.Length; i++) {
					DefaultClass c = new DefaultClass(pc.AssemblyCompilationUnit, reader.ReadString());
					classes[i] = c;
					types[i] = c.DefaultReturnType;
				}
				for (int i = classCount; i < types.Length; i++) {
					string name = reader.ReadString();
					types[i] = new GetClassReturnType(pc, name, reader.ReadByte());
				}
				stringArray = new string[reader.ReadInt32()];
				for (int i = 0; i < stringArray.Length; i++) {
					stringArray[i] = reader.ReadString();
				}
				ReadAttributes(pc.AssemblyCompilationUnit);
				for (int i = 0; i < classes.Length; i++) {
					ReadClass(classes[i]);
					pc.AddClassToNamespaceList(classes[i]);
					if (reader.ReadByte() != 64) {
						return false;
					}
				}
				return true;
			}
Ejemplo n.º 30
0
            void ReadClass(DefaultClass c)
            {
                this.currentClass = c;
                int count;

                count = reader.ReadByte();
                for (int i = 0; i < count; i++)
                {
                    c.TypeParameters.Add(new DefaultTypeParameter(c, ReadString(), i));
                }
                if (count > 0)
                {
                    foreach (ITypeParameter typeParameter in c.TypeParameters)
                    {
                        count = reader.ReadInt32();
                        for (int i = 0; i < count; i++)
                        {
                            typeParameter.Constraints.Add(ReadType());
                        }
                    }
                }
                else
                {
                    c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.BaseTypes.Add(ReadType());
                }
                c.Modifiers       = (ModifierEnum)reader.ReadInt32();
                c.CalculatedFlags = reader.ReadByte();
                c.ClassType       = (ClassType)reader.ReadByte();
                ReadAttributes(c);
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    DefaultClass innerClass = new DefaultClass(c.CompilationUnit, c);
                    innerClass.FullyQualifiedName = reader.ReadString();
                    c.InnerClasses.Add(innerClass);
                    ReadClass(innerClass);
                }
                this.currentClass = c;
                count             = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Methods.Add(ReadMethod());
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Properties.Add(ReadProperty());
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Events.Add(ReadEvent());
                }
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    c.Fields.Add(ReadField());
                }
                this.currentClass = null;
            }
Ejemplo n.º 31
0
        /// <summary>
        /// Gets all types the specified type inherits from (all classes and interfaces).
        /// Unlike the class inheritance tree, this method takes care of type arguments and calculates the type
        /// arguments that are passed to base classes.
        /// </summary>
        public static IEnumerable <IReturnType> GetTypeInheritanceTree(IReturnType typeToListInheritanceTreeFor)
        {
            if (typeToListInheritanceTreeFor == null)
            {
                throw new ArgumentNullException("typeToListInheritanceTreeFor");
            }

            lock (getTypeInheritanceTreeCache) {
                IEnumerable <IReturnType> result;
                if (getTypeInheritanceTreeCache.TryGetValue(typeToListInheritanceTreeFor, out result))
                {
                    return(result);
                }
            }

            IClass classToListInheritanceTreeFor = typeToListInheritanceTreeFor.GetUnderlyingClass();

            if (classToListInheritanceTreeFor == null)
            {
                return new IReturnType[] { typeToListInheritanceTreeFor }
            }
            ;

            if (typeToListInheritanceTreeFor.IsArrayReturnType)
            {
                IReturnType elementType = typeToListInheritanceTreeFor.CastToArrayReturnType().ArrayElementType;

                List <IReturnType> resultList = new List <IReturnType>();
                resultList.Add(typeToListInheritanceTreeFor);
                resultList.AddRange(GetTypeInheritanceTree(
                                        new ConstructedReturnType(
                                            classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.Generic.IList", 1).DefaultReturnType,
                                            new IReturnType[] { elementType }
                                            )
                                        ));
                resultList.Add(classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.IList", 0).DefaultReturnType);
                resultList.Add(classToListInheritanceTreeFor.ProjectContent.GetClass("System.Collections.ICollection", 0).DefaultReturnType);
                // non-generic IEnumerable is already added by generic IEnumerable
                return(resultList);
            }

            HashSet <IReturnType> visitedSet   = new HashSet <IReturnType>();
            List <IReturnType>    visitedList  = new List <IReturnType>();
            Queue <IReturnType>   typesToVisit = new Queue <IReturnType>();
            bool enqueuedLastBaseType          = false;

            IReturnType currentType  = typeToListInheritanceTreeFor;
            IClass      currentClass = classToListInheritanceTreeFor;
            IReturnType nextType;

            do
            {
                if (currentClass != null)
                {
                    if (visitedSet.Add(currentType))
                    {
                        visitedList.Add(currentType);
                        foreach (IReturnType type in currentClass.BaseTypes)
                        {
                            typesToVisit.Enqueue(TranslateIfRequired(currentType, type));
                        }
                    }
                }
                if (typesToVisit.Count > 0)
                {
                    nextType = typesToVisit.Dequeue();
                }
                else
                {
                    nextType             = enqueuedLastBaseType ? null : DefaultClass.GetBaseTypeByClassType(classToListInheritanceTreeFor);
                    enqueuedLastBaseType = true;
                }
                if (nextType != null)
                {
                    currentType  = nextType;
                    currentClass = nextType.GetUnderlyingClass();
                }
            } while (nextType != null);
            lock (getTypeInheritanceTreeCache) {
                if (getTypeInheritanceTreeCache.Count == 0)
                {
                    DomCache.RegisterForClear(ClearGetTypeInheritanceTreeCache);
                }
                getTypeInheritanceTreeCache[typeToListInheritanceTreeFor] = visitedList;
            }
            return(visitedList);
        }
Ejemplo n.º 32
0
		void ConvertTemplates(AST.Node node, DefaultClass c)
		{
			c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
		}
Ejemplo n.º 33
0
		public override void OnCallableDefinition(AST.CallableDefinition node)
		{
			LoggingService.Debug("OnCallableDefinition: " + node.FullName);
			DomRegion region = GetRegion(node);
			DefaultClass c = new DefaultClass(_cu, ClassType.Delegate, GetModifier(node), region, OuterClass);
			ConvertAttributes(node, c);
			c.BaseTypes.Add(c.ProjectContent.SystemTypes.Delegate);
			c.FullyQualifiedName = node.FullName;
			if (_currentClass.Count > 0) {
				OuterClass.InnerClasses.Add(c);
			} else {
				_cu.Classes.Add(c);
			}
			_currentClass.Push(c); // necessary for CreateReturnType
			ConvertTemplates(node, c);
			IReturnType returnType = CreateReturnType(node.ReturnType);
			DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
			ConvertParameters(node.Parameters, invokeMethod);
			c.Methods.Add(invokeMethod);
			invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
			ConvertParameters(node.Parameters, invokeMethod);
			if (invokeMethod.Parameters == DefaultParameter.EmptyParameterList) {
				invokeMethod.Parameters = new List<IParameter>();
			}
			invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
			invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
			c.Methods.Add(invokeMethod);
			invokeMethod = new DefaultMethod("EndInvoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
			invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
			c.Methods.Add(invokeMethod);
			_currentClass.Pop();
		}
		IClass AddClass(string className, AXmlElement element) {
			if (projectContent.Language == LanguageProperties.VBNet && projectContent.Project is IProject)
				className = ((IProject)projectContent.Project).RootNamespace + "." + className;
			
			DefaultClass c = new DefaultClass(CompilationUnit, className);
			string modifierValue = (element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "ClassModifier") ?? string.Empty).Trim();
			
			c.Modifiers = ModifierEnum.Partial;
			
			string internalString = currentAmbience.ConvertAccessibility(ModifierEnum.Internal).Trim();
			
			if (projectContent.Language.NameComparer.Compare(modifierValue, internalString) == 0)
				c.Modifiers |= ModifierEnum.Internal;
			else
				c.Modifiers |= ModifierEnum.Public;
			
			c.Region = CreateRegion(element.StartOffset, element.EndOffset);
			var baseType = TypeFromXmlNode(CompilationUnit, element);
			if (baseType != null)
				c.BaseTypes.Add(baseType);
			CompilationUnit.Classes.Add(c);

			DefaultMethod initializeComponent = new DefaultMethod(
				"InitializeComponent",
				projectContent.SystemTypes.Void,
				ModifierEnum.Public | ModifierEnum.Synthetic, c.Region, DomRegion.Empty,
				c);
			c.Methods.Add(initializeComponent);
			
			return c;
		}
Ejemplo n.º 35
0
		static IClass CreateMyComputer(ICompilationUnit cu, string ns)
		{
			DefaultClass c = new DefaultClass(cu, ns + ".MyComputer");
			c.ClassType = ClassType.Class;
			c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic;
			c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));
			c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.Devices.Computer"));
			return c;
		}
			void ReadClass(DefaultClass c)
			{
				this.currentClass = c;
				int count;
				count = reader.ReadByte();
				for (int i = 0; i < count; i++) {
					c.TypeParameters.Add(new DefaultTypeParameter(c, ReadString(), i));
				}
				if (count > 0) {
					foreach (ITypeParameter typeParameter in c.TypeParameters) {
						count = reader.ReadInt32();
						for (int i = 0; i < count; i++) {
							typeParameter.Constraints.Add(ReadType());
						}
					}
				} else {
					c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
				}
				count = reader.ReadInt32();
				for (int i = 0; i < count; i++) {
					c.BaseTypes.Add(ReadType());
				}
				c.Modifiers = (ModifierEnum)reader.ReadInt32();
				c.CalculatedFlags = reader.ReadByte();
				c.ClassType = (ClassType)reader.ReadByte();
				ReadAttributes(c);
				count = reader.ReadInt32();
				for (int i = 0; i < count; i++) {
					DefaultClass innerClass = new DefaultClass(c.CompilationUnit, c);
					innerClass.FullyQualifiedName = reader.ReadString();
					c.InnerClasses.Add(innerClass);
					ReadClass(innerClass);
				}
				this.currentClass = c;
				count = reader.ReadInt32();
				for (int i = 0; i < count; i++) {
					c.Methods.Add(ReadMethod());
				}
				count = reader.ReadInt32();
				for (int i = 0; i < count; i++) {
					c.Properties.Add(ReadProperty());
				}
				count = reader.ReadInt32();
				for (int i = 0; i < count; i++) {
					c.Events.Add(ReadEvent());
				}
				count = reader.ReadInt32();
				for (int i = 0; i < count; i++) {
					c.Fields.Add(ReadField());
				}
				this.currentClass = null;
			}
Ejemplo n.º 37
0
		static IClass GetPrimitiveClass(IProjectContent pc, string systemType, string newName)
		{
			IClass c = pc.GetClass(systemType, 0);
			if (c == null) {
				LoggingService.Warn("Could not find " + systemType);
				return null;
			}
			DefaultClass c2 = new DefaultClass(c.CompilationUnit, newName);
			c2.ClassType = c.ClassType;
			c2.Modifiers = c.Modifiers;
			c2.Documentation = c.Documentation;
			c2.BaseTypes.AddRange(c.BaseTypes);
			c2.Methods.AddRange(c.Methods);
			c2.Fields.AddRange(c.Fields);
			c2.Properties.AddRange(c.Properties);
			c2.Events.AddRange(c.Events);
			return c2;
		}
		public static DefaultClass GetDummyClassForTypeParameter(ITypeParameter p)
		{
			DefaultClass c = new DefaultClass(p.Class.CompilationUnit, p.Name);
			if (p.Method != null) {
				c.Region = new DomRegion(p.Method.Region.BeginLine, p.Method.Region.BeginColumn);
			} else {
				c.Region = new DomRegion(p.Class.Region.BeginLine, p.Class.Region.BeginColumn);
			}
			c.Modifiers = ModifierEnum.Public;
			if (p.HasValueTypeConstraint) {
				c.ClassType = ClassType.Struct;
			} else if (p.HasConstructableConstraint) {
				c.ClassType = ClassType.Class;
			} else {
				c.ClassType = ClassType.Interface;
			}
			return c;
		}