Exemplo n.º 1
0
 internal void Update(Project project)
 {
     foreach (var file in project.Files)
     {
         TypeSystemService.ParseFile(project, file.FilePath);
     }
 }
Exemplo n.º 2
0
        public static void AddNewMember(ITypeDefinition type, IUnresolvedTypeDefinition part, IUnresolvedMember newMember, bool implementExplicit = false)
        {
            bool isOpen;
            var  data           = TextFileProvider.Instance.GetTextEditorData(part.Region.FileName, out isOpen);
            var  parsedDocument = TypeSystemService.ParseFile(data.FileName, data.MimeType, data.Text);

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

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

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

            generator.IndentLevel = CalculateBodyIndentLevel(parsedDocument.GetInnermostTypeDefinition(type.Region.Begin));
            var generatedCode = generator.CreateMemberImplementation(type, part, newMember, implementExplicit);

            suitableInsertionPoint.Insert(data, generatedCode.Code);
            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));
                }
            }
        }
Exemplo n.º 3
0
 public void Update(Project project)
 {
     System.Threading.Tasks.Task.Factory.StartNew(delegate {
         foreach (var file in project.Files)
         {
             TypeSystemService.ParseFile(project, file.FilePath);
         }
     });
 }
Exemplo n.º 4
0
 internal void Update(Project project)
 {
     foreach (var file in project.Files)
     {
         if (file.BuildAction == BuildAction.None)
         {
             continue;
         }
         TypeSystemService.ParseFile(project, file.FilePath);
     }
 }
Exemplo n.º 5
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);

            var code = sw.ToString();

            if (!string.IsNullOrEmpty(code))
            {
                suitableInsertionPoint.Insert(data, code);
            }
            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));
        }
Exemplo n.º 6
0
        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));
                }
            }
        }
Exemplo n.º 7
0
        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());
        }