Esempio n. 1
0
        public static bool IsBetterPart(IUnresolvedTypeDefinition part1, IUnresolvedTypeDefinition part2, string codeFileExtension)
        {
            IUnresolvedFile file1 = part1.UnresolvedFile;
            IUnresolvedFile file2 = part2.UnresolvedFile;

            if (file1 != null && file2 == null)
            {
                return(true);
            }
            if (file1 == null)
            {
                return(false);
            }
            bool file1HasExtension = file1.FileName.EndsWith(codeFileExtension, StringComparison.OrdinalIgnoreCase);
            bool file2HasExtension = file2.FileName.EndsWith(codeFileExtension, StringComparison.OrdinalIgnoreCase);

            if (file1HasExtension && !file2HasExtension)
            {
                return(true);
            }
            if (!file1HasExtension && file2HasExtension)
            {
                return(false);
            }
            return(file1.FileName.Length < file2.FileName.Length);
        }
Esempio n. 2
0
        public IProjectContent UpdateProjectContent(IUnresolvedFile oldFile, IUnresolvedFile newFile)
        {
            if (oldFile == null && newFile == null)
            {
                return(this);
            }
            if (oldFile != null && newFile != null)
            {
                if (!Base.Platform.FileNameComparer.Equals(oldFile.FileName, newFile.FileName))
                {
                    throw new ArgumentException("When both oldFile and newFile are specified, they must use the same file name.");
                }
            }
            VSharpProjectContent pc = Clone();

            if (newFile == null)
            {
                pc.unresolvedFiles.Remove(oldFile.FileName);
            }
            else
            {
                pc.unresolvedFiles[newFile.FileName] = newFile;
            }
            return(pc);
        }
        public void AddCodeFile(string fileName, string code)
        {
            IUnresolvedFile oldFile = projectContent.GetFile(fileName);
            IUnresolvedFile newFile = Parse(fileName, code);

            projectContent = projectContent.AddOrUpdateFiles(newFile);
        }
Esempio n. 4
0
        public void ResetProject(Tuple <string, string>[] sourceFiles = null, params string[] assemblies)
        {
            Project = null;

            if (sourceFiles == null)
            {
                sourceFiles = new Tuple <string, string> [0]; //will happen only during the testing
            }
            var projectContents = new IUnresolvedAssembly[assemblies.Length];

            Parallel.For(0, assemblies.Length, i =>
            {
                projectContents[i] = new CecilLoader {
                    DocumentationProvider = GetXmlDocumentation(assemblies[i])
                }.LoadAssemblyFile(assemblies[i]);
            });

            var unresolvedAsms  = builtInLibs.Value.Concat(projectContents);
            var unresolvedFiles = new IUnresolvedFile[sourceFiles.Length];

            Parallel.For(0, unresolvedFiles.Length, i =>
            {
                var pair       = sourceFiles[i];
                var syntaxTree = new CSharpParser().Parse(pair.Item1, pair.Item2);
                syntaxTree.Freeze();
                unresolvedFiles[i] = syntaxTree.ToTypeSystem();
            });

            IProjectContent project = new CSharpProjectContent();

            project = project.AddAssemblyReferences(unresolvedAsms);
            project = project.AddOrUpdateFiles(unresolvedFiles);
            Project = project;
        }
