Esempio n. 1
0
		public NSObjectProjectInfo (TypeSystemService.ProjectContentWrapper dom, NSObjectInfoService infoService, IAssembly lookinAssembly)
		{
			this.infoService = infoService;
			this.dom = dom;
			this.lookinAssembly = lookinAssembly;
			needsUpdating = true;
		}
        void HandleTextReplacing(object sender, Core.Text.TextChangeEventArgs e)
        {
            var handler = TextChanged;

            if (handler != null)
            {
                lock (replaceLock) {
                    var oldText      = CurrentText;
                    var changes      = new Microsoft.CodeAnalysis.Text.TextChange[e.TextChanges.Count];
                    var changeRanges = new TextChangeRange[e.TextChanges.Count];
                    for (int i = 0; i < e.TextChanges.Count; ++i)
                    {
                        var c    = e.TextChanges[i];
                        var span = new TextSpan(c.Offset, c.RemovalLength);
                        changes[i]      = new Microsoft.CodeAnalysis.Text.TextChange(span, c.InsertedText.Text);
                        changeRanges[i] = new TextChangeRange(span, c.InsertionLength);
                    }
                    var newText = oldText.WithChanges(changes);
                    currentText = newText;
                    try {
                        handler(this, new Microsoft.CodeAnalysis.Text.TextChangeEventArgs(oldText, newText, changeRanges));
                    } catch (ArgumentException ae) {
                        if (!workspace.TryGetTarget(out var ws))
                        {
                            return;
                        }
                        if (!editor.TryGetTarget(out var ed))
                        {
                            return;
                        }
                        LoggingService.LogWarning(ae.Message + " re opening " + ed.FileName + " as roslyn source text.");
                        ws.InformDocumentClose(Id, ed.FileName);
                        Dispose();                          // 100% ensure that this object is disposed
                        if (ws.GetDocument(Id) != null)
                        {
                            TypeSystemService.InformDocumentOpen(Id, ed);
                        }
                    } catch (Exception ex) {
                        LoggingService.LogError("Error while text replacing", ex);
                    }
                }
            }
        }
Esempio n. 3
0
        public static IUnresolvedMember AddCodeDomMember(Project project, IUnresolvedTypeDefinition type, CodeTypeMember newMember)
        {
            bool isOpen;
            var  data           = TextFileProvider.Instance.GetTextEditorData(type.Region.FileName, out isOpen);
            var  parsedDocument = TypeSystemService.ParseFile(data.Document.FileName, data.Document.MimeType, data.Text);

            var insertionPoints = GetInsertionPoints(data, parsedDocument, type);

            var suitableInsertionPoint = GetSuitableInsertionPoint(insertionPoints, type, newMember);

            var dotNetProject = project as DotNetProject;

            if (dotNetProject == null)
            {
                LoggingService.LogError("Only .NET projects are supported.");
                return(null);
            }

            var          generator = dotNetProject.LanguageBinding.GetCodeDomProvider();
            StringWriter sw        = new StringWriter();
            var          options   = new CodeGeneratorOptions();

            options.IndentString = data.GetLineIndent(type.Region.BeginLine) + "\t";
            if (newMember is CodeMemberMethod)
            {
                options.BracingStyle = "C";
            }
            generator.GenerateCodeFromMember(newMember, sw, options);

            suitableInsertionPoint.Insert(data, sw.ToString());
            if (!isOpen)
            {
                try {
                    File.WriteAllText(type.Region.FileName, data.Text);
                } catch (Exception e) {
                    LoggingService.LogError(string.Format("Failed to write file '{0}'.", type.Region.FileName), e);
                    MessageService.ShowError(GettextCatalog.GetString("Failed to write file '{0}'.", type.Region.FileName));
                }
            }
            var newDocument = TypeSystemService.ParseFile(data.FileName, data.MimeType, data.Text);

            return(newDocument.ParsedFile.GetMember(suitableInsertionPoint.Location.Line, int.MaxValue));
        }
        public static void AddNewMembers(Project project, ITypeDefinition type, IUnresolvedTypeDefinition part, IEnumerable <IUnresolvedMember> newMembers, string regionName = null, Func <IUnresolvedMember, bool> implementExplicit = null)
        {
            IUnresolvedMember firstNewMember = newMembers.FirstOrDefault();

            if (firstNewMember == null)
            {
                return;
            }
            bool isOpen;
            var  data           = TextFileProvider.Instance.GetTextEditorData(part.Region.FileName, out isOpen);
            var  parsedDocument = TypeSystemService.ParseFile(project, data);

            var insertionPoints = GetInsertionPoints(data, parsedDocument, part);


            var suitableInsertionPoint = GetSuitableInsertionPoint(insertionPoints, part, firstNewMember);

            var generator = CreateCodeGenerator(data, type.Compilation);

            generator.IndentLevel = CalculateBodyIndentLevel(parsedDocument.GetInnermostTypeDefinition(part.Region.Begin));
            StringBuilder sb = new StringBuilder();

            foreach (var newMember in newMembers)
            {
                if (sb.Length > 0)
                {
                    sb.AppendLine();
                    sb.AppendLine();
                }
                sb.Append(generator.CreateMemberImplementation(type, part, newMember, implementExplicit != null ? implementExplicit(newMember) : false).Code);
            }
            suitableInsertionPoint.Insert(data, string.IsNullOrEmpty(regionName) ? sb.ToString() : generator.WrapInRegions(regionName, sb.ToString()));
            if (!isOpen)
            {
                try {
                    File.WriteAllText(type.Region.FileName, data.Text);
                } catch (Exception e) {
                    LoggingService.LogError(GettextCatalog.GetString("Failed to write file '{0}'.", type.Region.FileName), e);
                    MessageService.ShowError(GettextCatalog.GetString("Failed to write file '{0}'.", type.Region.FileName));
                }
            }
        }
