void OnFileRemoved(object sender, ProjectFileEventArgs args) { ArrayList toDelete = new ArrayList(); ParsedDocument doc = ProjectDomService.GetParsedDocument(ProjectDomService.GetProjectDom(args.Project), args.ProjectFile.Name); if (doc == null || doc.CompilationUnit == null) { return; } foreach (IType t in doc.CompilationUnit.Types) { GuiBuilderWindow win = GetWindowForClass(t.FullName); if (win != null) { toDelete.Add(win); } } foreach (GuiBuilderWindow win in toDelete) { Remove(win); } }
public static void AddNewMember(IType type, IMember newMember, bool implementExplicit = false) { bool isOpen; var data = TextFileProvider.Instance.GetTextEditorData(type.CompilationUnit.FileName, out isOpen); var parsedDocument = ProjectDomService.GetParsedDocument(type.SourceProjectDom, type.CompilationUnit.FileName); var insertionPoints = GetInsertionPoints(data, parsedDocument, type); var suitableInsertionPoint = GetSuitableInsertionPoint(insertionPoints, type, newMember); var generator = CreateCodeGenerator(data); generator.IndentLevel = CalculateBodyIndentLevel(parsedDocument.CompilationUnit.GetTypeAt(type.Location)); var generatedCode = generator.CreateMemberImplementation(type, newMember, implementExplicit); suitableInsertionPoint.Insert(data, generatedCode.Code); if (!isOpen) { try { File.WriteAllText(type.CompilationUnit.FileName, data.Text); } catch (Exception e) { LoggingService.LogError(GettextCatalog.GetString("Failed to write file '{0}'.", type.CompilationUnit.FileName), e); MessageService.ShowError(GettextCatalog.GetString("Failed to write file '{0}'.", type.CompilationUnit.FileName)); } } }
void OnFileAdded(object sender, ProjectFileEventArgs args) { ParsedDocument doc = ProjectDomService.GetParsedDocument(ProjectDomService.GetProjectDom(args.Project), args.ProjectFile.Name); if (doc == null || doc.CompilationUnit == null) { return; } string dir = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "stetic"), "deleted-designs"); if (!Directory.Exists(dir) || Directory.GetFiles(dir).Length == 0) { return; } foreach (IType t in doc.CompilationUnit.Types) { string path = Path.Combine(dir, t.FullName + ".xml"); if (!System.IO.File.Exists(path)) { continue; } XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(path); AddNewComponent(xmldoc.DocumentElement); System.IO.File.Delete(path); } }
public static GtkComponentType GetComponentType(this ProjectFile pf) { GtkDesignInfo info = GtkDesignInfo.FromProject(pf.Project); ParsedDocument doc = ProjectDomService.GetParsedDocument(ProjectDomService.GetProjectDom(pf.Project), pf.Name); //ParsedDocument doc = ProjectDomService.ParseFile (ProjectDomService.GetProjectDom (pf.Project), pf.FilePath.ToString ()); if (doc != null && doc.CompilationUnit != null) { foreach (IType t in doc.CompilationUnit.Types) { string className = t.FullName; if (className != null) { GuiBuilderWindow win = info.GuiBuilderProject.GetWindowForClass(className); if (win != null) { return(win.RootWidget.IsWindow ? GtkComponentType.Dialog : GtkComponentType.Widget); } Stetic.ActionGroupInfo action = info.GuiBuilderProject.GetActionGroup(className); if (action != null) { return(GtkComponentType.ActionGroup); } } } } if (pf.Name.Contains("IconFactory.gtkx")) { return(GtkComponentType.IconFactory); } return(GtkComponentType.None); }
public static void AddNewMembers(IType type, IEnumerable <IMember> newMembers, string regionName = null, Func <IMember, bool> implementExplicit = null) { bool isOpen; var data = TextFileProvider.Instance.GetTextEditorData(type.CompilationUnit.FileName, out isOpen); var parsedDocument = ProjectDomService.GetParsedDocument(type.SourceProjectDom, type.CompilationUnit.FileName); var insertionPoints = GetInsertionPoints(data, parsedDocument, type); var suitableInsertionPoint = GetSuitableInsertionPoint(insertionPoints, type, newMembers.First()); var generator = CreateCodeGenerator(data); StringBuilder sb = new StringBuilder(); foreach (IMember newMember in newMembers) { if (sb.Length > 0) { sb.AppendLine(); sb.AppendLine(); } sb.Append(generator.CreateMemberImplementation(type, 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.CompilationUnit.FileName, data.Text); } catch (Exception e) { LoggingService.LogError(GettextCatalog.GetString("Failed to write file '{0}'.", type.CompilationUnit.FileName), e); MessageService.ShowError(GettextCatalog.GetString("Failed to write file '{0}'.", type.CompilationUnit.FileName)); } } }
public ConditinalExpressionEvaluator(Mono.TextEditor.Document doc) { var project = GetProject(doc); if (project == null) { var ideDocument = IdeApp.Workbench.GetDocument(doc.FileName); if (ideDocument != null) { project = ideDocument.Project; } } if (project == null) { project = IdeApp.Workspace.GetProjectContainingFile(doc.FileName); } if (project != null) { var configuration = project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration; if (configuration != null) { var cparams = configuration.CompilationParameters as CSharpCompilerParameters; if (cparams != null) { string[] syms = cparams.DefineSymbols.Split(';', ',', ' ', '\t'); foreach (string s in syms) { string ss = s.Trim(); if (ss.Length > 0 && !symbols.Contains(ss)) { symbols.Add(ss); } } } } else { Console.WriteLine("NO CONFIGURATION"); } } var dom = ProjectDomService.GetProjectDom(project); var parsedDocument = ProjectDomService.GetParsedDocument(dom, doc.FileName); /* if (parsedDocument == null) * parsedDocument = ProjectDomService.ParseFile (dom, doc.FileName ?? "a.cs", delegate { return doc.Text; });*/ if (parsedDocument != null) { foreach (PreProcessorDefine define in parsedDocument.Defines) { symbols.Add(define.Define); } } }
protected virtual void MasterChanged(object sender, EventArgs e) { if (IsPartialView || !HasMaster) { return; } if (masterEntry.Text == oldMaster) { return; } oldMaster = masterEntry.Text; primaryPlaceholderStore.Clear(); ContentPlaceHolders.Clear(); string realPath = project.VirtualToLocalPath(oldMaster, null); if (!File.Exists(realPath)) { return; } var pd = ProjectDomService.GetParsedDocument(ProjectDomService.GetProjectDom(project), realPath) as AspNetParsedDocument; if (pd != null) { try { var visitor = new ContentPlaceHolderVisitor(); pd.RootNode.AcceptVisit(visitor); ContentPlaceHolders.AddRange(visitor.PlaceHolders); for (int i = 0; i < ContentPlaceHolders.Count; i++) { string placeholder = ContentPlaceHolders[i]; primaryPlaceholderStore.AppendValues(placeholder); if (placeholder.Contains("main") || placeholder.Contains("Main") || placeholder.Contains("content") || placeholder.Contains("Main")) { primaryPlaceholderCombo.Active = i; } } } catch (Exception ex) { LoggingService.LogError("Unhandled exception getting master regions for '" + realPath + "'", ex); } } Validate(); }
bool AnalyzeTargetExpression(RefactoringOptions options, ICSharpCode.NRefactory.CSharp.CompilationUnit unit) { var data = options.GetTextEditorData(); var target = unit.GetNodeAt(data.Caret.Line, data.Caret.Column); if (target == null) { return(false); } if (target.Parent is MemberReferenceExpression && ((MemberReferenceExpression)target.Parent).GetChildByRole(MemberReferenceExpression.Roles.Identifier) == target) { var memberReference = (MemberReferenceExpression)target.Parent; target = memberReference.Target; var targetResult = options.GetResolver().Resolve(new ExpressionResult(data.GetTextBetween(target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column)), resolvePosition); if (targetResult.StaticResolve) { modifiers = MonoDevelop.Projects.Dom.Modifiers.Static; } declaringType = options.Dom.GetType(targetResult.ResolvedType); methodName = memberReference.MemberName; } else if (target is Identifier) { if (options.ResolveResult != null) { declaringType = options.ResolveResult.CallingType; } else { declaringType = options.Document.CompilationUnit.GetTypeAt(options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column); } methodName = data.GetTextBetween(target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column); } if (declaringType != null && !HasCompatibleMethod(declaringType, methodName, invocation)) { if (declaringType.HasParts) { declaringType = declaringType.Parts.FirstOrDefault(t => t.CompilationUnit.FileName == options.Document.FileName) ?? declaringType; } if (declaringType == null || declaringType.CompilationUnit == null) { return(false); } var doc = ProjectDomService.GetParsedDocument(declaringType.SourceProjectDom, declaringType.CompilationUnit.FileName); declaringType = doc.CompilationUnit.GetTypeAt(declaringType.Location) ?? declaringType; return(true); } return(false); }
internal static GuiBuilderWindow GetWindow(string file) { if (!IdeApp.Workspace.IsOpen) { return(null); } Project project = null; foreach (Project p in IdeApp.Workspace.GetAllProjects()) { if (p.IsFileInProject(file)) { project = p; break; } } if (!GtkDesignInfo.HasDesignedObjects(project)) { return(null); } GtkDesignInfo info = GtkDesignInfo.FromProject(project); if (file.StartsWith(info.GtkGuiFolder)) { return(null); } ParsedDocument doc = ProjectDomService.GetParsedDocument(null, file); if (doc == null || doc.CompilationUnit == null) { return(null); } foreach (IType t in doc.CompilationUnit.Types) { GuiBuilderWindow win = info.GuiBuilderProject.GetWindowForClass(t.FullName); if (win != null) { return(win); } } return(null); }
IEnumerable <MemberReference> FindReferences(ProjectDom dom, FilePath fileName, INode member) { var editor = TextFileProvider.Instance.GetTextEditorData(fileName); var doc = ProjectDomService.GetParsedDocument(dom, fileName); if (doc == null || doc.CompilationUnit == null) { return(null); } var resolver = new NRefactoryResolver(dom, doc.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, editor, fileName); FindMemberAstVisitor visitor = new FindMemberAstVisitor(editor.Document, resolver, member); visitor.IncludeXmlDocumentation = IncludeDocumentation; visitor.RunVisitor(); return(visitor.FoundReferences); }
public override IEnumerable <MemberReference> FindClassReferences(RefactorerContext ctx, string fileName, IType cls, bool includeXmlComment) { var editor = ((Mono.TextEditor.ITextEditorDataProvider)ctx.GetFile(fileName)).GetTextEditorData(); var doc = ProjectDomService.GetParsedDocument(ctx.ParserContext, fileName); if (doc == null || doc.CompilationUnit == null) { return(null); } NRefactoryResolver resolver = new NRefactoryResolver(ctx.ParserContext, doc.CompilationUnit, ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, editor, fileName); FindMemberAstVisitor visitor = new FindMemberAstVisitor(editor.Document, cls); visitor.IncludeXmlDocumentation = includeXmlComment; visitor.RunVisitor(resolver); SetContext(visitor.FoundReferences, ctx); return(visitor.FoundReferences); }
public static IMember AddCodeDomMember(IType type, CodeTypeMember newMember) { bool isOpen; var data = TextFileProvider.Instance.GetTextEditorData(type.CompilationUnit.FileName, out isOpen); var parsedDocument = ProjectDomService.GetParsedDocument(type.SourceProjectDom, type.CompilationUnit.FileName); var insertionPoints = GetInsertionPoints(data, parsedDocument, type); var suitableInsertionPoint = GetSuitableInsertionPoint(insertionPoints, type, newMember); var dotNetProject = type.SourceProject 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 = "\t"; if (newMember is CodeMemberMethod) { options.BracingStyle = "C"; } generator.GenerateCodeFromMember(newMember, sw, options); suitableInsertionPoint.Insert(data, sw.ToString()); if (!isOpen) { try { File.WriteAllText(type.CompilationUnit.FileName, data.Text); } catch (Exception e) { LoggingService.LogError(string.Format("Failed to write file '{0}'.", type.CompilationUnit.FileName), e); MessageService.ShowError(GettextCatalog.GetString("Failed to write file '{0}'.", type.CompilationUnit.FileName)); } } var newDocument = ProjectDomService.Parse(type.SourceProject as Project, type.CompilationUnit.FileName, data.Text); return(newDocument.CompilationUnit.GetMemberAt(suitableInsertionPoint.Location.Line, int.MaxValue)); }
public Gtk.Window CreateTooltipWindow(Mono.TextEditor.TextEditor editor, int offset, Gdk.ModifierType modifierState, TooltipItem item) { ExtensibleTextEditor ed = (ExtensibleTextEditor)editor; ParsedDocument doc = ProjectDomService.GetParsedDocument(null, ed.Document.FileName); ResolveResult resolveResult = (ResolveResult)item.Item; if (lastResult != null && lastResult.ResolvedExpression != null && lastWindow.IsRealized && resolveResult != null && resolveResult.ResolvedExpression != null && lastResult.ResolvedExpression.Expression == resolveResult.ResolvedExpression.Expression) { return(lastWindow); } LanguageItemWindow result = new LanguageItemWindow(ed, modifierState, resolveResult, null, doc != null ? doc.CompilationUnit : null); lastWindow = result; lastResult = resolveResult; if (result.IsEmpty) { return(null); } return(result); }
ITypeNameResolver GetTypeNameResolver(IType cls) { if (cls.CompilationUnit == null || cls.CompilationUnit.FileName == FilePath.Null) { return(null); } string file = cls.CompilationUnit.FileName; ParsedDocument pi = ProjectDomService.GetParsedDocument(cls.SourceProjectDom, file); if (pi == null) { return(null); } ICompilationUnit unit = pi.CompilationUnit; if (unit != null) { return(new TypeNameResolver(unit, cls)); } else { return(null); } }
// string expression; /* IMember GetLanguageItem (Mono.TextEditor.Document document, LineSegment line, int offset, string expression) * { * string txt = document.Text; * ExpressionResult expressionResult = new ExpressionResult (expression); * // ExpressionResult expressionResult = expressionFinder.FindFullExpression (txt, offset); * int lineNumber = document.OffsetToLineNumber (offset); * expressionResult.Region = new DomRegion (lineNumber, offset - line.Offset, lineNumber, offset + expression.Length - line.Offset); * expressionResult.ExpressionContext = ExpressionContext.IdentifierExpected; * * resolver = new NRefactoryResolver (ctx, doc.CompilationUnit, doc.TextEditor, document.FileName); * ResolveResult result = resolver.Resolve (expressionResult, expressionResult.Region.Start); * * if (result is MemberResolveResult) * return ((MemberResolveResult)result).ResolvedMember; * return null; * }*/ public override void Analyze(Mono.TextEditor.Document doc, LineSegment line, Chunk startChunk, int startOffset, int endOffset) { if (!MonoDevelop.Core.PropertyService.Get("EnableSemanticHighlighting", false) || doc == null || line == null || startChunk == null) { return; } ctx = GetParserContext(doc); int lineNumber = doc.OffsetToLineNumber(line.Offset); ParsedDocument parsedDocument = ProjectDomService.GetParsedDocument(ctx, doc.FileName); ICompilationUnit unit = parsedDocument != null ? parsedDocument.CompilationUnit : null; if (unit == null) { return; } for (Chunk chunk = startChunk; chunk != null; chunk = chunk.Next) { if (chunk.Style != "text") { continue; } for (int i = chunk.Offset; i < chunk.EndOffset; i++) { char charBefore = i > 0 ? doc.GetCharAt(i - 1) : '}'; if (Char.IsLetter(doc.GetCharAt(i)) && !Char.IsLetterOrDigit(charBefore)) { } else { continue; } int start = i; bool wasWhitespace = false; bool wasDot = false; int bracketCount = 0; while (start > 0) { char ch = doc.GetCharAt(start); if (ch == '\n' || ch == '\r') { break; } if (wasWhitespace && IsNamePart(ch)) { start++; if (start < chunk.Offset) { start = Int32.MaxValue; } break; } if (ch == '<') { bracketCount--; if (bracketCount < 0) { start++; break; } start--; wasWhitespace = false; continue; } if (ch == '>') { if (wasWhitespace && !wasDot) { break; } bracketCount++; start--; wasWhitespace = false; continue; } if (!IsNamePart(ch) && !Char.IsWhiteSpace(ch) && ch != '.') { start++; break; } wasWhitespace = Char.IsWhiteSpace(ch); wasDot = ch == '.' || wasDot && wasWhitespace; start--; } int end = i; int genericCount = 0; wasWhitespace = false; List <Segment> nameSegments = new List <Segment> (); while (end < chunk.EndOffset) { char ch = doc.GetCharAt(end); if (wasWhitespace && IsNamePart(ch)) { break; } if (ch == '<') { genericCount = 1; while (end < doc.Length) { ch = doc.GetCharAt(end); if (ch == ',') { genericCount++; } if (ch == '>') { nameSegments.Add(new Segment(end, 1)); break; } end++; } break; } if (!IsNamePart(ch) && !Char.IsWhiteSpace(ch)) { break; } wasWhitespace = Char.IsWhiteSpace(ch); end++; } if (start >= end) { continue; } string typeString = doc.GetTextBetween(start, end); IReturnType returnType = NRefactoryResolver.ParseReturnType(new ExpressionResult(typeString)); int nameEndOffset = start; for (; nameEndOffset < end; nameEndOffset++) { char ch = doc.GetCharAt(nameEndOffset); if (nameEndOffset >= i && ch == '<') { nameEndOffset++; break; } } nameSegments.Add(new Segment(i, nameEndOffset - i)); int column = i - line.Offset; IType callingType = unit.GetTypeAt(lineNumber, column); List <IReturnType> genericParams = null; if (genericCount > 0) { genericParams = new List <IReturnType> (); for (int n = 0; n < genericCount; n++) { genericParams.Add(new DomReturnType("A")); } } IType type = null; if (ctx != null) { type = ctx.SearchType((MonoDevelop.Projects.Dom.INode)callingType ?? unit, returnType); } if (type == null && unit != null && returnType != null) { type = unit.GetType(returnType.FullName, returnType.GenericArguments.Count); } if (ctx != null && type == null && returnType != null) { returnType.Name += "Attribute"; type = ctx.SearchType((MonoDevelop.Projects.Dom.INode)callingType ?? unit, returnType); } if (type != null) { nameSegments.ForEach(segment => HighlightSegment(startChunk, segment, "keyword.semantic.type")); } } } }
ResolveResult Resolve(CSharpCompletionEngineBase.ExpressionResult expressionResult, DomLocation resolvePosition) { var expr = expressionResult as PythonExpressionResult; if (expr == null) { return(null); } var doc = ProjectDomService.GetParsedDocument(m_dom, m_filename); if (doc == null) { return(null); } var unit = doc.CompilationUnit as PythonCompilationUnit; if (unit == null) { return(null); } if (expr.Type == "def") { var type = unit.GetTypeAt(resolvePosition); if (type != null) { // resolving a method foreach (var func in type.Methods) { if (func.Name == expr.Word) { var l = new List <IMember> (); l.Add(func); return(new MethodResolveResult(l)); } } } } else if (expr.Type == "class") { var type = unit.GetTypeAt(resolvePosition); if (type != null && type.Name == expr.Word) { return(new MemberResolveResult(type)); } } else if (expr.Word == "self") { var type = unit.GetTypeAt(resolvePosition); if (type != null) { return(new MemberResolveResult(type)); } } else if (expr.Type == "self") { // looking for a member of self var type = unit.GetTypeAt(resolvePosition); if (type != null) { foreach (var attr in type.Fields) { if (attr.Name == expr.Word) { return(new MemberResolveResult(attr)); } } foreach (var method in type.Methods) { if (method.Name == expr.Word) { return(CreateMethodResult(method)); } } } } return(null); }
public override void ModifyTags(MonoDevelop.Projects.SolutionItem policyParent, MonoDevelop.Projects.Project project, string language, string identifier, string fileName, ref Dictionary <string, string> tags) { base.ModifyTags(policyParent, project, language, identifier, fileName, ref tags); if (fileName == null) { return; } tags["AspNetMaster"] = ""; tags["AspNetMasterContent"] = ""; AspNetAppProject aspProj = project as AspNetAppProject; if (aspProj == null) { throw new InvalidOperationException("MasterContentFileDescriptionTemplate is only valid for ASP.NET projects"); } ProjectFile masterPage = null; string masterContent = ""; var dialog = new MonoDevelop.Ide.Projects.ProjectFileSelectorDialog(aspProj, null, "*.master"); try { dialog.Title = GettextCatalog.GetString("Select a Master Page..."); int response = MonoDevelop.Ide.MessageService.RunCustomDialog(dialog); if (response == (int)Gtk.ResponseType.Ok) { masterPage = dialog.SelectedFile; } } finally { dialog.Destroy(); } if (masterPage == null) { return; } tags["AspNetMaster"] = aspProj.LocalToVirtualPath(masterPage); try { AspNetParsedDocument pd = ProjectDomService.GetParsedDocument(ProjectDomService.GetProjectDom(project), masterPage.FilePath) as AspNetParsedDocument; if (pd == null) { return; } ContentPlaceHolderVisitor visitor = new ContentPlaceHolderVisitor(); pd.RootNode.AcceptVisit(visitor); System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (string id in visitor.PlaceHolders) { sb.Append("<asp:Content ContentPlaceHolderID=\""); sb.Append(id); sb.Append("\" ID=\""); sb.Append(id); sb.Append("Content\" runat=\"server\">\n</asp:Content>\n"); } tags["AspNetMasterContent"] = sb.ToString(); } catch (Exception ex) { //no big loss if we just insert blank space //it's just a template for the user to start editing } }