Esempio n. 5
0
 public ICompilation CreateCompilationForSingleFile(FileName fileName, IUnresolvedFile unresolvedFile)
 {
     return(new CSharpProjectContent()
            .AddAssemblyReferences(defaultReferences.Value)
            .AddOrUpdateFiles(unresolvedFile)
            .CreateCompilation());
 }
        public void RegisterUnresolvedFile(IProject project, IUnresolvedFile unresolvedFile)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (unresolvedFile == null)
            {
                throw new ArgumentNullException("unresolvedFile");
            }
            FreezableHelper.Freeze(unresolvedFile);
            var newParseInfo = new ParseInformation(unresolvedFile, null, false);

            rwLock.EnterWriteLock();
            try {
                int index = FindIndexForProject(project);
                if (index >= 0)
                {
                    currentVersion = null;
                    var args = new ParseInformationEventArgs(project, entries[index].UnresolvedFile, newParseInfo);
                    entries[index] = new ProjectEntry(project, unresolvedFile, null);
                    project.OnParseInformationUpdated(args);
                    parserService.RaiseParseInformationUpdated(args);
                }
            } finally {
                rwLock.ExitWriteLock();
            }
        }
        void AddCodeElements()
        {
            ICompilation compilation = project.GetCompilationUnit();

            var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (projectContent != null)
            {
                IUnresolvedFile file = projectContent.GetFile(context.FilteredFileName);
                if (file != null)
                {
                    var csharpFile = file as CSharpUnresolvedFile;
                    if (csharpFile != null)
                    {
                        AddUsings(csharpFile.RootUsingScope, compilation);
                    }

                    var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly);
                    AddTypes(
                        file.TopLevelTypeDefinitions
                        .Select(td => td.Resolve(resolveContext) as ITypeDefinition)
                        .Where(td => td != null)
                        .Distinct());
                }
            }
        }
		public GenerateNamespaceImport GetResult (IUnresolvedFile unit, IType type, MonoDevelop.Ide.Gui.Document doc)
		{
			GenerateNamespaceImport result;
			if (cache.TryGetValue (type.Namespace, out result))
				return result;
			result = new GenerateNamespaceImport ();
			cache[type.Namespace] = result;
			TextEditorData data = doc.Editor;
			
			result.InsertNamespace  = false;
			var loc = new TextLocation (data.Caret.Line, data.Caret.Column);
			foreach (var ns in RefactoringOptions.GetUsedNamespaces (doc, loc)) {
				if (type.Namespace == ns) {
					result.GenerateUsing = false;
					return result;
				}
			}
			
			result.GenerateUsing = true;
			string name = type.Name;
			
			foreach (string ns in RefactoringOptions.GetUsedNamespaces (doc, loc)) {
				if (doc.Compilation.MainAssembly.GetTypeDefinition (ns, name, type.TypeParameterCount) != null) {
					result.GenerateUsing = false;
					result.InsertNamespace = true;
					return result;
				}
			}
			return result;
		}
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VB6UnresolvedMethod"/> class.
 /// </summary>
 /// <param name="method">The instance of <see cref="IVbMethod"/> that is the source of this entity.</param>
 /// <param name="file">The file that is the source of this entity.</param>
 /// <param name="typeReference">The <see cref="IUnresolvedTypeReference"/> that this member is a child of. May be null.</param>
 /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
 internal VB6UnresolvedMethod(IVbMethod method, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition)
     : base(method, file, typeReference, typeDefinition)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VB6UnresolvedMethod"/> class.
 /// </summary>
 /// <param name="method">The instance of <see cref="IVbMethod"/> that is the source of this entity.</param>
 /// <param name="file">The file that is the source of this entity.</param>
 /// <param name="typeReference">The <see cref="IUnresolvedTypeReference"/> that this member is a child of. May be null.</param>
 /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
 internal VB6UnresolvedMethod(IVbMethod method, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition)
     : base(method, file, typeReference, typeDefinition)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
 }
Esempio n. 11
0
 public ParseInformation(IUnresolvedFile unresolvedFile, ITextSourceVersion parsedVersion, bool isFullParseInformation)
 {
     if (unresolvedFile == null)
         throw new ArgumentNullException("unresolvedFile");
     this.unresolvedFile = unresolvedFile;
     this.parsedVersion = parsedVersion;
     this.isFullParseInformation = isFullParseInformation;
 }
 static IProjectContent CreateContent(IUnresolvedFile unresolvedFile)
 {
     return(new CSharpProjectContent()
            .AddOrUpdateFiles(unresolvedFile)
            .AddAssemblyReferences(new[] {
         CecilLoaderTests.Mscorlib
     })
            .SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name));
 }
		static IProjectContent CreateContent (IUnresolvedFile unresolvedFile)
		{
			return new CSharpProjectContent()
				.AddOrUpdateFiles(unresolvedFile)
				.AddAssemblyReferences(new[] {
					CecilLoaderTests.Mscorlib
				})
				.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
		}
Esempio n. 14
0
 /// <summary>
 /// Updates the list of available classes.
 /// This causes the classes combo box to lose its current selection,
 /// so the members combo box will be cleared.
 /// </summary>
 public void Update(IUnresolvedFile compilationUnit)
 {
     runUpdateWhenDropDownClosed   = true;
     runUpdateWhenDropDownClosedCU = compilationUnit;
     if (!IsDropDownOpen)
     {
         ComboBox_DropDownClosed(null, null);
     }
 }
 void AddToDirtyList(IUnresolvedFile unresolvedFile)
 {
     if (unresolvedFile != null)
     {
         foreach (var td in unresolvedFile.TopLevelTypeDefinitions)
         {
             AddToDirtyList(new TopLevelTypeName(td.Namespace, td.Name, td.TypeParameters.Count));
         }
     }
 }
Esempio n. 16
0
 public void Parse(IProject project, string fileName, string source)
 {
     this.FileName = fileName;
     this.Content = new StringTextSource(source);
     this.Document = new StringBuilderDocument(this.Content);
     this.Project = project;
     CSharpParser p = project.CreateParser();
     this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
     this.ParsedFile = this.SyntaxTree.ToTypeSystem();
 }