Esempio n. 5
0
            IEnumerable <DocumentInfo> GenerateProjections(MonoDevelop.Projects.ProjectFile f, DocumentMap documentMap, MonoDevelop.Projects.Project p, ProjectData oldProjectData, HashSet <DocumentId> duplicates)
            {
                var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath);
                var node     = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction);

                if (node == null || !node.Parser.CanGenerateProjection(mimeType, f.BuildAction, p.SupportedLanguages))
                {
                    yield break;
                }
                var options = new ParseOptions {
                    FileName = f.FilePath,
                    Project  = p,
                    Content  = TextFileProvider.Instance.GetReadOnlyTextEditorData(f.FilePath),
                };
                var generatedProjections = node.Parser.GenerateProjections(options);
                var list  = new List <Projection> ();
                var entry = new ProjectionEntry {
                    File        = f,
                    Projections = list,
                };

                foreach (var projection in generatedProjections.Result)
                {
                    list.Add(projection);
                    if (duplicates != null && !duplicates.Add(documentMap.GetOrCreate(projection.Document.FileName, oldProjectData?.DocumentData)))
                    {
                        continue;
                    }
                    var plainName = projection.Document.FileName.FileName;
                    var folders   = GetFolders(p.Name, f);
                    yield return(DocumentInfo.Create(
                                     documentMap.GetOrCreate(projection.Document.FileName, oldProjectData?.DocumentData),
                                     plainName,
                                     folders,
                                     SourceCodeKind.Regular,
                                     TextLoader.From(TextAndVersion.Create(new MonoDevelopSourceText(projection.Document), VersionStamp.Create(), projection.Document.FileName)),
                                     projection.Document.FileName,
                                     false
                                     ));
                }
                projections.AddProjectionEntry(entry);
            }
Esempio n. 6
0
 IEnumerable <ProjectReference> CreateProjectReferences(MonoDevelop.Projects.Project p, CancellationToken token)
 {
     foreach (var pr in p.GetReferencedItems(MonoDevelop.Projects.ConfigurationSelector.Default))
     {
         if (token.IsCancellationRequested)
         {
             yield break;
         }
         var referencedProject = pr as MonoDevelop.Projects.DotNetProject;
         if (referencedProject == null)
         {
             continue;
         }
         if (TypeSystemService.IsOutputTrackedProject(referencedProject))
         {
             continue;
         }
         yield return(new ProjectReference(GetOrCreateProjectId(referencedProject)));
     }
 }
        public static IUnresolvedTypeDefinition AddType(DotNetProject project, string folder, string namspace, CodeTypeDeclaration type)
        {
            var unit = new CodeCompileUnit();
            var ns   = new CodeNamespace(namspace);

            ns.Types.Add(type);
            unit.Namespaces.Add(ns);

            string fileName = project.LanguageBinding.GetFileName(Path.Combine(folder, type.Name));

            using (var sw = new StreamWriter(fileName)) {
                var provider = project.LanguageBinding.GetCodeDomProvider();
                var options  = new CodeGeneratorOptions();
                options.IndentString = "\t";
                options.BracingStyle = "C";

                provider.GenerateCodeFromCompileUnit(unit, sw, options);
            }
            return(TypeSystemService.ParseFile(project, fileName).TopLevelTypeDefinitions.FirstOrDefault());
        }
