Browse Source

Fixed forum-7902: VB parser incorrectly added attribute sections on parameter declarations to all parameters.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3117 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
03a8ae3612
  1. 713
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 49
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 29
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  4. 2
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs
  5. 6
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  6. 9
      src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs

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

File diff suppressed because it is too large Load Diff

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

@ -2163,36 +2163,26 @@ AttributeSection<out AttributeSection section> @@ -2163,36 +2163,26 @@ AttributeSection<out AttributeSection section>
/* 9.2.5 */
FormalParameterList<List<ParameterDeclarationExpression> parameter>
(.
ParameterDeclarationExpression p;
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
.) =
{ AttributeSection<out section> (.attributes.Add(section); .) }
(
FormalParameter<out p>
(.
bool paramsFound = false;
p.Attributes = attributes;
parameter.Add(p);
.)
{
"," (. if (paramsFound) Error("params array must be at end of parameter list"); .)
{ AttributeSection<out section> (.attributes.Add(section); .) }
(
FormalParameter <out p> (. p.Attributes = attributes; parameter.Add(p); .)
)
}
)
.
(. ParameterDeclarationExpression p; .)
=
FormalParameter <out p> (. if (p != null) parameter.Add(p); .)
{ ","
FormalParameter <out p> (. if (p != null) parameter.Add(p); .)
}
.
/* 9.2.5 */
FormalParameter<out ParameterDeclarationExpression p>
(.
TypeReference type = null;
ParamModifierList mod = new ParamModifierList(this);
Expression expr = null;
p = null;ArrayList arrayModifiers = null;
.) =
(.
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
TypeReference type = null;
ParamModifierList mod = new ParamModifierList(this);
Expression expr = null;
p = null;
ArrayList arrayModifiers = null;
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ ParameterModifier<mod> }
Identifier (. string parameterName = t.val; .)
[ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
@ -2214,8 +2204,9 @@ FormalParameter<out ParameterDeclarationExpression p> @@ -2214,8 +2204,9 @@ FormalParameter<out ParameterDeclarationExpression p>
(.
mod.Check();
p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr);
p.Attributes = attributes;
.)
.
.
/* 10.1 */
Block<out Statement stmt>

29
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -179,6 +179,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -179,6 +179,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
#region Global scope
bool printAttributeSectionInline; // is set to true when printing parameter's attributes
public override object TrackedVisitAttributeSection(AttributeSection attributeSection, object data)
{
outputFormatter.Indent();
@ -197,7 +199,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -197,7 +199,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
|| "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) {
outputFormatter.NewLine();
} else {
outputFormatter.PrintLineContinuation();
if (printAttributeSectionInline)
outputFormatter.Space();
else
outputFormatter.PrintLineContinuation();
}
return null;
@ -206,17 +211,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -206,17 +211,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data)
{
outputFormatter.PrintIdentifier(attribute.Name);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(attribute.PositionalArguments);
if (attribute.NamedArguments != null && attribute.NamedArguments.Count > 0) {
if (attribute.PositionalArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.Space();
if (attribute.PositionalArguments.Count > 0 || attribute.NamedArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(attribute.PositionalArguments);
if (attribute.NamedArguments.Count > 0) {
if (attribute.PositionalArguments.Count > 0) {
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.Space();
}
AppendCommaSeparatedList(attribute.NamedArguments);
}
AppendCommaSeparatedList(attribute.NamedArguments);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null;
}
@ -800,7 +807,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -800,7 +807,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
{
printAttributeSectionInline = true;
VisitAttributes(parameterDeclarationExpression.Attributes, data);
printAttributeSectionInline = false;
OutputModifier(parameterDeclarationExpression.ParamModifier, parameterDeclarationExpression.StartLocation);
outputFormatter.PrintIdentifier(parameterDeclarationExpression.ParameterName);
outputFormatter.Space();

2
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs

@ -210,7 +210,7 @@ End Class"); @@ -210,7 +210,7 @@ End Class");
TestProgramCS2VB("class A { [PreserveSig] public void B(// comment\nint c) {} }",
"Class A\n" +
" ' comment\n" +
" <PreserveSig()> _\n" +
" <PreserveSig> _\n" +
" Public Sub B(c As Integer)\n" +
" End Sub\n" +
"End Class");

6
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -355,6 +355,12 @@ End Using"); @@ -355,6 +355,12 @@ End Using");
TestTypeMember("Public Shared Operator >>(ByVal bugNode As TheBug, ByVal b As Integer) As TheBug\nEnd Operator");
}
[Test]
public void AttributeOnParameter()
{
TestTypeMember("Sub Main(ByRef one As Integer, ByRef two As Integer, <Out> ByRef three As Integer)\nEnd Sub");
}
[Test]
public void UsingStatementForExistingVariable()
{

9
src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs

@ -202,14 +202,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -202,14 +202,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{
MenuCommand item = (MenuCommand)sender;
IMember member = (IMember)item.Tag;
string memberName;
if (member is IProperty && ((IProperty)member).IsIndexer) {
// The name of the default indexer is always "Indexer" in C#.
// Add the type name to clarify which indexer is referred to.
memberName = member.Name + " of " + member.DeclaringType.Name;
} else {
memberName = member.Name;
}
string memberName = member.DeclaringType.Name + "." + member.Name;
using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.FindReferences}"))
{
FindReferencesAndRenameHelper.ShowAsSearchResults(StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}",

Loading…
Cancel
Save