Esempio n. 17
0
 public ParseInformation(IUnresolvedFile unresolvedFile, ITextSourceVersion parsedVersion, bool isFullParseInformation)
 {
     if (unresolvedFile == null)
     {
         throw new ArgumentNullException("unresolvedFile");
     }
     this.unresolvedFile         = unresolvedFile;
     this.parsedVersion          = parsedVersion;
     this.isFullParseInformation = isFullParseInformation;
 }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VB6UnresolvedEntityBase"/> class.
        /// </summary>
        /// <param name="file">The file that is the source of this entity.</param>
        /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
        protected VB6UnresolvedEntityBase(IUnresolvedFile file, IUnresolvedTypeDefinition typeDefinition)
            : this()
        {
            this.UnresolvedFile = file;

            VB6UnresolvedFile vb6File = (VB6UnresolvedFile)file;
            this.VbpProject = vb6File.Project;

            this.DeclaringTypeDefinition = typeDefinition;
        }
Esempio n. 19
0
        IList <ICompletionItem> CreateAttributeList(XamlCompletionContext context, bool includeEvents)
        {
            if (context.ParseInformation == null)
            {
                return(EmptyList <ICompletionItem> .Instance);
            }
            AXmlElement     lastElement = context.ActiveElement;
            IUnresolvedFile file        = context.ParseInformation.UnresolvedFile;
            XamlResolver    resolver    = new XamlResolver(compilation);
            IType           type        = resolver.ResolveType(lastElement.Namespace, lastElement.LocalName.Trim('.'));

            var list = new List <ICompletionItem>();

            string xamlPrefix = context.XamlNamespacePrefix;
            string xKey       = string.IsNullOrEmpty(xamlPrefix) ? "" : xamlPrefix + ":";

            if (lastElement.Prefix == context.XamlNamespacePrefix && XamlConst.IsBuiltin(lastElement.LocalName))
            {
                return(EmptyList <ICompletionItem> .Instance);
            }

            if (lastElement.LocalName.EndsWith(".", StringComparison.OrdinalIgnoreCase) || context.PressedKey == '.')
            {
                if (type.Kind == TypeKind.Unknown)
                {
                    return(EmptyList <ICompletionItem> .Instance);
                }

                if (context.ParentElement != null &&
                    context.ParentElement.LocalName.StartsWith(lastElement.LocalName.TrimEnd('.'), StringComparison.OrdinalIgnoreCase))
                {
                    AddAttributes(type, list, includeEvents);
                }
                AddAttachedProperties(type.GetDefinition(), list);
            }
            else
            {
                if (type.Kind == TypeKind.Unknown)
                {
                    list.Add(new XamlCompletionItem(xKey + "Uid"));
                }
                else
                {
                    AddAttributes(type, list, includeEvents);
                    list.AddRange(GetListOfAttached(context, null, includeEvents, true));
                    list.AddRange(
                        XamlConst.XamlNamespaceAttributes
                        .Where(localName => XamlConst.IsAttributeAllowed(context.InRoot, localName))
                        .Select(item => new XamlCompletionItem(xKey + item))
                        );
                }
            }

            return(list);
        }
Esempio n. 20
0
        public void Parse(IProject project, string fileName, string source)
        {
            this.FileName = fileName;
            this.Content  = new StringTextSource(source);
            this.Document = new StringBuilderDocument(this.Content);
            this.Project  = project;
            CSharpParser p = project.CreateParser();

            this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
            this.ParsedFile = this.SyntaxTree.ToTypeSystem();
        }
Esempio n. 21
0
		public void Update(IUnresolvedFile oldFile, IUnresolvedFile newFile)
		{
			IList<IUnresolvedTypeDefinition> old = EmptyList<IUnresolvedTypeDefinition>.Instance;
			IList<IUnresolvedTypeDefinition> @new = EmptyList<IUnresolvedTypeDefinition>.Instance;
			if (oldFile != null)
				old = oldFile.TopLevelTypeDefinitions;
			if (newFile != null)
				@new = newFile.TopLevelTypeDefinitions;
			
			typeDeclarations.Update(old, @new);
		}
Esempio n. 22
0
 void DoUpdate(IUnresolvedFile unresolvedFile)
 {
     classItems = new List <EntityItem>();
     if (unresolvedFile != null)
     {
         ICompilation compilation = SD.ParserService.GetCompilationForFile(FileName.Create(unresolvedFile.FileName));
         AddClasses(unresolvedFile.TopLevelTypeDefinitions, compilation);
     }
     classItems.Sort();
     classComboBox.ItemsSource = classItems;
 }
 public ParseInformationEventArgs(IProject parentProject, IUnresolvedFile oldUnresolvedFile, ParseInformation newParseInformation)
 {
     if (oldUnresolvedFile == null && newParseInformation == null)
         throw new ArgumentNullException();
     if (oldUnresolvedFile != null && newParseInformation != null) {
         Debug.Assert(FileUtility.IsEqualFileName(oldUnresolvedFile.FileName, newParseInformation.FileName));
     }
     this.parentProject = parentProject;
     this.oldUnresolvedFile = oldUnresolvedFile;
     this.newParseInformation = newParseInformation;
 }
