Browse Source

created branch for VB.NET 9 and 10

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@5780 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 15 years ago
parent
commit
40ef20a177
  1. 187
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 6
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBStatement.cs
  3. 246
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs
  4. 31
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs
  5. 4
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetLanguageBinding.cs
  6. 4
      src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj
  7. 77
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs
  8. 12
      src/AddIns/Misc/Profiler/Hook/Hook.vcxproj
  9. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/VBNET-Mode.xshd
  10. 18
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/Rope.cs
  11. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlParser.cs
  12. 5
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs
  13. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs
  14. 38
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  15. 2
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs
  16. 2369
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  17. 54
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  18. 2580
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  19. 62
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  20. 53
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  21. 33
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  22. 9
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  23. 16
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  24. 12
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  25. 19
      src/Libraries/NRefactory/Test/Parser/GlobalScope/AttributeSectionTests.cs
  26. 74
      src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs
  27. 2
      src/Main/Base/Project/Src/Editor/IBracketSearcher.cs
  28. 1
      src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
  29. 1
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj
  30. 36
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs

187
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -27,11 +27,21 @@ namespace VBNetBinding @@ -27,11 +27,21 @@ namespace VBNetBinding
/// </summary>
public class VBNetFormattingStrategy : DefaultFormattingStrategy
{
List<VBStatement> statements;
IList<string> keywords;
VBStatement interfaceStatement;
static readonly List<VBStatement> statements;
List<int> blockTokens = new List<int>(
internal static List<VBStatement> Statements {
get { return statements; }
}
static readonly IList<string> keywords;
internal static IList<string> Keywords {
get { return keywords; }
}
static VBStatement interfaceStatement;
static List<int> blockTokens = new List<int>(
new int[] {
Tokens.Class, Tokens.Module, Tokens.Namespace, Tokens.Interface, Tokens.Structure,
Tokens.Sub, Tokens.Function, Tokens.Operator,
@ -42,33 +52,33 @@ namespace VBNetBinding @@ -42,33 +52,33 @@ namespace VBNetBinding
bool doCasing;
bool doInsertion;
public VBNetFormattingStrategy()
static VBNetFormattingStrategy()
{
statements = new List<VBStatement>();
statements.Add(new VBStatement(@"^if.*?(then|\s+_)$", "^end ?if$", "End If", 1));
statements.Add(new VBStatement(@"\bclass\s+\w+\s*($|\(\s*Of)", "^end class$", "End Class", 1));
statements.Add(new VBStatement(@"\bnamespace\s+\w+(\.\w+)*$", "^end namespace$", "End Namespace", 1));
statements.Add(new VBStatement(@"\bmodule\s+\w+$", "^end module$", "End Module", 1));
statements.Add(new VBStatement(@"\bstructure\s+\w+\s*($|\(\s*Of)", "^end structure$", "End Structure", 1));
statements.Add(new VBStatement(@"^while\s+", "^end while$", "End While", 1));
statements.Add(new VBStatement(@"^select case", "^end select$", "End Select", 1));
statements.Add(new VBStatement(@"(?<!\b(delegate|mustoverride|declare(\s+(unicode|ansi|auto))?)\s+)\bsub\s+\w+", @"^end\s+sub$", "End Sub", 1));
statements.Add(new VBStatement(@"(?<!\bmustoverride (readonly |writeonly )?)\bproperty\s+\w+", @"^end\s+property$", "End Property", 1));
statements.Add(new VBStatement(@"(?<!\b(delegate|mustoverride|declare(\s+(unicode|ansi|auto))?)\s+)\bfunction\s+\w+", @"^end\s+function$", "End Function", 1));
statements.Add(new VBStatement(@"\boperator(\s*[\+\-\*\/\&\^\>\<\=\\]+\s*|\s+\w+\s*)\(", @"^end\s+operator$", "End Operator", 1));
statements.Add(new VBStatement(@"\bfor\s+.*?$", "^next( \\w+)?$", "Next", 1));
statements.Add(new VBStatement(@"^synclock\s+.*?$", "^end synclock$", "End SyncLock", 1));
statements.Add(new VBStatement(@"^get$", "^end get$", "End Get", 1));
statements.Add(new VBStatement(@"^with\s+.*?$", "^end with$", "End With", 1));
statements.Add(new VBStatement(@"^set(\s*\(.*?\))?$", "^end set$", "End Set", 1));
statements.Add(new VBStatement(@"^try$", "^end try$", "End Try", 1));
statements.Add(new VBStatement(@"^do\s+.+?$", "^loop$", "Loop", 1));
statements.Add(new VBStatement(@"^do$", "^loop .+?$", "Loop While ", 1));
statements.Add(new VBStatement(@"\benum\s+\w+$", "^end enum$", "End Enum", 1));
interfaceStatement = new VBStatement(@"\binterface\s+\w+\s*($|\(\s*Of)", "^end interface$", "End Interface", 1);
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(@"(?<!\b(delegate|mustoverride|declare(\s+(unicode|ansi|auto))?)\s+)\bsub\s+\w+", @"^end\s+sub$", "End Sub", 1, Tokens.Sub));
statements.Add(new VBStatement(@"(?<!\bmustoverride (readonly |writeonly )?)\bproperty\s+\w+", @"^end\s+property$", "End Property", 1, Tokens.Property));
statements.Add(new VBStatement(@"(?<!\b(delegate|mustoverride|declare(\s+(unicode|ansi|auto))?)\s+)\bfunction\s+\w+", @"^end\s+function$", "End Function", 1, Tokens.Function));
statements.Add(new VBStatement(@"\boperator(\s*[\+\-\*\/\&\^\>\<\=\\]+\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));
statements.Add(new VBStatement(@"^#region\s+", "^#end region$", "#End Region", 0));
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));
keywords = new string[] {
"AddHandler", "AddressOf", "Alias", "And",
@ -139,15 +149,7 @@ namespace VBNetBinding @@ -139,15 +149,7 @@ namespace VBNetBinding
if (ch == '\n' && lineAboveText != null)
{
string textToReplace = lineAboveText;
// remove string content
MatchCollection strmatches = Regex.Matches(textToReplace, "\"[^\"]*?\"", RegexOptions.Singleline);
foreach (Match match in strmatches)
{
textToReplace = textToReplace.Remove(match.Index, match.Length).Insert(match.Index, new String('-', match.Length));
}
// remove comments
textToReplace = Regex.Replace(textToReplace, "'.*$", "", RegexOptions.Singleline);
string textToReplace = TrimLine(lineAboveText);
if (doCasing)
DoCasingOnLine(lineAbove, textToReplace, editor);
@ -158,11 +160,11 @@ namespace VBNetBinding @@ -158,11 +160,11 @@ namespace VBNetBinding
if (IsInString(lineAboveText)) {
if (IsFinishedString(curLineText)) {
editor.Document.Insert(lineAbove.Offset + lineAbove.Length,
"\" & _");
"\" & _");
editor.Document.Insert(currentLine.Offset, "\"");
} else {
editor.Document.Insert(lineAbove.Offset + lineAbove.Length,
"\"");
"\"");
}
} else {
string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, lineAbove.Offset);
@ -205,6 +207,18 @@ namespace VBNetBinding @@ -205,6 +207,18 @@ namespace VBNetBinding
}
}
internal static string TrimLine(string lineText)
{
string textToReplace = lineText;
// remove string content
MatchCollection strmatches = Regex.Matches(lineText, "\"[^\"]*?\"", RegexOptions.Singleline);
foreach (Match match in strmatches) {
textToReplace = textToReplace.Remove(match.Index, match.Length).Insert(match.Index, new String('-', match.Length));
}
// remove comments
return Regex.Replace(textToReplace, "'.*$", "", RegexOptions.Singleline);
}
void DoInsertionOnLine(string terminator, IDocumentLine currentLine, IDocumentLine lineAbove, string textToReplace, ITextEditor editor, int lineNr)
{
string curLineText = currentLine.Text;
@ -355,6 +369,8 @@ namespace VBNetBinding @@ -355,6 +369,8 @@ namespace VBNetBinding
if (currentToken.EndLocation.Line > lineNr)
break;
prevToken = currentToken;
}
if (tokens.Count > 0)
@ -400,7 +416,7 @@ namespace VBNetBinding @@ -400,7 +416,7 @@ namespace VBNetBinding
return !inString;
}
bool IsDeclaration(int type)
internal static bool IsDeclaration(int type)
{
return (type == Tokens.Class) ||
(type == Tokens.Module) ||
@ -489,7 +505,7 @@ namespace VBNetBinding @@ -489,7 +505,7 @@ namespace VBNetBinding
return false;
}
bool IsMatchingEnd(Token begin, Token end)
internal static bool IsMatchingEnd(Token begin, Token end)
{
if (begin.Kind == end.Kind)
return true;
@ -648,7 +664,7 @@ namespace VBNetBinding @@ -648,7 +664,7 @@ namespace VBNetBinding
indentation.Push((indentation.PeekOrDefault() ?? string.Empty) + addIndent);
}
bool IsBlockStart(ILexer lexer, Token current, Token prev)
internal static bool IsBlockStart(ILexer lexer, Token current, Token prev)
{
if (blockTokens.Contains(current.Kind)) {
if (current.Kind == Tokens.If) {
@ -714,7 +730,7 @@ namespace VBNetBinding @@ -714,7 +730,7 @@ namespace VBNetBinding
return IsSpecialCase(current, prev);
}
bool IsBlockEnd(Token current, Token prev)
internal static bool IsBlockEnd(Token current, Token prev)
{
if (current.Kind == Tokens.Next) {
if (prev.Kind == Tokens.Resume)
@ -736,7 +752,7 @@ namespace VBNetBinding @@ -736,7 +752,7 @@ namespace VBNetBinding
return IsSpecialCase(current, prev);
}
bool IsSpecialCase(Token current, Token prev)
static bool IsSpecialCase(Token current, Token prev)
{
switch (current.Kind) {
case Tokens.Else:
@ -789,9 +805,9 @@ namespace VBNetBinding @@ -789,9 +805,9 @@ namespace VBNetBinding
}
}
bool IsStatement(string text)
static bool IsStatement(string text)
{
foreach (VBStatement s in this.statements) {
foreach (VBStatement s in statements) {
if (Regex.IsMatch(text, s.StartRegex, RegexOptions.IgnoreCase))
return true;
}
@ -849,84 +865,5 @@ namespace VBNetBinding @@ -849,84 +865,5 @@ namespace VBNetBinding
{
SurroundSelectionWithSingleLineComment(editor, "'");
}
#region SearchBracket
/*
public override 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;
}
public override 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
}
}

6
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBStatement.cs

@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
// </file>
using System;
using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Parser.VB;
namespace VBNetBinding
{
@ -15,18 +17,20 @@ namespace VBNetBinding @@ -15,18 +17,20 @@ namespace VBNetBinding
public string EndRegex = "";
public string EndStatement = "";
public int StatementToken = 0;
public int IndentPlus = 0;
public VBStatement()
{
}
public VBStatement(string startRegex, string endRegex, string endStatement, int indentPlus)
public VBStatement(string startRegex, string endRegex, string endStatement, int indentPlus, int statementToken)
{
StartRegex = startRegex;
EndRegex = endRegex;
EndStatement = endStatement;
IndentPlus = indentPlus;
StatementToken = statementToken;
}
}
}

246
src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs

@ -0,0 +1,246 @@ @@ -0,0 +1,246 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
// <version>$Revision$</version>
// </file>
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 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
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;
}
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
int FindBeginStatementAroundOffset(IDocument document, int offset, out VBStatement statement, out int length)
{
length = 0;
statement = null;
return -1;
}
int FindEndStatementAroundOffset(IDocument document, int offset, out VBStatement statement)
{
IDocumentLine line = document.GetLineForOffset(offset);
string interestingText = VBNetFormattingStrategy.TrimLine(line.Text).Trim(' ', '\t');
//LoggingService.Debug("text: '" + interestingText + "'");
foreach (VBStatement s in VBNetFormattingStrategy.Statements) {
Match match = Regex.Matches(interestingText, s.EndRegex, RegexOptions.Singleline | RegexOptions.IgnoreCase).OfType<Match>().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;
}
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<Token> tokens = new Stack<Token>();
if (statement.EndStatement == "Next") {
lookFor = Tokens.For;
}
Token result = null;
while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) {
if (prevToken == null)
prevToken = currentToken;
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) {
IDocumentLine line = document.GetLine(result.Location.Line);
string interestingText = VBNetFormattingStrategy.TrimLine(line.Text).Trim(' ', '\t');
//LoggingService.Debug("text2: '" + interestingText + "'");
Match matchResult = Regex.Match(interestingText, statement.StartRegex, RegexOptions.Singleline | RegexOptions.IgnoreCase);
if (matchResult != null) {
length = matchResult.Value.TrimEnd(' ', '\t').Length;
int diff = line.Length - line.Text.TrimStart(' ', '\t').Length;
int start = diff + line.Offset;
if (IsDeclaration(result.Kind)) {
length += diff + matchResult.Index;
return start;
}
return matchResult.Index + start;
}
}
length = 0;
return -1;
}
int FindEndStatement(IDocument document, VBStatement statement)
{
return -1;
}
#endregion
bool IsDeclaration(int kind)
{
return kind == Tokens.Sub || kind == Tokens.Function || kind == Tokens.Operator || VBNetFormattingStrategy.IsDeclaration(kind);
}
}
}

31
src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs

@ -41,7 +41,38 @@ namespace VBNetBinding @@ -41,7 +41,38 @@ namespace VBNetBinding
return CodeCompletionKeyPressResult.Completed;
} else if (ch == '\n') {
TryDeclarationTypeInference(editor, editor.Document.GetLineForOffset(editor.Caret.Offset));
} else if (char.IsLetter(ch) && CodeCompletionOptions.CompleteWhenTyping) {
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);
}
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) : ' ';
}
if (!char.IsLetterOrDigit(prevChar) && prevChar != '.' && !IsInComment(editor)) {
VBExpressionFinder ef = new VBExpressionFinder();
ExpressionResult result = ef.FindExpression(editor.Document.Text, cursor);
LoggingService.Debug("CC: Beginning to type a word, result=" + result + ", context=" + result.Context);
if (result.Context != ExpressionContext.IdentifierExpected) {
var ctrlSpaceProvider = new NRefactoryCtrlSpaceCompletionItemProvider(LanguageProperties.VBNet, result.Context);
ctrlSpaceProvider.ShowTemplates = true;
ctrlSpaceProvider.AllowCompleteExistingExpression = afterUnderscore;
ctrlSpaceProvider.ShowCompletion(editor);
return CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion;
}
}
}
return base.HandleKeyPress(editor, ch);
}

4
src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetLanguageBinding.cs

@ -19,5 +19,9 @@ namespace VBNetBinding @@ -19,5 +19,9 @@ namespace VBNetBinding
public override IFormattingStrategy FormattingStrategy {
get { return new VBNetFormattingStrategy(); }
}
public override IBracketSearcher BracketSearcher {
get { return new VBNetBracketSearcher(); }
}
}
}

4
src/AddIns/BackendBindings/VBNetBinding/Project/VBNetBinding.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -51,6 +52,7 @@ @@ -51,6 +52,7 @@
<EmbeddedResource Include="Resources\BuildOptions.xfrm" />
<Compile Include="Src\Extensions.cs" />
<Compile Include="Src\FormattingStrategy\VBStatement.cs" />
<Compile Include="Src\VBNetBracketSearcher.cs" />
<Compile Include="Src\VBNetLanguageBinding.cs" />
<Compile Include="Src\VBNetProjectBinding.cs" />
<Compile Include="Src\FormattingStrategy\VBNetFormattingStrategy.cs" />

77
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -28,7 +28,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
bgBrush = new SolidColorBrush(Color.FromArgb(0x30, 0x20, 0x20, 0xff));
bgBrush.Freeze();
selBrush = new SolidColorBrush(Color.FromArgb(0xC0, 0xff, 0xb7, 0x4f));
selBrush = new SolidColorBrush(Color.FromArgb(0xc0, 0xff, 0xb7, 0x4f));
selBrush.Freeze();
}
@ -147,7 +147,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -147,7 +147,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
.FirstOrDefault(r => insertionPosition >= r.Offset &&
insertionPosition <= (r.Offset + r.ActualHeight));
if (current == null || !gridItem.Services.Selection.IsComponentSelected(gridItem.Services.Component.GetDesignItem(current)))
if (current != null && !gridItem.Services.Selection.IsComponentSelected(gridItem.Services.Component.GetDesignItem(current)))
return;
} else {
double insertionPosition = e.GetPosition(this).X;
@ -155,7 +155,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -155,7 +155,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
.FirstOrDefault(r => insertionPosition >= r.Offset &&
insertionPosition <= (r.Offset + r.ActualWidth));
if (current == null || !gridItem.Services.Selection.IsComponentSelected(gridItem.Services.Component.GetDesignItem(current)))
if (current != null && !gridItem.Services.Selection.IsComponentSelected(gridItem.Services.Component.GetDesignItem(current)))
return;
}
@ -175,22 +175,27 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -175,22 +175,27 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
DesignItem component;
if (current == null || !gridItem.Services.Selection.IsComponentSelected(component = gridItem.Services.Component.GetDesignItem(current)))
return;
if (current != null) {
component = gridItem.Services.Component.GetDesignItem(current);
if (!gridItem.Services.Selection.IsComponentSelected(component))
return;
rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75;
rpUnitSelector.WidthOffset = RailSize + RailDistance;
rpUnitSelector.WidthRelativeToContentWidth = 1;
rpUnitSelector.HeightOffset = 55;
rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25;
unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType;
AdornerPanel.SetPlacement(unitSelector, rpUnitSelector);
}
rp.XOffset = -(RailSize + RailDistance);
rp.WidthOffset = RailSize + RailDistance;
rp.WidthRelativeToContentWidth = 1;
rp.HeightOffset = SplitterWidth;
rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2;
rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75;
rpUnitSelector.WidthOffset = RailSize + RailDistance;
rpUnitSelector.WidthRelativeToContentWidth = 1;
rpUnitSelector.HeightOffset = 55;
rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25;
unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType;
} else {
double insertionPosition = e.GetPosition(this).X;
ColumnDefinition current = grid.ColumnDefinitions
@ -199,26 +204,30 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -199,26 +204,30 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
DesignItem component;
if (current == null || !gridItem.Services.Selection.IsComponentSelected(component = gridItem.Services.Component.GetDesignItem(current)))
return;
if (current == null) {
component = gridItem.Services.Component.GetDesignItem(current);
if (!gridItem.Services.Selection.IsComponentSelected(component))
return;
rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.75;
rpUnitSelector.HeightOffset = RailSize + RailDistance;
rpUnitSelector.HeightRelativeToContentHeight = 1;
rpUnitSelector.WidthOffset = 75;
rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35;
unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType;
AdornerPanel.SetPlacement(unitSelector, rpUnitSelector);
}
rp.YOffset = -(RailSize + RailDistance);
rp.HeightOffset = RailSize + RailDistance;
rp.HeightRelativeToContentHeight = 1;
rp.WidthOffset = SplitterWidth;
rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2;
rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.75;
rpUnitSelector.HeightOffset = RailSize + RailDistance;
rpUnitSelector.HeightRelativeToContentHeight = 1;
rpUnitSelector.WidthOffset = 75;
rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35;
unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType;
}
AdornerPanel.SetPlacement(previewAdorner, rp);
AdornerPanel.SetPlacement(unitSelector, rpUnitSelector);
}
protected override void OnMouseLeave(MouseEventArgs e)
@ -253,15 +262,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -253,15 +262,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (current != null)
currentRow = gridItem.Services.Component.GetDesignItem(current);
}
if (currentRow == null)
currentRow = gridItem.Services.Component.GetDesignItem(grid.RowDefinitions.Last());
unitSelector.SelectedItem = currentRow;
if (!gridItem.Services.Selection.IsComponentSelected(currentRow)) {
if (currentRow != null && !gridItem.Services.Selection.IsComponentSelected(currentRow)) {
unitSelector.SelectedItem = currentRow;
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { currentRow }, SelectionTypes.Auto);
changeGroup.Commit();
if (!adornerPanel.Children.Contains(previewAdorner))
adornerPanel.Children.Add(previewAdorner);
@ -311,14 +317,11 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -311,14 +317,11 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
currentColumn = gridItem.Services.Component.GetDesignItem(current);
}
if (currentColumn == null)
currentColumn = gridItem.Services.Component.GetDesignItem(grid.ColumnDefinitions.Last());
unitSelector.SelectedItem = currentColumn;
if (!gridItem.Services.Selection.IsComponentSelected(currentColumn)) {
if (currentColumn != null && !gridItem.Services.Selection.IsComponentSelected(currentColumn)) {
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { currentColumn }, SelectionTypes.Auto);
unitSelector.SelectedItem = currentColumn;
changeGroup.Commit();
if (!adornerPanel.Children.Contains(previewAdorner))
adornerPanel.Children.Add(previewAdorner);
OnMouseMove(e);

12
src/AddIns/Misc/Profiler/Hook/Hook.vcxproj

@ -31,18 +31,6 @@ @@ -31,18 +31,6 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<Import Condition="Exists('$(VCTargetsPath)\Microsoft.Cpp.targets')" Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PlatformToolset>v90</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PlatformToolset>v90</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PlatformToolset>v90</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PlatformToolset>v90</PlatformToolset>
</PropertyGroup>
<PropertyGroup>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/VBNET-Mode.xshd

@ -201,6 +201,16 @@ @@ -201,6 +201,16 @@
<Word>Next</Word>
<Word>Select</Word>
<Word>Case</Word>
<Word>From</Word>
<Word>Aggregate</Word>
<Word>Distinct</Word>
<Word>Group</Word>
<Word>Where</Word>
<Word>Skip</Word>
<Word>Join</Word>
<Word>Into</Word>
<Word>Equals</Word>
<Word>Take</Word>
</Keywords>
<Keywords color="ContextKeywords">
<Word>Ansi</Word>

18
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/Rope.cs

@ -199,7 +199,7 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -199,7 +199,7 @@ namespace ICSharpCode.AvalonEdit.Utils
/// <summary>
/// Inserts new elemetns into this rope.
/// Runs in O(lg N + M).
/// Runs in O(lg N + M), where N is the length of this rope and M is the number of new elements.
/// </summary>
/// <exception cref="ArgumentNullException">newElements is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">index or length is outside the valid range.</exception>
@ -218,7 +218,7 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -218,7 +218,7 @@ namespace ICSharpCode.AvalonEdit.Utils
/// <summary>
/// Inserts new elements into this rope.
/// Runs in O(lg N + M).
/// Runs in O(lg N + M), where N is the length of this rope and M is the number of new elements.
/// </summary>
/// <exception cref="ArgumentNullException">newElements is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">index or length is outside the valid range.</exception>
@ -235,8 +235,8 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -235,8 +235,8 @@ namespace ICSharpCode.AvalonEdit.Utils
}
/// <summary>
/// Inserts a piece of text in this rope.
/// Runs in O(lg N + M), where M is the length of the new text.
/// Appends multiple elements to the end of this rope.
/// Runs in O(lg N + M), where N is the length of this rope and M is the number of new elements.
/// </summary>
/// <exception cref="ArgumentNullException">newElements is null.</exception>
public void AddRange(IEnumerable<T> newElements)
@ -245,10 +245,10 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -245,10 +245,10 @@ namespace ICSharpCode.AvalonEdit.Utils
}
/// <summary>
/// Inserts another rope into this rope.
/// Runs in O(lg N), plus a per-node cost as if <c>newText.Clone()</c> was called.
/// Appends another rope to the end of this rope.
/// Runs in O(lg N + lg M), plus a per-node cost as if <c>newElements.Clone()</c> was called.
/// </summary>
/// <exception cref="ArgumentNullException">newText is null.</exception>
/// <exception cref="ArgumentNullException">newElements is null.</exception>
public void AddRange(Rope<T> newElements)
{
InsertRange(this.Length, newElements);
@ -256,7 +256,7 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -256,7 +256,7 @@ namespace ICSharpCode.AvalonEdit.Utils
/// <summary>
/// Appends new elements to the end of this rope.
/// Runs in O(lg N + M).
/// Runs in O(lg N + M), where N is the length of this rope and M is the number of new elements.
/// </summary>
/// <exception cref="ArgumentNullException">array is null.</exception>
public void AddRange(T[] array, int arrayIndex, int count)
@ -265,7 +265,7 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -265,7 +265,7 @@ namespace ICSharpCode.AvalonEdit.Utils
}
/// <summary>
/// Removes a piece of text from the rope.
/// Removes a range of elements from the rope.
/// Runs in O(lg N).
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlParser.cs

@ -132,7 +132,7 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -132,7 +132,7 @@ namespace ICSharpCode.AvalonEdit.Xml
[Conditional("DEBUG")]
internal static void Log(string text, params object[] pars)
{
System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "XML: " + text, pars));
//System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "XML: " + text, pars));
}
/// <summary>

5
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs

@ -379,4 +379,9 @@ namespace NRefactoryASTGenerator.Ast @@ -379,4 +379,9 @@ namespace NRefactoryASTGenerator.Ast
QueryExpressionJoinVBClause joinClause;
List<ExpressionRangeVariable> intoVariables;
}
[ImplementNullable]
abstract class XmlLiteralExpression : AbstractNode, INullable { }
}

2
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs

@ -159,7 +159,6 @@ namespace NRefactoryASTGenerator.Ast @@ -159,7 +159,6 @@ namespace NRefactoryASTGenerator.Ast
class OperatorDeclaration : MethodDeclaration
{
ConversionType conversionType;
List<AttributeSection> returnTypeAttributes;
OverloadableOperatorType overloadableOperator;
}
@ -185,6 +184,7 @@ namespace NRefactoryASTGenerator.Ast @@ -185,6 +184,7 @@ namespace NRefactoryASTGenerator.Ast
Location bodyEnd;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
Expression initializer;
public PropertyDeclaration(Modifiers modifier, List<AttributeSection> attributes,
string name, List<ParameterDeclarationExpression> parameters)

38
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -2991,8 +2991,6 @@ public Location ExtendedEndLocation { get; set; } @@ -2991,8 +2991,6 @@ public Location ExtendedEndLocation { get; set; }
ConversionType conversionType;
List<AttributeSection> returnTypeAttributes;
OverloadableOperatorType overloadableOperator;
public ConversionType ConversionType {
@ -3004,15 +3002,6 @@ public Location ExtendedEndLocation { get; set; } @@ -3004,15 +3002,6 @@ public Location ExtendedEndLocation { get; set; }
}
}
public List<AttributeSection> ReturnTypeAttributes {
get {
return returnTypeAttributes;
}
set {
returnTypeAttributes = value ?? new List<AttributeSection>();
}
}
public OverloadableOperatorType OverloadableOperator {
get {
return overloadableOperator;
@ -3023,7 +3012,6 @@ public Location ExtendedEndLocation { get; set; } @@ -3023,7 +3012,6 @@ public Location ExtendedEndLocation { get; set; }
}
public OperatorDeclaration() {
returnTypeAttributes = new List<AttributeSection>();
}
public bool IsConversionOperator {
@ -3037,10 +3025,9 @@ public Location ExtendedEndLocation { get; set; } @@ -3037,10 +3025,9 @@ public Location ExtendedEndLocation { get; set; }
}
public override string ToString() {
return string.Format("[OperatorDeclaration ConversionType={0} ReturnTypeAttributes={1} OverloadableOper" +
"ator={2} Body={3} HandlesClause={4} Templates={5} IsExtensionMethod={6} Interfac" +
"eImplementations={7} TypeReference={8} Name={9} Parameters={10} Attributes={11} " +
"Modifier={12}]", ConversionType, GetCollectionString(ReturnTypeAttributes), OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
return string.Format("[OperatorDeclaration ConversionType={0} OverloadableOperator={1} Body={2} Handles" +
"Clause={3} Templates={4} IsExtensionMethod={5} InterfaceImplementations={6} Type" +
"Reference={7} Name={8} Parameters={9} Attributes={10} Modifier={11}]", ConversionType, OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
}
}
@ -3299,6 +3286,8 @@ public Location ExtendedEndLocation { get; set; } @@ -3299,6 +3286,8 @@ public Location ExtendedEndLocation { get; set; }
PropertySetRegion setRegion;
Expression initializer;
public Location BodyStart {
get {
return bodyStart;
@ -3337,6 +3326,16 @@ public Location ExtendedEndLocation { get; set; } @@ -3337,6 +3326,16 @@ public Location ExtendedEndLocation { get; set; }
}
}
public Expression Initializer {
get {
return initializer;
}
set {
initializer = value ?? Expression.Null;
if (!initializer.IsNull) initializer.Parent = this;
}
}
public PropertyDeclaration(Modifiers modifier, List<AttributeSection> attributes, string name, List<ParameterDeclarationExpression> parameters) {
Modifier = modifier;
Attributes = attributes;
@ -3346,6 +3345,7 @@ public Location ExtendedEndLocation { get; set; } @@ -3346,6 +3345,7 @@ public Location ExtendedEndLocation { get; set; }
bodyEnd = Location.Empty;
getRegion = PropertyGetRegion.Null;
setRegion = PropertySetRegion.Null;
initializer = Expression.Null;
}
public bool HasGetRegion {
@ -3395,9 +3395,9 @@ public Location ExtendedEndLocation { get; set; } @@ -3395,9 +3395,9 @@ public Location ExtendedEndLocation { get; set; }
}
public override string ToString() {
return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Interf" +
"aceImplementations={4} TypeReference={5} Name={6} Parameters={7} Attributes={8} " +
"Modifier={9}]", BodyStart, BodyEnd, GetRegion, SetRegion, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Initia" +
"lizer={4} InterfaceImplementations={5} TypeReference={6} Name={7} Parameters={8}" +
" Attributes={9} Modifier={10}]", BodyStart, BodyEnd, GetRegion, SetRegion, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier);
}
}

2
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs

@ -246,6 +246,8 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -246,6 +246,8 @@ namespace ICSharpCode.NRefactory.Parser.VB
public static BitArray Null = NewSet(Nothing);
public static BitArray BlockSucc = NewSet(Case, Catch, Else, ElseIf, End, Finally, Loop, Next);
public static BitArray IdentifierTokens = NewSet(Text, Binary, Compare, Assembly, Ansi, Auto, Preserve, Unicode, Until, Off, Explicit, Infer, From, Join, Equals, Distinct, Where, Take, Skip, Order, By, Ascending, Descending, Group, Into, Aggregate);
public static BitArray TypeLevel = NewSet(Public, Friend, Class, Interface, Structure, Enum, Delegate, Shared, Partial, Protected, Private, Public, Const, Event, Explicit, New, Operator);
public static BitArray GlobalLevel = NewSet(Namespace, Imports, Public, Friend, Class, Interface, Structure, Enum, Delegate, Partial);
static string[] tokenList = new string[] {
// ----- terminal classes -----

2369
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

54
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -252,39 +252,47 @@ Attribute<out ASTAttribute attribute> @@ -252,39 +252,47 @@ Attribute<out ASTAttribute attribute>
.
AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
(.
bool nameFound = false;
string name = "";
Expression expr;
.)
=
"("
[
[
IF (IsAssignment()) (. nameFound = true; .)
Identifier (. name = t.val; .)
"="
] Expr<out expr> (. if (expr != null) {if(name == "") positional.Add(expr);
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
}
.)
AttributeArgument<positional, named>
{
","
(
IF (IsAssignment()) (. nameFound = true; .)
Identifier (. name = t.val; .)
"="
| /*Empty*/ (. if (nameFound) Error("no positional argument after named argument"); .)
) Expr<out expr> (. if (expr != null) { if(name == "") positional.Add(expr);
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
}
.)
AttributeArgument<positional, named>
}
]
")"
.
AttributeArgument<List<Expression> positional, List<NamedArgumentExpression> named>
(. string name = null; bool isNamed = false; Expression expr; .)
=
(
IF (IsAssignment()) (. isNamed = true; .)
Identifier (. name = t.val; .)
"="
|
IF (IdentAndColon())
Identifier (. name = t.val; .)
":"
| /* empty */
)
Expr<out expr>
(.
if (expr != null) {
if (isNamed) {
named.Add(new NamedArgumentExpression(name, expr));
} else {
if (named.Count > 0)
Error("positional argument after named argument is not allowed");
if (name != null)
expr = new NamedArgumentExpression(name, expr);
positional.Add(expr);
}
}
.)
.
AttributeSection<out AttributeSection section>
(.
string attributeTarget = "";

2580
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

62
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -890,7 +890,16 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -890,7 +890,16 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. name = t.val; .)
TypeParameterList<templates>
[ "(" [ FormalParameterList<p> ] ")" ]
["As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
["As" {
AttributeSection<out returnTypeAttributeSection>
(.
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
attributes.Add(returnTypeAttributeSection);
}
.)
}
TypeName<out type> ]
(.
if(type == null) {
type = new TypeReference("System.Object", true);
@ -918,10 +927,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -918,10 +927,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates,
InterfaceImplementations = implementsClause
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
.)
|
@ -936,10 +942,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -936,10 +942,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
@ -1064,20 +1066,45 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1064,20 +1066,45 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
m.Check(Modifiers.VBProperties);
Location startPos = t.Location;
List<InterfaceImplementation> implementsClause = null;
AttributeSection returnTypeAttributeSection = null;
Expression initializer = null;
.)
Identifier (. string propertyName = t.val; .)
[ "(" [ FormalParameterList<p> ] ")" ]
[ "As" TypeName<out type> ]
[
"As" {
AttributeSection<out returnTypeAttributeSection>
(.
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
attributes.Add(returnTypeAttributeSection);
}
.)
}
(
IF (IsNewExpression()) ObjectCreateExpression<out initializer>
(.
if (initializer is ObjectCreateExpression) {
type = ((ObjectCreateExpression)initializer).CreateType.Clone();
} else {
type = ((ArrayCreateExpression)initializer).CreateType.Clone();
}
.)
|
TypeName<out type>
)
]
(.
if(type == null) {
type = new TypeReference("System.Object", true);
}
.)
[ "=" VariableInitializer<out initializer> ]
[ ImplementsClause<out implementsClause> ]
EndOfStmt
(
/* abstract properties without a body */
IF(IsMustOverride(m))
IF(IsMustOverride(m) || IsAutomaticProperty())
(.
PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
@ -1085,6 +1112,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1085,6 +1112,8 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
pDecl.TypeReference = type;
pDecl.InterfaceImplementations = implementsClause;
pDecl.Parameters = p;
if (initializer != null)
pDecl.Initializer = initializer;
compilationUnit.AddChild(pDecl);
.)
|
@ -1105,7 +1134,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1105,7 +1134,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(.
pDecl.GetRegion = getRegion;
pDecl.SetRegion = setRegion;
pDecl.BodyEnd = t.EndLocation;
pDecl.BodyEnd = t.Location; // t = EndOfStmt; not "Property"
compilationUnit.AddChild(pDecl);
.)
)
@ -1181,7 +1210,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1181,7 +1210,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
OverloadableOperatorType operatorType;
AttributeSection section;
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
.)
OverloadableOperator<out operatorType>
"(" [ "ByVal" ] Identifier (. operandName = t.val; .)
@ -1196,7 +1224,12 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1196,7 +1224,12 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
}
")"
(. Location endPos = t.EndLocation; .)
[ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> (. endPos = t.EndLocation; .) ]
[ "As" { AttributeSection<out section>
(. if (section != null) {
section.AttributeTarget = "return";
attributes.Add(section);
} .)
} TypeName<out returnType> (. endPos = t.EndLocation; .) ]
EOL
Block<out stmt> "End" "Operator" EndOfStmt
(.
@ -1207,7 +1240,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1207,7 +1240,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
TypeReference = returnType,
OverloadableOperator = operatorType,
ConversionType = opConversionType,
ReturnTypeAttributes = returnTypeAttributes,
Body = (BlockStatement)stmt,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = endPos

53
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -5,12 +5,14 @@ @@ -5,12 +5,14 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.Visitors;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors;
namespace ICSharpCode.NRefactory.Parser.VB
{
@ -173,6 +175,10 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -173,6 +175,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
bool IsObjectCreation() {
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
}
bool IsNewExpression() {
return la.kind == Tokens.New;
}
/*
True, if "<" is followed by the ident "assembly" or "module"
@ -256,15 +262,52 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -256,15 +262,52 @@ namespace ICSharpCode.NRefactory.Parser.VB
int peek = Peek(1).kind;
return la.kind == Tokens.Resume && peek == Tokens.Next;
}
/*
True, if ident/literal integer is followed by ":"
*/
/// <summary>
/// Returns True, if ident/literal integer is followed by ":"
/// </summary>
bool IsLabel()
{
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
&& Peek(1).kind == Tokens.Colon;
}
/// <summary>
/// Returns true if a property declaration is an automatic property.
/// </summary>
bool IsAutomaticProperty()
{
lexer.StartPeek();
Token tn = la;
int braceCount = 0;
// look for attributes
while (tn.kind == Tokens.LessThan) {
while (braceCount > 0 || tn.kind != Tokens.GreaterThan) {
tn = lexer.Peek();
if (tn.kind == Tokens.OpenParenthesis)
braceCount++;
if (tn.kind == Tokens.CloseParenthesis)
braceCount--;
}
Debug.Assert(tn.kind == Tokens.GreaterThan);
tn = lexer.Peek();
}
// look for modifiers
var allowedTokens = new[] {
Tokens.Public, Tokens.Protected,
Tokens.Friend, Tokens.Private
};
while (allowedTokens.Contains(tn.kind))
tn = lexer.Peek();
if (tn.Kind != Tokens.Get && tn.Kind != Tokens.Set)
return true;
return false;
}
bool IsNotStatementSeparator()
{

33
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -276,7 +276,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -276,7 +276,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
PrintFormattedComma();
}
for (int i = 0; i < attribute.NamedArguments.Count; ++i) {
TrackVisit((INode)attribute.NamedArguments[i], data);
NamedArgumentExpression nae = attribute.NamedArguments[i];
outputFormatter.PrintIdentifier(nae.Name);
if (prettyPrintOptions.AroundAssignmentParentheses)
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
if (prettyPrintOptions.AroundAssignmentParentheses)
outputFormatter.Space();
nae.Expression.AcceptVisitor(this, data);
if (i + 1 < attribute.NamedArguments.Count) {
PrintFormattedComma();
}
@ -292,10 +299,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -292,10 +299,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
{
outputFormatter.PrintIdentifier(namedArgumentExpression.Name);
if (this.prettyPrintOptions.AroundAssignmentParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.PrintToken(Tokens.Colon);
if (this.prettyPrintOptions.AroundAssignmentParentheses) {
outputFormatter.Space();
}
@ -2878,7 +2882,24 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2878,7 +2882,24 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.NewLine ();
outputFormatter.Indent ();
}
this.AppendCommaSeparatedList (arrayInitializerExpression.CreateExpressions, true);
var createExprs = arrayInitializerExpression.CreateExpressions;
for (int i = 0; i < createExprs.Count; i++) {
if (i > 0) {
PrintFormattedCommaAndNewLine();
}
NamedArgumentExpression nae = createExprs[i] as NamedArgumentExpression;
if (nae != null) {
outputFormatter.PrintIdentifier(nae.Name);
if (prettyPrintOptions.AroundAssignmentParentheses)
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
if (prettyPrintOptions.AroundAssignmentParentheses)
outputFormatter.Space();
nae.Expression.AcceptVisitor(this, data);
} else {
createExprs[i].AcceptVisitor(this, data);
}
}
if (arrayInitializerExpression.CreateExpressions.Count == 1) {
outputFormatter.Space ();
} else {

9
src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs

@ -704,7 +704,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -704,7 +704,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((operatorDeclaration.TypeReference != null));
Debug.Assert((operatorDeclaration.Body != null));
Debug.Assert((operatorDeclaration.Templates != null));
Debug.Assert((operatorDeclaration.ReturnTypeAttributes != null));
foreach (AttributeSection o in operatorDeclaration.Attributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
@ -723,10 +722,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -723,10 +722,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
foreach (AttributeSection o in operatorDeclaration.ReturnTypeAttributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}
@ -779,6 +774,7 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -779,6 +774,7 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((propertyDeclaration.TypeReference != null));
Debug.Assert((propertyDeclaration.GetRegion != null));
Debug.Assert((propertyDeclaration.SetRegion != null));
Debug.Assert((propertyDeclaration.Initializer != null));
foreach (AttributeSection o in propertyDeclaration.Attributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
@ -793,7 +789,8 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -793,7 +789,8 @@ namespace ICSharpCode.NRefactory.Visitors {
}
propertyDeclaration.TypeReference.AcceptVisitor(this, data);
propertyDeclaration.GetRegion.AcceptVisitor(this, data);
return propertyDeclaration.SetRegion.AcceptVisitor(this, data);
propertyDeclaration.SetRegion.AcceptVisitor(this, data);
return propertyDeclaration.Initializer.AcceptVisitor(this, data);
}
public virtual object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) {

16
src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs

@ -1269,7 +1269,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1269,7 +1269,6 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((operatorDeclaration.TypeReference != null));
Debug.Assert((operatorDeclaration.Body != null));
Debug.Assert((operatorDeclaration.Templates != null));
Debug.Assert((operatorDeclaration.ReturnTypeAttributes != null));
for (int i = 0; i < operatorDeclaration.Attributes.Count; i++) {
AttributeSection o = operatorDeclaration.Attributes[i];
Debug.Assert(o != null);
@ -1320,17 +1319,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1320,17 +1319,6 @@ namespace ICSharpCode.NRefactory.Visitors {
else
operatorDeclaration.Templates[i] = o;
}
for (int i = 0; i < operatorDeclaration.ReturnTypeAttributes.Count; i++) {
AttributeSection o = operatorDeclaration.ReturnTypeAttributes[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (AttributeSection)nodeStack.Pop();
if (o == null)
operatorDeclaration.ReturnTypeAttributes.RemoveAt(i--);
else
operatorDeclaration.ReturnTypeAttributes[i] = o;
}
return null;
}
@ -1407,6 +1395,7 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1407,6 +1395,7 @@ namespace ICSharpCode.NRefactory.Visitors {
Debug.Assert((propertyDeclaration.TypeReference != null));
Debug.Assert((propertyDeclaration.GetRegion != null));
Debug.Assert((propertyDeclaration.SetRegion != null));
Debug.Assert((propertyDeclaration.Initializer != null));
for (int i = 0; i < propertyDeclaration.Attributes.Count; i++) {
AttributeSection o = propertyDeclaration.Attributes[i];
Debug.Assert(o != null);
@ -1449,6 +1438,9 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1449,6 +1438,9 @@ namespace ICSharpCode.NRefactory.Visitors {
nodeStack.Push(propertyDeclaration.SetRegion);
propertyDeclaration.SetRegion.AcceptVisitor(this, data);
propertyDeclaration.SetRegion = ((PropertySetRegion)(nodeStack.Pop()));
nodeStack.Push(propertyDeclaration.Initializer);
propertyDeclaration.Initializer.AcceptVisitor(this, data);
propertyDeclaration.Initializer = ((Expression)(nodeStack.Pop()));
return null;
}

12
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -789,5 +789,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -789,5 +789,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestTypeMember("void M(int x = 0);");
}
[Test]
public void NamedArguments()
{
TestExpression("M(x: 1)");
}
[Test]
public void TestAttributeWithNamedArgument()
{
TestProgram("[assembly: Foo(1, namedArg: 2, prop = 3)]");
}
}
}

19
src/Libraries/NRefactory/Test/Parser/GlobalScope/AttributeSectionTests.cs

@ -81,6 +81,25 @@ public class Form1 { @@ -81,6 +81,25 @@ public class Form1 {
Assert.AreEqual("assembly", decl.AttributeTarget);
}
[Test]
public void AssemblyAttributeCSharpWithNamedArguments()
{
string program = @"[assembly: Foo(1, namedArg: 2, prop = 3)]";
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
Assert.AreEqual("assembly", decl.AttributeTarget);
var a = decl.Attributes[0];
Assert.AreEqual("Foo", a.Name);
Assert.AreEqual(2, a.PositionalArguments.Count);
Assert.AreEqual(1, a.NamedArguments.Count);
Assert.AreEqual(1, ((PrimitiveExpression)a.PositionalArguments[0]).Value);
NamedArgumentExpression nae = a.PositionalArguments[1] as NamedArgumentExpression;
Assert.AreEqual("namedArg", nae.Name);
Assert.AreEqual(2, ((PrimitiveExpression)nae.Expression).Value);
nae = a.NamedArguments[0];
Assert.AreEqual("prop", nae.Name);
Assert.AreEqual(3, ((PrimitiveExpression)nae.Expression).Value);
}
[Test]
public void ModuleAttributeCSharp()
{

74
src/Libraries/NRefactory/Test/Parser/TypeLevel/PropertyDeclarationTests.cs

@ -120,19 +120,89 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -120,19 +120,89 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetSimpleGetPropertyDeclarationTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty \nGet\nEnd Get\nEnd Property");
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty \nGet\nEnd Get\nEnd Property");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsFalse(pd.HasSetRegion);
Assert.IsTrue((pd.Modifier & Modifiers.ReadOnly) == Modifiers.ReadOnly);
}
[Test]
public void VBNetSimpleSetPropertyDeclarationTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty \n Set\nEnd Set\nEnd Property ");
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty \n Set\nEnd Set\nEnd Property ");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsFalse(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.IsTrue((pd.Modifier & Modifiers.WriteOnly) == Modifiers.WriteOnly);
}
[Test]
public void VBNetAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer, Expression.Null);
}
[Test]
public void VBNetReadOnlyAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsFalse(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer, Expression.Null);
}
[Test]
public void VBNetWriteOnlyAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsFalse(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer, Expression.Null);
}
[Test]
public void VBNetSimpleInitializerAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty = 5");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Object", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
}
[Test]
public void VBNetSimpleInitializerAutoPropertyWithTypeTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer = 5");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("System.Int32", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
}
[Test]
public void VBNetSimpleObjectInitializerAutoPropertyTest()
{
PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember<PropertyDeclaration>("Property MyProperty As New List");
Assert.AreEqual("MyProperty", pd.Name);
Assert.AreEqual("List", pd.TypeReference.Type);
Assert.IsTrue(pd.HasGetRegion);
Assert.IsTrue(pd.HasSetRegion);
Assert.AreEqual(pd.Initializer.ToString(), new ObjectCreateExpression(new TypeReference("List"), null).ToString());
}
#endregion
}