Esempio n. 8
0
        IEnumerable <DocumentInfo> GenerateProjections(MonoDevelop.Projects.ProjectFile f, ProjectData projectData, MonoDevelop.Projects.Project p, HashSet <DocumentId> duplicates = null)
        {
            var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath);
            var node     = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction);

            if (node == null || !node.Parser.CanGenerateProjection(mimeType, f.BuildAction, p.SupportedLanguages))
            {
                yield break;
            }
            var options = new ParseOptions {
                FileName = f.FilePath,
                Project  = p,
                Content  = StringTextSource.ReadFrom(f.FilePath),
            };
            var projections = node.Parser.GenerateProjections(options);
            var entry       = new ProjectionEntry();

            entry.File = f;
            var list = new List <Projection> ();

            entry.Projections = list;
            foreach (var projection in projections.Result)
            {
                list.Add(projection);
                if (duplicates != null && !duplicates.Add(projectData.GetOrCreateDocumentId(projection.Document.FileName)))
                {
                    continue;
                }
                var plainName = projection.Document.FileName.FileName;
                yield return(DocumentInfo.Create(
                                 projectData.GetOrCreateDocumentId(projection.Document.FileName),
                                 plainName,
                                 new [] { p.Name }.Concat(f.ProjectVirtualPath.ParentDirectory.ToString().Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)),
                                 SourceCodeKind.Regular,
                                 TextLoader.From(TextAndVersion.Create(new MonoDevelopSourceText(projection.Document), VersionStamp.Create(), projection.Document.FileName)),
                                 projection.Document.FileName,
                                 false
                                 ));
            }
            projectionList.Add(entry);
        }
            public IPersistentStorage GetStorage(Solution solution)
            {
                // check whether the solution actually exist on disk
                if (!File.Exists(solution.FilePath))
                {
                    return(NoOpPersistentStorageInstance);
                }

                // get working folder path
                string workingFolderPath;

                lock (getStorageLock) {
                    workingFolderPath = TypeSystemService.GetCacheDirectory(solution.FilePath, true);
                    if (workingFolderPath == null)
                    {
                        // we don't have place to save. don't use caching
                        return(NoOpPersistentStorageInstance);
                    }
                }

                return(GetStorage(solution, workingFolderPath));
            }