Esempio n. 24
0
		public void UpdateClassMemberBookmarks(IUnresolvedFile parseInfo, IDocument document)
		{
			for (int i = bookmarks.Count - 1; i >= 0; i--) {
				if (bookmarks[i] is EntityBookmark)
					bookmarks.RemoveAt(i);
			}
			if (parseInfo == null)
				return;
			foreach (var c in parseInfo.TopLevelTypeDefinitions) {
				AddEntityBookmarks(c, document);
			}
		}
Esempio n. 25
0
 static IProjectContent CreateContent(IUnresolvedFile unresolvedFile)
 {
     return(new CSharpProjectContent()
            .AddOrUpdateFiles(unresolvedFile)
            .AddAssemblyReferences(new[] {
         CecilLoaderTests.Mscorlib
     })
            .SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name)
            .AddResources(new EmbeddedResource("ICSharpCode.NRefactory.TypeSystem.EmbeddedResource.txt", Path.Combine("TypeSystem", "EmbeddedResource.txt"), isPublic: true),
                          new EmbeddedResource("ICSharpCode.NRefactory.TypeSystem.PrivateEmbeddedResource.txt", Path.Combine("TypeSystem", "PrivateEmbeddedResource.txt"), isPublic: false),
                          new LinkedResource("ICSharpCode.NRefactory.TypeSystem.LinkedResource.txt", "LinkedResource.txt", Path.GetDirectoryName(typeof(TypeSystemConvertVisitorTests).Assembly.Location), isPublic: true)));
 }
Esempio n. 26
0
		public void NotifyParseInformationChanged(IUnresolvedFile oldUnresolvedFile, IUnresolvedFile newUnresolvedFile)
		{
			// We use delay-loading: the nested tests of a project are
			// initialized only when the NestedTests collection is actually accessed
			// (e.g. when the test tree node is expanded)
			if (!NestedTestsInitialized)
				return;
			// dirtyTypeDefinitions = new HashSet<FullNameAndTypeParameterCount>();
			AddToDirtyList(oldUnresolvedFile);
			AddToDirtyList(newUnresolvedFile);
			ProcessUpdates();
		}
		static IProjectContent CreateContent (IUnresolvedFile unresolvedFile)
		{
			return new CSharpProjectContent()
				.AddOrUpdateFiles(unresolvedFile)
				.AddAssemblyReferences(new[] {
					CecilLoaderTests.Mscorlib
				})
				.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name)
				.AddResources(new EmbeddedResource("ICSharpCode.NRefactory.TypeSystem.EmbeddedResource.txt", Path.Combine("TypeSystem", "EmbeddedResource.txt"), isPublic: true),
				              new EmbeddedResource("ICSharpCode.NRefactory.TypeSystem.PrivateEmbeddedResource.txt", Path.Combine("TypeSystem", "PrivateEmbeddedResource.txt"), isPublic: false),
				              new LinkedResource("ICSharpCode.NRefactory.TypeSystem.LinkedResource.txt", "LinkedResource.txt", Path.GetDirectoryName(typeof(TypeSystemConvertVisitorTests).Assembly.Location), isPublic: true));
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="VB6UnresolvedEntityBase"/> class.
        /// </summary>
        /// <param name="file">The file that is the source of this entity.</param>
        /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
        protected VB6UnresolvedEntityBase(IUnresolvedFile file, IUnresolvedTypeDefinition typeDefinition)
            : this()
        {
            this.UnresolvedFile = file;

            VB6UnresolvedFile vb6File = (VB6UnresolvedFile)file;

            this.VbpProject = vb6File.Project;


            this.DeclaringTypeDefinition = typeDefinition;
        }
Esempio n. 29
0
 private void Parse(IProject project, string fileName, string source)
 {
     Console.WriteLine("Loading " + fileName);
     this.FileName = fileName;
     this.Content = new StringTextSource(source);
     this.Document = new StringBuilderDocument(this.Content);
     this.Project = project;
     CSharpParser p = project.CreateParser();
     this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
     this.ParsedFile = this.SyntaxTree.ToTypeSystem();
     if(this.Project.ProjectContent != null)
         this.Project.ProjectContent.AddOrUpdateFiles(this.ParsedFile);
 }
 public void NotifyParseInformationChanged(IUnresolvedFile oldUnresolvedFile, IUnresolvedFile newUnresolvedFile)
 {
     // We use delay-loading: the nested tests of a project are
     // initialized only when the NestedTests collection is actually accessed
     // (e.g. when the test tree node is expanded)
     if (!NestedTestsInitialized)
     {
         return;
     }
     // dirtyTypeDefinitions = new HashSet<FullNameAndTypeParameterCount>();
     AddToDirtyList(oldUnresolvedFile);
     AddToDirtyList(newUnresolvedFile);
     ProcessUpdates();
 }
