private PartialTypeCollection( CodeModelState state, FileCodeModel fileCodeModel, AbstractCodeType parent) : base(state, parent) { }
/// <summary> /// Walks the given FileCodeModel, turning CodeElements into code items within the specified /// code items set. /// </summary> /// <param name="codeItems">The code items set for accumulation.</param> /// <param name="fcm">The FileCodeModel to walk.</param> private static void RetrieveCodeItems(SetCodeItems codeItems, FileCodeModel fcm) { if (fcm != null && fcm.CodeElements != null) { RetrieveCodeItemsFromElements(codeItems, fcm.CodeElements); } }
private CodeVariable( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind, name) { }
internal AbstractCodeType( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind, name) { }
private CodeFunctionDeclareDecl( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind, name) { }
private CodeFunctionDeclareDecl( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int? nodeKind) : base(state, fileCodeModel, nodeKey, nodeKind) { }
private CodeNamespace( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int? nodeKind) : base(state, fileCodeModel, nodeKey, nodeKind) { }
private CodeNamespace( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind, name) { }
private CodeStruct( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind, name) { }
internal AbstractCodeType( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int? nodeKind) : base(state, fileCodeModel, nodeKey, nodeKind) { }
private PartialTypeCollection( CodeModelState state, FileCodeModel fileCodeModel, AbstractCodeType parent) : base(state, parent) { _fileCodeModelHandle = new ComHandle<EnvDTE.FileCodeModel, FileCodeModel>(fileCodeModel); }
internal static EnvDTE.CodeElements Create( CodeModelState state, FileCodeModel fileCodeModel, AbstractCodeType parent) { var collection = new PartialTypeCollection(state, fileCodeModel, parent); return (EnvDTE.CodeElements)ComAggregate.CreateAggregatedObject(collection); }
private CodeFunctionWithEventHandler( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int? nodeKind) : base(state, fileCodeModel, nodeKey, nodeKind) { }
private CodeFunctionWithEventHandler( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind, name) { }
private CodeStruct( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int? nodeKind) : base(state, fileCodeModel, nodeKey, nodeKind) { }
private CodeInheritsStatement( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind) { _namespaceName = name; }
internal static EnvDTE.CodeNamespace CreateUnknown( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) { var element = new CodeNamespace(state, fileCodeModel, nodeKind, name); return (EnvDTE.CodeNamespace)ComAggregate.CreateAggregatedObject(element); }
private CodeOptionsStatement( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) : base(state, fileCodeModel, nodeKind) { _name = name; }
internal static EnvDTE.CodeElements Create( CodeModelState state, object parent, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey) { var collection = new TypeCollection(state, parent, fileCodeModel, nodeKey); return (EnvDTE.CodeElements)ComAggregate.CreateAggregatedObject(collection); }
private CodeImport( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string dottedName) : base(state, fileCodeModel, nodeKind) { _dottedName = dottedName; }
internal static EnvDTE80.CodeElement2 CreateUnknown( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) { var element = new CodeOptionsStatement(state, fileCodeModel, nodeKind, name); return (EnvDTE80.CodeElement2)ComAggregate.CreateAggregatedObject(element); }
internal static EnvDTE80.CodeImport CreateUnknown( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string dottedName) { var element = new CodeImport(state, fileCodeModel, nodeKind, dottedName); return (EnvDTE80.CodeImport)ComAggregate.CreateAggregatedObject(element); }
internal static new EnvDTE.CodeFunction CreateUnknown( CodeModelState state, FileCodeModel fileCodeModel, int nodeKind, string name) { var element = new CodeFunctionWithEventHandler(state, fileCodeModel, nodeKind, name); return (EnvDTE.CodeFunction)ComAggregate.CreateAggregatedObject(element); }
private CodeImport( CodeModelState state, FileCodeModel fileCodeModel, AbstractCodeElement parent, string dottedName) : base(state, fileCodeModel) { _parentHandle = new ParentHandle<AbstractCodeElement>(parent); _dottedName = dottedName; }
private CodeOptionsStatement( CodeModelState state, FileCodeModel fileCodeModel, string name, int ordinal) : base(state, fileCodeModel) { _name = name; _ordinal = ordinal; }
internal static EnvDTE80.CodeImport Create( CodeModelState state, FileCodeModel fileCodeModel, AbstractCodeElement parent, string dottedName) { var element = new CodeImport(state, fileCodeModel, parent, dottedName); var result = (EnvDTE80.CodeImport)ComAggregate.CreateAggregatedObject(element); return result; }
internal static EnvDTE80.CodeElement2 Create( CodeModelState state, FileCodeModel fileCodeModel, string name, int ordinal) { var element = new CodeOptionsStatement(state, fileCodeModel, name, ordinal); var result = (EnvDTE80.CodeElement2)ComAggregate.CreateAggregatedObject(element); return result; }
private TypeCollection( CodeModelState state, object parent, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey) : base(state, parent) { Debug.Assert(fileCodeModel != null); _fileCodeModel = new ComHandle<EnvDTE.FileCodeModel, FileCodeModel>(fileCodeModel); _nodeKey = nodeKey; }
/// <summary> /// Returns the namespace element from file code. /// </summary> /// <param name="fileCodeModel"></param> /// <returns></returns> public static CodeNamespace GetNameSpaceFromFileCode(FileCodeModel fileCodeModel) { var codeElements = fileCodeModel.CodeElements; foreach (CodeElement codeElement in codeElements) { if (codeElement.Kind == vsCMElement.vsCMElementNamespace) { return (CodeNamespace)codeElement; } } return null; }
/// <summary> /// Returns the code class from the file code model. /// </summary> /// <param name="fileCodeModel"></param> public static CodeClass GetCodeClassFromFileCode(FileCodeModel fileCodeModel) { var codeNameSpace = GetNameSpaceFromFileCode(fileCodeModel); foreach (CodeElement namespaceChild in codeNameSpace.Children) { if (namespaceChild.Kind == vsCMElement.vsCMElementClass) { return (CodeClass)namespaceChild; } } return null; }
internal static new EnvDTE.CodeFunction Create( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int?nodeKind ) { var element = new CodeFunctionWithEventHandler(state, fileCodeModel, nodeKey, nodeKind); var result = (EnvDTE.CodeFunction)ComAggregate.CreateAggregatedObject(element); fileCodeModel.OnCodeElementCreated(nodeKey, (EnvDTE.CodeElement)result); return(result); }
internal static EnvDTE.CodeClass Create( CodeModelState state, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey, int?nodeKind ) { var element = new CodeClass(state, fileCodeModel, nodeKey, nodeKind); var result = (EnvDTE.CodeClass)ComAggregate.CreateAggregatedObject(element); fileCodeModel.OnCodeElementCreated(nodeKey, (EnvDTE.CodeElement)result); return(result); }
/// <summary> /// Returns the code class from the file code model. /// </summary> /// <param name="fileCodeModel"></param> public static CodeClass GetCodeClassFromFileCode(FileCodeModel fileCodeModel) { var codeNameSpace = GetNameSpaceFromFileCode(fileCodeModel); foreach (CodeElement namespaceChild in codeNameSpace.Children) { if (namespaceChild.Kind == vsCMElement.vsCMElementClass) { return((CodeClass)namespaceChild); } } return(null); }
private bool TryGetFunctionFromPoint(TextPoint point, out CodeFunction codeFunction) { try { FileCodeModel codeModel = _dte.ActiveDocument.ProjectItem.FileCodeModel; codeFunction = codeModel.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction) as CodeFunction; return(true); } catch { codeFunction = null; return(false); } }
protected override void SetName(string value) { FileCodeModel.EnsureEditor(() => { var nodeKeyValidation = new NodeKeyValidation(); nodeKeyValidation.AddFileCodeModel(this.FileCodeModel); var node = LookupNode(); FileCodeModel.UpdateName(node, value); nodeKeyValidation.RestoreKeys(); }); }
public EnvDTE.CodeEnum AddEnum( string name, object position, object bases, EnvDTE.vsCMAccess access ) { return(FileCodeModel.EnsureEditor( () => { return FileCodeModel.AddEnum(LookupNode(), name, position, bases, access); } )); }
public EnvDTE.CodeDelegate AddDelegate( string name, object type, object position, EnvDTE.vsCMAccess access ) { return(FileCodeModel.EnsureEditor( () => { return FileCodeModel.AddDelegate(LookupNode(), name, type, position, access); } )); }
/// <summary> /// Finds the or create namespace. /// </summary> /// <param name="fileCodeModel">The file code model.</param> /// <param name="namespace">The @namespace.</param> /// <returns></returns> internal static CodeNamespace FindOrCreateNamespace(FileCodeModel fileCodeModel, string @namespace) { // On considère qu'il n'y a qu'un namespace par fichier foreach (CodeElement ce in fileCodeModel.CodeElements) { if (ce is CodeNamespace) { ce.Name = @namespace; return((CodeNamespace)ce); } } return(fileCodeModel.AddNamespace(@namespace, 0)); }
protected void UpdateNodeAndReaquireNodeKey <T>(Action <SyntaxNode, T> updater, T value, bool trackKinds = true) { FileCodeModel.EnsureEditor(() => { // Sometimes, changing an element can result in needing to update its node key. var node = LookupNode(); var nodePath = new SyntaxPath(node, trackKinds); updater(node, value); ReaquireNodeKey(nodePath, CancellationToken.None); }); }
/// <summary> /// Returns the namespace element from file code. /// </summary> /// <param name="fileCodeModel"></param> /// <returns></returns> public static CodeNamespace GetNameSpaceFromFileCode(FileCodeModel fileCodeModel) { var codeElements = fileCodeModel.CodeElements; foreach (CodeElement codeElement in codeElements) { if (codeElement.Kind == vsCMElement.vsCMElementNamespace) { return((CodeNamespace)codeElement); } } return(null); }
/// <summary> /// Performs the style task. /// </summary> /// <param name="projectItem">The project Item</param> /// <param name="ideWindow">The IDE window.</param> protected override void DoWork(ProjectItem projectItem, EnvDTE.Window ideWindow) { Debug.WriteLine("Adding missing access modifiers: " + projectItem.Name); FileCodeModel fileCodeModel = projectItem.FileCodeModel; for (int i = 1; i <= fileCodeModel.CodeElements.Count; i++) { if (fileCodeModel.CodeElements.Item(i).Kind == vsCMElement.vsCMElementNamespace) { CodeElement element = fileCodeModel.CodeElements.Item(i); AddMissingAccessModifiers(element as CodeElement); } } }
/// <summary> /// This function re-acquires the key for this code element using the given syntax path. /// </summary> internal void ReacquireNodeKey(SyntaxPath syntaxPath, CancellationToken cancellationToken) { Debug.Assert(syntaxPath != null); SyntaxNode node; if (!syntaxPath.TryResolve(GetSyntaxTree(), cancellationToken, out node)) { throw Exceptions.ThrowEFail(); } var nodeKey = CodeModelService.GetNodeKey(node); FileCodeModel.ResetElementNodeKey(this, nodeKey); }
public CodeElement[] GetCodeElementsAtCursor(vsCMElement?kind = null) { TextSelection sel = (TextSelection)DTE.ActiveDocument.Selection; TextPoint pnt = (TextPoint)sel.ActivePoint; // Discover every code element containing the insertion point. FileCodeModel fcm = DTE.ActiveDocument.ProjectItem.FileCodeModel; var res = GetCodeElementsAtPoint(fcm, pnt); if (kind.HasValue) { res = res.Where((x) => x.Kind == vsCMElement.vsCMElementProperty).ToArray(); } return(res); }
public EnvDTE.CodeVariable AddVariable( string name, object type, object position, EnvDTE.vsCMAccess access, object location ) { return(FileCodeModel.EnsureEditor( () => { return FileCodeModel.AddVariable(LookupNode(), name, type, position, access); } )); }
protected virtual void GetImplementedInterfaces([NotNull] FileCodeModel fileCodeModel, [NotNull] CodeClass2 codeClass, [NotNull] ICollection <string> baseTemplates, [NotNull] ICollection <string> baseFields) { Debug.ArgumentNotNull(fileCodeModel, nameof(fileCodeModel)); Debug.ArgumentNotNull(codeClass, nameof(codeClass)); Debug.ArgumentNotNull(baseTemplates, nameof(baseTemplates)); Debug.ArgumentNotNull(baseFields, nameof(baseFields)); foreach (var implementedInterface in codeClass.ImplementedInterfaces.OfType <CodeInterface2>()) { var baseTemplateId = fileCodeModel.GetHash(implementedInterface.Attributes, implementedInterface.Name).Format(); baseTemplates.Add(baseTemplateId); GetImplementedInterface(implementedInterface, baseFields); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private async void Execute(object sender, EventArgs e) { var dte = await ServiceProvider.GetServiceAsync(typeof(DTE)).ConfigureAwait(false) as DTE2 ?? throw new NullReferenceException("DTE alınamadı"); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); FileCodeModel activeFileCodeModel = dte.ActiveDocument.ProjectItem.FileCodeModel; if (activeFileCodeModel == null) { MessageBox.Show("Aktif dosya içeriği desteklenmiyor"); return; } Utility.SortFunctionBodyIfExist(activeFileCodeModel, Utility.GeneratedFunctionName); }
private void ParseClassFile(string file) { var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE)); ProjectItem projectItem = dte.Solution.FindProjectItem(file); //if (!VsShellUtilities.IsDocumentOpen(ServiceProvider.GlobalProvider, filePath, //VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame)) //{ // VsShellUtilities.OpenDocument(ServiceProvider.GlobalProvider, filePath, // VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame); //} FileCodeModel codeModel = projectItem.FileCodeModel; DetectElementsInFile(codeModel.CodeElements); }
private CodeFunction FindMethod(FileCodeModel model, string className, string methodName) { foreach (CodeNamespace eNamespace in model.CodeElements.Cast <CodeElement>().OfType <CodeNamespace>()) { foreach (CodeClass eClass in eNamespace.Children.Cast <CodeElement>().OfType <CodeClass>().Where(p => p.Name == className)) { CodeFunction eFunction = eClass.Children.Cast <CodeElement>().OfType <CodeFunction>().FirstOrDefault(p => p.Name == methodName); if (eFunction != null) { return(eFunction); } } } return(null); }
internal static EnvDTE.CodeElements Create( CodeModelState state, object parent, FileCodeModel fileCodeModel, SyntaxNodeKey nodeKey ) { var collection = new InheritsImplementsCollection( state, parent, fileCodeModel, nodeKey ); return((EnvDTE.CodeElements)ComAggregate.CreateAggregatedObject(collection)); }
public EnvDTE.CodeParameter AddParameter(string name, object type, object position) { return(FileCodeModel.EnsureEditor(() => { // The parameters are part of the node key, so we need to update it // after adding a parameter. var node = LookupNode(); var nodePath = new SyntaxPath(node); var parameter = FileCodeModel.AddParameter(this, node, name, type, position); ReaquireNodeKey(nodePath, CancellationToken.None); return parameter; })); }
public B4SmartTagger(ITextBuffer buffer, ITextView view, B4SmartTaggerProvider provider, ITextSearchService textSearchService, ITextStructureNavigator textStructureNavigator, DTE dte) { _buffer = buffer; _view = view; //_provider = provider; _view.LayoutChanged += OnLayoutChanged; ITextDocument document; view.TextDataModel.DataBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document); _textSearchService = textSearchService; _textStructureNavigator = textStructureNavigator; _codeModel = GetDocumentCodeModel(document, dte.Windows); }
public B4ErrorTagger(ITextView view, ITextBuffer sourceBuffer, ITextSearchService textSearchService, ITextStructureNavigator textStructureNavigator, DTE dte) { this.View = view; this.SourceBuffer = sourceBuffer; this.TextSearchService = textSearchService; this.TextStructureNavigator = textStructureNavigator; this.WordSpans = new NormalizedSnapshotSpanCollection(); this.CurrentWord = null; this.View.LayoutChanged += ViewLayoutChanged; ITextDocument document; view.TextDataModel.DataBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document); FCM = GetDocumentCodeModel(document, dte.Windows); }
public EnvDTE.CodeInterface AddImplementedInterface(object @base, object position) { return(FileCodeModel.EnsureEditor(() => { var name = FileCodeModel.AddImplementedInterface(LookupNode(), @base, position); var codeElements = this.ImplementedInterfaces as ICodeElements; var hr = codeElements.Item(name, out var element); if (ErrorHandler.Succeeded(hr)) { return element as EnvDTE.CodeInterface; } return null; })); }
public EnvDTE.CodeElement AddBase(object @base, object position) { return(FileCodeModel.EnsureEditor(() => { FileCodeModel.AddBase(LookupNode(), @base, position); var codeElements = this.Bases as ICodeElements; var hr = codeElements.Item(1, out var element); if (ErrorHandler.Succeeded(hr)) { return element; } return null; })); }
protected virtual void GetBaseClasses([NotNull] FileCodeModel fileCodeModel, [NotNull] CodeClass2 codeClass, [NotNull] ICollection <string> baseTemplates) { Debug.ArgumentNotNull(fileCodeModel, nameof(fileCodeModel)); Debug.ArgumentNotNull(codeClass, nameof(codeClass)); Debug.ArgumentNotNull(baseTemplates, nameof(baseTemplates)); foreach (var baseClass in codeClass.Bases.OfType <CodeClass2>()) { if (baseClass.Name == "Object") { continue; } var baseTemplateId = fileCodeModel.GetHash(baseClass.Attributes, baseClass.Name).Format(); baseTemplates.Add(baseTemplateId); } }
public void TestProjectCreationWithDTE() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); // test nested project item EnvDTE.ProjectItem nestedProject = ((OAProject)project.GetAutomationObject()).ProjectItems.Item("ANestedProject"); Assert.IsNotNull(nestedProject, "Failed to retrieve nested projects"); Assert.IsNotNull(nestedProject.SubProject, "Failed to retrieve nested projects's subproject"); // Add a cs file to the nested project. string newFileName = Path.GetFullPath(TestUtils.GetNewFileName(project.ProjectFolder, "GetClassWithCodeModel", "cs")); EnvDTE.ProjectItem newFile = nestedProject.SubProject.ProjectItems.AddFromFile(newFileName); CodeModel codeModel = nestedProject.SubProject.CodeModel; Assert.IsNotNull(codeModel, "Failed to retrieve nested projects's subproject"); FileCodeModel fileCodeModel = newFile.FileCodeModel; CodeClass cc = fileCodeModel.AddClass("MyClass", 0, null, null, vsCMAccess.vsCMAccessPublic); IEnumerator enumerator = fileCodeModel.CodeElements.GetEnumerator(); bool found = false; while (enumerator.MoveNext()) { CodeElement element = enumerator.Current as CodeElement; if (element.Name == "MyClass") { found = true; break; } } Assert.IsTrue(found, "Could not find the class in the code model associated to the nested project"); }); }
private VCCodeFunction GetMethodFromFilePos(FileCodeModel fcm, int lineNum, int linePos) { if (fcm == null) { return(null); } foreach (CodeElement codeElem in fcm.CodeElements) { VCCodeFunction theMethod = GetMethodFromFilePos(codeElem, lineNum, linePos); if (theMethod != null) { return(theMethod); } } return(null); }
public FileCodeModel GetFileCodeModel(string documentName) { FileCodeModel fcm = null; var projectItem = FindProjectItemInProject(_dte.ActiveDocument.ProjectItem.ContainingProject, documentName, true); if (projectItem == null) { _log.ErrorFormat("ERROR projectItem is null for Active Document:{0}", _dte.ActiveDocument.FullName); } else { fcm = projectItem.FileCodeModel; } return(fcm); }
public static List <CodeClass> GetCodeClasses(FileCodeModel fileCodeModel) { List <CodeClass> lstCodeClasses = new List <CodeClass>(); if (fileCodeModel == null || fileCodeModel.CodeElements == null || fileCodeModel.CodeElements.Count == 0) { return(lstCodeClasses); } try { foreach (CodeElement tvCodeElementOutter in fileCodeModel.CodeElements) { if (tvCodeElementOutter is CodeNamespace) { try { foreach (CodeElement tvCodeElement in ((CodeNamespace)tvCodeElementOutter).Members) { if (tvCodeElement != null && tvCodeElement is CodeClass) { lstCodeClasses.Add((CodeClass)tvCodeElement); } } } catch (Exception ex) { //ignore Logger.LogException(ex); } } else if (tvCodeElementOutter is CodeClass) { lstCodeClasses.Add((CodeClass)tvCodeElementOutter); } } } catch (Exception ex) { //ignore Logger.LogException(ex); } return(lstCodeClasses); }
protected virtual void ProcessTemplate([NotNull] FileCodeModel fileCodeModel, [NotNull] Template template, [NotNull] CodeInterface2 codeInterface) { Debug.ArgumentNotNull(fileCodeModel, nameof(fileCodeModel)); Debug.ArgumentNotNull(template, nameof(template)); Debug.ArgumentNotNull(codeInterface, nameof(codeInterface)); template.Name = codeInterface.Name; template.TemplateItemId = new ItemId(fileCodeModel.GetHash(codeInterface.Attributes, codeInterface.Name)); var baseTemplates = new List <string>(); GetImplementedInterfaces(fileCodeModel, codeInterface, baseTemplates); ProcessClassAttributes(codeInterface, template); template.BaseTemplates = string.Join("|", baseTemplates); ProcessTemplateSections(fileCodeModel, template, codeInterface); }