2
src/Main/Base/Project/Src/Editor/IBracketSearcher.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -17,7 +17,7 @@ namespace ICSharpCode.SharpDevelop.Editor
/// <summary>
/// Searches for a matching bracket from the given offset to the start of the document.
/// </summary>
/// <returns>A BracketSearchResult that contains the positions and lengths of the brackets.</returns>
/// <returns>A BracketSearchResult that contains the positions and lengths of the brackets. Return null if there is nothing to highlight.</returns>
BracketSearchResult SearchBracket(IDocument document, int offset);
}

1
src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

@ -101,6 +101,7 @@ @@ -101,6 +101,7 @@
<Compile Include="Utils\MockTextMarkerService.cs" />
<Compile Include="Utils\Tests\MockAssemblyTests.cs" />
<Compile Include="VBExpressionFinderTests.cs" />
<Compile Include="VBNetExpressionFinderTests.cs" />
<Compile Include="WebReferences\ValidReferenceNameTests.cs" />
<Compile Include="WebReferences\ValidWebReferenceNamespaceTests.cs" />
<Compile Include="WebReferences\WebReferenceProjectItemsTest.cs" />

1
src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj

@ -144,6 +144,7 @@ @@ -144,6 +144,7 @@
<Compile Include="Src\IComment.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionTypeNameSyntaxError.cs" />
<Compile Include="Src\SignatureComparer.cs" />
<Compile Include="Src\VBNet\VBNetExpressionFinder.cs" />
<Compile Include="Src\XmlDoc.cs" />
<Compile Include="Src\Tag.cs" />
<Compile Include="Src\ResolveResult.cs" />