Esempio n. 31
0
		public ICompilation CreateCompilationForSingleFile(FileName fileName, IUnresolvedFile unresolvedFile)
		{
			DecompiledTypeReference reference = DecompiledTypeReference.FromFileName(fileName);
			if (reference != null) {
				var model = SD.GetService<IClassBrowser>().FindAssemblyModel(reference.AssemblyFile);
				if (model == null)
					model = SD.AssemblyParserService.GetAssemblyModelSafe(reference.AssemblyFile, true);
				if (model != null)
					return model.Context.GetCompilation();
			}
			return new CSharpProjectContent()
				.AddOrUpdateFiles(unresolvedFile)
				.CreateCompilation();
		}
Esempio n. 32
0
        private void AddOrUpdateFiles()
        {
            typeSystemCache.Clear();
            var unresolvedFiles = new IUnresolvedFile[sourceFiles.Count];

            Parallel.For(0, unresolvedFiles.Length, i =>
            {
                var syntaxTree     = sourceFiles[i].SyntaxTree;
                unresolvedFiles[i] = GetTypeSystem(syntaxTree);
            });

            project     = project.AddOrUpdateFiles(unresolvedFiles);
            compilation = project.CreateCompilation();
        }
		public static ITypeDefinition GetDesignableClass(IUnresolvedFile parsedFile, ICompilation compilation, out IUnresolvedTypeDefinition primaryPart)
		{
			primaryPart = null;
			if (parsedFile == null)
				return null;
			foreach (var utd in parsedFile.TopLevelTypeDefinitions) {
				var td = utd.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)).GetDefinition();
				if (IsDesignable(td)) {
					primaryPart = utd;
					return td;
				}
			}
			return null;
		}
 public ParseInformationEventArgs(IProject parentProject, IUnresolvedFile oldUnresolvedFile, ParseInformation newParseInformation)
 {
     if (oldUnresolvedFile == null && newParseInformation == null)
     {
         throw new ArgumentNullException();
     }
     if (oldUnresolvedFile != null && newParseInformation != null)
     {
         Debug.Assert(FileUtility.IsEqualFileName(oldUnresolvedFile.FileName, newParseInformation.FileName));
     }
     this.parentProject       = parentProject;
     this.oldUnresolvedFile   = oldUnresolvedFile;
     this.newParseInformation = newParseInformation;
 }
Esempio n. 35
0
 void ComboBox_DropDownClosed(object sender, EventArgs e)
 {
     if (runUpdateWhenDropDownClosed)
     {
         runUpdateWhenDropDownClosed = false;
         DoUpdate(runUpdateWhenDropDownClosedCU);
         runUpdateWhenDropDownClosedCU = null;
     }
     if (runSelectItemWhenDropDownClosed)
     {
         runSelectItemWhenDropDownClosed = false;
         DoSelectItem(runSelectItemWhenDropDownClosedLocation);
     }
 }
        public UnknownCodeContext(ICompilation compilation, IUnresolvedFile file, TextLocation location)
            : this(compilation)
        {
            var curDef = file.GetInnermostTypeDefinition (location);
            if (curDef != null) {
                var resolvedDef = curDef.Resolve (context).GetDefinition ();
                if (resolvedDef != null) {
                    context = context.WithCurrentTypeDefinition (resolvedDef);

                    var curMember = resolvedDef.Members.FirstOrDefault (m => m.Region.FileName == file.FileName && m.Region.Begin <= location && location < m.BodyRegion.End);
                    if (curMember != null)
                        context = context.WithCurrentMember (curMember);
                }
            }
        }
Esempio n. 37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VB6UnresolvedMemberBase"/> class.
        /// </summary>
        /// <param name="member">The instance of <see cref="IVbMember"/> that is the source of this entity.</param>
        /// <param name="file">The file that is the source of this entity.</param>
        /// <param name="typeReference">The <see cref="IUnresolvedTypeReference"/> that this member is a child of. May be null.</param>
        /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
        protected VB6UnresolvedMemberBase(IVbMember member, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition)
            : base(file, typeDefinition)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            this.Member = member;

            this.Name = member.Name;
            this.Accessibility = member.ToAccessibility();

            this.DeclaringTypeReference = typeReference;
        }