Esempio n. 10
0
            async Task <ProjectCacheInfo> LoadProjectCacheInfo(MonoDevelop.Projects.Project p, DotNetProjectConfiguration config, CancellationToken token)
            {
                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var(references, projectReferences) = await metadataHandler.Value.CreateReferences(p, token).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var sourceFiles = await p.GetSourceFilesAsync(config?.Selector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var analyzerFiles = await p.GetAnalyzerFilesAsync(config?.Selector).ConfigureAwait(false);

                return(new ProjectCacheInfo {
                    AnalyzerFiles = analyzerFiles,
                    SourceFiles = sourceFiles,
                    ProjectReferences = projectReferences,
                    References = references
                });
            }
Esempio n. 11
0
            bool AddMetadataProjectReferences(AddMetadataReferencesData data)
            {
                try {
                    var referencedProjects = data.Project.GetReferencedItems(data.ConfigurationSelector);
                    foreach (var pr in referencedProjects)
                    {
                        if (data.Token.IsCancellationRequested)
                        {
                            return(false);
                        }

                        if (!(pr is MonoDevelop.Projects.DotNetProject referencedProject) || !TypeSystemService.IsOutputTrackedProject(referencedProject))
                        {
                            continue;
                        }

                        var fileName = referencedProject.GetOutputFileName(data.ConfigurationSelector);
                        if (!data.Visited.Add(fileName))
                        {
                            continue;
                        }

                        var metadataReference = manager.GetOrCreateMetadataReference(fileName, MetadataReferenceProperties.Assembly);
                        if (metadataReference != null)
                        {
                            data.Result.Add(metadataReference);
                        }
                    }
                } catch (Exception e) {
                    LoggingService.LogError("Error while getting referenced assemblies", e);
                    // TODO: Check whether this should return false, I retained compat for now.
                    return(true);
                }

                return(true);
            }
Esempio n. 12
0
            async Task <ProjectCacheInfo> LoadProjectCacheInfo(
                MonoDevelop.Projects.Project p,
                DotNetProjectConfiguration config,
                string framework,
                CancellationToken token)
            {
                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var(references, projectReferences) = await metadataHandler.Value.CreateReferences(p, framework, token).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var configSelector = config?.Selector;

                if (p is MonoDevelop.Projects.DotNetProject && configSelector != null && !string.IsNullOrEmpty(framework))
                {
                    configSelector = new MonoDevelop.Projects.DotNetProjectFrameworkConfigurationSelector(config.Selector, framework);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var sourceFiles = await p.GetSourceFilesAsync(configSelector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var editorConfigFiles = await p.GetEditorConfigFilesAsync(configSelector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var additionalFiles = await p.GetAdditionalFilesAsync(configSelector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                await TypeSystemService.SafeFreezeLoad().ConfigureAwait(false);

                var analyzerFiles = await p.GetAnalyzerFilesAsync(configSelector).ConfigureAwait(false);

                return(new ProjectCacheInfo {
                    AdditionalFiles = additionalFiles,
                    AnalyzerFiles = analyzerFiles,
                    EditorConfigFiles = editorConfigFiles,
                    SourceFiles = sourceFiles,
                    ProjectReferences = projectReferences,
                    References = references
                });
            }
 static void OnWorkspaceItemAdded(object s, MonoDevelop.Projects.WorkspaceItemEventArgs args)
 {
     Task.Run(() => TypeSystemService.Load(args.Item, null));
 }
Esempio n. 14
0
        static async Task <List <MetadataReference> > CreateMetadataReferences(MonoDevelop.Projects.Project p, ProjectId projectId, CancellationToken token)
        {
            List <MetadataReference> result = new List <MetadataReference> ();

            var netProject = p as MonoDevelop.Projects.DotNetProject;

            if (netProject == null)
            {
                return(result);
            }

            var configurationSelector = IdeApp.Workspace?.ActiveConfiguration ?? MonoDevelop.Projects.ConfigurationSelector.Default;
            var hashSet = new HashSet <string> (FilePath.PathComparer);

            bool addFacadeAssemblies = false;

            try {
                foreach (string file in await netProject.GetReferencedAssemblies(configurationSelector, false).ConfigureAwait(false))
                {
                    if (token.IsCancellationRequested)
                    {
                        return(result);
                    }
                    string fileName;
                    if (!Path.IsPathRooted(file))
                    {
                        fileName = Path.Combine(Path.GetDirectoryName(netProject.FileName), file);
                    }
                    else
                    {
                        fileName = Path.GetFullPath(file);
                    }
                    if (hashSet.Contains(fileName))
                    {
                        continue;
                    }
                    hashSet.Add(fileName);
                    if (!File.Exists(fileName))
                    {
                        continue;
                    }
                    result.Add(MetadataReferenceCache.LoadReference(projectId, fileName));
                    addFacadeAssemblies |= MonoDevelop.Core.Assemblies.SystemAssemblyService.ContainsReferenceToSystemRuntime(fileName);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while getting referenced assemblies", e);
            }
            // HACK: Facade assemblies should be added by the project system. Remove that when the project system can do that.
            if (addFacadeAssemblies)
            {
                if (netProject != null)
                {
                    var runtime = netProject.TargetRuntime ?? MonoDevelop.Core.Runtime.SystemAssemblyService.DefaultRuntime;
                    var facades = runtime.FindFacadeAssembliesForPCL(netProject.TargetFramework);
                    foreach (var facade in facades)
                    {
                        if (!File.Exists(facade))
                        {
                            continue;
                        }
                        result.Add(MetadataReferenceCache.LoadReference(projectId, facade));
                    }
                }
            }

            foreach (var pr in p.GetReferencedItems(configurationSelector))
            {
                if (token.IsCancellationRequested)
                {
                    return(result);
                }
                var referencedProject = pr as MonoDevelop.Projects.DotNetProject;
                if (referencedProject == null)
                {
                    continue;
                }
                if (TypeSystemService.IsOutputTrackedProject(referencedProject))
                {
                    var fileName = referencedProject.GetOutputFileName(configurationSelector);
                    if (!File.Exists(fileName))
                    {
                        continue;
                    }
                    result.Add(MetadataReferenceCache.LoadReference(projectId, fileName));
                }
            }
            return(result);
        }
Esempio n. 15
0
        IEnumerable <DocumentInfo> CreateDocuments(ProjectData projectData, MonoDevelop.Projects.Project p, CancellationToken token, MonoDevelop.Projects.ProjectFile[] sourceFiles)
        {
            var duplicates = new HashSet <DocumentId> ();

            // use given source files instead of project.Files because there may be additional files added by msbuild targets
            foreach (var f in sourceFiles)
            {
                if (token.IsCancellationRequested)
                {
                    yield break;
                }
                if (f.Subtype == MonoDevelop.Projects.Subtype.Directory)
                {
                    continue;
                }
                if (TypeSystemParserNode.IsCompileBuildAction(f.BuildAction))
                {
                    if (!duplicates.Add(projectData.GetOrCreateDocumentId(f.Name)))
                    {
                        continue;
                    }
                    yield return(CreateDocumentInfo(solutionData, p.Name, projectData, f));

                    continue;
                }
                var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath);
                var node     = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction);
                if (node == null || !node.Parser.CanGenerateProjection(mimeType, f.BuildAction, p.SupportedLanguages))
                {
                    continue;
                }
                var options = new ParseOptions {
                    FileName = f.FilePath,
                    Project  = p,
                    Content  = StringTextSource.ReadFrom(f.FilePath),
                };
                var projections = node.Parser.GenerateProjections(options);
                var entry       = new ProjectionEntry();
                entry.File = f;
                var list = new List <Projection> ();
                entry.Projections = list;
                foreach (var projection in projections.Result)
                {
                    list.Add(projection);
                    if (!duplicates.Add(projectData.GetOrCreateDocumentId(projection.Document.FileName)))
                    {
                        continue;
                    }
                    var plainName = projection.Document.FileName.FileName;
                    yield return(DocumentInfo.Create(
                                     projectData.GetOrCreateDocumentId(projection.Document.FileName),
                                     plainName,
                                     new [] { p.Name }.Concat(f.ProjectVirtualPath.ParentDirectory.ToString().Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)),
                                     SourceCodeKind.Regular,
                                     TextLoader.From(TextAndVersion.Create(new MonoDevelopSourceText(projection.Document), VersionStamp.Create(), projection.Document.FileName)),
                                     projection.Document.FileName,
                                     false
                                     ));
                }
                projectionList.Add(entry);
            }
        }
Esempio n. 16
0
		NSObjectTypeInfo ConvertType (TypeSystemService.ProjectContentWrapper dom, ITypeDefinition type)
		{
			string objcName = null;
			bool isModel = false;
			bool registeredInDesigner = true;
			
			foreach (var att in type.Attributes) {
				var attType = att.AttributeType;
				if (attType.Equals (Resolve (dom, registerAttType))) {
					if (type.GetProjectContent () != null) {
						registeredInDesigner &=
							MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (att.Region.FileName);
					}
					
					//type registered with an explicit type name are up to the user to provide a valid name
					var posArgs = att.PositionalArguments;
					if (posArgs.Count == 1 || posArgs.Count == 2)
						objcName = posArgs [0].ConstantValue as string;
					//non-nested types in the root namespace have names accessible from obj-c
					else if (string.IsNullOrEmpty (type.Namespace) && type.Name.IndexOf ('.') < 0)
						objcName = type.Name;
				}
				
				if (attType.Equals (Resolve (dom, modelAttType)))
					isModel = true;
			}
			
			if (string.IsNullOrEmpty (objcName))
				return null;
			
			string baseType = type.DirectBaseTypes.First ().ReflectionName;
			if (baseType == "System.Object")
				baseType = null;
			
			bool isUserType = !type.ParentAssembly.Equals (Resolve (dom, nsobjectType).ParentAssembly);
			
			var info = new NSObjectTypeInfo (objcName, type.ReflectionName, null, baseType, isModel, isUserType, registeredInDesigner);

			if (info.IsUserType) {
				UpdateTypeMembers (dom, info, type);
				info.DefinedIn = type.Parts.Select (p => (string) p.Region.FileName).ToArray ();
			}
			
			return info;
		}
 private static IEnumerable<ITypeDefinition> GetMatchingTypeDefinitions(TypeSystemService.ProjectContentWrapper wrapper, Func<ITypeDefinition, bool> matcher)
 {
     IEnumerable<ITypeDefinition> typeDefinitions = wrapper.Compilation.MainAssembly.GetAllTypeDefinitions ();
     return GetMatchingTypeDefinitions (typeDefinitions, matcher);
 }
Esempio n. 18
0
		public NSObjectProjectInfo GetProjectInfo (TypeSystemService.ProjectContentWrapper dom, IAssembly lookinAssembly = null)
		{
			NSObjectProjectInfo info;
			
			lock (infos) {
				if (infos.TryGetValue (dom, out info))
					return info;
				
				var nso = Resolve (dom, nsobjectType);
				//only include DOMs that can resolve NSObject
				if (nso == null || nso.Kind == TypeKind.Unknown)
					return null;
				
				info = new NSObjectProjectInfo (dom, this, lookinAssembly);
				infos[dom] = info;
			}
			return info;
		}
Esempio n. 19
0
		ITypeDefinition Resolve (TypeSystemService.ProjectContentWrapper dom, ITypeReference reference)
		{
			return reference.Resolve (dom.Compilation).GetDefinition ();
		}
Esempio n. 20
0
		void UpdateTypeMembers (TypeSystemService.ProjectContentWrapper dom, NSObjectTypeInfo info, ITypeDefinition type)
		{
			info.Actions.Clear ();
			info.Outlets.Clear ();
			foreach (var prop in type.Properties) {
				foreach (var att in prop.Attributes) {
					var attType = att.AttributeType;
					bool isIBOutlet = attType.Equals (Resolve (dom, iboutletAttType));
					if (!isIBOutlet) {
						if (!attType.Equals (Resolve (dom, connectAttType)))
							continue;
					}
					string name = null;
					var posArgs = att.PositionalArguments;
					if (posArgs.Count == 1)
						name = posArgs [0].ConstantValue as string;
					if (string.IsNullOrEmpty (name))
						name = prop.Name;
					
					// HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet
					// with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid 
					// conflicts with the view property mapped there
					if (name == "view") {
						if (type.GetAllBaseTypeDefinitions ().Any (p => p.ReflectionName == "MonoTouch.UIKit.UIViewController"))
							continue;
					}
					
					var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.ReflectionName);
					if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.Region.FileName))
						ol.IsDesigner = true;
					info.Outlets.Add (ol);
					break;
				}
			}
			
			foreach (var meth in type.Methods) {
				foreach (var att in meth.Attributes) {
					var attType = att.AttributeType;
					bool isIBAction = attType.Equals (Resolve (dom, ibactionAttType));
					if (!isIBAction) {
						if (!attType.Equals (Resolve (dom, exportAttType)))
							continue;
					}
					bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (
						meth.DeclaringTypeDefinition.Region.FileName);
					//only support Export from old designer files, user code must be IBAction
					if (!isDesigner && !isIBAction)
						continue;
					
					string[] name = null;
					var posArgs = att.PositionalArguments;
					if (posArgs.Count == 1 || posArgs.Count == 2) {
						var n = posArgs [0].ConstantValue as string;
						if (!string.IsNullOrEmpty (n))
							name = n.Split (colonChar);
					}
					var action = new IBAction (name != null ? name [0] : meth.Name, meth.Name);
					int i = 1;
					foreach (var param in meth.Parameters) {
						string label = name != null && i < name.Length ? name [i] : null;
						if (label != null && label.Length == 0)
							label = null;
						action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.Type.ReflectionName));
					}
					if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.Region.FileName))
						action.IsDesigner = true;
					info.Actions.Add (action);
					break;
				}
			}
		}
