diff --git a/.gitignore b/.gitignore index d8e1a848b8..defcc3fe2f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ bin/ /src/Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config /src/Main/SharpDevelop/app.config /src/Main/GlobalAssemblyInfo.cs +/src/Main/GlobalAssemblyInfo.vb /src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.cs /src/AddIns/Misc/PackageManagement/Packages/AvalonEdit/lib \ No newline at end of file diff --git a/SharpDevelop.sln b/SharpDevelop.sln index ed3347e366..9eb0534988 100644 --- a/SharpDevelop.sln +++ b/SharpDevelop.sln @@ -69,6 +69,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixBinding", "src\AddIns\Ba EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Scripting", "src\AddIns\BackendBindings\Scripting\Project\ICSharpCode.Scripting.csproj", "{7048AE18-EB93-4A84-82D0-DD60EB58ADBD}" EndProject +Project("{00000000-0000-0000-0000-000000000000}") = "VBNetBinding", "src\AddIns\BackendBindings\VBNetBinding\Project\VBNetBinding.vbproj", "{EB9FBA17-88C7-4BA6-8471-1088F8C494F5}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{F3662720-9EA2-4591-BBC6-97361DCE50A9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SearchAndReplace", "src\AddIns\Misc\SearchAndReplace\Project\SearchAndReplace.csproj", "{9196DD8A-B4D4-4780-8742-C5762E547FC2}" @@ -441,6 +443,10 @@ Global {3DF4060F-5EE0-41CF-8096-F27355FD5511}.Debug|Any CPU.Build.0 = Debug|Any CPU {3DF4060F-5EE0-41CF-8096-F27355FD5511}.Release|Any CPU.ActiveCfg = Release|Any CPU {3DF4060F-5EE0-41CF-8096-F27355FD5511}.Release|Any CPU.Build.0 = Release|Any CPU + {EB9FBA17-88C7-4BA6-8471-1088F8C494F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB9FBA17-88C7-4BA6-8471-1088F8C494F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB9FBA17-88C7-4BA6-8471-1088F8C494F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB9FBA17-88C7-4BA6-8471-1088F8C494F5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -475,6 +481,7 @@ Global {D781721F-C2A7-4E95-B76F-247170AC3B13} = {E0646C25-36F2-4524-969F-FA621353AB94} {E1B288A2-08EE-4318-8BBB-8AB72C69E33E} = {E0646C25-36F2-4524-969F-FA621353AB94} {7048AE18-EB93-4A84-82D0-DD60EB58ADBD} = {E0646C25-36F2-4524-969F-FA621353AB94} + {EB9FBA17-88C7-4BA6-8471-1088F8C494F5} = {E0646C25-36F2-4524-969F-FA621353AB94} {F3662720-9EA2-4591-BBC6-97361DCE50A9} = {39327899-ED91-4F7F-988C-4FE4E17C014D} {9196DD8A-B4D4-4780-8742-C5762E547FC2} = {F3662720-9EA2-4591-BBC6-97361DCE50A9} {7D5C266F-D6FF-4D14-B315-0C0FC6C4EF51} = {F3662720-9EA2-4591-BBC6-97361DCE50A9} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/CompareKind.vb b/src/AddIns/BackendBindings/VBNetBinding/Project/CompareKind.vb new file mode 100644 index 0000000000..be40c4e555 --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/CompareKind.vb @@ -0,0 +1,7 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +Public Enum CompareKind + Binary + Text +End Enum diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Configuration/AssemblyInfo.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Configuration/AssemblyInfo.cs deleted file mode 100644 index 95b129496e..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Configuration/AssemblyInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following -// attributes. -// -// change them to the information which is associated with the assembly -// you compile. - -[assembly: AssemblyTitle("VB.NET Binding")] -[assembly: AssemblyDescription("VB.NET language binding for #develop")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: InternalsVisibleTo("ICSharpCode.VBNetBinding.Tests")] diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Configuration/AssemblyInfo.vb b/src/AddIns/BackendBindings/VBNetBinding/Project/Configuration/AssemblyInfo.vb new file mode 100644 index 0000000000..ca2134b60a --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Configuration/AssemblyInfo.vb @@ -0,0 +1,18 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +Imports System.Reflection +Imports System.Runtime.CompilerServices + +' Information about this assembly is defined by the following +' attributes. +' +' change them to the information which is associated with the assembly +' you compile. + + + + + + + diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.xaml b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/BuildOptions.xaml similarity index 97% rename from src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.xaml rename to src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/BuildOptions.xaml index ed0d8e7207..c38f883f73 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.xaml +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/BuildOptions.xaml @@ -1,5 +1,5 @@  - + diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/BuildOptions.xaml.vb b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/BuildOptions.xaml.vb new file mode 100644 index 0000000000..db5da9afc4 --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/BuildOptions.xaml.vb @@ -0,0 +1,153 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +Imports System.Collections.Generic +Imports ICSharpCode.SharpDevelop.Gui.OptionPanels +Imports ICSharpCode.SharpDevelop.Project + +Namespace OptionPanels + ''' + ''' Interaction logic for BuildOptionsXaml.xaml + ''' + Public Partial Class BuildOptions + Inherits ProjectOptionPanel + Public Sub New() + InitializeComponent() + DataContext = Me + + + m_optionExplicitItems = New List(Of KeyItemPair)() + m_optionExplicitItems.Add(New KeyItemPair("Off", "Explicit Off")) + m_optionExplicitItems.Add(New KeyItemPair("On", "Explicit On")) + OptionExplicitItems = m_optionExplicitItems + + m_optionStrictItems = New List(Of KeyItemPair)() + m_optionStrictItems.Add(New KeyItemPair("Off", "Strict Off")) + m_optionStrictItems.Add(New KeyItemPair("On", "Strict On")) + OptionStrictItems = m_optionStrictItems + + + m_optionCompareItems = New List(Of KeyItemPair)() + m_optionCompareItems.Add(New KeyItemPair("Binary", "Compare Binary")) + m_optionCompareItems.Add(New KeyItemPair("Text", "Compare Text")) + OptionCompareItems = m_optionCompareItems + + m_optionInferItems = New List(Of KeyItemPair)() + m_optionInferItems.Add(New KeyItemPair("Off", "Infer Off")) + m_optionInferItems.Add(New KeyItemPair("On", "Infer On")) + OptionInferItems = m_optionInferItems + End Sub + + + Public ReadOnly Property DefineConstants() As ProjectProperty(Of String) + Get + Return GetProperty("DefineConstants", "", TextBoxEditMode.EditRawProperty) + End Get + End Property + + Public ReadOnly Property Optimize() As ProjectProperty(Of Boolean) + Get + Return GetProperty("Optimize", False, PropertyStorageLocations.ConfigurationSpecific) + End Get + End Property + + Public ReadOnly Property RemoveIntegerChecks() As ProjectProperty(Of String) + Get + Return GetProperty("RemoveIntegerChecks", "", TextBoxEditMode.EditRawProperty) + End Get + End Property + + Public ReadOnly Property OptionExplicit() As ProjectProperty(Of String) + Get + Return GetProperty("OptionExplicit", "", TextBoxEditMode.EditRawProperty) + End Get + End Property + + Public ReadOnly Property OptionStrict() As ProjectProperty(Of String) + Get + Return GetProperty("OptionStrict", "Off", TextBoxEditMode.EditRawProperty) + End Get + End Property + + Public ReadOnly Property OptionCompare() As ProjectProperty(Of String) + Get + Return GetProperty("OptionCompare", "Binary", TextBoxEditMode.EditRawProperty) + End Get + End Property + + Public ReadOnly Property OptionInfer() As ProjectProperty(Of String) + Get + Return GetProperty("OptionInfer", "Off", TextBoxEditMode.EditRawProperty) + End Get + End Property + + + #Region "OptionItems" + + Private m_optionExplicitItems As List(Of KeyItemPair) + + Public Property OptionExplicitItems() As List(Of KeyItemPair) + Get + Return m_optionExplicitItems + End Get + Set + m_optionExplicitItems = value + MyBase.RaisePropertyChanged(Function() OptionExplicitItems) + End Set + End Property + + + Private m_optionStrictItems As List(Of KeyItemPair) + + Public Property OptionStrictItems() As List(Of KeyItemPair) + Get + Return m_optionStrictItems + End Get + Set + m_optionStrictItems = value + MyBase.RaisePropertyChanged(Function() OptionStrictItems) + End Set + End Property + + + Private m_optionCompareItems As List(Of KeyItemPair) + + Public Property OptionCompareItems() As List(Of KeyItemPair) + Get + Return m_optionCompareItems + End Get + Set + m_optionCompareItems = value + MyBase.RaisePropertyChanged(Function() OptionCompareItems) + End Set + End Property + + + Private m_optionInferItems As List(Of KeyItemPair) + + Public Property OptionInferItems() As List(Of KeyItemPair) + Get + Return m_optionInferItems + End Get + Set + m_optionInferItems = value + MyBase.RaisePropertyChanged(Function() OptionInferItems) + End Set + End Property + + + #End Region + + #Region "overrides" + + + Protected Overrides Sub Initialize() + MyBase.Initialize() + buildOutput.Initialize(Me) + Me.buildAdvanced.Initialize(Me) + Me.errorsAndWarnings.Initialize(Me) + Me.treatErrorsAndWarnings.Initialize(Me) + End Sub + #End Region + End Class +End Namespace diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/ProjectImports.xaml b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/ProjectImports.xaml similarity index 96% rename from src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/ProjectImports.xaml rename to src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/ProjectImports.xaml index 79dda5dd20..b5bdfc9cfc 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/ProjectImports.xaml +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/ProjectImports.xaml @@ -1,6 +1,6 @@  + ''' Interaction logic for ProjectImportsOptions.xaml + ''' + Public Partial Class ProjectImports + Inherits ProjectOptionPanel + + Public Sub New() + InitializeComponent() + End Sub + + #Region "override" + + Protected Overrides Sub Initialize() + ProjectItems = New ObservableCollection(Of String)() + NameSpaceItems = New ObservableCollection(Of String)() + + For Each item As ProjectItem In MyBase.Project.Items + If item.ItemType = ItemType.Import Then + ProjectItems.Add(item.Include) + End If + Next + + + Dim projectContent As IProjectContent = ParserService.GetProjectContent(MyBase.Project) + For Each refProjectContent As IProjectContent In projectContent.ThreadSafeGetReferencedContents() + AddNamespaces(refProjectContent) + Next + AddNamespaces(projectContent) + End Sub + + + Protected Overrides Function Save(project As MSBuildBasedProject, configuration As String, platform As String) As Boolean + Dim [imports] As New List(Of ProjectItem)() + For Each item As ProjectItem In project.Items + If item.ItemType = ItemType.Import Then + [imports].Add(item) + End If + Next + + For Each item As ImportProjectItem In [imports] + ProjectService.RemoveProjectItem(project, item) + Next + + For Each importedNamespace As String In ProjectItems + ProjectService.AddProjectItem(project, New ImportProjectItem(project, importedNamespace)) + Next + + Return MyBase.Save(project, configuration, platform) + End Function + + #End Region + + + Private m_projectItems As ObservableCollection(Of String) + + Public Property ProjectItems() As ObservableCollection(Of String) + Get + Return m_projectItems + End Get + Set + m_projectItems = value + MyBase.RaisePropertyChanged(Function() ProjectItems) + End Set + End Property + + Private m_selectedProjectItem As String + + Public Property SelectedProjectItem() As String + Get + Return m_selectedProjectItem + End Get + Set + m_selectedProjectItem = value + MyBase.RaisePropertyChanged(Function() SelectedProjectItem) + RemoveButtonEnable = True + AddButtonEnable = False + End Set + End Property + + Private m_nameSpaceItems As ObservableCollection(Of String) + + Public Property NameSpaceItems() As ObservableCollection(Of String) + Get + Return m_nameSpaceItems + End Get + Set + m_nameSpaceItems = value + MyBase.RaisePropertyChanged(Function() NameSpaceItems) + End Set + End Property + + + Private m_selectedNameSpace As String + + Public Property SelectedNameSpace() As String + Get + Return m_selectedNameSpace + End Get + Set + m_selectedNameSpace = value + MyBase.RaisePropertyChanged(Function() SelectedNameSpace) + AddButtonEnable = True + End Set + End Property + + + Private m_addButtonEnable As Boolean + + Public Property AddButtonEnable() As Boolean + Get + Return m_addButtonEnable + End Get + Set + m_addButtonEnable = value + MyBase.RaisePropertyChanged(Function() AddButtonEnable) + End Set + End Property + + Private m_removeButtonEnable As Boolean + + Public Property RemoveButtonEnable() As Boolean + Get + Return m_removeButtonEnable + End Get + Set + m_removeButtonEnable = value + MyBase.RaisePropertyChanged(Function() RemoveButtonEnable) + End Set + End Property + + + + Private Sub AddNamespaces(projectContent As IProjectContent) + For Each projectNamespace As String In projectContent.NamespaceNames + If Not String.IsNullOrEmpty(projectNamespace) Then + + If Not NameSpaceItems.Contains(projectNamespace) Then + NameSpaceItems.Add(projectNamespace) + End If + End If + Next + End Sub + + Private Sub AddButton_Click(sender As Object, e As RoutedEventArgs) + ProjectItems.Add(SelectedNameSpace) + IsDirty = True + End Sub + + Private Sub RemoveButton_Click(sender As Object, e As RoutedEventArgs) + ProjectItems.Remove(SelectedProjectItem) + SelectedProjectItem = Nothing + RemoveButtonEnable = False + AddButtonEnable = False + IsDirty = True + End Sub + End Class +End Namespace diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/TextEditorOptions.xaml b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/TextEditorOptions.xaml similarity index 91% rename from src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/TextEditorOptions.xaml rename to src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/TextEditorOptions.xaml index a4e9f39616..524cc80fcc 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/TextEditorOptions.xaml +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/OptionPanels/TextEditorOptions.xaml @@ -1,4 +1,4 @@ - + ''' Interaction logic for TextEditorOptions.xaml + ''' + Public Partial Class TextEditorOptions + Public Sub New() + InitializeComponent() + End Sub + + Public Shared Property EnableEndConstructs() As Boolean + Get + Return PropertyService.[Get]("VBBinding.TextEditor.EnableEndConstructs", True) + End Get + Set + PropertyService.[Set]("VBBinding.TextEditor.EnableEndConstructs", value) + End Set + End Property + + Public Shared Property EnableCasing() As Boolean + Get + Return PropertyService.[Get]("VBBinding.TextEditor.EnableCasing", True) + End Get + Set + PropertyService.[Set]("VBBinding.TextEditor.EnableCasing", value) + End Set + End Property + End Class +End Namespace diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Readme.txt b/src/AddIns/BackendBindings/VBNetBinding/Project/Readme.txt new file mode 100644 index 0000000000..8726ed16e6 --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Readme.txt @@ -0,0 +1,11 @@ +This version of the VB binding contains following features: + +- Basic support for compilation and the project format + +If you want to help us with VB support, please contact us in our community +forums on http://community.sharpdevelop.net/ or submit pull requests to our +github repository on https://github.com/icsharpcode/SharpDevelop/. + +Skills required for future development: +- Knowledge of VB +- Knowledge of parsers, internals of IDEs and debuggers \ No newline at end of file diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs deleted file mode 100644 index 09a285906f..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -using ICSharpCode.Core; -using ICSharpCode.NRefactory.Parser.VB; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; -using ICSharpCode.SharpDevelop.Editor; -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; - -namespace ICSharpCode.VBNetBinding -{ - public static class CompletionDataHelper - { - public static VBNetCompletionItemList GenerateCompletionData(this ExpressionResult expressionResult, ITextEditor editor, char pressedKey) - { - VBNetCompletionItemList result = new VBNetCompletionItemList(); - - IResolver resolver = ParserService.CreateResolver(editor.FileName); - ParseInformation info = ParserService.GetParseInformation(editor.FileName); - - if (info == null) - return result; - - List data = new List(); - - bool completingDotExpression = false; - IReturnType resolvedType = null; - - if (expressionResult.Context != ExpressionContext.Global && expressionResult.Context != ExpressionContext.TypeDeclaration) { - if (expressionResult.Context == ExpressionContext.Importable - && string.IsNullOrWhiteSpace(expressionResult.Expression)) { - expressionResult.Expression = "Global"; - } else if (pressedKey == '\0') { - int idx = string.IsNullOrWhiteSpace(expressionResult.Expression) - ? -1 - : expressionResult.Expression.LastIndexOf('.'); - - if (idx > -1) { - expressionResult.Expression = expressionResult.Expression.Substring(0, idx); - // its the same as if . was pressed - completingDotExpression = true; - } else { - expressionResult.Expression = ""; - } - } - - var rr = resolver.Resolve(expressionResult, info, editor.Document.Text); - - if (rr == null || !rr.IsValid || (pressedKey != '.' && !completingDotExpression)) { - if (((BitArray)expressionResult.Tag)[Tokens.Identifier]) - data = new NRefactoryResolver(LanguageProperties.VBNet) - .CtrlSpace(editor.Caret.Line, editor.Caret.Column, info, editor.Document.Text, expressionResult.Context, - ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces); - } else { - if (rr is MethodGroupResolveResult) { - IMethod singleMethod = ((MethodGroupResolveResult)rr).GetMethodWithEmptyParameterList(); - if (singleMethod != null) - rr = new MemberResolveResult(rr.CallingClass, rr.CallingMember, singleMethod); - } - - if (rr is IntegerLiteralResolveResult && pressedKey == '.') - return result; - - data = rr.GetCompletionData(info.CompilationUnit.ProjectContent, ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces) ?? new List(); - - resolvedType = rr.ResolvedType; - } - } - - bool addedKeywords = false; - - if (expressionResult.Tag != null && (expressionResult.Context != ExpressionContext.Importable) && pressedKey != '.' && !completingDotExpression) { - AddVBNetKeywords(data, (BitArray)expressionResult.Tag); - addedKeywords = true; - } - - CodeCompletionItemProvider.ConvertCompletionData(result, data, expressionResult.Context); - - if (addedKeywords && result.Items.Any()) - AddTemplates(editor, result); - - string word = editor.GetWordBeforeCaret().Trim(); - - IClass c = GetCurrentClass(editor); - IMember m = GetCurrentMember(editor); - - HandleKeyword(ref result, resolvedType, word, c, m, editor, pressedKey); - - AddSpecialItems(ref result, info, resolvedType, m, expressionResult, editor); - - char prevChar; - - if (pressedKey == '\0') { // ctrl+space - prevChar = editor.Caret.Offset > 0 ? editor.Document.GetCharAt(editor.Caret.Offset - 1) : '\0'; - word = char.IsLetterOrDigit(prevChar) || prevChar == '_' ? editor.GetWordBeforeCaret() : ""; - - if (!string.IsNullOrWhiteSpace(word)) - result.PreselectionLength = word.Length; - } - - prevChar = editor.Caret.Offset > 0 ? editor.Document.GetCharAt(editor.Caret.Offset - 1) : '\0'; - - if (prevChar == '_') - result.PreselectionLength++; - - result.SortItems(); - - return result; - } - - static void HandleKeyword(ref VBNetCompletionItemList result, IReturnType resolvedType, string word, IClass c, IMember m, ITextEditor editor, char pressedKey) - { - if (pressedKey == ' ') { - if (word.Equals("return", StringComparison.OrdinalIgnoreCase) && m != null) { - c = m.ReturnType != null ? m.ReturnType.GetUnderlyingClass() : null; - if (c != null) { - foreach (CodeCompletionItem item in result.Items.OfType()) { - IClass itemClass = item.Entity as IClass; - if (itemClass != null && c.FullyQualifiedName == itemClass.FullyQualifiedName && c.TypeParameters.Count == itemClass.TypeParameters.Count) { - result.SuggestedItem = item; - break; - } - } - } - } - - if (word.Equals("overrides", StringComparison.OrdinalIgnoreCase) && c != null) { - result = new OverrideCompletionItemProvider().GenerateCompletionList(editor).ToVBCCList(); - } - } - } - - static void AddSpecialItems(ref VBNetCompletionItemList result, ParseInformation info, IReturnType resolvedType, IMember m, ExpressionResult expressionResult, ITextEditor editor) - { - if (expressionResult.Context == ExpressionContext.Type && m != null && m.BodyRegion.IsInside(editor.Caret.Line, editor.Caret.Column)) { - result.Items.Add(new DefaultCompletionItem("? =") { - Image = ClassBrowserIconService.GotoArrow, - Description = StringParser.Parse("${res:AddIns.VBNetBinding.CodeCompletion.QuestionmarkEqualsItem.Description}") - }); - } - if (resolvedType != null && AllowsDescendentAccess(resolvedType, info.CompilationUnit.ProjectContent)) - result.Items.Add(new DefaultCompletionItem("..") { Image = ClassBrowserIconService.GotoArrow }); - if (resolvedType != null && AllowsAttributeValueAccess(resolvedType, info.CompilationUnit.ProjectContent)) - result.Items.Add(new DefaultCompletionItem("@") { Image = ClassBrowserIconService.GotoArrow }); - } - - static bool AllowsAttributeValueAccess(IReturnType resolvedType, IProjectContent content) - { - /* See VB 10 Spec, pg. 282: - * If an attribute access, System.Xml.Linq.XElement or a derived type, or - * System.Collections.Generic.IEnumerable(Of T) or a derived type, where T is - * System.Xml.Linq.XElement or a derived type. - **/ - - string baseClass = "System.Xml.Linq.XElement"; - string methodName = "Attributes"; - - return AllowsHelper(baseClass, methodName, resolvedType, content); - } - - static bool AllowsDescendentAccess(IReturnType resolvedType, IProjectContent content) - { - /* See VB 10 Spec, pg. 282: - * If an element or descendents access, System.Xml.Linq.XContainer or a - * derived type, or System.Collections.Generic.IEnumerable(Of T) or a derived - * type, where T is System.Xml.Linq.XContainer or a derived type. - **/ - - string baseClass = "System.Xml.Linq.XContainer"; - string methodName = "Descendants"; - - return AllowsHelper(baseClass, methodName, resolvedType, content); - } - - static bool AllowsHelper(string baseClass, string methodName, IReturnType resolvedType, IProjectContent content) - { - IClass extensions = content.GetClass("System.Xml.Linq.Extensions", 0); - if (extensions == null) - return false; - IMethod descendents = extensions.Methods.FirstOrDefault(m => m.Name == methodName); - if (descendents == null) - return false; - IParameter param = descendents.Parameters.FirstOrDefault(); - if (param == null) - return false; - IClass resolvedTypeClass = resolvedType.GetUnderlyingClass(); - if (resolvedTypeClass == null) - return false; - return MemberLookupHelper.IsApplicable(resolvedType, param, descendents) - || resolvedTypeClass.IsTypeInInheritanceTree(content.GetClass(baseClass, 0)); - } - - static void AddVBNetKeywords(List ar, BitArray keywords) - { - for (int i = 0; i < keywords.Length; i++) { - if (keywords[i] && i >= Tokens.AddHandler && i < Tokens.MaxToken) { - ar.Add(new KeywordEntry(Tokens.GetTokenString(i))); - } - } - } - - static void AddTemplates(ITextEditor editor, DefaultCompletionItemList list) - { - if (list == null) - return; - List snippets = editor.GetSnippets().ToList(); - snippets.RemoveAll(item => !FitsToContext(item, list.Items)); - list.Items.RemoveAll(item => item.Image == ClassBrowserIconService.Keyword && snippets.Exists(i => i.Text == item.Text)); - list.Items.AddRange(snippets); - list.SortItems(); - } - - static bool FitsToContext(ICompletionItem item, List list) - { - var snippetItem = item as ISnippetCompletionItem; - - if (snippetItem == null) - return false; - - if (string.IsNullOrEmpty(snippetItem.Keyword)) - return true; - - return list.Any(x => x.Image == ClassBrowserIconService.Keyword - && x.Text == snippetItem.Keyword); - } - - static IMember GetCurrentMember(ITextEditor editor) - { - var caret = editor.Caret; - NRefactoryResolver r = new NRefactoryResolver(LanguageProperties.VBNet); - if (r.Initialize(ParserService.GetParseInformation(editor.FileName), caret.Line, caret.Column)) { - return r.CallingMember; - } else { - return null; - } - } - - static IClass GetCurrentClass(ITextEditor editor) - { - var caret = editor.Caret; - NRefactoryResolver r = new NRefactoryResolver(LanguageProperties.VBNet); - if (r.Initialize(ParserService.GetParseInformation(editor.FileName), caret.Line, caret.Column)) { - return r.CallingClass; - } else { - return null; - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Extensions.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Extensions.cs deleted file mode 100644 index 96fea507aa..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Extensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; - -namespace ICSharpCode.VBNetBinding -{ - public static class Extensions - { - public static T PeekOrDefault(this Stack stack) - { - if (stack.Count > 0) - return stack.Peek(); - - return default(T); - } - - public static T PopOrDefault(this Stack stack) - { - if (stack.Count > 0) - return stack.Pop(); - - return default(T); - } - - internal static VBNetCompletionItemList ToVBCCList(this ICompletionItemList list) - { - var result = new VBNetCompletionItemList() { - SuggestedItem = list.SuggestedItem, - PreselectionLength = list.PreselectionLength - }; - - result.Items.AddRange(list.Items); - - return result; - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs deleted file mode 100644 index 621a18f8f4..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs +++ /dev/null @@ -1,918 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Text.RegularExpressions; - -using ICSharpCode.Core; -using ICSharpCode.NRefactory; -using ICSharpCode.NRefactory.Parser; -using ICSharpCode.NRefactory.Parser.VB; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Editor; - -namespace ICSharpCode.VBNetBinding -{ - /// - /// This class handles the auto and smart indenting in the textbuffer while - /// you type. - /// - public class VBNetFormattingStrategy : DefaultFormattingStrategy - { - #region VB Statements - static readonly List statements; - - internal static List Statements { - get { return statements; } - } - - static readonly string[] keywords = new string[] { - "AddHandler", "AddressOf", "Alias", "And", - "AndAlso", "As", "Boolean", "ByRef", - "Byte", "ByVal", "Call", "Case", - "Catch", "CBool", "CByte", "CChar", - "CDate", "CDbl", "CDec", "Char", - "CInt", "Class", "CLng", "CObj", - "Const", "Continue", "CSByte", "CShort", - "CSng", "CStr", "CType", "CUInt", - "CULng", "CUShort", "Date", "Decimal", - "Declare", "Default", "Delegate", "Dim", - "DirectCast", "Do", "Double", "Each", - "Else", "ElseIf", "End", "EndIf", // EndIf special case: converted to "End If" - "Enum", "Erase", "Error", "Event", - "Exit", "False", "Finally", "For", - "Friend", "Function", "Get", "GetType", - "Global", "GoSub", "GoTo", "Handles", - "If", "Implements", "Imports", "In", - "Inherits", "Integer", "Interface", "Is", - "IsNot", "Let", "Lib", "Like", - "Long", "Loop", "Me", "Mod", - "Module", "MustInherit", "MustOverride", "MyBase", - "MyClass", "Namespace", "Narrowing", "New", - "Next", "Not", "Nothing", "NotInheritable", - "NotOverridable", "Object", "Of", "On", - "Operator", "Option", "Optional", "Or", - "OrElse", "Overloads", "Overridable", "Overrides", - "ParamArray", "Partial", "Private", "Property", - "Protected", "Public", "RaiseEvent", "ReadOnly", - "ReDim", "REM", "RemoveHandler", "Resume", - "Return", "SByte", "Select", "Set", - "Shadows", "Shared", "Short", "Single", - "Static", "Step", "Stop", "String", - "Structure", "Sub", "SyncLock", "Then", - "Throw", "To", "True", "Try", - "TryCast", "TypeOf", "UInteger", "ULong", - "UShort", "Using", "Variant", "Wend", - "When", "While", "Widening", "With", - "WithEvents", "WriteOnly", "Xor", - // these are not keywords, but context dependend - "Until", "Ansi", "Unicode", "Region", "Preserve" - }; - - internal static IList Keywords { - get { return keywords; } - } - - static VBStatement interfaceStatement; - - static List blockTokens = new List( - new int[] { - Tokens.Class, Tokens.Module, Tokens.Namespace, Tokens.Interface, Tokens.Structure, - Tokens.Sub, Tokens.Function, Tokens.Operator, Tokens.Enum, - Tokens.If, Tokens.For, Tokens.Do, Tokens.While, Tokens.With, Tokens.Select, Tokens.Try, Tokens.Using, Tokens.SyncLock, - Tokens.Property, Tokens.Get, Tokens.Set - }); - #endregion - - bool doCasing; - bool doInsertion; - - static VBNetFormattingStrategy() - { - statements = new List(); - statements.Add(new VBStatement(@"^if.*?(then|\s+_)$", "^end ?if$", "End If", 1, Tokens.If)); - statements.Add(new VBStatement(@"\bclass\s+\w+\s*($|\(\s*Of)", "^end class$", "End Class", 1, Tokens.Class)); - statements.Add(new VBStatement(@"\bnamespace\s+\w+(\.\w+)*$", "^end namespace$", "End Namespace", 1, Tokens.Namespace)); - statements.Add(new VBStatement(@"\bmodule\s+\w+$", "^end module$", "End Module", 1, Tokens.Module)); - statements.Add(new VBStatement(@"\bstructure\s+\w+\s*($|\(\s*Of)", "^end structure$", "End Structure", 1, Tokens.Structure)); - statements.Add(new VBStatement(@"^while\s+", "^end while$", "End While", 1, Tokens.While)); - statements.Add(new VBStatement(@"^select case", "^end select$", "End Select", 1, Tokens.Select)); - statements.Add(new VBStatement(@"(?\<\=\\]+\s*|\s+\w+\s*)\(", @"^end\s+operator$", "End Operator", 1, Tokens.Operator)); - statements.Add(new VBStatement(@"\bfor\s+.*?$", "^next( \\w+)?$", "Next", 1, Tokens.For)); - statements.Add(new VBStatement(@"^synclock\s+.*?$", "^end synclock$", "End SyncLock", 1, Tokens.SyncLock)); - statements.Add(new VBStatement(@"^get$", "^end get$", "End Get", 1, Tokens.Get)); - statements.Add(new VBStatement(@"^with\s+.*?$", "^end with$", "End With", 1, Tokens.With)); - statements.Add(new VBStatement(@"^set(\s*\(.*?\))?$", "^end set$", "End Set", 1, Tokens.Set)); - statements.Add(new VBStatement(@"^try$", "^end try$", "End Try", 1, Tokens.Try)); - statements.Add(new VBStatement(@"^do\s+.+?$", "^loop$", "Loop", 1, Tokens.Do)); - statements.Add(new VBStatement(@"^do$", "^loop .+?$", "Loop While ", 1, Tokens.Do)); - statements.Add(new VBStatement(@"\benum\s+\w+$", "^end enum$", "End Enum", 1, Tokens.Enum)); - interfaceStatement = new VBStatement(@"\binterface\s+\w+\s*($|\(\s*Of)", "^end interface$", "End Interface", 1, Tokens.Interface); - statements.Add(interfaceStatement); - statements.Add(new VBStatement(@"\busing\s+", "^end using$", "End Using", 1, Tokens.Using)); - statements.Add(new VBStatement(@"^#region\s+", "^#end region$", "#End Region", 0, -1)); - } - - public override void FormatLine(ITextEditor editor, char charTyped) - { - using (editor.Document.OpenUndoGroup()) { - FormatLineInternal(editor, editor.Caret.Line, editor.Caret.Offset, charTyped); - } - } - - void FormatLineInternal(ITextEditor editor, int lineNr, int cursorOffset, char ch) - { - string terminator = DocumentUtilitites.GetLineTerminator(editor.Document, lineNr); - doCasing = PropertyService.Get("VBBinding.TextEditor.EnableCasing", true); - doInsertion = PropertyService.Get("VBBinding.TextEditor.EnableEndConstructs", true); - - IDocumentLine currentLine = editor.Document.GetLine(lineNr); - IDocumentLine lineAbove = lineNr > 1 ? editor.Document.GetLine(lineNr - 1) : null; - - string curLineText = currentLine == null ? "" : currentLine.Text; - string lineAboveText = lineAbove == null ? "" : lineAbove.Text; - - if (ch == '\'') { - InsertDocumentationComments(editor, lineNr, cursorOffset); - } - - if (ch == '\n' && lineAbove != null) { - if (LanguageUtils.IsInsideDocumentationComment(editor, lineAbove, lineAbove.EndOffset)) { - editor.Document.Insert(cursorOffset, "''' "); - return; - } - - string textToReplace = lineAboveText.TrimLine(); - - if (doCasing) - DoCasingOnLine(lineAbove, textToReplace, editor); - - if (doInsertion) - DoInsertionOnLine(terminator, currentLine, lineAbove, textToReplace, editor, lineNr); - - if (IsInString(lineAboveText)) { - if (IsFinishedString(curLineText)) { - editor.Document.Insert(lineAbove.EndOffset, "\" & _"); - editor.Document.Insert(currentLine.Offset, "\""); - } else { - editor.Document.Insert(lineAbove.EndOffset, "\""); - } - } else { - string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, lineAbove.Offset); - if (indent.Length > 0) { - string newLineText = indent + currentLine.Text.Trim(); - editor.Document.Replace(currentLine.Offset, currentLine.Length, newLineText); - } - editor.Caret.Column = indent.Length + 1; - } - - IndentLines(editor, lineNr - 1, lineNr); - } else if(ch == '>') { - if (LanguageUtils.IsInsideDocumentationComment(editor, currentLine, cursorOffset)) { - int column = editor.Caret.Offset - currentLine.Offset; - int index = Math.Min(column - 1, curLineText.Length - 1); - - while (index > 0 && curLineText[index] != '<') { - --index; - if(curLineText[index] == '/') - return; // the tag was an end tag or already - } - - if (index > 0) { - StringBuilder commentBuilder = new StringBuilder(""); - for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i) { - commentBuilder.Append(curLineText[i]); - } - string tag = commentBuilder.ToString().Trim(); - if (!tag.EndsWith(">", StringComparison.OrdinalIgnoreCase)) { - tag += ">"; - } - if (!tag.StartsWith("/", StringComparison.OrdinalIgnoreCase)) { - string endTag = " 1) ? editor.Document.GetLine(lineNr - 1) : null; - - string curLineText = currentLine.Text; - string lineAboveText = previousLine == null ? null : previousLine.Text; - - if (curLineText != null && curLineText.EndsWith("'''", StringComparison.OrdinalIgnoreCase) && (lineAboveText == null || !lineAboveText.Trim().StartsWith("'''", StringComparison.OrdinalIgnoreCase))) { - string indentation = DocumentUtilitites.GetWhitespaceAfter(editor.Document, currentLine.Offset); - object member = GetMemberAfter(editor, lineNr); - if (member != null) { - StringBuilder sb = new StringBuilder(); - sb.Append(" "); - sb.Append(terminator); - sb.Append(indentation); - sb.Append("''' "); - sb.Append(terminator); - sb.Append(indentation); - sb.Append("''' "); - if (member is IMethod) { - IMethod method = (IMethod)member; - if (method.Parameters != null && method.Parameters.Count > 0) { - for (int i = 0; i < method.Parameters.Count; ++i) { - sb.Append(terminator); - sb.Append(indentation); - sb.Append("''' "); - } - } - if (method.ReturnType != null && !method.IsConstructor && method.ReturnType.FullyQualifiedName != "System.Void") { - sb.Append(terminator); - sb.Append(indentation); - sb.Append("''' "); - } - } - editor.Document.Insert(cursorOffset, sb.ToString()); - editor.Caret.Position = editor.Document.OffsetToPosition(cursorOffset + indentation.Length + "/// ".Length + " ".Length + terminator.Length); - } - } - } - - static bool LookForEndRegion(ITextEditor editor) - { - string lineText = editor.Document.GetLine(1).Text; - int count = 0; - int lineNr = 0; - while ((!Regex.IsMatch(lineText, @"^\s*#End\s+Region", RegexOptions.IgnoreCase) || count >= 0) && (lineNr < editor.Document.TotalNumberOfLines)) { - if (Regex.IsMatch(lineText, @"^\s*#Region", RegexOptions.IgnoreCase)) - count++; - if (Regex.IsMatch(lineText, @"^\s*#End\s+Region", RegexOptions.IgnoreCase)) - count--; - lineNr++; - if (lineNr < editor.Document.TotalNumberOfLines) - lineText = editor.Document.GetLine(1).Text; - } - - return (count > 0); - } - - static bool IsInsideInterface(ITextEditor editor, int lineNr) - { - ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(editor.Document.Text)); - - Stack tokens = new Stack(); - - Token currentToken = null; - Token prevToken = null; - - while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) { - if (prevToken == null) - prevToken = currentToken; - - if (currentToken.EndLocation.Line <= lineNr && - IsDeclaration(currentToken.Kind) && - IsBlockStart(lexer, currentToken, prevToken)) { - - tokens.Push(currentToken); - } - - if (currentToken.EndLocation.Line <= lineNr && - IsDeclaration(currentToken.Kind) && - IsBlockEnd(currentToken, prevToken)) { - - if (tokens.Count > 0) - tokens.Pop(); - } - - if (currentToken.EndLocation.Line > lineNr) - break; - - prevToken = currentToken; - } - - if (tokens.Count > 0) - return tokens.Pop().Kind == Tokens.Interface; - - return false; - } - - static bool IsInString(string start) - { - bool inString = false; - for (int i = 0; i < start.Length; i++) { - if (start[i] == '"') - inString = !inString; - if (!inString && start[i] == '\'') - return false; - } - return inString; - } - - static bool IsFinishedString(string end) - { - bool inString = true; - for (int i = 0; i < end.Length; i++) { - if (end[i] == '"') - inString = !inString; - if (!inString && end[i] == '\'') - break; - } - return !inString; - } - - internal static bool IsDeclaration(int type) - { - return (type == Tokens.Class) || - (type == Tokens.Module) || - (type == Tokens.Structure) || - (type == Tokens.Enum) || - (type == Tokens.Interface); - } - - bool IsEndStatementNeeded(ITextEditor editor, ref VBStatement statement, int lineNr) - { - Stack tokens = new Stack(); - List missingEnds = new List(); - - ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(editor.Document.Text)); - - Token currentToken = null; - Token prevToken = null; - - while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) { - if (prevToken == null) - prevToken = currentToken; - if (IsBlockStart(lexer, currentToken, prevToken) && !IsAutomaticPropertyWithDefaultValue(lexer, currentToken, prevToken)) { - if ((tokens.Count > 0 && tokens.Peek().Kind != Tokens.Interface) || IsDeclaration(currentToken.Kind)) - tokens.Push(currentToken); - } - - if (IsBlockEnd(currentToken, prevToken)) { - while (tokens.Count > 0 && !IsMatchingEnd(tokens.Peek(), currentToken)) { - missingEnds.Add(tokens.Pop()); - } - - if (tokens.Count > 0) { - if (IsMatchingEnd(tokens.Peek(), currentToken)) - tokens.Pop(); - } - } - - prevToken = currentToken; - } - - while (tokens.Count > 0) - missingEnds.Add(tokens.Pop()); - - if (missingEnds.Count > 0) - return GetClosestMissing(missingEnds, statement, editor, lineNr) != null; - else - return false; - } - - static bool IsAutomaticPropertyWithDefaultValue(ILexer lexer, Token currentToken, Token prevToken) - { - if (currentToken.Kind != Tokens.Property) - return false; - lexer.StartPeek(); - - int parenthesesNesting = 0; - - // look for parameter list, = or EOL - Token t; - while ((t = lexer.Peek()).Kind != Tokens.EOF) { - if (t.Kind == Tokens.OpenParenthesis) - parenthesesNesting++; - if (t.Kind == Tokens.CloseParenthesis) - parenthesesNesting--; - if (parenthesesNesting == 0 && t.Kind == Tokens.Assign) - return true; - if (t.Kind == Tokens.EOL) - return false; - } - - return false; - } - - static Token GetClosestMissing(List missingEnds, VBStatement statement, ITextEditor editor, int lineNr) - { - Token closest = null; - int diff = 0; - - foreach (Token t in missingEnds) { - if (!IsSingleLine(t.Location.Line, editor)) { - if (IsMatchingStatement(t, statement) && ((diff = lineNr - t.Location.Line) > 0)) { - if (closest == null) { - closest = t; - } else { - if (diff < lineNr - closest.Location.Line) - closest = t; - } - } - } - } - - return closest; - } - - static bool IsSingleLine(int line, ITextEditor editor) - { - if (line < 1) - return false; - - IDocumentLine lineSeg = editor.Document.GetLine(line); - - if (lineSeg == null) - return false; - - string text = lineSeg.Text; - - if (text.TrimComments().Trim(' ', '\t', '\r', '\n').EndsWith("_", StringComparison.OrdinalIgnoreCase)) - return true; - else - return false; - } - - internal static bool IsMatchingEnd(Token begin, Token end) - { - if (begin.Kind == end.Kind) - return true; - - if (begin.Kind == Tokens.For && end.Kind == Tokens.Next) - return true; - - if (begin.Kind == Tokens.Do && end.Kind == Tokens.Loop) - return true; - - return false; - } - - static bool IsMatchingStatement(Token token, VBStatement statement) - { - if (token.Kind == Tokens.For && statement.EndStatement == "Next") - return true; - - if (token.Kind == Tokens.Do && statement.EndStatement.StartsWith("Loop", StringComparison.OrdinalIgnoreCase)) - return true; - - bool empty = !string.IsNullOrEmpty(token.Value); - bool match = statement.EndStatement.IndexOf(token.Value, StringComparison.OrdinalIgnoreCase) != -1; - - return empty && match; - } - - public override void IndentLines(ITextEditor editor, int begin, int end) - { - SmartIndentInternal(editor, begin, end); - } - - static int SmartIndentInternal(ITextEditor editor, int begin, int end) - { - ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(editor.Document.Text)); - - ExpressionFinder context = new ExpressionFinder(); - - Stack indentation = new Stack(); - indentation.Push(string.Empty); - - List eols = new List(); - - bool inInterface = false; - bool isMustOverride = false; - bool isDeclare = false; - bool isDelegate = false; - - Token currentToken = null; - Token prevToken = null; - - int blockStart = 1; - int lambdaNesting = 0; - - bool sawAttribute = false; - - while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) { - if (context.InContext(Context.Attribute) && currentToken.Kind == Tokens.GreaterThan) - sawAttribute = true; - - context.InformToken(currentToken); - - if (prevToken == null) - prevToken = currentToken; - - if (currentToken.Kind == Tokens.MustOverride) - isMustOverride = true; - - if (currentToken.Kind == Tokens.Delegate) - isDelegate = true; - - if (currentToken.Kind == Tokens.Declare) - isDeclare = true; - - if (currentToken.Kind == Tokens.EOL) { - isDelegate = isDeclare = isMustOverride = sawAttribute = false; - eols.Add(currentToken.Location.Line); - } - - if (IsBlockEnd(currentToken, prevToken)) { - // indent the lines inside the block - // this is an End-statement - // hence we indent from blockStart to the previous line - int blockEnd = currentToken.Location.Line - 1; - - // if this is a lambda end include End-Statement in block -// if (lambdaNesting > 0 && (currentToken.Kind == Tokens.Function || currentToken.Kind == Tokens.Sub)) { -// blockEnd++; -// } - - ApplyToRange(editor, indentation, eols, blockStart, blockEnd, begin, end, sawAttribute); - - if (lambdaNesting > 0 && (currentToken.Kind == Tokens.Function || currentToken.Kind == Tokens.Sub)) { - Unindent(indentation); - - ApplyToRange(editor, indentation, eols, currentToken.Location.Line, currentToken.Location.Line, begin, end, sawAttribute); - } - - if (currentToken.Kind == Tokens.Interface) - inInterface = false; - - if (!inInterface && !isMustOverride && !isDeclare && !isDelegate) { - Unindent(indentation); - - if (currentToken.Kind == Tokens.Select) - Unindent(indentation); - } - - // block start is this line (for the lines between two blocks) - blockStart = currentToken.Location.Line; - - if (lambdaNesting > 0 && (currentToken.Kind == Tokens.Function || currentToken.Kind == Tokens.Sub)) { - blockStart++; - lambdaNesting--; - } - } - - bool isMultiLineLambda; - if (IsBlockStart(lexer, currentToken, prevToken, out isMultiLineLambda)) { - // indent the lines between the last and this block - // this is a Begin-statement - // hence we indent from blockStart to the this line - int lastVisualLine = FindNextEol(lexer); - eols.Add(lastVisualLine); - ApplyToRange(editor, indentation, eols, blockStart, lastVisualLine, begin, end, sawAttribute); - - if (isMultiLineLambda && (currentToken.Kind == Tokens.Function || currentToken.Kind == Tokens.Sub)) { - lambdaNesting++; - int endColumn = currentToken.Location.Column; - if (prevToken.Kind == Tokens.Iterator || prevToken.Kind == Tokens.Async) - endColumn = prevToken.Location.Column; - int startColumn = DocumentUtilitites.GetWhitespaceAfter(editor.Document, editor.Document.GetLine(lastVisualLine).Offset).Length; - if (startColumn < endColumn) - Indent(editor, indentation, new string(' ', endColumn - startColumn - 1)); - } - - if (!inInterface && !isMustOverride && !isDeclare && !isDelegate && !IsAutomaticPropertyWithDefaultValue(lexer, currentToken, prevToken)) { - Indent(editor, indentation); - - if (currentToken.Kind == Tokens.Select) - Indent(editor, indentation); - } - - if (currentToken.Kind == Tokens.Interface) - inInterface = true; - - // block start is the following line (for the lines inside a block) - blockStart = lastVisualLine + 1; - } - - prevToken = currentToken; - } - - ApplyToRange(editor, indentation, eols, blockStart, editor.Document.TotalNumberOfLines, begin, end, sawAttribute); - - return (indentation.PeekOrDefault() ?? string.Empty).Length; - } - - static int FindNextEol(ILexer lexer) - { - lexer.StartPeek(); - - Token t = lexer.Peek(); - - while (t.Kind > Tokens.EOL) // break on EOF(0) or EOL(1) - t = lexer.Peek(); - - return t.Location.Line; - } - - static void ApplyToRange(ITextEditor editor, Stack indentation, List eols, int blockStart, int blockEnd, int selectionStart, int selectionEnd, bool sawAttribute) { - LoggingService.InfoFormatted("indenting line {0} to {1} with {2}", blockStart, blockEnd, (indentation.PeekOrDefault() ?? "").Length); - - int nextEol = -1; - bool wasMultiLine = false; - - for (int i = blockStart; i <= blockEnd; i++) { - IDocumentLine curLine = editor.Document.GetLine(i); - string lineText = curLine.Text.TrimStart(); - // preprocessor directives cannot be multiline (just as comments) - // and they are not included in normal block indentation -> - // treat preprocessor directives as comments -> remove them - string noComments = lineText.TrimComments().TrimPreprocessorDirectives().TrimEnd().TrimEnd('_').TrimEnd(); - - // adjust indentation if the current line is not selected - // lines between the selection will be aligned to the selected level - if (i < selectionStart || i > selectionEnd) { - indentation.PopOrDefault(); - indentation.Push(DocumentUtilitites.GetWhitespaceAfter(editor.Document, curLine.Offset)); - } - - // look for next eol if line is not empty - // (the lexer does not produce eols for empty lines) - if (!string.IsNullOrEmpty(noComments) && i >= nextEol) { - int search = eols.BinarySearch(i); - if (search < 0) - search = ~search; - nextEol = search < eols.Count ? eols[search] : i; - } - - // remove indentation in last line of multiline array(, collection, object) initializers - if (i == nextEol && wasMultiLine && (noComments == "}" || sawAttribute)) { - wasMultiLine = false; - Unindent(indentation); - } - - // apply the indentation - editor.Document.SmartReplaceLine(curLine, (indentation.PeekOrDefault() ?? "") + lineText); - - // indent line if it is ended by (implicit) line continuation - if (i < nextEol && !wasMultiLine) { - wasMultiLine = true; - Indent(editor, indentation); - } - - // unindent if this is the last line of a multiline statement - if (i == nextEol && wasMultiLine) { - wasMultiLine = false; - Unindent(indentation); - } - } - } - - static void Unindent(Stack indentation) - { - indentation.PopOrDefault(); - } - - static void Indent(ITextEditor editor, Stack indentation, string indent = null) - { - indentation.Push((indentation.PeekOrDefault() ?? string.Empty) + (indent ?? editor.Options.IndentationString)); - } - - internal static bool IsBlockStart(ILexer lexer, Token current, Token prev) - { - bool tmp; - return IsBlockStart(lexer, current, prev, out tmp); - } - - static bool IsBlockStart(ILexer lexer, Token current, Token prev, out bool isMultiLineLambda) - { - isMultiLineLambda = false; - - if (blockTokens.Contains(current.Kind)) { - if (current.Kind == Tokens.If) { - if (prev.Kind != Tokens.EOL) - return false; - - lexer.StartPeek(); - - Token currentToken = null; - - while ((currentToken = lexer.Peek()).Kind > Tokens.EOL) { - if (currentToken.Kind == Tokens.Then) - return lexer.Peek().Kind == Tokens.EOL; - } - } - - // check if it is a lambda - if (current.Kind == Tokens.Function || current.Kind == Tokens.Sub) { - lexer.StartPeek(); - - bool isSingleLineLambda = false; - - if (lexer.Peek().Kind == Tokens.OpenParenthesis) { - isSingleLineLambda = true; - - int brackets = 1; - - // look for end of parameter list - while (brackets > 0) { - var t = lexer.Peek(); - if (t.Kind == Tokens.OpenParenthesis) - brackets++; - if (t.Kind == Tokens.CloseParenthesis) - brackets--; - } - - // expression is multi-line lambda if next Token is EOL - if (brackets == 0) - return isMultiLineLambda = (lexer.Peek().Kind == Tokens.EOL); - } - - // do not indent if current token is start of single-line lambda - if (isSingleLineLambda) - return false; - } - - if (current.Kind == Tokens.With && prev.Kind > Tokens.EOL) - return false; - - if (current.Kind == Tokens.While && (prev.Kind == Tokens.Skip || prev.Kind == Tokens.Take)) - return false; - - if (current.Kind == Tokens.Select && prev.Kind > Tokens.EOL) - return false; - - if (current.Kind == Tokens.Class || current.Kind == Tokens.Structure) { - lexer.StartPeek(); - - Token t = lexer.Peek(); - - if (t.Kind == Tokens.CloseParenthesis || t.Kind == Tokens.CloseCurlyBrace || t.Kind == Tokens.Comma) - return false; - } - - if (current.Kind == Tokens.Module) { - lexer.StartPeek(); - - Token t = lexer.Peek(); - - if (t.Kind == Tokens.Colon) - return false; - } - - if (prev.Kind == Tokens.End || - prev.Kind == Tokens.Loop || - prev.Kind == Tokens.Exit || - prev.Kind == Tokens.Continue || - prev.Kind == Tokens.Resume || - prev.Kind == Tokens.GoTo || - prev.Kind == Tokens.Do) - return false; - else - return true; - } - - return IsSpecialCase(current, prev); - } - - internal static bool IsBlockEnd(Token current, Token prev) - { - if (current.Kind == Tokens.Next) - return prev.Kind == Tokens.EOL || prev.Kind == Tokens.Colon; - - if (current.Kind == Tokens.Loop) - return prev.Kind == Tokens.EOL || prev.Kind == Tokens.Colon; - - if (blockTokens.Contains(current.Kind)) - return prev.Kind == Tokens.End; - - return IsSpecialCase(current, prev); - } - - static bool IsSpecialCase(Token current, Token prev) - { - switch (current.Kind) { - case Tokens.Else: - return true; - case Tokens.Case: - return prev.Kind != Tokens.Select; - case Tokens.ElseIf: - return true; - case Tokens.Catch: - return true; - case Tokens.Finally: - return true; - } - - return false; - } - - /// - /// Gets the next member after the specified caret position. - /// - static object GetMemberAfter(ITextEditor editor, int caretLine) - { - string fileName = editor.FileName; - object nextElement = null; - if (fileName != null && fileName.Length > 0 ) { - ParseInformation parseInfo = ParserService.ParseFile(fileName, editor.Document); - if (parseInfo != null) { - ICompilationUnit currentCompilationUnit = parseInfo.CompilationUnit; - if (currentCompilationUnit != null) { - IClass currentClass = currentCompilationUnit.GetInnermostClass(caretLine, 0); - int nextElementLine = int.MaxValue; - if (currentClass == null) { - foreach (IClass c in currentCompilationUnit.Classes) { - if (c.Region.BeginLine < nextElementLine && c.Region.BeginLine > caretLine) { - nextElementLine = c.Region.BeginLine; - nextElement = c; - } - } - } else { - foreach (IClass c in currentClass.InnerClasses) { - if (c.Region.BeginLine < nextElementLine && c.Region.BeginLine > caretLine) { - nextElementLine = c.Region.BeginLine; - nextElement = c; - } - } - foreach (IMember m in currentClass.AllMembers) { - if (m.Region.BeginLine < nextElementLine && m.Region.BeginLine > caretLine) { - nextElementLine = m.Region.BeginLine; - nextElement = m; - } - } - } - } - } - } - return nextElement; - } - - public override void IndentLine(ITextEditor editor, IDocumentLine line) - { - IndentLines(editor, line.LineNumber, line.LineNumber); - } - - public override void SurroundSelectionWithComment(ITextEditor editor) - { - SurroundSelectionWithSingleLineComment(editor, "'"); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBStatement.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBStatement.cs deleted file mode 100644 index 5830116507..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBStatement.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.NRefactory.Parser; -using ICSharpCode.NRefactory.Parser.VB; - -namespace ICSharpCode.VBNetBinding -{ - public class VBStatement - { - string startRegex = ""; - - public string StartRegex { - get { return startRegex; } - } - - string endRegex = ""; - - public string EndRegex { - get { return endRegex; } - } - - string endStatement = ""; - - public string EndStatement { - get { return endStatement; } - } - - int statementToken = 0; - - public int StatementToken { - get { return statementToken; } - } - - int indentPlus = 0; - - public int IndentPlus { - get { return indentPlus; } - } - - public VBStatement() - { - } - - public VBStatement(string startRegex, string endRegex, string endStatement, int indentPlus, int statementToken) - { - this.startRegex = startRegex; - this.endRegex = endRegex; - this.endStatement = endStatement; - this.indentPlus = indentPlus; - this.statementToken = statementToken; - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/LanguageUtils.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/LanguageUtils.cs deleted file mode 100644 index 105ad91c27..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/LanguageUtils.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Text.RegularExpressions; -using ICSharpCode.SharpDevelop.Editor; - -namespace ICSharpCode.VBNetBinding -{ - public static class LanguageUtils - { - public static string TrimComments(this string line) - { - if (string.IsNullOrEmpty(line)) - return string.Empty; - - bool inStr = false; - - for (int i = 0; i < line.Length; i++) { - if (line[i] == '"') - inStr = !inStr; - if (line[i] == '\'' && !inStr) - return line.Substring(0, i); - } - - return line; - } - - public static string TrimPreprocessorDirectives(this string line) - { - if (string.IsNullOrEmpty(line)) - return string.Empty; - - bool wsOnly = true; - - for (int i = 0; i < line.Length; i++) { - if (line[i] == '#' && wsOnly) { - if (i < line.Length - 1) { - if (char.IsLetter(line[i + 1])) - return line.Substring(0, i); - } else - return line.Substring(0, i); - } - if (!char.IsWhiteSpace(line[i])) - wsOnly = false; - } - - return line; - } - - public static string TrimLine(this string line) - { - if (string.IsNullOrEmpty(line)) - return string.Empty; - // remove string content - MatchCollection matches = Regex.Matches(line, "\"[^\"]*?\"", RegexOptions.Singleline); - foreach (Match match in matches) { - line = line.Remove(match.Index, match.Length).Insert(match.Index, new string('-', match.Length)); - } - // remove comments - return TrimComments(line); - } - - public static bool IsInsideDocumentationComment(ITextEditor editor) - { - return IsInsideDocumentationComment(editor, editor.Document.GetLineForOffset(editor.Caret.Offset), editor.Caret.Offset); - } - - public static bool IsInsideDocumentationComment(ITextEditor editor, IDocumentLine curLine, int cursorOffset) - { - for (int i = curLine.Offset; i < cursorOffset; ++i) { - char ch = editor.Document.GetCharAt(i); - if (ch == '"') - return false; - if (ch == '\'' && i + 2 < cursorOffset && editor.Document.GetCharAt(i + 1) == '\'' && - editor.Document.GetCharAt(i + 2) == '\'') - return true; - } - return false; - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs deleted file mode 100644 index a703211c44..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.VBNetBinding -{ - public static class MyNamespaceBuilder - { - /// - /// Builds Visual Basic's "My" namespace for the specified project. - /// - public static void BuildNamespace(VBNetProject project, IProjectContent pc) - { - if ("custom".Equals(project.GetEvaluatedProperty("MyType"), StringComparison.OrdinalIgnoreCase)) - return; - - ICompilationUnit cu = new DefaultCompilationUnit(pc); - //cu.FileName = "GeneratedMyNamespace.vb"; // leave FileName null - fixes SD2-854 - string ns; - if (project.RootNamespace == null || project.RootNamespace.Length == 0) - ns = "My"; - else - ns = project.RootNamespace + ".My"; - IClass myApp = CreateMyApplication(cu, project, ns); - IClass myComp = CreateMyComputer(cu, ns); - - cu.Classes.Add(myApp); - cu.Classes.Add(myComp); - - IClass myForms = null; - if (project.OutputType == OutputType.WinExe) { - myForms = CreateMyForms(cu, ns); - cu.Classes.Add(myForms); - } - DefaultClass c = new DefaultClass(cu, ns + ".MyProject"); - c.ClassType = ClassType.Module; - c.Modifiers = ModifierEnum.Internal | ModifierEnum.Partial | ModifierEnum.Sealed | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); - - // we need to use GetClassReturnType instead of DefaultReturnType because we need - // a reference to the compound class. - c.Properties.Add(new DefaultProperty("Application", - new GetClassReturnType(pc, myApp.FullyQualifiedName, 0), - ModifierEnum.Public | ModifierEnum.Static, - DomRegion.Empty, DomRegion.Empty, c)); - c.Properties.Add(new DefaultProperty("Computer", - new GetClassReturnType(pc, myComp.FullyQualifiedName, 0), - ModifierEnum.Public | ModifierEnum.Static, - DomRegion.Empty, DomRegion.Empty, c)); - if (myForms != null) { - c.Properties.Add(new DefaultProperty("Forms", - new GetClassReturnType(pc, myForms.FullyQualifiedName, 0), - ModifierEnum.Public | ModifierEnum.Static, - DomRegion.Empty, DomRegion.Empty, c)); - } - c.Properties.Add(new DefaultProperty("User", - new GetClassReturnType(pc, "Microsoft.VisualBasic.ApplicationServices.User", 0), - ModifierEnum.Public | ModifierEnum.Static, - DomRegion.Empty, DomRegion.Empty, c)); - cu.Classes.Add(c); - pc.UpdateCompilationUnit(null, cu, cu.FileName); - } - - static IClass CreateMyApplication(ICompilationUnit cu, VBNetProject project, string ns) - { - DefaultClass c = new DefaultClass(cu, ns + ".MyApplication"); - c.ClassType = ClassType.Class; - c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); - switch (project.OutputType) { - case OutputType.WinExe: - c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase")); - if (project.GetEvaluatedProperty("MyType") == "WindowsForms") { - c.Methods.Add( - new DefaultMethod(c, "Main") { - Modifiers = ModifierEnum.Internal | ModifierEnum.Static, - ReturnType = c.ProjectContent.SystemTypes.Void, - Parameters = new[] { - new DefaultParameter( - "args", - new ArrayReturnType(c.ProjectContent, c.ProjectContent.SystemTypes.String, 1), - DomRegion.Empty - ) - } - }); - } - break; - case OutputType.Exe: - c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase")); - break; - default: - c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ApplicationBase")); - break; - } - return c; - } - - static IReturnType CreateTypeRef(ICompilationUnit cu, string fullName) - { - return new GetClassReturnType(cu.ProjectContent, fullName, 0); - } - - static IClass CreateMyComputer(ICompilationUnit cu, string ns) - { - DefaultClass c = new DefaultClass(cu, ns + ".MyComputer"); - c.ClassType = ClassType.Class; - c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); - c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.Devices.Computer")); - return c; - } - - static IClass CreateMyForms(ICompilationUnit cu, string ns) - { - DefaultClass c = new MyFormsClass(cu, ns + ".MyForms"); - c.ClassType = ClassType.Class; - c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Synthetic; - c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); - return c; - } - - class MyFormsClass : DefaultClass - { - public MyFormsClass(ICompilationUnit cu, string fullName) : base(cu, fullName) {} - - public override IList Properties { - get { - // TODO: This class must be immutable when frozen, we cannot change the properties! - - List properties = new List(); - IClass formClass = this.ProjectContent.GetClass("System.Windows.Forms.Form", 0); - if (formClass == null) - return properties; - foreach (IClass c in this.ProjectContent.Classes) { - if (c.IsTypeInInheritanceTree(formClass)) { - properties.Add(new DefaultProperty(c.Name, - new GetClassReturnType(this.ProjectContent, c.FullyQualifiedName, 0), - ModifierEnum.Public | ModifierEnum.Static, - DomRegion.Empty, DomRegion.Empty, c)); - } - } - return properties; - } - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.xaml.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.xaml.cs deleted file mode 100644 index cac16699dc..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.xaml.cs +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Created by SharpDevelop. - * User: Peter Forstmeier - * Date: 06.08.2012 - * Time: 19:43 - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ -using System; -using System.Collections.Generic; -using ICSharpCode.SharpDevelop.Gui.OptionPanels; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.VBNetBinding.OptionPanels -{ - /// - /// Interaction logic for BuildOptionsXaml.xaml - /// - public partial class BuildOptions : ProjectOptionPanel - { - public BuildOptions() - { - InitializeComponent(); - DataContext = this; - - - optionExplicitItems = new List(); - optionExplicitItems.Add(new KeyItemPair("Off","Explicit Off")); - optionExplicitItems.Add(new KeyItemPair("On","Explicit On")); - OptionExplicitItems = optionExplicitItems; - - optionStrictItems = new List(); - optionStrictItems.Add(new KeyItemPair("Off", "Strict Off")); - optionStrictItems.Add(new KeyItemPair("On", "Strict On")); - OptionStrictItems = optionStrictItems; - - - optionCompareItems = new List(); - optionCompareItems.Add(new KeyItemPair("Binary", "Compare Binary")); - optionCompareItems.Add(new KeyItemPair("Text", "Compare Text")); - OptionCompareItems = optionCompareItems; - - optionInferItems = new List(); - optionInferItems.Add(new KeyItemPair("Off", "Infer Off")); - optionInferItems.Add(new KeyItemPair("On", "Infer On")); - OptionInferItems = optionInferItems; - } - - - public ProjectProperty DefineConstants { - get { return GetProperty("DefineConstants", "", TextBoxEditMode.EditRawProperty); } - } - - public ProjectProperty Optimize { - get { return GetProperty("Optimize", false, PropertyStorageLocations.ConfigurationSpecific); } - } - - public ProjectProperty RemoveIntegerChecks { - get { return GetProperty("RemoveIntegerChecks", "", TextBoxEditMode.EditRawProperty); } - } - - public ProjectProperty OptionExplicit { - get {return GetProperty("OptionExplicit", "", TextBoxEditMode.EditRawProperty); } - } - - public ProjectProperty OptionStrict { - get { return GetProperty("OptionStrict", "Off", TextBoxEditMode.EditRawProperty); } - } - - public ProjectProperty OptionCompare { - get { return GetProperty("OptionCompare", "Binary", TextBoxEditMode.EditRawProperty); } - } - - public ProjectProperty OptionInfer { - get { return GetProperty("OptionInfer", "Off", TextBoxEditMode.EditRawProperty); } - } - - - #region OptionItems - - List optionExplicitItems; - - public List OptionExplicitItems { - get { return optionExplicitItems; } - set { optionExplicitItems = value; - base.RaisePropertyChanged(() => OptionExplicitItems); - } - } - - - List optionStrictItems; - - public List OptionStrictItems { - get { return optionStrictItems; } - set { optionStrictItems = value; - base.RaisePropertyChanged(() => OptionStrictItems); - } - } - - - private List optionCompareItems; - - public List OptionCompareItems { - get { return optionCompareItems; } - set { optionCompareItems = value; - base.RaisePropertyChanged(() => OptionCompareItems); - } - } - - - List optionInferItems; - - public List OptionInferItems { - get { return optionInferItems; } - set { optionInferItems = value; - base.RaisePropertyChanged(()=>OptionInferItems); - } - } - - - #endregion - - #region overrides - - - protected override void Initialize() - { - base.Initialize(); - buildOutput.Initialize(this); - this.buildAdvanced.Initialize(this); - this.errorsAndWarnings.Initialize(this); - this.treatErrorsAndWarnings.Initialize(this); - } - #endregion - } -} \ No newline at end of file diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/ProjectImports.xaml.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/ProjectImports.xaml.cs deleted file mode 100644 index 5275b02e0c..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/ProjectImports.xaml.cs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Linq; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Gui; -using ICSharpCode.SharpDevelop.Gui.OptionPanels; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.VBNetBinding.OptionPanels -{ - /// - /// Interaction logic for ProjectImportsOptions.xaml - /// - public partial class ProjectImports : ProjectOptionPanel - { - - public ProjectImports() - { - InitializeComponent(); - } - - #region override - - protected override void Initialize() - { - ProjectItems = new ObservableCollection(); - NameSpaceItems = new ObservableCollection (); - - foreach(ProjectItem item in base.Project.Items) - { - if(item.ItemType == ItemType.Import) { - ProjectItems.Add(item.Include); - } - } - - - IProjectContent projectContent = ParserService.GetProjectContent(base.Project); - foreach(IProjectContent refProjectContent in projectContent.ThreadSafeGetReferencedContents()) { - AddNamespaces(refProjectContent); - } - AddNamespaces(projectContent); - } - - - protected override bool Save(MSBuildBasedProject project, string configuration, string platform) - { - List imports = new List(); - foreach(ProjectItem item in project.Items) - { - if(item.ItemType == ItemType.Import) - { - imports.Add(item); - } - } - - foreach(ImportProjectItem item in imports) - { - ProjectService.RemoveProjectItem(project, item); - } - - foreach(string importedNamespace in ProjectItems) - { - ProjectService.AddProjectItem(project, new ImportProjectItem(project, importedNamespace)); - } - - return base.Save(project, configuration, platform); - } - - #endregion - - - private ObservableCollection projectItems; - - public ObservableCollection ProjectItems { - get { return projectItems; } - set { projectItems = value; - base.RaisePropertyChanged(() => ProjectItems); - } - } - - private string selectedProjectItem; - - public string SelectedProjectItem { - get { return selectedProjectItem; } - set { selectedProjectItem = value; - base.RaisePropertyChanged(() => SelectedProjectItem); - RemoveButtonEnable = true; - AddButtonEnable = false; - } - } - - private ObservableCollection nameSpaceItems; - - public ObservableCollection NameSpaceItems { - get { return nameSpaceItems; } - set { nameSpaceItems = value; - base.RaisePropertyChanged(() => NameSpaceItems); - } - } - - - private string selectedNameSpace; - - public string SelectedNameSpace { - get { return selectedNameSpace; } - set { selectedNameSpace = value; - base.RaisePropertyChanged(()=>SelectedNameSpace); - AddButtonEnable = true; - } - } - - - private bool addButtonEnable; - - public bool AddButtonEnable { - get { return addButtonEnable; } - set { addButtonEnable = value; - base.RaisePropertyChanged(() => AddButtonEnable); - } - } - - private bool removeButtonEnable; - - public bool RemoveButtonEnable { - get { return removeButtonEnable; } - set { removeButtonEnable = value; - base.RaisePropertyChanged(() => RemoveButtonEnable); - } - } - - - - private void AddNamespaces(IProjectContent projectContent) - { - foreach(string projectNamespace in projectContent.NamespaceNames) { - if (!string.IsNullOrEmpty(projectNamespace)) { - - if (!NameSpaceItems.Contains(projectNamespace)) { - NameSpaceItems.Add(projectNamespace); - } - } - } - } - - void AddButton_Click(object sender, RoutedEventArgs e) - { - ProjectItems.Add(SelectedNameSpace); - IsDirty = true; - } - - void RemoveButton_Click(object sender, RoutedEventArgs e) - { - ProjectItems.Remove(SelectedProjectItem); - SelectedProjectItem = null; - RemoveButtonEnable = false; - AddButtonEnable = false; - IsDirty = true; - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/TextEditorOptions.xaml.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/TextEditorOptions.xaml.cs deleted file mode 100644 index d153e739ad..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/TextEditorOptions.xaml.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using ICSharpCode.Core; - -namespace ICSharpCode.VBNetBinding.OptionPanels -{ - /// - /// Interaction logic for TextEditorOptions.xaml - /// - public partial class TextEditorOptions - { - public TextEditorOptions() - { - InitializeComponent(); - } - - public static bool EnableEndConstructs { - get { return PropertyService.Get("VBBinding.TextEditor.EnableEndConstructs", true); } - set { PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", value); } - } - - public static bool EnableCasing { - get { return PropertyService.Get("VBBinding.TextEditor.EnableCasing", true); } - set { PropertyService.Set("VBBinding.TextEditor.EnableCasing", value); } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs deleted file mode 100644 index 388100c388..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; -using ICSharpCode.SharpDevelop.Dom.VBNet; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.VBNetBinding -{ - public class TParser : IParser - { - ///IParser Interface - string[] lexerTags; - - public string[] LexerTags { - get { return lexerTags; } - set { lexerTags = value; } - } - - public LanguageProperties Language { - get { return LanguageProperties.VBNet; } - } - - public IExpressionFinder CreateExpressionFinder(string fileName) - { - return new VBNetExpressionFinder(ParserService.GetParseInformation(fileName)); - } - - public bool CanParse(string fileName) - { - return Path.GetExtension(fileName).Equals(".VB", StringComparison.OrdinalIgnoreCase); - } - - public bool CanParse(IProject project) - { - return project.Language == "VBNet"; - } - - static void RetrieveRegions(ICompilationUnit cu, ICSharpCode.NRefactory.Parser.SpecialTracker tracker) - { - Stack regionStartDirectives = new Stack(); - - foreach (ICSharpCode.NRefactory.PreprocessingDirective directive in tracker.CurrentSpecials.OfType()) { - if (directive.Cmd.Equals("#region", StringComparison.OrdinalIgnoreCase)) - regionStartDirectives.Push(directive); - if (directive.Cmd.Equals("#end", StringComparison.OrdinalIgnoreCase) - // using StartsWith allows comments at end of line - // fixes http://community.sharpdevelop.net/forums/t/12252.aspx - && directive.Arg.StartsWith("region", StringComparison.OrdinalIgnoreCase) - && regionStartDirectives.Any()) { - ICSharpCode.NRefactory.PreprocessingDirective start = regionStartDirectives.Pop(); - cu.FoldingRegions.Add(new FoldingRegion(start.Arg.TrimComments().Trim().Trim('"'), DomRegion.FromLocation(start.StartPosition, directive.EndPosition))); - } - } - } - - public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ICSharpCode.SharpDevelop.ITextBuffer fileContent) - { - using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.VBNet, fileContent.CreateReader())) { - return Parse(p, fileName, projectContent); - } - } - - ICompilationUnit Parse(ICSharpCode.NRefactory.IParser p, string fileName, IProjectContent projectContent) - { - p.Lexer.SpecialCommentTags = lexerTags; - p.ParseMethodBodies = false; - p.Parse(); - - NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(projectContent, ICSharpCode.NRefactory.SupportedLanguage.VBNet); - if (projectContent.Project != null) { - visitor.VBRootNamespace = ((IProject)projectContent.Project).RootNamespace; - } - visitor.Specials = p.Lexer.SpecialTracker.CurrentSpecials; - visitor.VisitCompilationUnit(p.CompilationUnit, null); - visitor.Cu.FileName = fileName; - visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0; - RetrieveRegions(visitor.Cu, p.Lexer.SpecialTracker); - AddCommentTags(visitor.Cu, p.Lexer.TagComments); - - return visitor.Cu; - } - - static void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List tagComments) - { - foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) - { - DomRegion tagRegion = new DomRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X); - var tag = new ICSharpCode.SharpDevelop.Dom.TagComment(tagComment.Tag, tagRegion, tagComment.CommentText); - cu.TagComments.Add(tag); - } - } - - public IResolver CreateResolver() - { - return new NRefactoryResolver(LanguageProperties.VBNet); - } - ///////// IParser Interface END - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBNetConverter.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBNetConverter.cs deleted file mode 100644 index a19696289c..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBNetConverter.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using ICSharpCode.NRefactory; -using ICSharpCode.NRefactory.Ast; -using ICSharpCode.NRefactory.PrettyPrinter; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; -using ICSharpCode.SharpDevelop.Project; -using ICSharpCode.SharpDevelop.Project.Converter; - -namespace ICSharpCode.VBNetBinding -{ - public class CSharpToVBNetConverter : NRefactoryLanguageConverter - { - public override string TargetLanguageName { - get { - return VBNetProjectBinding.LanguageName; - } - } - - IList defaultImports = new[] { "Microsoft.VisualBasic", "System" }; - - protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject) - { - VBNetProject project = (VBNetProject)base.CreateProject(targetProjectDirectory, sourceProject); - IProjectItemListProvider provider = (IProjectItemListProvider)project; - foreach (string import in defaultImports) { - provider.AddProjectItem(new ImportProjectItem(project, import)); - } - return project; - } - - protected override void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem) - { - ConvertFile(sourceItem, targetItem, ".cs", ".vb", SupportedLanguage.CSharp, new VBNetOutputVisitor()); - } - - string startupObject; - - protected override void ConvertAst(CompilationUnit compilationUnit, List specials, FileProjectItem sourceItem) - { - PreprocessingDirective.CSharpToVB(specials); - IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent; - CSharpToVBNetConvertVisitor visitor = new CSharpToVBNetConvertVisitor(pc, ParserService.GetParseInformation(sourceItem.FileName)); - visitor.RootNamespaceToRemove = sourceItem.Project.RootNamespace; - visitor.DefaultImportsToRemove = defaultImports; - visitor.StartupObjectToMakePublic = startupObject; - compilationUnit.AcceptVisitor(visitor, null); - } - - protected override void CopyProperties(IProject sourceProject, IProject targetProject) - { - VBNetProject vbProject = (VBNetProject)targetProject; - base.CopyProperties(sourceProject, targetProject); - vbProject.ChangeProperty("DefineConstants", v => v.Replace(';', ',')); - vbProject.ChangeProperty("ProjectTypeGuids", - v => v.Replace(ProjectTypeGuids.CSharp, ProjectTypeGuids.VBNet, StringComparison.OrdinalIgnoreCase)); - - // determine the StartupObject - startupObject = vbProject.GetEvaluatedProperty("StartupObject"); - if (string.IsNullOrEmpty(startupObject)) { - IList startupObjects = ICSharpCode.SharpDevelop.Gui.OptionPanels.ApplicationSettings.GetPossibleStartupObjects(sourceProject); - if (startupObjects.Count == 1) { - startupObject = startupObjects[0].FullyQualifiedName; - if (vbProject.OutputType == OutputType.WinExe) { - // we have to set StartupObject to prevent the VB compiler from choosing - // the generated Main method. - vbProject.SetProperty("StartupObject", startupObject); - } - } - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/VBNetProject.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/VBNetProject.cs deleted file mode 100644 index d6c1d6689c..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/VBNetProject.cs +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.CodeDom; -using System.ComponentModel; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Dom.VBNet; -using ICSharpCode.SharpDevelop.Internal.Templates; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.VBNetBinding -{ - public class VBNetProject : CompilableProject, IVBNetOptionProvider - { - protected override void OnPropertyChanged(ProjectPropertyChangedEventArgs e) - { - base.OnPropertyChanged(e); - if (e.PropertyName == "OutputType") { - switch (this.OutputType) { - case OutputType.WinExe: - SetProperty(e.Configuration, e.Platform, - "MyType", "WindowsForms", e.NewLocation, true); - break; - case OutputType.Exe: - SetProperty(e.Configuration, e.Platform, - "MyType", "Console", e.NewLocation, true); - break; - default: - SetProperty(e.Configuration, e.Platform, - "MyType", "Windows", e.NewLocation, true); - break; - } - } - } - - public override IAmbience GetAmbience() - { - return new VBNetAmbience(); - } - - public VBNetProject(ProjectLoadInformation info) - : base(info) - { - InitVB(); - } - - public const string DefaultTargetsFile = @"$(MSBuildToolsPath)\Microsoft.VisualBasic.targets"; - - public VBNetProject(ProjectCreateInformation info) - : base(info) - { - InitVB(); - - this.AddImport(DefaultTargetsFile, null); - - SetProperty("Debug", null, "DefineConstants", "DEBUG=1,TRACE=1", - PropertyStorageLocations.ConfigurationSpecific, true); - SetProperty("Release", null, "DefineConstants", "TRACE=1", - PropertyStorageLocations.ConfigurationSpecific, true); - } - - protected override ParseProjectContent CreateProjectContent() - { - ParseProjectContent pc = base.CreateProjectContent(); - MyNamespaceBuilder.BuildNamespace(this, pc); - return pc; - } - - public override IEnumerable ResolveAssemblyReferences(CancellationToken cancellationToken) - { - ReferenceProjectItem[] additionalItems = { - new ReferenceProjectItem(this, "mscorlib"), - new ReferenceProjectItem(this, "Microsoft.VisualBasic"), - }; - return MSBuildInternals.ResolveAssemblyReferences(this, additionalItems); - } - - void InitVB() - { - reparseReferencesSensitiveProperties.Add("TargetFrameworkVersion"); - reparseCodeSensitiveProperties.Add("DefineConstants"); - } - - public override string Language { - get { return VBNetProjectBinding.LanguageName; } - } - - public override LanguageProperties LanguageProperties { - get { return LanguageProperties.VBNet; } - } - - public override void StartBuild(ProjectBuildOptions options, IBuildFeedbackSink feedbackSink) - { - if (this.MinimumSolutionVersion == Solution.SolutionVersionVS2005) { - MSBuildEngine.StartBuild(this, - options, - feedbackSink, - MSBuildEngine.AdditionalTargetFiles.Concat( - new [] { Path.Combine(MSBuildEngine.SharpDevelopBinPath, "SharpDevelop.CheckMSBuild35Features.targets") })); - } else { - base.StartBuild(options, feedbackSink); - } - } - - public Nullable OptionInfer { - get { return GetValue("OptionInfer", false); } - } - - public Nullable OptionStrict { - get { return GetValue("OptionStrict", false); } - } - - public Nullable OptionExplicit { - get { return GetValue("OptionExplicit", true); } - } - - public Nullable OptionCompare { - get { - string val = GetEvaluatedProperty("OptionCompare"); - - if ("Text".Equals(val, StringComparison.OrdinalIgnoreCase)) - return CompareKind.Text; - - return CompareKind.Binary; - } - } - - bool? GetValue(string name, bool defaultVal) - { - string val; - try { - val = GetEvaluatedProperty(name); - } catch (ObjectDisposedException) { - // This can happen when the project is disposed but the resolver still tries - // to access Option Infer (or similar). - val = null; - } - - if (val == null) - return defaultVal; - - return "On".Equals(val, StringComparison.OrdinalIgnoreCase); - } - - public override string GetDefaultNamespace(string fileName) - { - // use root namespace everywhere, ignore the folder name - return this.RootNamespace; - } - - public override System.CodeDom.Compiler.CodeDomProvider CreateCodeDomProvider() - { - return new Microsoft.VisualBasic.VBCodeProvider(); - } - - public override void GenerateCodeFromCodeDom(CodeCompileUnit compileUnit, TextWriter writer) - { - // the root namespace is implicit in VB - string rootNamespace = this.RootNamespace; - foreach (CodeNamespace ns in ccu.Namespaces) { - if (string.Equals(ns.Name, rootNamespace, StringComparison.OrdinalIgnoreCase)) { - ns.Name = string.Empty; - } else if (ns.Name.StartsWith(rootNamespace + ".", StringComparison.OrdinalIgnoreCase)) { - ns.Name = ns.Name.Substring(rootNamespace.Length + 1); - } - } - base.GenerateCodeFromCodeDom(compileUnit, writer); - } - - protected override ProjectBehavior CreateDefaultBehavior() - { - return new VBProjectBehavior(this, base.CreateDefaultBehavior()); - } - } - - public class VBProjectBehavior : ProjectBehavior - { - public VBProjectBehavior(VBNetProject project, ProjectBehavior next = null) - : base(project, next) - { - - } - - public override ItemType GetDefaultItemType(string fileName) - { - if (string.Equals(Path.GetExtension(fileName), ".vb", StringComparison.OrdinalIgnoreCase)) - return ItemType.Compile; - else - return base.GetDefaultItemType(fileName); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs deleted file mode 100644 index fa0f91d1ba..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs +++ /dev/null @@ -1,234 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using ICSharpCode.Core; -using ICSharpCode.NRefactory; -using ICSharpCode.NRefactory.Parser; -using ICSharpCode.NRefactory.Parser.VB; -using ICSharpCode.SharpDevelop.Editor; - -namespace ICSharpCode.VBNetBinding -{ - public class VBNetBracketSearcher : IBracketSearcher - { - string openingBrackets = "([{"; - string closingBrackets = ")]}"; - - public BracketSearchResult SearchBracket(IDocument document, int offset) - { - if (offset > 0) { - char c = document.GetCharAt(offset - 1); - int index = openingBrackets.IndexOf(c); - int otherOffset = -1; - if (index > -1) - otherOffset = SearchBracketForward(document, offset, openingBrackets[index], closingBrackets[index]); - - index = closingBrackets.IndexOf(c); - if (index > -1) - otherOffset = SearchBracketBackward(document, offset - 2, openingBrackets[index], closingBrackets[index]); - - if (otherOffset > -1) - return new BracketSearchResult(Math.Min(offset - 1, otherOffset), 1, - Math.Max(offset - 1, otherOffset), 1); - - int length; - VBStatement statement; - - int startIndex = FindBeginStatementAroundOffset(document, offset, out statement, out length); - int endIndex = 0; - - if (statement != null) - endIndex = FindEndStatement(document, statement); - else { - endIndex = FindEndStatementAroundOffset(document, offset, out statement); - - if (statement != null) - startIndex = FindBeginStatement(document, statement, document.OffsetToPosition(endIndex), out length); - } - - if (startIndex > -1 && endIndex > -1) - return new BracketSearchResult(startIndex, length, endIndex, - statement.EndStatement.Length); - } - - return null; - } - - #region bracket search - static int SearchBracketBackward(IDocument document, int offset, char openBracket, char closingBracket) - { - bool inString = false; - char ch; - int brackets = -1; - for (int i = offset; i > 0; --i) { - ch = document.GetCharAt(i); - if (ch == openBracket && !inString) { - ++brackets; - if (brackets == 0) return i; - } else if (ch == closingBracket && !inString) { - --brackets; - } else if (ch == '"') { - inString = !inString; - } else if (ch == '\n') { - int lineStart = ScanLineStart(document, i); - if (lineStart >= 0) { // line could have a comment - inString = false; - for (int j = lineStart; j < i; ++j) { - ch = document.GetCharAt(j); - if (ch == '"') inString = !inString; - if (ch == '\'' && !inString) { - // comment found! - // Skip searching in the comment: - i = j; - break; - } - } - } - inString = false; - } - } - return -1; - } - - static int ScanLineStart(IDocument document, int offset) - { - bool hasComment = false; - for (int i = offset - 1; i > 0; --i) { - char ch = document.GetCharAt(i); - if (ch == '\n') { - if (!hasComment) return -1; - return i + 1; - } else if (ch == '\'') { - hasComment = true; - } - } - return 0; - } - - static int SearchBracketForward(IDocument document, int offset, char openBracket, char closingBracket) - { - bool inString = false; - bool inComment = false; - int brackets = 1; - for (int i = offset; i < document.TextLength; ++i) { - char ch = document.GetCharAt(i); - if (ch == '\n') { - inString = false; - inComment = false; - } - if (inComment) continue; - if (ch == '"') inString = !inString; - if (inString) continue; - if (ch == '\'') { - inComment = true; - } else if (ch == openBracket) { - ++brackets; - } else if (ch == closingBracket) { - --brackets; - if (brackets == 0) return i; - } - } - return -1; - } - #endregion - - #region statement search - static int FindBeginStatementAroundOffset(IDocument document, int offset, out VBStatement statement, out int length) - { - length = 0; - statement = null; - return -1; - } - - static int FindEndStatementAroundOffset(IDocument document, int offset, out VBStatement statement) - { - IDocumentLine line = document.GetLineForOffset(offset); - - string interestingText = line.Text.TrimLine().Trim(' ', '\t'); - - //LoggingService.Debug("text: '" + interestingText + "'"); - - foreach (VBStatement s in VBNetFormattingStrategy.Statements) { - Match match = Regex.Matches(interestingText, s.EndRegex, RegexOptions.Singleline | RegexOptions.IgnoreCase).OfType().FirstOrDefault(); - if (match != null) { - //LoggingService.DebugFormatted("Found end statement at offset {1}: {0}", s, offset); - statement = s; - int result = match.Index + (line.Length - line.Text.TrimStart(' ', '\t').Length) + line.Offset; - if (offset >= result && offset <= (result + match.Length)) - return result; - } - } - - statement = null; - return -1; - } - - static int FindBeginStatement(IDocument document, VBStatement statement, Location endLocation, out int length) - { - ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, document.CreateReader()); - - Token currentToken = null; - Token prevToken = null; - - int lookFor = statement.StatementToken; - Stack tokens = new Stack(); - - if (statement.EndStatement == "Next") { - lookFor = Tokens.For; - } - - Token result = null; -// Token firstModifier = null; - - while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) { - if (prevToken == null) - prevToken = currentToken; - -// if (IsModifier(currentToken)) { -// if (firstModifier == null) -// firstModifier = currentToken; -// } else -// firstModifier = null; - - - if (VBNetFormattingStrategy.IsBlockStart(lexer, currentToken, prevToken)) { - tokens.Push(currentToken); - } - if (VBNetFormattingStrategy.IsBlockEnd(currentToken, prevToken)) { - while (tokens.Count > 0 && !VBNetFormattingStrategy.IsMatchingEnd(tokens.Peek(), currentToken)) - tokens.Pop(); - if (tokens.Count > 0) { - Token t = tokens.Pop(); - if (currentToken.Location.Line == endLocation.Line) { - result = t; - break; - } - } - } - - prevToken = currentToken; - } - - if (result != null) { - int endOffset = document.PositionToOffset(result.EndLocation.Line, result.EndLocation.Column); - int offset = document.PositionToOffset(result.Location.Line, result.Location.Column); - length = endOffset - offset; - return offset; - } - - length = 0; - - return -1; - } - - static int FindEndStatement(IDocument document, VBStatement statement) - { - return -1; - } - #endregion - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs deleted file mode 100644 index f3457d140a..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs +++ /dev/null @@ -1,314 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using ICSharpCode.Core; -using ICSharpCode.NRefactory; -using ICSharpCode.NRefactory.Parser; -using ICSharpCode.NRefactory.Parser.VB; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using Dom = ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; -using ICSharpCode.SharpDevelop.Dom.Refactoring; -using ICSharpCode.SharpDevelop.Dom.VBNet; -using ICSharpCode.SharpDevelop.Editor; -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; - -namespace ICSharpCode.VBNetBinding -{ - public class VBNetCompletionBinding : ICodeCompletionBinding - { - static VBNetCompletionBinding instance; - - public static VBNetCompletionBinding Instance { - get { - if (instance == null) - instance = new VBNetCompletionBinding(); - return instance; - } - } - - NRefactoryInsightWindowHandler insightHandler = new NRefactoryInsightWindowHandler(SupportedLanguage.VBNet); - - public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) - { - if (LanguageUtils.IsInsideDocumentationComment(editor) && ch == '<') { - new CommentCompletionItemProvider().ShowCompletion(editor); - return CodeCompletionKeyPressResult.Completed; - } - - if (IsInComment(editor) || IsInString(editor)) - return CodeCompletionKeyPressResult.None; - - if (editor.SelectionLength > 0) { - // allow code completion when overwriting an identifier - int endOffset = editor.SelectionStart + editor.SelectionLength; - // but block code completion when overwriting only part of an identifier - if (endOffset < editor.Document.TextLength && char.IsLetterOrDigit(editor.Document.GetCharAt(endOffset))) - return CodeCompletionKeyPressResult.None; - - editor.Document.Remove(editor.SelectionStart, editor.SelectionLength); - } - - VBNetExpressionFinder ef = new VBNetExpressionFinder(ParserService.GetParseInformation(editor.FileName)); - - ExpressionResult result; - - switch (ch) { - case '(': - if (CodeCompletionOptions.InsightEnabled) { - IInsightWindow insightWindow = editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor)); - if (insightWindow != null) { - insightHandler.InitializeOpenedInsightWindow(editor, insightWindow); - insightHandler.HighlightParameter(insightWindow, 0); - } - return CodeCompletionKeyPressResult.Completed; - } - break; - case ',': - if (CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled) { - IInsightWindow insightWindow; - if (insightHandler.InsightRefreshOnComma(editor, ch, out insightWindow)) - return CodeCompletionKeyPressResult.Completed; - } - break; - case '\n': - TryDeclarationTypeInference(editor, editor.Document.GetLineForOffset(editor.Caret.Offset)); - break; - case '.': - string w = editor.GetWordBeforeCaret(); int index = w.IndexOf('.'); - - if (index > -1 && w.Length - index == 2) - index = editor.Caret.Offset - 2; - else - index = editor.Caret.Offset; - - result = ef.FindExpression(editor.Document.Text, index); - LoggingService.Debug("CC: After dot, result=" + result + ", context=" + result.Context); - if (ShowCompletion(result, editor, ch)) - return CodeCompletionKeyPressResult.Completed; - else - return CodeCompletionKeyPressResult.None; - case '@': - if (editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.') - return CodeCompletionKeyPressResult.None; - goto default; - case ' ': - editor.Document.Insert(editor.Caret.Offset, " "); - result = ef.FindExpression(editor.Document.Text, editor.Caret.Offset); - - string word = editor.GetWordBeforeCaret().Trim(); - if (word.Equals("overrides", StringComparison.OrdinalIgnoreCase) || word.Equals("return", StringComparison.OrdinalIgnoreCase) || !LiteralMayFollow((BitArray)result.Tag) && !OperatorMayFollow((BitArray)result.Tag) && ExpressionContext.IdentifierExpected != result.Context) { - LoggingService.Debug("CC: After space, result=" + result + ", context=" + result.Context); - ShowCompletion(result, editor, ch); - } - return CodeCompletionKeyPressResult.EatKey; - default: - if (CodeCompletionOptions.CompleteWhenTyping) { - int cursor = editor.Caret.Offset; - char prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' '; - char ppChar = cursor > 2 ? editor.Document.GetCharAt(cursor - 2) : ' '; - - result = ef.FindExpression(editor.Document.Text, cursor); - - if ((result.Context != ExpressionContext.IdentifierExpected && char.IsLetter(ch)) && - (!char.IsLetterOrDigit(prevChar) && prevChar != '.')) { - if (prevChar == '@' && ppChar == '.') - return CodeCompletionKeyPressResult.None; - if (IsTypeCharacter(ch, prevChar)) - return CodeCompletionKeyPressResult.None; - if (prevChar == '_') { - result.Expression = '_' + result.Expression; - result.Region = new DomRegion(result.Region.BeginLine, result.Region.BeginColumn - 1, result.Region.EndLine, result.Region.EndColumn); - } - LoggingService.Debug("CC: Beginning to type a word, result=" + result + ", context=" + result.Context); - ShowCompletion(result, editor, ch); - return CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion; - } - } - break; - } - - return CodeCompletionKeyPressResult.None; - } - - static bool IsTypeCharacter(char ch, char prevChar) - { - ch = char.ToUpperInvariant(ch); - - // char type character - if (ch == 'C' && prevChar == '"') - return true; - - // start of hex or octal literal - if (prevChar == '&' && (ch == 'H' || ch == 'O')) - return true; - - if (char.IsDigit(prevChar)) - return true; - - return false; - } - - static bool ShowCompletion(ExpressionResult result, ITextEditor editor, char ch) - { - VBNetCompletionItemList list = CompletionDataHelper.GenerateCompletionData(result, editor, ch); - list.Editor = editor; - list.Window = editor.ShowCompletionWindow(list); - return list.Items.Any(); - } - - #region Helpers - static bool OperatorMayFollow(BitArray array) - { - if (array == null) - return false; - - return array[Tokens.Xor]; - } - - static bool LiteralMayFollow(BitArray array) - { - if (array == null) - return false; - - for (int i = 0; i < array.Length; i++) { - if (array[i] && i >= Tokens.LiteralString && i <= Tokens.LiteralDate) - return true; - } - - return false; - } - - static void GetCommentOrStringState(ITextEditor editor, out bool inString, out bool inComment) - { - ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, editor.Document.CreateReader()); - - Token t = lexer.NextToken(); - bool inXml = false; - - inString = false; - inComment = false; - - while (t.Location < editor.Caret.Position) { - t = lexer.NextToken(); - - if (inXml && (t.Kind != Tokens.Identifier && t.Kind != Tokens.LiteralString && !(t.Kind > Tokens.LiteralDate && t.Kind < Tokens.Colon))) { - inXml = false; - continue; - } - - if (t.Kind > Tokens.LiteralDate && t.Kind < Tokens.Assign) - inXml = true; - } - - if (inXml) { - // TODO - } else { - string lineText = editor.Document.GetLine(editor.Caret.Line).Text; - - for (int i = 0; i < editor.Caret.Column - 1; i++) { - char ch = lineText[i]; - - if (!inComment && ch == '"') - inString = !inString; - if (!inString && ch == '\'') - inComment = true; - } - } - } - - static bool IsInString(ITextEditor editor) - { - bool inString, inComment; - GetCommentOrStringState(editor, out inString, out inComment); - return inString; - } - - static bool IsInComment(ITextEditor editor) - { - bool inString, inComment; - GetCommentOrStringState(editor, out inString, out inComment); - return inComment; - } - #endregion - - public bool CtrlSpace(ITextEditor editor) - { - if (IsInComment(editor)) - return false; - - if (editor.SelectionLength > 0) { - // allow code completion when overwriting an identifier - int endOffset = editor.SelectionStart + editor.SelectionLength; - // but block code completion when overwriting only part of an identifier - if (endOffset < editor.Document.TextLength && char.IsLetterOrDigit(editor.Document.GetCharAt(endOffset))) - return false; - - editor.Document.Remove(editor.SelectionStart, editor.SelectionLength); - } - - int cursor = editor.Caret.Offset; - char prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' '; - bool afterUnderscore = prevChar == '_'; - - if (afterUnderscore) { - cursor--; - prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' '; - } - - VBNetExpressionFinder ef = new VBNetExpressionFinder(ParserService.GetParseInformation(editor.FileName)); - ExpressionResult result = ef.FindExpression(editor.Document.Text, cursor); - LoggingService.Debug("CC: Beginning to type a word, result=" + result + ", context=" + result.Context); - ShowCompletion(result, editor, '\0'); - return true; - } - - static bool TryDeclarationTypeInference(ITextEditor editor, IDocumentLine curLine) - { - string lineText = editor.Document.GetText(curLine.Offset, curLine.Length); - ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new System.IO.StringReader(lineText)); - if (lexer.NextToken().Kind != Tokens.Dim) - return false; - if (lexer.NextToken().Kind != Tokens.Identifier) - return false; - if (lexer.NextToken().Kind != Tokens.As) - return false; - Token t1 = lexer.NextToken(); - if (t1.Kind != Tokens.QuestionMark) - return false; - Token t2 = lexer.NextToken(); - if (t2.Kind != Tokens.Assign) - return false; - string expr = lineText.Substring(t2.Location.Column); - LoggingService.Debug("DeclarationTypeInference: >" + expr + "<"); - ResolveResult rr = ParserService.Resolve(new ExpressionResult(expr), - editor.Caret.Line, - t2.Location.Column, editor.FileName, - editor.Document.Text); - if (rr != null && rr.ResolvedType != null) { - ClassFinder context = new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.Caret.Line, t1.Location.Column); - VBNetAmbience ambience = new VBNetAmbience(); - if (CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context)) - ambience.ConversionFlags = ConversionFlags.None; - else - ambience.ConversionFlags = ConversionFlags.UseFullyQualifiedTypeNames; - string typeName = ambience.Convert(rr.ResolvedType); - using (editor.Document.OpenUndoGroup()) { - int offset = curLine.Offset + t1.Location.Column - 1; - editor.Document.Remove(offset, 1); - editor.Document.Insert(offset, typeName); - } - editor.Caret.Column += typeName.Length - 1; - return true; - } - return false; - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionItemList.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionItemList.cs deleted file mode 100644 index 2524ad2697..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionItemList.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -using ICSharpCode.Core; -using ICSharpCode.NRefactory.Parser.VB; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; -using ICSharpCode.SharpDevelop.Editor; -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; - -namespace ICSharpCode.VBNetBinding -{ - public class VBNetCompletionItemList : NRefactoryCompletionItemList - { - public ITextEditor Editor { get; set; } - - public ICompletionListWindow Window { get; set; } - - public override CompletionItemListKeyResult ProcessInput(char key) - { - if (key == '?' && string.IsNullOrWhiteSpace(Editor.Document.GetText(Window.StartOffset, Window.EndOffset - Window.StartOffset))) - return CompletionItemListKeyResult.NormalKey; - - if (key == '@' && Window.StartOffset > 0 && Editor.Document.GetCharAt(Window.StartOffset - 1) == '.') - return CompletionItemListKeyResult.NormalKey; - - return base.ProcessInput(key); - } - - public override void Complete(CompletionContext context, ICompletionItem item) - { - base.Complete(context, item); - - if (item.Text == "..") { - VBNetCompletionBinding.Instance.CtrlSpace(context.Editor); - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetLanguageBinding.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetLanguageBinding.cs deleted file mode 100644 index 847a4d48a7..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetLanguageBinding.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Editor; - -namespace ICSharpCode.VBNetBinding -{ - /// - /// Description of VBNetLanguageBinding. - /// - public class VBNetLanguageBinding : DefaultLanguageBinding - { - public override IFormattingStrategy FormattingStrategy { - get { return new VBNetFormattingStrategy(); } - } - - public override IBracketSearcher BracketSearcher { - get { return new VBNetBracketSearcher(); } - } - - public override LanguageProperties Properties { - get { return LanguageProperties.VBNet; } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetProjectBinding.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetProjectBinding.cs deleted file mode 100644 index d7f4ab3460..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetProjectBinding.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Xml; -using ICSharpCode.SharpDevelop.Internal.Templates; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.VBNetBinding -{ - public class VBNetProjectBinding : IProjectBinding - { - public const string LanguageName = "VBNet"; - - public string Language - { - get { - return LanguageName; - } - } - - public IProject LoadProject(ProjectLoadInformation info) - { - return new VBNetProject(info); - } - - public IProject CreateProject(ProjectCreateInformation info) - { - return new VBNetProject(info); - } - - public bool HandlingMissingProject { - get { - return false; - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VbcEncodingFixingLogger.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VbcEncodingFixingLogger.cs deleted file mode 100644 index e6cd73ae28..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VbcEncodingFixingLogger.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Text; -using ICSharpCode.SharpDevelop.Project; -using Microsoft.Build.Framework; -using System.IO; - -namespace ICSharpCode.VBNetBinding -{ - /// - /// Fixes SD2-995 : Special characters not correctly encoded for languages others than English - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Vbc")] - public sealed class VbcEncodingFixingLogger : IMSBuildLoggerFilter - { - public IMSBuildChainedLoggerFilter CreateFilter(MSBuildEngine engine, IMSBuildChainedLoggerFilter nextFilter) - { - return new VbcLoggerImpl(nextFilter); - } - - sealed class VbcLoggerImpl : IMSBuildChainedLoggerFilter - { - readonly IMSBuildChainedLoggerFilter nextFilter; - - public VbcLoggerImpl(IMSBuildChainedLoggerFilter nextFilter) - { - this.nextFilter = nextFilter; - } - - static string FixEncoding(string text) - { - if (text == null) - return text; - return Encoding.Default.GetString(ICSharpCode.SharpDevelop.Util.ProcessRunner.OemEncoding.GetBytes(text)); - } - - public void HandleError(BuildError error) - { - error.ErrorText = FixEncoding(error.ErrorText); - error.FileName = FixEncoding(error.FileName); - error.Column = FixColumn(error.FileName, error.Line, error.Column); - nextFilter.HandleError(error); - } - - public void HandleBuildEvent(Microsoft.Build.Framework.BuildEventArgs e) - { - nextFilter.HandleBuildEvent(e); - if (e is TaskFinishedEventArgs && lastFile != null) { - lastFile.Close(); - lastFile = null; - } - } - - string lastFileName, lastLineText; - StreamReader lastFile; - int lastLine; - - // fixes SD-1746 - VB compiler errors are shown in incorrect column if the line contains tabs - // (http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1746&PROJID=4) - int FixColumn(string fileName, int line, int column) - { - if (!File.Exists(fileName) || line < 1 || column < 1) - return column; - - if (fileName != lastFileName || line < lastLine || lastFile == null) { - if (lastFile != null) - lastFile.Close(); - lastFile = new StreamReader(fileName); - lastFileName = fileName; - lastLineText = ""; - lastLine = 0; - } - - while (lastLine < line && lastLineText != null) { - lastLineText = lastFile.ReadLine(); - lastLine++; - } - - if (!string.IsNullOrEmpty(lastLineText)) { - for (int i = 0; i < column && i < lastLineText.Length; i++) { - if (lastLineText[i] == '\t') - column -= 3; - } - } - - return column; - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.addin b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.addin index e1f71368ce..e45724ad67 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.addin +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.addin @@ -11,13 +11,7 @@ - - - - - - - - - - - - - - - - - + + - + class = "ICSharpCode.VBNetBinding.OptionPanels.ProjectImports"/> --> - - - - - - - - diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj.user b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj.user deleted file mode 100644 index be50c2622a..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj.user +++ /dev/null @@ -1,10 +0,0 @@ - - - 8.0.50215 - ShowAllFiles - 0 - - - ..\..\..\..\..\bin\SharpDevelop.exe - - \ No newline at end of file diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.vbproj similarity index 63% rename from src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj rename to src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.vbproj index d88fa1f552..6af2fbbe20 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.vbproj @@ -1,17 +1,17 @@  - + Debug AnyCPU 8.0.50630 2.0 - {BF38FB72-B380-4196-AF8C-95749D726C61} + {6D209CBB-D8C1-478A-BC30-D3FC87B7858F} ICSharpCode.VBNetBinding Library 4 False False - v4.0 + v4.5 OnSuccessfulBuild Library File @@ -22,8 +22,7 @@ AnyCPU 4096 ICSharpCode.VBNetBinding - - + true @@ -42,6 +41,11 @@ None + + + + + @@ -54,49 +58,36 @@ 4.0 - - - - - - - BuildOptions.xaml - Code - - - ProjectImports.xaml - Code + + Configuration\GlobalAssemblyInfo.vb - - TextEditorOptions.xaml - Code + + + + BuildOptions.xaml - - - - - - - - + + + + + + Always - - - - - Configuration\GlobalAssemblyInfo.cs - - - - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} - NRefactory + + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} + ICSharpCode.AvalonEdit + False + + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory False @@ -114,11 +105,6 @@ ICSharpCode.Core.Presentation False - - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} - ICSharpCode.SharpDevelop.Dom - False - {8035765F-D51F-4A0C-A746-2FD100E19419} ICSharpCode.SharpDevelop.Widgets @@ -126,9 +112,10 @@ - - - + + + + - + \ No newline at end of file diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetProject.vb b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetProject.vb new file mode 100644 index 0000000000..fe555aea52 --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetProject.vb @@ -0,0 +1,152 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +Imports System.CodeDom +Imports System.ComponentModel +Imports System.Collections.Generic +Imports System.IO +Imports System.Linq +Imports System.Threading.Tasks +Imports System.Threading + +Imports ICSharpCode.Core +Imports ICSharpCode.SharpDevelop +Imports ICSharpCode.SharpDevelop.Project + +Public Class VBNetProject + Inherits CompilableProject + + Protected Overrides Sub OnPropertyChanged(e As ProjectPropertyChangedEventArgs) + MyBase.OnPropertyChanged(e) + If e.PropertyName = "OutputType" Then + Select Case Me.OutputType + Case OutputType.WinExe + SetProperty(e.Configuration, e.Platform, "MyType", "WindowsForms", e.NewLocation, True) + Exit Select + Case OutputType.Exe + SetProperty(e.Configuration, e.Platform, "MyType", "Console", e.NewLocation, True) + Exit Select + Case Else + SetProperty(e.Configuration, e.Platform, "MyType", "Windows", e.NewLocation, True) + Exit Select + End Select + End If + End Sub + + Public Sub New(info As ProjectLoadInformation) + MyBase.New(info) + InitVB() + End Sub + + Public Const DefaultTargetsFile As String = "$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" + + Public Sub New(info As ProjectCreateInformation) + MyBase.New(info) + InitVB() + + Me.AddImport(DefaultTargetsFile, Nothing) + + SetProperty("Debug", Nothing, "DefineConstants", "DEBUG=1,TRACE=1", PropertyStorageLocations.ConfigurationSpecific, True) + SetProperty("Release", Nothing, "DefineConstants", "TRACE=1", PropertyStorageLocations.ConfigurationSpecific, True) + End Sub + + Public Overrides Function ResolveAssemblyReferences(cancellationToken As CancellationToken) As IEnumerable(Of ReferenceProjectItem) + Dim additionalItems As ReferenceProjectItem() = {New ReferenceProjectItem(Me, "mscorlib"), New ReferenceProjectItem(Me, "Microsoft.VisualBasic")} + Return SD.MSBuildEngine.ResolveAssemblyReferences(Me, additionalItems) + End Function + + Private Sub InitVB() + reparseReferencesSensitiveProperties.Add("TargetFrameworkVersion") + reparseCodeSensitiveProperties.Add("DefineConstants") + End Sub + + Public Overrides ReadOnly Property Language() As String + Get + Return VBNetProjectBinding.LanguageName + End Get + End Property + + Public Overrides Function BuildAsync(options As ProjectBuildOptions, feedbackSink As IBuildFeedbackSink, progressMonitor As IProgressMonitor) As Task(Of Boolean) + If Me.MinimumSolutionVersion = SolutionFormatVersion.VS2005 Then + Return SD.MSBuildEngine.BuildAsync(Me, options, feedbackSink, progressMonitor.CancellationToken, { Path.Combine(FileUtility.ApplicationRootPath, "bin\SharpDevelop.CheckMSBuild35Features.targets") }) + End If + + Return MyBase.BuildAsync(options, feedbackSink, progressMonitor) + End Function + + Public ReadOnly Property OptionInfer() As Nullable(Of Boolean) + Get + Return GetValue("OptionInfer", False) + End Get + End Property + + Public ReadOnly Property OptionStrict() As Nullable(Of Boolean) + Get + Return GetValue("OptionStrict", False) + End Get + End Property + + Public ReadOnly Property OptionExplicit() As Nullable(Of Boolean) + Get + Return GetValue("OptionExplicit", True) + End Get + End Property + + Public ReadOnly Property OptionCompare() As Nullable(Of CompareKind) + Get + Dim val As String = GetEvaluatedProperty("OptionCompare") + + If "Text".Equals(val, StringComparison.OrdinalIgnoreCase) Then + Return CompareKind.Text + End If + + Return CompareKind.Binary + End Get + End Property + + Private Function GetValue(name As String, defaultVal As Boolean) As System.Nullable(Of Boolean) + Dim val As String + Try + val = GetEvaluatedProperty(name) + Catch generatedExceptionName As ObjectDisposedException + ' This can happen when the project is disposed but the resolver still tries + ' to access Option Infer (or similar). + val = Nothing + End Try + + If val Is Nothing Then + Return defaultVal + End If + + Return "On".Equals(val, StringComparison.OrdinalIgnoreCase) + End Function + + Public Overrides Function GetDefaultNamespace(fileName As String) As String + ' use root namespace everywhere, ignore the folder name + Return Me.RootNamespace + End Function + + Public Overrides Function CreateCodeDomProvider() As System.CodeDom.Compiler.CodeDomProvider + Return New Microsoft.VisualBasic.VBCodeProvider() + End Function + + Protected Overrides Function CreateDefaultBehavior() As ProjectBehavior + Return New VBProjectBehavior(Me, MyBase.CreateDefaultBehavior()) + End Function +End Class + +Public Class VBProjectBehavior + Inherits ProjectBehavior + Public Sub New(project As VBNetProject, Optional [next] As ProjectBehavior = Nothing) + + MyBase.New(project, [next]) + End Sub + + Public Overrides Function GetDefaultItemType(fileName As String) As ItemType + If String.Equals(Path.GetExtension(fileName), ".vb", StringComparison.OrdinalIgnoreCase) Then + Return ItemType.Compile + Else + Return MyBase.GetDefaultItemType(fileName) + End If + End Function +End Class diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetProjectBinding.vb b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetProjectBinding.vb new file mode 100644 index 0000000000..f20f11f04a --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/VBNetProjectBinding.vb @@ -0,0 +1,30 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +Imports System.Xml +Imports ICSharpCode.SharpDevelop.Project + +Public Class VBNetProjectBinding + Implements IProjectBinding + Public Const LanguageName As String = "VBNet" + + Public ReadOnly Property Language() As String Implements IProjectBinding.Language + Get + Return LanguageName + End Get + End Property + + Public Function LoadProject(info As ProjectLoadInformation) As IProject Implements IProjectBinding.LoadProject + Return New VBNetProject(info) + End Function + + Public Function CreateProject(info As ProjectCreateInformation) As IProject Implements IProjectBinding.CreateProject + Return New VBNetProject(info) + End Function + + Public ReadOnly Property HandlingMissingProject() As Boolean Implements IProjectBinding.HandlingMissingProject + Get + Return False + End Get + End Property +End Class diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/VbcEncodingFixingLogger.vb b/src/AddIns/BackendBindings/VBNetBinding/Project/VbcEncodingFixingLogger.vb new file mode 100644 index 0000000000..5a84e57e25 --- /dev/null +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/VbcEncodingFixingLogger.vb @@ -0,0 +1,88 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +Imports System.Text +Imports ICSharpCode.SharpDevelop.Project +Imports Microsoft.Build.Framework +Imports System.IO + +''' +''' Fixes SD2-995 : Special characters not correctly encoded for languages others than English +''' + _ +Public NotInheritable Class VbcEncodingFixingLogger + Implements IMSBuildLoggerFilter + Public Function CreateFilter(context As IMSBuildLoggerContext, nextFilter As IMSBuildChainedLoggerFilter) As IMSBuildChainedLoggerFilter Implements IMSBuildLoggerFilter.CreateFilter + Return New VbcLoggerImpl(nextFilter) + End Function + + Private NotInheritable Class VbcLoggerImpl + Implements IMSBuildChainedLoggerFilter + ReadOnly nextFilter As IMSBuildChainedLoggerFilter + + Public Sub New(nextFilter As IMSBuildChainedLoggerFilter) + Me.nextFilter = nextFilter + End Sub + + Private Shared Function FixEncoding(text As String) As String + If text Is Nothing Then + Return text + End If + Return Encoding.[Default].GetString(ICSharpCode.SharpDevelop.ProcessRunner.OemEncoding.GetBytes(text)) + End Function + + Public Sub HandleError([error] As BuildError) Implements IMSBuildChainedLoggerFilter.HandleError + [error].ErrorText = FixEncoding([error].ErrorText) + [error].FileName = FixEncoding([error].FileName) + [error].Column = FixColumn([error].FileName, [error].Line, [error].Column) + nextFilter.HandleError([error]) + End Sub + + Public Sub HandleBuildEvent(e As Microsoft.Build.Framework.BuildEventArgs) Implements IMSBuildChainedLoggerFilter.HandleBuildEvent + nextFilter.HandleBuildEvent(e) + If TypeOf e Is TaskFinishedEventArgs AndAlso lastFile IsNot Nothing Then + lastFile.Close() + lastFile = Nothing + End If + End Sub + + Private lastFileName As String, lastLineText As String + Private lastFile As StreamReader + Private lastLine As Integer + + ' fixes SD-1746 - VB compiler errors are shown in incorrect column if the line contains tabs + ' (http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1746&PROJID=4) + Private Function FixColumn(fileName As String, line As Integer, column As Integer) As Integer + If Not File.Exists(fileName) OrElse line < 1 OrElse column < 1 Then + Return column + End If + + If fileName <> lastFileName OrElse line < lastLine OrElse lastFile Is Nothing Then + If lastFile IsNot Nothing Then + lastFile.Close() + End If + lastFile = New StreamReader(fileName) + lastFileName = fileName + lastLineText = "" + lastLine = 0 + End If + + While lastLine < line AndAlso lastLineText IsNot Nothing + lastLineText = lastFile.ReadLine() + lastLine += 1 + End While + + If Not String.IsNullOrEmpty(lastLineText) Then + Dim i As Integer = 0 + While i < column AndAlso i < lastLineText.Length + If lastLineText(i) = ControlChars.Tab Then + column -= 3 + End If + i += 1 + End While + End If + + Return column + End Function + End Class +End Class diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs deleted file mode 100644 index a16f27a629..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - [TestFixture] - public class CodeCompletionTests : TextEditorBasedTests - { - [Test] - public void TestEmptyFile() - { - TestKeyPress("|", 'o', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, - list => { - Assert.IsTrue(list.Items.Any()); - Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); - ContainsAll(list.Items.Select(item => item.Text).ToArray(), - "Class", "Delegate", "Friend", "Imports", "Module", - "Namespace", "Option", "Private", "Protected", "Public", - "Shadows", "Structure", "Interface", "Enum", "Partial", "NotInheritable"); - } - ); - } - - [Test] - public void TestOptions() - { - TestKeyPress("Option|\n", ' ', CodeCompletionKeyPressResult.EatKey, - list => { - Assert.IsTrue(list.Items.Any()); - Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); - ContainsAll(list.Items.Select(item => item.Text).ToArray(), - "Explicit", "Infer", "Compare", "Strict"); - } - ); - } - - [Test] - public void TestOptionCompare() - { - TestKeyPress("Option Compare|\n", ' ', CodeCompletionKeyPressResult.EatKey, - list => { - Assert.IsTrue(list.Items.Any()); - Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); - ContainsAll(list.Items.Select(item => item.Text).ToArray(), - "Text", "Binary"); - } - ); - } - - [Test] - public void TestOnOffOptions() - { - foreach (string option in new[] { "Infer", "Strict", "Explicit" }) { - TestKeyPress(string.Format("Option {0} |\n", option), 'o', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, - list => { - Assert.IsTrue(list.Items.Any()); - Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); - ContainsAll(list.Items.Select(item => item.Text).ToArray(), - "On", "Off"); - } - ); - } - } - - void ContainsAll(ICollection items, params string[] expected) - { -// Assert.AreEqual(expected.Length, items.Count); - - foreach (string element in expected) - Assert.Contains(element, items); - } - - [Test] - public void TestDotAfterDigit() - { - string text = @"Module Test - Public Function fn() As Double - Dim f As Double - f = 1| - End Function -End Module"; - - TestKeyPress(text, '.', CodeCompletionKeyPressResult.None, list => Assert.IsFalse(list.Items.Any())); - } - - [Test] - public void TestDotAfterIdentifier() - { - string text = @"Module Test - Public Function fn(x As Double) As Double - Dim f As Double - f = x| - End Function -End Module"; - - TestKeyPress(text, '.', CodeCompletionKeyPressResult.Completed, list => Assert.IsTrue(list.Items.Any())); - } - - [Test] - public void TestWithBlockCtrlSpace() - { - string text = @"Module Test - Sub Test2(a As Exception) - With a - | - End With - End Sub -End Module"; - - // TODO seems to be wrong! - - TestCtrlSpace(text, true, list => Assert.IsFalse(list.Items.Any(i => i.Text == "InnerException"))); - } - - [Test] - public void TestLocalVariablesAvailableAtEndOfForLoop() - { - string text = @"Module Test - Public Sub f() - Dim cheeses = { ""cheddar"", ""brie"", ""edam"" } - For Each cheese As String In cheeses - Dim gouda = ""is tasty"" - | - Next - End Sub -End Module"; - - TestKeyPress(text, 'g', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, list => Assert.IsTrue(list.Items.Any(i => i.Text == "gouda"))); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/Configuration/AssemblyInfo.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/Configuration/AssemblyInfo.cs deleted file mode 100644 index e9174e0526..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/Configuration/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System.Reflection; -using NUnit.Framework; - -// Information about this assembly is defined by the following -// attributes. -// -// change them to the information which is associated with the assembly -// you compile. - -[assembly: AssemblyTitle("VBNetBinding.Tests")] -[assembly: AssemblyDescription("VB.NET language binding for #develop")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Run unit tests on STA thread. -[assembly: RequiresSTA] diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndOperatorTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndOperatorTests.cs deleted file mode 100644 index cf6d71ef2a..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndOperatorTests.cs +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.SharpDevelop.Editor.AvalonEdit; -using System; -using ICSharpCode.AvalonEdit; -using ICSharpCode.Core; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - /// - /// Tests that Operator overrides have "End Operator" added after the user presses the return key. - /// - [TestFixture] - public class EndOperatorTests - { - [TestFixtureSetUp] - public void SetUpFixture() - { - if (!PropertyService.Initialized) { - PropertyService.InitializeService(String.Empty, String.Empty, "VBNetBindingTests"); - } - } - - /// - /// Checks that when the user presses the return key after the Operator line that the - /// expected code is generated. - /// - void RunFormatLineTest(string code, string expectedCode, int expectedOffset) - { - string foo = "As Foo\r\n"; - int cursorOffset = code.IndexOf(foo) + foo.Length; - - AvalonEditTextEditorAdapter editor = new AvalonEditTextEditorAdapter(new TextEditor()); - editor.Document.Text = code; - editor.Caret.Offset = cursorOffset; - VBNetFormattingStrategy formattingStrategy = new VBNetFormattingStrategy(); - formattingStrategy.FormatLine(editor, '\n'); - - Assert.AreEqual(expectedCode, editor.Document.Text); - Assert.AreEqual(expectedOffset, editor.Caret.Offset); - } - - [Test] - public void AdditionOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void AdditionOperatorWithExistingEndOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "\tEnd Operator\r\n" + - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void ExistingEndOperatorHasWhitespaceInbetween() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "\tEnd Operator\r\n" + - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void AdditionOperatorHasWhitespaceAfterOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator + (ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator + (ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator + (ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void AdditionOperatorWithNoWhitespace() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator+(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator+(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator+(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void SubtractionOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator -(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator -(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator -(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void IsTrueOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator IsTrue(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator IsTrue(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator IsTrue(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void MultiplicationOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator *(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator *(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator *(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void DivisionOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator /(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator /(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator /(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void IntegerDivisionOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator \\(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator \\(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator \\(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void StringConcatenationOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator &(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator &(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator &(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void ExponentationcationOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator ^(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator ^(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator ^(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void EqualityOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator =(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator =(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator =(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void GreaterThanOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator >(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator >(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator >(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void LessThanOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator <(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator <(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator <(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - [Test] - public void InequalityOperator() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared Operator <>(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared Operator <>(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t\r\n" + - "\tEnd Operator\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared Operator <>(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - - /// - /// Check that a method that starts with "Operator" is ignored. - /// - [Test] - public void MethodStartsWithOperatorString() - { - string code = "Public Class Foo\r\n" + - "\tPublic Shared OperatorIgnore(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Shared OperatorIgnore(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Shared OperatorIgnore(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" + - "\t").Length; - - RunFormatLineTest(code, expectedCode, expectedOffset); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndSubTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndSubTests.cs deleted file mode 100644 index fd3624b556..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndSubTests.cs +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.AvalonEdit; -using ICSharpCode.Core; -using ICSharpCode.SharpDevelop.Editor.AvalonEdit; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - /// - /// Tests that Operator overrides have "End Operator" added after the user presses the return key. - /// - [TestFixture] - public class EndInsertionTests - { - [TestFixtureSetUp] - public void SetUpFixture() - { - if (!PropertyService.Initialized) { - PropertyService.InitializeService(String.Empty, String.Empty, "VBNetBindingTests"); - } - } - - [Test] - public void EndSub() - { - string code = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string bar = "Bar\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\t\r\n" + - "\tEnd Sub\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - - - void RunTest(string code, int cursorOffset, string expectedCode, int expectedOffset, char keyPressed) - { - AvalonEditTextEditorAdapter editor = new AvalonEditTextEditorAdapter(new TextEditor()); - editor.Document.Text = code; - editor.Caret.Offset = cursorOffset; - VBNetFormattingStrategy formattingStrategy = new VBNetFormattingStrategy(); - formattingStrategy.FormatLine(editor, keyPressed); - Assert.AreEqual(expectedCode, editor.Document.Text); - Assert.AreEqual(expectedOffset, editor.Caret.Offset); - } - - [Test] - public void EndIf() - { - string code = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tIf True Then\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "\tEnd Sub\r\n" + - "End Class"; - - string bar = "Then\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tIf True Then\r\n" + - "\t\t\t\r\n" + - "\t\tEnd If\r\n" + - "\tEnd Sub\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tIf True Then\r\n" + - "\t\t\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - - [Test] - public void EndUsing() - { - string code = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tUsing a As New StreamReader()\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "\tEnd Sub\r\n" + - "End Class"; - - string bar = "Using a As New StreamReader()\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tUsing a As New StreamReader()\r\n" + - "\t\t\t\r\n" + - "\t\tEnd Using\r\n" + - "\tEnd Sub\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tUsing a As New StreamReader()\r\n" + - "\t\t\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - - [Test] - public void EndSyncLock() - { - string code = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tSyncLock a\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "\tEnd Sub\r\n" + - "End Class"; - - string bar = "SyncLock a\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tSyncLock a\r\n" + - "\t\t\t\r\n" + - "\t\tEnd SyncLock\r\n" + - "\tEnd Sub\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tSyncLock a\r\n" + - "\t\t\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - - [Test] - public void SingleLineIf() - { - string code = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tIf True Then _\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "\tEnd Sub\r\n" + - "End Class"; - - string bar = "Then _\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tIf True Then _\r\n" + - "\t\t\t\r\n" + - "\tEnd Sub\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\tIf True Then _\r\n" + - "\t\t\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - - [Test] - public void AutomaticPropertyWithInitializer() - { - string code = "Public Class Foo\r\n" + - "\tPublic Property Bar As Boolean = True\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string bar = "= True\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Property Bar As Boolean = True\r\n" + - "\t\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Property Bar As Boolean = True\r\n" + - "\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - - [Test] - public void StandardProperty() - { - string code = "Public Class Foo\r\n" + - "\tPublic Property Bar As Boolean\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Class"; - - string bar = "As Boolean\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Class Foo\r\n" + - "\tPublic Property Bar As Boolean\r\n" + - "\t\t\r\n" + - "\tEnd Property\r\n" + - "End Class"; - - int expectedOffset = ("Public Class Foo\r\n" + - "\tPublic Property Bar As Boolean\r\n" + - "\t\t").Length; - - RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n'); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs deleted file mode 100644 index da07315820..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs +++ /dev/null @@ -1,595 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.SharpDevelop.Editor.AvalonEdit; -using System; -using ICSharpCode.AvalonEdit; -using ICSharpCode.Core; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - [TestFixture] - public class IndentationTests - { - [Test] - public void SimpleInterfaceTest() - { - string code = @"Interface t -Sub Test() -Sub Test2() -End Interface"; - - string expectedCode = @"Interface t - Sub Test() - Sub Test2() -End Interface"; - - RunFormatTest(code, expectedCode); - } - - [Test] - public void SimpleInterfaceWithModifierTest() - { - string code = @"Public Interface t -Sub Test() -Sub Test2() -End Interface"; - - string expectedCode = @"Public Interface t - Sub Test() - Sub Test2() -End Interface"; - - RunFormatTest(code, expectedCode); - } - - [Test] - public void InterfaceWithNewLineAtEndTest() - { - string code = @"Interface t -Sub Test() -Sub Test2() - -End Interface"; - - string expectedCode = @"Interface t - Sub Test() - Sub Test2() - -End Interface"; - - RunFormatTest(code, expectedCode); - } - - [Test] - public void SD1775_Fix() - { - string expected = @"Public Class Test - Private Sub Tester() - B = New Burger With {Cheese = True, _ - Lettuce = True, _ - Tomato = True, _ - CookLevel = MeatCookLevel.WellDone} - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -B = New Burger With {Cheese = True, _ -Lettuce = True, _ -Tomato = True, _ -CookLevel = MeatCookLevel.WellDone} -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void Simple() - { - string expected = @"' -' Created by SharpDevelop. -' User: Siegfried -' Date: 25.02.2011 -' Time: 14:41 -' -' To change this template use Tools | Options | Coding | Edit Standard Headers. -' -Imports Microsoft.VisualBasic.ApplicationServices - -Namespace My - ' This file controls the behaviour of the application. - Partial Class MyApplication - Public Sub New() - MyBase.New(AuthenticationMode.Windows) - Me.IsSingleInstance = False - Me.EnableVisualStyles = True - Me.SaveMySettingsOnExit = True - Me.ShutDownStyle = ShutdownMode.AfterMainFormCloses - End Sub - - Protected Overrides Sub OnCreateMainForm() - Me.MainForm = My.Forms.MainForm - End Sub - End Class -End Namespace"; - - string code = @"' -' Created by SharpDevelop. -' User: Siegfried -' Date: 25.02.2011 -' Time: 14:41 -' -' To change this template use Tools | Options | Coding | Edit Standard Headers. -' -Imports Microsoft.VisualBasic.ApplicationServices - -Namespace My -' This file controls the behaviour of the application. -Partial Class MyApplication -Public Sub New() -MyBase.New(AuthenticationMode.Windows) -Me.IsSingleInstance = False -Me.EnableVisualStyles = True -Me.SaveMySettingsOnExit = True -Me.ShutDownStyle = ShutdownMode.AfterMainFormCloses -End Sub - -Protected Overrides Sub OnCreateMainForm() -Me.MainForm = My.Forms.MainForm -End Sub -End Class -End Namespace"; - - RunFormatTest(code, expected); - } - - [Test] - public void ArrayInitializerTest() - { - string expected = @"Public Class Test - Private Sub Tester() - test(asdf, _ - asdf, _ - asdf, _ - asdf) - - Dim test As Integer() = { _ - 2,2,3,34,4,5 _ - } - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -test(asdf, _ -asdf, _ -asdf, _ -asdf) - -Dim test As Integer() = { _ -2,2,3,34,4,5 _ -} -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void IfLineContinuationTest() - { - string expected = @"Public Class Test - Private Sub Tester() - If True _ - Then - test() - End If - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -If True _ -Then -test() -End If -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void IfMultiLineContinuationTest() - { - string expected = @"Public Class Test - Private Sub Tester() - If IsCorrect(i) _ - And _ - IsHIgherThan(i, 5) _ - Then - test() - End If - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -If IsCorrect(i) _ -And _ -IsHIgherThan(i, 5) _ -Then -test() -End If -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void ElseIfMultiLineContinuationTest() - { - string expected = @"Public Class Test - Private Sub Tester() - If True Then - 'CODE HERE - Else If False And _ - False Then - 'CODE HERE1 - End If - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -If True Then -'CODE HERE -Else If False And _ -False Then -'CODE HERE1 -End If -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void SelectCaseTest() - { - string expected = @"Public Class Test - Private Sub Tester() - Select Case a - Case 0 - DoSomething() - ' TEST CASE 0 - Case 1 - 'TEST CASE 1 - Case 2 - 'TEST CASE 2 - Case Else - DoElse() - End Select - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -Select Case a -Case 0 -DoSomething() -' TEST CASE 0 -Case 1 -'TEST CASE 1 -Case 2 -'TEST CASE 2 -Case Else -DoElse() -End Select -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void SelectCaseTest2() - { - string expected = @"Public Class Test - Private Sub Tester() - Select Case a - Case 0 - DoSomething() - Case 1 - Case 2 - Case Else - DoElse() - End Select - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -Select Case a -Case 0 -DoSomething() -Case 1 -Case 2 -Case Else -DoElse() -End Select -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void WithTest() - { - string expected = @"Public Class Test - Private Sub Tester() - With a - If True Then - ' Test - ElseIf False Then - ' Test3 - Else - ' Test2 - End If - End With - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -With a -If True Then -' Test -ElseIf False Then -' Test3 -Else -' Test2 -End If -End With -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void WithTest2() - { - string expected = @"Public Class Test - Private Sub Tester() - With a - If True Then - ' Test - ElseIf False Then - ' Test3 - Else - Try - DoSomething() - Catch ex As Exception - 'Handle - End Try - End If - End With - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -With a -If True Then -' Test -ElseIf False Then -' Test3 -Else -Try -DoSomething() -Catch ex As Exception -'Handle -End Try -End If -End With -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test, Ignore] - // TODO : find out why unit test does not work, but normal run works - public void FunctionLambda() - { - string expected = @"Public Class Test - Private Sub Tester() - Dim increment1 = Function(x) x + 1 - Dim increment2 = Function(x) - Return x + 2 - End Function - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -Dim increment1 = Function(x) x + 1 -Dim increment2 = Function(x) -Return x + 2 -End Function -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test, Ignore] - // TODO : find out why unit test does not work, but normal run works - public void SubLambda() - { - string expected = @"Public Class Test - Private Sub Tester() - Dim writeline1 = Sub(x) Console.WriteLine(x) - Dim writeline2 = Sub(x) - Console.WriteLine(x) - End Sub - End Sub -End Class"; - - string code = @"Public Class Test -Private Sub Tester() -Dim writeline1 = Sub(x) Console.WriteLine(x) -Dim writeline2 = Sub(x) -Console.WriteLine(x) -End Sub -End Sub -End Class"; - - RunFormatTest(code, expected); - } - - [Test] - public void Region() - { - string expected = @"Module Program - #Region Test - - #End Region - - Sub asdf() - - End Sub -End Module"; - - string code = @"Module Program -#Region Test - -#End Region - -Sub asdf() - -End Sub -End Module"; - - RunFormatTest(code, expected); - } - - [Test] - public void Attribute() - { - string expected = @"Module Core - _ - Sub Main - - End Sub -End Module"; - - string code = @"Module Core - _ -Sub Main - -End Sub -End Module"; - - RunFormatTest(code, expected); - } - - [Test] - public void Attribute2() - { - string expected = @"Module Core - _ - Sub Main - - End Sub -End Module"; - - string code = @"Module Core - _ -Sub Main - -End Sub -End Module"; - - RunFormatTest(code, expected); - } - - [Test] - public void ForNextOneLine() - { - string expected = @"Module Core - Sub Main - Dim a = 1 - For i = 0 To 10 : Console.WriteLine(i) : Next - Dim b = 2 - End Sub -End Module"; - - string code = @"Module Core -Sub Main -Dim a = 1 -For i = 0 To 10 : Console.WriteLine(i) : Next -Dim b = 2 -End Sub -End Module"; - - RunFormatTest(code, expected); - } - - [Test] - public void RandomNext() - { - string expected = @"Module Core - Public Function GetRandomNumber( _ - Optional ByVal Low As Integer = 1, _ - Optional ByVal High As Integer = 100) As Integer - ' Returns a random number, - ' between the optional Low and High parameters - Return objRandom.Next(Low, High + 1) - End Function -End Module"; - - string code = @"Module Core -Public Function GetRandomNumber( _ -Optional ByVal Low As Integer = 1, _ -Optional ByVal High As Integer = 100) As Integer -' Returns a random number, -' between the optional Low and High parameters -Return objRandom.Next(Low, High + 1) -End Function -End Module"; - - RunFormatTest(code, expected); - } - - void RunFormatTest(string code, string expectedCode) - { - AvalonEditTextEditorAdapter editor = new AvalonEditTextEditorAdapter(new TextEditor()); - editor.Document.Text = code; - VBNetFormattingStrategy formattingStrategy = new VBNetFormattingStrategy(); - formattingStrategy.IndentLines(editor, 1, editor.Document.TotalNumberOfLines); - - Console.WriteLine(editor.Document.Text); - - Assert.AreEqual(expectedCode, editor.Document.Text); - } - - [TestFixtureSetUp] - public void Init() - { - if (!PropertyService.Initialized) { - PropertyService.InitializeService(String.Empty, String.Empty, "VBNetBindingTests"); - } - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/InterfaceTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/InterfaceTests.cs deleted file mode 100644 index 87f656fe75..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/InterfaceTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.AvalonEdit; -using System; -using ICSharpCode.Core; -using ICSharpCode.SharpDevelop.Editor.AvalonEdit; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - /// - /// Tests the special case of an interface. for ex. no insertion of End-Tags etc. - /// - [TestFixture] - public class InterfaceTests - { - [TestFixtureSetUp] - public void SetUpFixture() - { - if (!PropertyService.Initialized) { - PropertyService.InitializeService(String.Empty, String.Empty, "VBNetBindingTests"); - } - } - - [Test] - public void InterfaceEndSub() - { - string code = "Public Interface Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\r\n" + // This extra new line is required. This is the new line just entered by the user. - "End Interface"; - - string bar = "Sub Bar\r\n"; - int cursorOffset = code.IndexOf(bar) + bar.Length; - - string expectedCode = "Public Interface Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t\r\n" + - "End Interface"; - - int expectedOffset = ("Public Interface Foo\r\n" + - "\tPublic Sub Bar\r\n" + - "\t").Length; - - AvalonEditTextEditorAdapter editor = new AvalonEditTextEditorAdapter(new TextEditor()); - editor.Document.Text = code; - editor.Caret.Offset = cursorOffset; - VBNetFormattingStrategy formattingStrategy = new VBNetFormattingStrategy(); - formattingStrategy.FormatLine(editor, '\n'); - - Assert.AreEqual(expectedCode, editor.Document.Text); - Assert.AreEqual(expectedOffset, editor.Caret.Offset); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/LanguageUtilsTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/LanguageUtilsTests.cs deleted file mode 100644 index 407777e83e..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/LanguageUtilsTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - [TestFixture] - public class LanguageUtilsTests - { - [Test] - public void TrimPreprocessorDirectives1() - { - string input = " #Region Test"; - string expectedOutput = " "; - - TestTrimPreprocessorDirectives(input, expectedOutput); - } - - [Test] - public void TrimPreprocessorDirectives2() - { - string input = "Dim a# = 12.0"; - string expectedOutput = "Dim a# = 12.0"; - - TestTrimPreprocessorDirectives(input, expectedOutput); - } - - [Test] - public void TrimPreprocessorDirectives3() - { - string input = "Dim a = 12.0#"; - string expectedOutput = "Dim a = 12.0#"; - - TestTrimPreprocessorDirectives(input, expectedOutput); - } - - [Test] - public void TrimPreprocessorDirectives4() - { - string input = " #10/10/2010#"; - string expectedOutput = " #10/10/2010#"; - - TestTrimPreprocessorDirectives(input, expectedOutput); - } - - [Test] - public void TrimPreprocessorDirectives5() - { - string input = "Dim a = 12.0# "; - string expectedOutput = "Dim a = 12.0# "; - - TestTrimPreprocessorDirectives(input, expectedOutput); - } - - [Test] - public void TrimPreprocessorDirectives6() - { - string input = " #10/10/2010# "; - string expectedOutput = " #10/10/2010# "; - - TestTrimPreprocessorDirectives(input, expectedOutput); - } - - void TestTrimPreprocessorDirectives(string input, string expectedOutput) - { - string output = LanguageUtils.TrimPreprocessorDirectives(input); - Assert.AreEqual(expectedOutput, output); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/MockTextEditor.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/MockTextEditor.cs deleted file mode 100644 index 616eebbb0d..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/MockTextEditor.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using ICSharpCode.AvalonEdit; -using ICSharpCode.AvalonEdit.Highlighting; -using ICSharpCode.Core; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Editor; -using ICSharpCode.SharpDevelop.Editor.AvalonEdit; -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; - -namespace ICSharpCode.VBNetBinding.Tests -{ - /// - /// Text editor for unit tests. - /// Because the tested code completion has complex requirements for the ITextEditor - /// implementation, we use a real AvalonEdit instead of mocking everything. - /// However, we override UI-displaying - /// - public class MockTextEditor : AvalonEditTextEditorAdapter - { - DefaultProjectContent pc; - - public MockTextEditor() - : base(new TextEditor()) - { - PropertyService.InitializeServiceForUnitTests(); - pc = new DefaultProjectContent(); - pc.Language = LanguageProperties.VBNet; - pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib); - - Dictionary referencedAssemblies = new Dictionary() { - { "System", typeof(Uri).Module.FullyQualifiedName }, - { "System.Core", typeof(Enumerable).Module.FullyQualifiedName }, - { "Microsoft.VisualBasic", typeof(Microsoft.VisualBasic.Constants).Module.FullyQualifiedName } - }; - foreach (var assembly in referencedAssemblies) { - IProjectContent referenceProjectContent = AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference(assembly.Key, assembly.Value ?? assembly.Key); - if (referenceProjectContent == null) - throw new Exception("Error loading " + assembly.Key); - pc.ReferencedContents.Add(referenceProjectContent); - if (referenceProjectContent is ReflectionProjectContent) { - (referenceProjectContent as ReflectionProjectContent).InitializeReferences(); - } - } - -// this.TextEditor.TextArea.TextView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(this.TextEditor)); - this.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("VBNet"); - - new VBNetLanguageBinding().Attach(this); - } - - public override FileName FileName { - get { return new FileName("mockFileName.vb"); } - } - - public void CreateParseInformation() - { - ParserService.RegisterAvailableParsers(new ParserDescriptor(typeof(TParser), "VBNet", new string[] { ".vb" })); - var parser = new VBNetBinding.TParser(); - parser.LexerTags = new string[0]; - var cu = parser.Parse(pc, this.FileName, this.Document); - ParserService.RegisterParseInformation(this.FileName, cu); - pc.UpdateCompilationUnit(null, cu, this.FileName); - } - - ICompletionItemList lastCompletionItemList; - - public ICompletionItemList LastCompletionItemList { - get { return lastCompletionItemList; } - } - - public override ICompletionListWindow ShowCompletionWindow(ICompletionItemList data) - { - this.lastCompletionItemList = data; - return null; - } - - IEnumerable lastInsightItems; - - public IEnumerable LastInsightItems { - get { return lastInsightItems; } - } - - public override IInsightWindow ShowInsightWindow(IEnumerable items) - { - this.lastInsightItems = items; - return null; - } - } - -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs deleted file mode 100644 index d7d0ba1966..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using ICSharpCode.SharpDevelop.Editor.CodeCompletion; -using System; -using ICSharpCode.SharpDevelop.Dom; -using NUnit.Framework; - -namespace ICSharpCode.VBNetBinding.Tests -{ - public class TextEditorBasedTests - { - protected MockTextEditor textEditor; - - [SetUp] - public void SetupTest() - { - this.textEditor = new MockTextEditor(); - } - - protected void TestCtrlSpace(string file, bool expected, Action constraint) - { - int insertionPoint = file.IndexOf('|'); - - if (insertionPoint < 0) - Assert.Fail("insertionPoint not found in text!"); - - this.textEditor.Document.Text = file.Replace("|", ""); - this.textEditor.Caret.Offset = insertionPoint; - this.textEditor.CreateParseInformation(); - - bool invoked = new VBNetCompletionBinding().CtrlSpace(textEditor); - - Assert.AreEqual(expected, invoked); - - ICompletionItemList list = this.textEditor.LastCompletionItemList; - - constraint(list); - } - - protected void TestKeyPress(string file, char keyPressed, CodeCompletionKeyPressResult keyPressResult, Action constraint) - { - int insertionPoint = file.IndexOf('|'); - - if (insertionPoint < 0) - Assert.Fail("insertionPoint not found in text!"); - - this.textEditor.Document.Text = file.Replace("|", ""); - this.textEditor.Caret.Offset = insertionPoint; - this.textEditor.CreateParseInformation(); - - CodeCompletionKeyPressResult result = new VBNetCompletionBinding().HandleKeyPress(textEditor, keyPressed); - - Assert.AreEqual(keyPressResult, result); - - ICompletionItemList list = this.textEditor.LastCompletionItemList; - - constraint(list); - } - - protected void TestTextInsert(string file, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset) - { - int insertionPoint = file.IndexOf('|'); - - if (insertionPoint < 0) - Assert.Fail("insertionPoint not found in text!"); - - this.textEditor.Document.Text = file.Replace("|", ""); - this.textEditor.Caret.Offset = insertionPoint; - this.textEditor.CreateParseInformation(); - - CompletionContext context = new CompletionContext() { - Editor = this.textEditor, - CompletionChar = completionChar, - StartOffset = textEditor.Caret.Offset, - EndOffset = textEditor.Caret.Offset - }; - - list.Complete(context, item); - - if (!context.CompletionCharHandled && context.CompletionChar != '\n') - this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + ""); - - string insertedText = this.textEditor.Document.GetText(insertionPoint, this.textEditor.Document.TextLength - file.Length + 1); - - Assert.AreEqual(expectedOutput, insertedText); - Assert.AreEqual(insertionPoint + expectedOffset, textEditor.Caret.Offset); - } - } -} diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj b/src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj deleted file mode 100644 index 10a9920dc7..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj +++ /dev/null @@ -1,96 +0,0 @@ - - - - Library - ICSharpCode.VBNetBinding.Tests - ICSharpCode.VBNetBinding.Tests - Debug - AnyCPU - {50A89267-A28B-4DF3-8E62-912E005143B8} - ..\..\..\..\..\bin\UnitTests\ - False - False - False - Auto - 4194304 - x86 - 4096 - 4 - false - False - True - v4.0 - - - DEBUG;TRACE - true - Full - - - TRACE - False - None - - - - - 3.0 - - - 3.0 - - - - 3.5 - - - - 4.0 - - - - ..\..\..\..\Tools\NUnit\nunit.framework.dll - False - - - 3.0 - - - - - Configuration\GlobalAssemblyInfo.cs - - - - - - - - {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} - ICSharpCode.AvalonEdit - - - {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} - ICSharpCode.Core - - - {BF38FB72-B380-4196-AF8C-95749D726C61} - VBNetBinding - - - {2748AD25-9C63-4E12-877B-4DCE96FBED54} - ICSharpCode.SharpDevelop - - - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} - ICSharpCode.SharpDevelop.Dom - - - - - - - - - - \ No newline at end of file diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.sln b/src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.sln deleted file mode 100644 index d30c11a130..0000000000 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.sln +++ /dev/null @@ -1,54 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -# SharpDevelop 3.0.0.2993 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VBNetBinding.Tests", "VBNetBinding.Tests.csproj", "{50A89267-A28B-4DF3-8E62-912E005143B8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VBNetBinding", "..\Project\VBNetBinding.csproj", "{BF38FB72-B380-4196-AF8C-95749D726C61}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj", "{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop", "..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj", "{2748AD25-9C63-4E12-877B-4DCE96FBED54}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Dom", "..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj", "{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor", "..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj", "{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {50A89267-A28B-4DF3-8E62-912E005143B8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {50A89267-A28B-4DF3-8E62-912E005143B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {50A89267-A28B-4DF3-8E62-912E005143B8}.Release|Any CPU.Build.0 = Release|Any CPU - {50A89267-A28B-4DF3-8E62-912E005143B8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BF38FB72-B380-4196-AF8C-95749D726C61}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BF38FB72-B380-4196-AF8C-95749D726C61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BF38FB72-B380-4196-AF8C-95749D726C61}.Release|Any CPU.Build.0 = Release|Any CPU - {BF38FB72-B380-4196-AF8C-95749D726C61}.Release|Any CPU.ActiveCfg = Release|Any CPU - {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Release|Any CPU.Build.0 = Release|Any CPU - {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2748AD25-9C63-4E12-877B-4DCE96FBED54}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2748AD25-9C63-4E12-877B-4DCE96FBED54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.Build.0 = Release|Any CPU - {2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.ActiveCfg = Release|Any CPU - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Release|Any CPU.Build.0 = Release|Any CPU - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.Build.0 = Release|Any CPU - {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Release|Any CPU.Build.0 = Release|Any CPU - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Release|Any CPU.ActiveCfg = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/src/Main/GlobalAssemblyInfo.template b/src/Main/GlobalAssemblyInfo.cs.template similarity index 97% rename from src/Main/GlobalAssemblyInfo.template rename to src/Main/GlobalAssemblyInfo.cs.template index 76851c96ad..7251a7d3ce 100644 --- a/src/Main/GlobalAssemblyInfo.template +++ b/src/Main/GlobalAssemblyInfo.cs.template @@ -24,6 +24,7 @@ using System.Reflection; [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly", Justification = "AssemblyInformationalVersion does not need to be a parsable version")] +// DO NOT FORGET TO EDIT the GlobalAssemblyInfo.vb.template! internal static class RevisionClass { public const string Major = "5"; diff --git a/src/Main/GlobalAssemblyInfo.vb.template b/src/Main/GlobalAssemblyInfo.vb.template new file mode 100644 index 0000000000..7de41f7087 --- /dev/null +++ b/src/Main/GlobalAssemblyInfo.vb.template @@ -0,0 +1,35 @@ +' Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +' This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'' '' +'' DO NOT EDIT GlobalAssemblyInfo.vb, it is recreated using AssemblyInfo.vb.template whenever '' +'' ICSharpCode.Core is compiled. '' +'' '' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Imports System.Resources +Imports System.Reflection + + + + + + + + + + + +' DO NOT FORGET TO EDIT the GlobalAssemblyInfo.cs.template! +Friend NotInheritable Class RevisionClass + Public Const Major As String = "5" + Public Const Minor As String = "0" + Public Const Build As String = "0" + Public Const Revision As String = "$INSERTREVISION$" + Public Const VersionName As String = "alpha" ' "" is not valid for no version name, you have to use Nothing if you don't want a version name (eg "Beta 1") + + Public Const FullVersion As String = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$$INSERTVERSIONNAMEPOSTFIX$" +End Class diff --git a/src/Main/SharpDevelop/SharpDevelop.csproj b/src/Main/SharpDevelop/SharpDevelop.csproj index 5946a52b0c..c46f82b779 100644 --- a/src/Main/SharpDevelop/SharpDevelop.csproj +++ b/src/Main/SharpDevelop/SharpDevelop.csproj @@ -90,6 +90,10 @@ + + Configuration\GlobalAssemblyInfo.cs + GlobalAssemblyInfo.cs.template + Project\Build\MSBuildEngine\BuildJob.cs @@ -223,6 +227,12 @@ Resources\StringResources.resx + + Configuration\GlobalAssemblyInfo.cs.template + + + Configuration\GlobalAssemblyInfo.vb.template + Never @@ -233,10 +243,6 @@ Never - - Configuration\GlobalAssemblyInfo.cs - GlobalAssemblyInfo.template - @@ -279,9 +285,6 @@ ICSharpCode.Core False - - Configuration\GlobalAssemblyInfo.template - {7E4A7172-7FF5-48D0-B719-7CD959DD1AC9} diff --git a/src/Tools/UpdateAssemblyInfo/Main.cs b/src/Tools/UpdateAssemblyInfo/Main.cs index f65e434bc4..258820d705 100644 --- a/src/Tools/UpdateAssemblyInfo/Main.cs +++ b/src/Tools/UpdateAssemblyInfo/Main.cs @@ -22,12 +22,16 @@ namespace UpdateAssemblyInfo const string BaseCommit = "4ba2785f66bebeaa21c68cf4f6733fc19ddb0d9d"; const int BaseCommitRev = 0; - const string globalAssemblyInfoTemplateFile = "src/Main/GlobalAssemblyInfo.template"; + const string globalAssemblyInfoTemplateFile = "src/Main/GlobalAssemblyInfo.cs.template"; static readonly TemplateFile[] templateFiles = { new TemplateFile { Input = globalAssemblyInfoTemplateFile, Output = "src/Main/GlobalAssemblyInfo.cs" }, + new TemplateFile { + Input = "src/Main/GlobalAssemblyInfo.vb.template", + Output = "src/Main/GlobalAssemblyInfo.vb" + }, new TemplateFile { Input = "src/Main/SharpDevelop/app.template.config", Output = "src/Main/SharpDevelop/app.config"