Esempio n. 38
0
        // Token: 0x06000027 RID: 39 RVA: 0x00002B98 File Offset: 0x00000D98
        private IUnresolvedFile[] GetFiles(VSProject vsproject)
        {
            string[]          files           = this.GetFilePaths(vsproject);
            IUnresolvedFile[] projectFiles    = new IUnresolvedFile[files.Length];
            ParallelOptions   parallelOptions = new ParallelOptions
            {
                TaskScheduler = TaskScheduler.Default
            };

            Parallel.For(0, files.Length, parallelOptions, delegate(int i)
            {
                projectFiles[i] = this.LoadFile(files[i]);
            });
            return(projectFiles);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VB6UnresolvedMemberBase"/> class.
        /// </summary>
        /// <param name="member">The instance of <see cref="IVbMember"/> that is the source of this entity.</param>
        /// <param name="file">The file that is the source of this entity.</param>
        /// <param name="typeReference">The <see cref="IUnresolvedTypeReference"/> that this member is a child of. May be null.</param>
        /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
        protected VB6UnresolvedMemberBase(IVbMember member, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition)
            : base(file, typeDefinition)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            this.Member = member;

            this.Name          = member.Name;
            this.Accessibility = member.ToAccessibility();

            this.DeclaringTypeReference = typeReference;
        }
Esempio n. 40
0
        public void Update(IUnresolvedFile oldFile, IUnresolvedFile newFile)
        {
            IList <IUnresolvedTypeDefinition> old  = EmptyList <IUnresolvedTypeDefinition> .Instance;
            IList <IUnresolvedTypeDefinition> @new = EmptyList <IUnresolvedTypeDefinition> .Instance;

            if (oldFile != null)
            {
                old = oldFile.TopLevelTypeDefinitions;
            }
            if (newFile != null)
            {
                @new = newFile.TopLevelTypeDefinitions;
            }

            typeDeclarations.Update(old, @new);
        }
Esempio n. 41
0
        private void Parse(IProject project, string fileName, string source)
        {
            Console.WriteLine("Loading " + fileName);
            this.FileName = fileName;
            this.Content  = new StringTextSource(source);
            this.Document = new StringBuilderDocument(this.Content);
            this.Project  = project;
            CSharpParser p = project.CreateParser();

            this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
            this.ParsedFile = this.SyntaxTree.ToTypeSystem();
            if (this.Project.ProjectContent != null)
            {
                this.Project.ProjectContent.AddOrUpdateFiles(this.ParsedFile);
            }
        }
Esempio n. 42
0
        void AddAllMembersMatchingText(string text)
        {
            ITextEditor editor = GetEditor();

            if (editor != null)
            {
                IUnresolvedFile parseInfo = SD.ParserService.GetExistingUnresolvedFile(editor.FileName);
                if (parseInfo != null)
                {
                    foreach (IUnresolvedTypeDefinition c in parseInfo.TopLevelTypeDefinitions)
                    {
                        AddAllMembersMatchingText(c, text, true);
                    }
                }
            }
        }
Esempio n. 43
0
		public LanguageItemWindow (ExtensibleTextEditor ed, Gdk.ModifierType modifierState, ResolveResult result, string errorInformations, IUnresolvedFile unit)
		{
			string tooltip = null;
			if (result is UnknownIdentifierResolveResult) {
				tooltip = string.Format ("error CS0103: The name `{0}' does not exist in the current context", ((UnknownIdentifierResolveResult)result).Identifier);
			} else if (result is UnknownMemberResolveResult) {
				var ur = (UnknownMemberResolveResult)result;
				if (ur.TargetType.Kind != TypeKind.Unknown)
					tooltip = string.Format ("error CS0117: `{0}' does not contain a definition for `{1}'", ur.TargetType.FullName, ur.MemberName);
			} else if (result != null && ed.TextEditorResolverProvider != null) {
				//tooltip = ed.TextEditorResolverProvider.CreateTooltip (unit, result, errorInformations, ambience, modifierState);
				// TODO: Type sysetm conversion. (btw. this isn't required because the analyzer should provide semantic error messages.)	
				//				if (result.ResolveErrors.Count > 0) {
				//					StringBuilder sb = new StringBuilder ();
				//					sb.Append (tooltip);
				//					sb.AppendLine ();
				//					sb.AppendLine ();
				//					sb.AppendLine (GettextCatalog.GetPluralString ("Error:", "Errors:", result.ResolveErrors.Count));
				//					for (int i = 0; i < result.ResolveErrors.Count; i++) {
				//						sb.Append ('\t');
				//						sb.Append (result.ResolveErrors[i]);
				//						if (i + 1 < result.ResolveErrors.Count) 
				//							sb.AppendLine ();
				//					}
				//					tooltip = sb.ToString ();
				//				}
			} else {
				tooltip = errorInformations;
			}
			if (string.IsNullOrEmpty (tooltip)|| tooltip == "?") {
				IsEmpty = true;
				return;
			}

			var label = new MonoDevelop.Components.FixedWidthWrapLabel () {
				Wrap = Pango.WrapMode.WordChar,
				Indent = -20,
				BreakOnCamelCasing = true,
				BreakOnPunctuation = true,
				Markup = tooltip,
			};
			this.BorderWidth = 3;
			Add (label);
			UpdateFont (label);
			
			EnableTransparencyControl = true;
		}
        /// <summary>
        /// Gets the next member after the specified caret position.
        /// </summary>
        IUnresolvedEntity GetMemberAfter(ITextEditor editor, int caretLine)
        {
            FileName          fileName    = editor.FileName;
            IUnresolvedEntity nextElement = null;

            if (fileName != null)
            {
                IUnresolvedFile unresolvedFile = SD.ParserService.ParseFile(fileName, editor.Document);
                if (unresolvedFile != null)
                {
                    var currentClass    = unresolvedFile.GetInnermostTypeDefinition(caretLine, 0);
                    int nextElementLine = int.MaxValue;
                    if (currentClass == null)
                    {
                        foreach (var c in unresolvedFile.TopLevelTypeDefinitions)
                        {
                            if (c.Region.BeginLine < nextElementLine && c.Region.BeginLine > caretLine)
                            {
                                nextElementLine = c.Region.BeginLine;
                                nextElement     = c;
                            }
                        }
                    }
                    else
                    {
                        foreach (var c in currentClass.NestedTypes)
                        {
                            if (c.Region.BeginLine < nextElementLine && c.Region.BeginLine > caretLine)
                            {
                                nextElementLine = c.Region.BeginLine;
                                nextElement     = c;
                            }
                        }
                        foreach (var m in currentClass.Members)
                        {
                            if (m.Region.BeginLine < nextElementLine && m.Region.BeginLine > caretLine)
                            {
                                nextElementLine = m.Region.BeginLine;
                                nextElement     = m;
                            }
                        }
                    }
                }
            }
            return(nextElement);
        }