Esempio n. 21
0
        static async Task <List <MetadataReference> > CreateMetadataReferences(MonoDevelop.Projects.DotNetProject netProject, ProjectId projectId, CancellationToken token)
        {
            List <MetadataReference> result = new List <MetadataReference> ();

            var configurationSelector = IdeApp.Workspace?.ActiveConfiguration ?? MonoDevelop.Projects.ConfigurationSelector.Default;
            var hashSet = new HashSet <string> (FilePath.PathComparer);

            try {
                foreach (string file in await netProject.GetReferencedAssemblies(configurationSelector, false).ConfigureAwait(false))
                {
                    if (token.IsCancellationRequested)
                    {
                        return(result);
                    }
                    string fileName;
                    if (!Path.IsPathRooted(file))
                    {
                        fileName = Path.Combine(Path.GetDirectoryName(netProject.FileName), file);
                    }
                    else
                    {
                        fileName = Path.GetFullPath(file);
                    }
                    if (hashSet.Contains(fileName))
                    {
                        continue;
                    }
                    hashSet.Add(fileName);
                    if (!File.Exists(fileName))
                    {
                        LoggingService.LogError("Error while getting referenced Assembly " + fileName + " for project " + netProject.Name + ": File doesn't exist");
                        continue;
                    }
                    var metadataReference = MetadataReferenceCache.LoadReference(projectId, fileName);
                    if (metadataReference == null)
                    {
                        continue;
                    }
                    result.Add(metadataReference);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while getting referenced assemblies", e);
            }

            foreach (var pr in netProject.GetReferencedItems(configurationSelector))
            {
                if (token.IsCancellationRequested)
                {
                    return(result);
                }
                var referencedProject = pr as MonoDevelop.Projects.DotNetProject;
                if (referencedProject == null)
                {
                    continue;
                }
                if (TypeSystemService.IsOutputTrackedProject(referencedProject))
                {
                    var fileName = referencedProject.GetOutputFileName(configurationSelector);
                    if (!File.Exists(fileName))
                    {
                        LoggingService.LogError("Error while getting project Reference (" + referencedProject.Name + ") " + fileName + " for project " + netProject.Name + ": File doesn't exist");
                        continue;
                    }
                    var metadataReference = MetadataReferenceCache.LoadReference(projectId, fileName);
                    if (metadataReference != null)
                    {
                        result.Add(metadataReference);
                    }
                }
            }
            return(result);
        }
Esempio n. 22
0
		internal IEnumerable<NSObjectTypeInfo> GetRegisteredObjects (TypeSystemService.ProjectContentWrapper dom, IAssembly assembly)
		{
			var nso = Resolve (dom, nsobjectType);
			if (nso == null || nso.Kind == TypeKind.Unknown)
				throw new Exception ("Could not get NSObject from type database");
			
			//FIXME: only emit this for the wrapper NS
//			yield return new NSObjectTypeInfo ("NSObject", nso.GetDefinition ().FullName, null, null, false, false, false);
			int cnt = 0, infcnt=0, models=0;
			
			foreach (var contextType in assembly.GetAllTypeDefinitions ()) {
				if (contextType.IsDerivedFrom (nso)) {
					var info = ConvertType (dom, contextType);
					if (info != null)
						yield return info;
				}
			}
		}
 static void OnWorkspaceItemAdded(object s, MonoDevelop.Projects.WorkspaceItemEventArgs args)
 {
     TypeSystemService.Load(args.Item, null).Ignore();
 }
 private static void CollectReferences(ICollection<TypeSystemService.ProjectContentWrapper> wrappers, TypeSystemService.ProjectContentWrapper wrapper)
 {
     if (wrapper == null) {
         return;
     }
     if (wrappers.Contains (wrapper)) {
         return;
     }
     wrappers.Add (wrapper);
     foreach (Project project in wrapper.ReferencedProjects) {
         TypeSystemService.ProjectContentWrapper referenceWrapper = TypeSystemService.GetProjectContentWrapper (project);
         CollectReferences (wrappers, referenceWrapper);
     }
 }