36
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs

@ -1117,6 +1117,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -1117,6 +1117,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
}
static void AddVBNetKeywords(List<ICompletionEntry> ar, BitArray keywords)
{
for (int i = 0; i < keywords.Length; i++) {
if (keywords[i]) {
ar.Add(new KeywordEntry(NR.Parser.VB.Tokens.GetTokenString(i)));
}
}
}
public List<ICompletionEntry> CtrlSpace(int caretLine, int caretColumn, ParseInformation parseInfo, string fileContent, ExpressionContext context)
{
if (!Initialize(parseInfo, caretLine, caretColumn))
@ -1124,15 +1133,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -1124,15 +1133,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
List<ICompletionEntry> result = new List<ICompletionEntry>();
if (language == NR.SupportedLanguage.VBNet) {
foreach (KeyValuePair<string, string> pair in TypeReference.PrimitiveTypesVB) {
if ("System." + pair.Key != pair.Value) {
IClass c = GetPrimitiveClass(pair.Value, pair.Key);
if (c != null) result.Add(c);
}
if (context == ExpressionContext.TypeDeclaration) {
AddVBNetKeywords(result, NR.Parser.VB.Tokens.TypeLevel);
} else if (context == ExpressionContext.Global) {
AddVBNetKeywords(result, NR.Parser.VB.Tokens.GlobalLevel);
} else {
AddVBNetPrimitiveTypes(result);
CtrlSpaceInternal(result, fileContent);
}
result.Add(new KeywordEntry("Global"));
result.Add(new KeywordEntry("New"));
CtrlSpaceInternal(result, fileContent);
} else {
if (context == ExpressionContext.TypeDeclaration) {
AddCSharpKeywords(result, NR.Parser.CSharp.Tokens.TypeLevel);
@ -1217,6 +1230,17 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -1217,6 +1230,17 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
return result;
}
void AddVBNetPrimitiveTypes(List<ICompletionEntry> result)
{
foreach (KeyValuePair<string, string> pair in TypeReference.PrimitiveTypesVB) {
if ("System." + pair.Key != pair.Value) {
IClass c = GetPrimitiveClass(pair.Value, pair.Key);
if (c != null)
result.Add(c);
}
}
}
void AddCSharpPrimitiveTypes(List<ICompletionEntry> result)
{

Loading…
Cancel
Save