Esempio n. 45
0
        IUnresolvedTypeDefinition GetCurrentClass(SDTask item)
        {
            // Tasks are created by parsing, so the parse information for item.FileName should already be present.
            // If they aren't, that's because the file might have been deleted/renamed in the meantime.
            // We use GetExistingParseInformation to avoid trying to parse a file that might have been deleted/renamed.
            IUnresolvedFile parseInfo = SD.ParserService.GetExistingUnresolvedFile(item.FileName);

            if (parseInfo != null)
            {
                var c = parseInfo.GetInnermostTypeDefinition(item.Line, item.Column);
                if (c != null)
                {
                    return(c);
                }
            }

            return(null);
        }
Esempio n. 46
0
 public static ITypeDefinition GetDesignableClass(IUnresolvedFile parsedFile, ICompilation compilation, out IUnresolvedTypeDefinition primaryPart)
 {
     primaryPart = null;
     if (parsedFile == null)
     {
         return(null);
     }
     foreach (var utd in parsedFile.TopLevelTypeDefinitions)
     {
         var td = utd.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)).GetDefinition();
         if (IsDesignable(td))
         {
             primaryPart = utd;
             return(td);
         }
     }
     return(null);
 }
Esempio n. 47
0
 public static void LoadBaseType(IProjectContent prj)
 {
     try
     {
         if (BaseTypeFile == null)
         {
             var source      = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "ALBASE.al");
             var asyntaxTree = parser.Parse(source, AppDomain.CurrentDomain.BaseDirectory + "ALBASE.al");
             asyntaxTree.Freeze();
             BaseTypeFile = asyntaxTree.ToTypeSystem();
         }
         prj.AddOrUpdateFiles(BaseTypeFile);
     }
     catch
     {
         BaseTypeFile = null;
     }
 }
Esempio n. 48
0
 private void Parse(IProject project, string fileName, string source)
 {
     Console.WriteLine("Loading " + fileName);
     this.FileName = fileName;
     this.Content = new StringTextSource(source);
     this.Document = new ReadOnlyDocument(this.Content);
     this.Project = project;
     CSharpParser p = project.CreateParser();
     this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
     if (p.HasErrors)
     {
         Console.WriteLine("Error parsing " + fileName + ":");
         foreach (var error in p.Errors)
         {
             Console.WriteLine("  " + error.Region + " " + error.Message);
         }
     }
     this.ParsedFile = this.SyntaxTree.ToTypeSystem();
 }
Esempio n. 49
0
        private void AddOrUpdateFiles()
        {
            var unresolvedFiles = new IUnresolvedFile[this.sourceFiles.Count];

            Parallel.For(0, unresolvedFiles.Length, i =>
            {
                var syntaxTree = this.sourceFiles[i].SyntaxTree;

                if (this.CanFreeze)
                {
                    //syntaxTree.Freeze();
                }

                unresolvedFiles[i] = syntaxTree.ToTypeSystem();
            });

            this.project = this.project.AddOrUpdateFiles(unresolvedFiles);
            this.compilation = this.project.CreateCompilation();
        }
        internal VB6UnresolvedTypeDefinition(IUnresolvedFile file, IVbModule module, IVbpProject project)
            : base(file, null)
        {
            this.Module = module;

            _typeKind = this.Module.ToTypeKind();

            this.Accessibility = (_typeKind != TypeKind.Module) ? Accessibility.Public : Accessibility.Private;

            _events = new List<IUnresolvedEvent>();
            _fields = new List<IUnresolvedField>();
            _properties = new List<IUnresolvedProperty>();
            _methods = new List<IUnresolvedMethod>();
            _members = new List<IUnresolvedMember>();

            this.DeclaringTypeDefinition = this;
            this.FullName = GetName(true);
            this.Name = GetName(false);
            this.Namespace = "(implicit)";
            this.ReflectionName = GetName(true);

            ProcessModule();
        }
		public void ParseInformationUpdated(IUnresolvedFile oldFile, IUnresolvedFile newFile)
		{
			// This method is called by the parser service within the parser service (per-file) lock.
			lock (lockObj) {
				if (!disposed) {
					if (newFile != null)
						projectContent = projectContent.AddOrUpdateFiles(newFile);
					else
						projectContent = projectContent.RemoveFiles(oldFile.FileName);
					serializedProjectContentIsUpToDate = false;
					SD.ParserService.InvalidateCurrentSolutionSnapshot();
					if (!SD.ParserService.LoadSolutionProjectsThread.IsRunning)
						SD.MainThread.InvokeAsyncAndForget(delegate { assemblyModel.Update(oldFile, newFile); });
				}
			}
		}
			public ProjectEntry(IProject project, IUnresolvedFile unresolvedFile, ParseInformation cachedParseInformation)
			{
				this.Project = project;
				this.UnresolvedFile = unresolvedFile;
				this.CachedParseInformation = cachedParseInformation;
			}
		public void RegisterUnresolvedFile(IProject project, IUnresolvedFile unresolvedFile)
		{
			if (project == null)
				throw new ArgumentNullException("project");
			if (unresolvedFile == null)
				throw new ArgumentNullException("unresolvedFile");
			FreezableHelper.Freeze(unresolvedFile);
			var newParseInfo = new ParseInformation(unresolvedFile, null, false);
			lock (this) {
				int index = FindIndexForProject(project);
				if (index >= 0) {
					currentVersion = null;
					var args = new ParseInformationEventArgs(project, entries[index].UnresolvedFile, newParseInfo);
					entries[index] = new ProjectEntry(project, unresolvedFile, null);
					project.OnParseInformationUpdated(args);
					parserService.RaiseParseInformationUpdated(args);
				}
			}
		}
Esempio n. 54
0
		public IProjectContent UpdateProjectContent(IUnresolvedFile oldFile, IUnresolvedFile newFile)
		{
			if (oldFile == null && newFile == null)
				return this;
			if (oldFile != null && newFile != null) {
				if (!Platform.FileNameComparer.Equals(oldFile.FileName, newFile.FileName))
					throw new ArgumentException("When both oldFile and newFile are specified, they must use the same file name.");
			}
			CSharpProjectContent pc = Clone();
			if (newFile == null)
				pc.unresolvedFiles.Remove(oldFile.FileName);
			else
				pc.unresolvedFiles[newFile.FileName] = newFile;
			return pc;
		}
		static bool IsSerializable(IUnresolvedFile unresolvedFile)
		{
			return unresolvedFile != null && unresolvedFile.GetType().IsSerializable && unresolvedFile.LastWriteTime != default(DateTime);
		}
Esempio n. 56
0
		public void RegisterUnresolvedFile(FileName fileName, IProject project, IUnresolvedFile unresolvedFile)
		{
			GetFileEntry(fileName, true).RegisterUnresolvedFile(project, unresolvedFile);
		}
Esempio n. 57
0
 public ParsedFileEventArgs(IUnresolvedFile file)
 {
     this.File = file;
 }
Esempio n. 58
0
		public ICompilation CreateCompilationForSingleFile(FileName fileName, IUnresolvedFile unresolvedFile)
		{
			return new CSharpProjectContent()
				.AddAssemblyReferences(defaultReferences.Value)
				.AddOrUpdateFiles(unresolvedFile)
				.CreateCompilation();
		}
		public static bool IsDesignable(IUnresolvedFile parsedFile, ICompilation compilation)
		{
			IUnresolvedTypeDefinition td;
			return GetDesignableClass(parsedFile, compilation, out td) != null;
		}
Esempio n. 60
0
 internal VB6UnresolvedProperty(IVbProperty property, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition)
     : base(property, file, typeReference, typeDefinition)
 {
     this.CanGet = (property.Accessor == VbPropertyAccessor.Get);
     this.CanSet = !this.CanGet;
 }