Browse Source

replaced IndexerDeclaration by PropertyDeclaration with IsIndexer property (uses Default modifier)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5748 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 15 years ago
parent
commit
2fd5c0d873
  1. 12
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs
  2. 34
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs
  3. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
  4. 8
      src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/MemberFindAstVisitor.cs
  5. 24
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs
  6. 230
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  7. 2
      src/Libraries/NRefactory/Project/Src/IAstVisitor.cs
  8. 1657
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  9. 9
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  10. 47
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  11. 54
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  12. 25
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  13. 53
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  14. 11
      src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs
  15. 4
      src/Libraries/NRefactory/Project/Src/Visitors/NotImplementedAstVisitor.cs
  16. 4
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs
  17. 9
      src/Libraries/NRefactory/Test/Parser/TypeLevel/IndexerDeclarationTests.cs
  18. 41
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  19. 57
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs

12
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs

@ -142,18 +142,6 @@ namespace NRefactoryToBooConverter @@ -142,18 +142,6 @@ namespace NRefactoryToBooConverter
if ((m & Modifiers.WithEvents) != 0) {
// not necessary in Boo
}
if ((m & Modifiers.Default) != 0) {
ParametrizedNode parametrizedNode = node as ParametrizedNode;
string name = null;
if (parametrizedNode != null) {
name = parametrizedNode.Name;
} else {
AddError(node, "Default modifier is not supported on this member.");
}
if (name != null && currentType != null) {
currentType.Attributes.Add(MakeAttribute("System.Reflection.DefaultMember", new B.StringLiteralExpression(name)));
}
}
return r;
}

34
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs

@ -188,6 +188,7 @@ namespace NRefactoryToBooConverter @@ -188,6 +188,7 @@ namespace NRefactoryToBooConverter
ConvertAttributes(propertyDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
ConvertParameters(propertyDeclaration.Parameters, m.Parameters);
if (propertyDeclaration.IsIndexer) m.Name = "self";
m.EndSourceLocation = GetLocation(propertyDeclaration.EndLocation);
m.Type = ConvertTypeReference(propertyDeclaration.TypeReference);
m.ExplicitInfo = ConvertInterfaceImplementations(propertyDeclaration.InterfaceImplementations, propertyDeclaration, m);
@ -211,39 +212,6 @@ namespace NRefactoryToBooConverter @@ -211,39 +212,6 @@ namespace NRefactoryToBooConverter
return m;
}
public object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
{
B.Property m = new B.Property(GetLexicalInfo(indexerDeclaration));
m.Modifiers = ConvertModifier(indexerDeclaration, B.TypeMemberModifiers.Private);
ConvertAttributes(indexerDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
ConvertParameters(indexerDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetLocation(indexerDeclaration.EndLocation);
m.Type = ConvertTypeReference(indexerDeclaration.TypeReference);
m.Name = "this";
m.ExplicitInfo = ConvertInterfaceImplementations(indexerDeclaration.InterfaceImplementations, indexerDeclaration, m);
m.Name = "self";
if (!indexerDeclaration.IsWriteOnly) {
m.Getter = new B.Method(GetLexicalInfo(indexerDeclaration.GetRegion));
if (indexerDeclaration.GetRegion != null) {
ConvertAttributes(indexerDeclaration.GetRegion.Attributes, m.Getter.Attributes);
m.Modifiers = ConvertModifier(indexerDeclaration.GetRegion, m.Visibility);
m.Getter.Body = ConvertMethodBlock(indexerDeclaration.GetRegion.Block);
m.Getter.ReturnType = m.Type;
}
}
if (!indexerDeclaration.IsReadOnly) {
m.Setter = new B.Method(GetLexicalInfo(indexerDeclaration.SetRegion));
if (indexerDeclaration.SetRegion != null) {
ConvertAttributes(indexerDeclaration.SetRegion.Attributes, m.Setter.Attributes);
m.Modifiers = ConvertModifier(indexerDeclaration.SetRegion, m.Visibility);
m.Setter.Body = ConvertMethodBlock(indexerDeclaration.SetRegion.Block);
}
}
return m;
}
public object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data)
{
throw new ApplicationException("PropertyGetRegion visited.");

6
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs

@ -713,12 +713,6 @@ namespace ICSharpCode.PythonBinding @@ -713,12 +713,6 @@ namespace ICSharpCode.PythonBinding
return null;
}
public override object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
{
Console.WriteLine("VisitIndexerDeclaration");
return null;
}
public override object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data)
{
indexerExpression.TargetObject.AcceptVisitor(this, data);

8
src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/MemberFindAstVisitor.cs

@ -116,14 +116,6 @@ namespace Hornung.ResourceToolkit.Resolver @@ -116,14 +116,6 @@ namespace Hornung.ResourceToolkit.Resolver
return base.VisitFieldDeclaration(fieldDeclaration, data);
}
public override object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
{
if (this.CheckNode(indexerDeclaration)) {
return null;
}
return base.VisitIndexerDeclaration(indexerDeclaration, data);
}
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
{
if (this.CheckNode(localVariableDeclaration)) {

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

@ -167,6 +167,7 @@ namespace NRefactoryASTGenerator.Ast @@ -167,6 +167,7 @@ namespace NRefactoryASTGenerator.Ast
[IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")]
[IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")]
[IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")]
[IncludeBoolProperty("IsIndexer", "return (Modifier & Modifiers.Default) != 0;")]
[IncludeMember(@"
internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List<AttributeSection> attributes) : this(modifier, attributes, name, null)
{
@ -222,29 +223,6 @@ namespace NRefactoryASTGenerator.Ast @@ -222,29 +223,6 @@ namespace NRefactoryASTGenerator.Ast
public DestructorDeclaration(string name, Modifiers modifier, List<AttributeSection> attributes) : base(modifier, attributes) {}
}
[IncludeBoolProperty("HasGetRegion", "return !getRegion.IsNull;")]
[IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")]
[IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")]
[IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")]
class IndexerDeclaration : AttributedNode
{
List<ParameterDeclarationExpression> parameters;
List<InterfaceImplementation> interfaceImplementations;
TypeReference typeReference;
Location bodyStart;
Location bodyEnd;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
public IndexerDeclaration(Modifiers modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes)
: base(modifier, attributes)
{}
public IndexerDeclaration(TypeReference typeReference, List<ParameterDeclarationExpression> parameters, Modifiers modifier, List<AttributeSection> attributes)
: base(modifier, attributes)
{}
}
enum CharsetModifier { None }
class DeclareDeclaration : ParametrizedNode

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

@ -1665,9 +1665,9 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1665,9 +1665,9 @@ namespace ICSharpCode.NRefactory.Ast {
initializer = Expression.Null;
}
public bool HasRaiseRegion {
public bool HasAddRegion {
get {
return !raiseRegion.IsNull;
return !addRegion.IsNull;
}
}
@ -1677,9 +1677,9 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1677,9 +1677,9 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public bool HasAddRegion {
public bool HasRaiseRegion {
get {
return !addRegion.IsNull;
return !raiseRegion.IsNull;
}
}
@ -1983,6 +1983,15 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1983,6 +1983,15 @@ namespace ICSharpCode.NRefactory.Ast {
}
public TypeReference GetTypeForField(int fieldIndex)
{
if (!typeReference.IsNull) {
return typeReference;
}
return ((VariableDeclaration)Fields[fieldIndex]).TypeReference;
}
public VariableDeclaration GetVariableDeclaration(string variableName)
{
foreach (VariableDeclaration variableDeclaration in Fields) {
@ -1993,15 +2002,6 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1993,15 +2002,6 @@ namespace ICSharpCode.NRefactory.Ast {
return null;
}
public TypeReference GetTypeForField(int fieldIndex)
{
if (!typeReference.IsNull) {
return typeReference;
}
return ((VariableDeclaration)Fields[fieldIndex]).TypeReference;
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitFieldDeclaration(this, data);
}
@ -2459,147 +2459,6 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2459,147 +2459,6 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public class IndexerDeclaration : AttributedNode {
List<ParameterDeclarationExpression> parameters;
List<InterfaceImplementation> interfaceImplementations;
TypeReference typeReference;
Location bodyStart;
Location bodyEnd;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
public List<ParameterDeclarationExpression> Parameters {
get {
return parameters;
}
set {
parameters = value ?? new List<ParameterDeclarationExpression>();
}
}
public List<InterfaceImplementation> InterfaceImplementations {
get {
return interfaceImplementations;
}
set {
interfaceImplementations = value ?? new List<InterfaceImplementation>();
}
}
public TypeReference TypeReference {
get {
return typeReference;
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
public Location BodyStart {
get {
return bodyStart;
}
set {
bodyStart = value;
}
}
public Location BodyEnd {
get {
return bodyEnd;
}
set {
bodyEnd = value;
}
}
public PropertyGetRegion GetRegion {
get {
return getRegion;
}
set {
getRegion = value ?? PropertyGetRegion.Null;
if (!getRegion.IsNull) getRegion.Parent = this;
}
}
public PropertySetRegion SetRegion {
get {
return setRegion;
}
set {
setRegion = value ?? PropertySetRegion.Null;
if (!setRegion.IsNull) setRegion.Parent = this;
}
}
public IndexerDeclaration(Modifiers modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes) {
Modifier = modifier;
Parameters = parameters;
Attributes = attributes;
interfaceImplementations = new List<InterfaceImplementation>();
typeReference = TypeReference.Null;
bodyStart = Location.Empty;
bodyEnd = Location.Empty;
getRegion = PropertyGetRegion.Null;
setRegion = PropertySetRegion.Null;
}
public IndexerDeclaration(TypeReference typeReference, List<ParameterDeclarationExpression> parameters, Modifiers modifier, List<AttributeSection> attributes) {
TypeReference = typeReference;
Parameters = parameters;
Modifier = modifier;
Attributes = attributes;
interfaceImplementations = new List<InterfaceImplementation>();
bodyStart = Location.Empty;
bodyEnd = Location.Empty;
getRegion = PropertyGetRegion.Null;
setRegion = PropertySetRegion.Null;
}
public bool HasSetRegion {
get {
return !setRegion.IsNull;
}
}
public bool IsReadOnly {
get {
return HasGetRegion && !HasSetRegion;
}
}
public bool IsWriteOnly {
get {
return !HasGetRegion && HasSetRegion;
}
}
public bool HasGetRegion {
get {
return !getRegion.IsNull;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitIndexerDeclaration(this, data);
}
public override string ToString() {
return string.Format("[IndexerDeclaration Parameters={0} InterfaceImplementations={1} TypeReference={2}" +
" BodyStart={3} BodyEnd={4} GetRegion={5} SetRegion={6} Attributes={7} Modifier={" +
"8}]", GetCollectionString(Parameters), GetCollectionString(InterfaceImplementations), TypeReference, BodyStart, BodyEnd, GetRegion, SetRegion, GetCollectionString(Attributes), Modifier);
}
}
public class IndexerExpression : Expression {
Expression targetObject;
@ -3489,9 +3348,9 @@ public Location ExtendedEndLocation { get; set; } @@ -3489,9 +3348,9 @@ public Location ExtendedEndLocation { get; set; }
setRegion = PropertySetRegion.Null;
}
public bool IsReadOnly {
public bool HasGetRegion {
get {
return HasGetRegion && !HasSetRegion;
return !getRegion.IsNull;
}
}
@ -3501,12 +3360,24 @@ public Location ExtendedEndLocation { get; set; } @@ -3501,12 +3360,24 @@ public Location ExtendedEndLocation { get; set; }
}
}
public bool IsReadOnly {
get {
return HasGetRegion && !HasSetRegion;
}
}
public bool IsWriteOnly {
get {
return !HasGetRegion && HasSetRegion;
}
}
public bool IsIndexer {
get {
return (Modifier & Modifiers.Default) != 0;
}
}
internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List<AttributeSection> attributes) : this(modifier, attributes, name, null)
{
@ -3519,12 +3390,6 @@ public Location ExtendedEndLocation { get; set; } @@ -3519,12 +3390,6 @@ public Location ExtendedEndLocation { get; set; }
}
}
public bool HasGetRegion {
get {
return !getRegion.IsNull;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitPropertyDeclaration(this, data);
}
@ -5336,10 +5201,10 @@ public Location ExtendedEndLocation { get; set; } @@ -5336,10 +5201,10 @@ public Location ExtendedEndLocation { get; set; }
Usings = usings;
}
public UsingDeclaration(string @namespace, TypeReference alias) { usings = new List<Using>(1); usings.Add(new Using(@namespace, alias)); }
public UsingDeclaration(string @namespace) : this(@namespace, null) {}
public UsingDeclaration(string @namespace, TypeReference alias) { usings = new List<Using>(1); usings.Add(new Using(@namespace, alias)); }
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitUsingDeclaration(this, data);
}
@ -5497,6 +5362,43 @@ public UsingDeclaration(string @namespace) : this(@namespace, null) {} @@ -5497,6 +5362,43 @@ public UsingDeclaration(string @namespace) : this(@namespace, null) {}
}
}
public abstract class XmlLiteralExpression : AbstractNode, INullable {
protected XmlLiteralExpression() {
}
public virtual bool IsNull {
get {
return false;
}
}
public static XmlLiteralExpression Null {
get {
return NullXmlLiteralExpression.Instance;
}
}
}
internal sealed class NullXmlLiteralExpression : XmlLiteralExpression {
internal static NullXmlLiteralExpression Instance = new NullXmlLiteralExpression();
public override bool IsNull {
get {
return true;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return null;
}
public override string ToString() {
return "[NullXmlLiteralExpression]";
}
}
public class YieldStatement : Statement {
Statement statement;

2
src/Libraries/NRefactory/Project/Src/IAstVisitor.cs

@ -119,8 +119,6 @@ namespace ICSharpCode.NRefactory { @@ -119,8 +119,6 @@ namespace ICSharpCode.NRefactory {
object VisitIfElseStatement(IfElseStatement ifElseStatement, object data);
object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data);
object VisitIndexerExpression(IndexerExpression indexerExpression, object data);
object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data);

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

File diff suppressed because it is too large Load Diff

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

@ -952,10 +952,11 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -952,10 +952,11 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
/*--- unqualified indexer declaration (without interface name): */
| (. m.Check(Modifiers.Indexers); .)
"this" "[" FormalParameterList<p> "]" (. Location endLocation = t.EndLocation; .) "{" (.
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
PropertyDeclaration indexer = new PropertyDeclaration(m.Modifier | Modifiers.Default, attributes, "Item", p);
indexer.StartLocation = startPos;
indexer.EndLocation = endLocation;
indexer.BodyStart = t.Location;
indexer.TypeReference = type;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
@ -1024,9 +1025,10 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1024,9 +1025,10 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
/*--- qualified indexer declaration (with interface name): */
| (. m.Check(Modifiers.Indexers); .)
"." "this" "[" FormalParameterList<p> "]" (.
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
PropertyDeclaration indexer = new PropertyDeclaration(m.Modifier | Modifiers.Default, attributes, "Item", p);
indexer.StartLocation = m.GetDeclarationLocation(startPos);
indexer.EndLocation = t.EndLocation;
indexer.TypeReference = type;
if (explicitInterface != null)
SafeAdd(indexer, indexer.InterfaceImplementations, new InterfaceImplementation(explicitInterface, "this"));
PropertyGetRegion getRegion;
@ -1121,7 +1123,8 @@ InterfaceMemberDecl @@ -1121,7 +1123,8 @@ InterfaceMemberDecl
/*--- interface indexer declaration: */
| "this" "[" FormalParameterList<parameters> "]"
(. Location bracketEndLocation = t.EndLocation; .)
(. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes);
(. PropertyDeclaration id = new PropertyDeclaration(mod | Modifiers.Default, attributes, "Item", parameters);
id.TypeReference = type;
compilationUnit.AddChild(id); .)
"{" (. Location bodyStart = t.Location;.)
InterfaceAccessors<out getBlock, out setBlock>

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

@ -604,7 +604,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -604,7 +604,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TrackVisit(propertyDeclaration.InterfaceImplementations[0].InterfaceType, data);
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintIdentifier(propertyDeclaration.Name);
if (propertyDeclaration.IsIndexer) {
outputFormatter.PrintToken(Tokens.This);
outputFormatter.PrintToken(Tokens.OpenSquareBracket);
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}
AppendCommaSeparatedList(propertyDeclaration.Parameters);
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseSquareBracket);
} else
outputFormatter.PrintIdentifier(propertyDeclaration.Name);
OutputGetAndSetRegion(propertyDeclaration.GetRegion, propertyDeclaration.SetRegion);
@ -979,38 +992,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -979,38 +992,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public override object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
{
VisitAttributes(indexerDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(indexerDeclaration.Modifier);
TrackVisit(indexerDeclaration.TypeReference, data);
outputFormatter.Space();
if (indexerDeclaration.InterfaceImplementations.Count > 0) {
TrackVisit(indexerDeclaration.InterfaceImplementations[0].InterfaceType, data);
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintToken(Tokens.This);
outputFormatter.PrintToken(Tokens.OpenSquareBracket);
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}
AppendCommaSeparatedList(indexerDeclaration.Parameters);
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseSquareBracket);
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle, this.prettyPrintOptions.IndentPropertyBody);
TrackVisit(indexerDeclaration.GetRegion, data);
TrackVisit(indexerDeclaration.SetRegion, data);
outputFormatter.EndBrace(this.prettyPrintOptions.IndentPropertyBody);
return null;
}
public override object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data)
{
VisitAttributes(destructorDeclaration.Attributes, data);

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

@ -814,7 +814,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -814,7 +814,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
printAttributeSectionInline = true;
VisitAttributes(parameterDeclarationExpression.Attributes, data);
printAttributeSectionInline = false;
OutputModifier(parameterDeclarationExpression.ParamModifier, parameterDeclarationExpression.StartLocation);
OutputModifier(parameterDeclarationExpression.ParamModifier);
outputFormatter.PrintIdentifier(parameterDeclarationExpression.ParameterName);
if (!parameterDeclarationExpression.TypeReference.IsNull) {
outputFormatter.Space();
@ -971,51 +971,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -971,51 +971,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public override object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
{
VisitAttributes(indexerDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(indexerDeclaration.Modifier);
outputFormatter.PrintToken(Tokens.Default);
outputFormatter.Space();
if (indexerDeclaration.IsReadOnly) {
outputFormatter.PrintToken(Tokens.ReadOnly);
outputFormatter.Space();
} else if (indexerDeclaration.IsWriteOnly) {
outputFormatter.PrintToken(Tokens.WriteOnly);
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.Property);
outputFormatter.Space();
outputFormatter.PrintIdentifier("Item");
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(indexerDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
VisitReturnTypeAttributes(indexerDeclaration.Attributes, data);
TrackedVisit(indexerDeclaration.TypeReference, data);
PrintInterfaceImplementations(indexerDeclaration.InterfaceImplementations);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
exitTokenStack.Push(Tokens.Property);
TrackedVisit(indexerDeclaration.GetRegion, data);
TrackedVisit(indexerDeclaration.SetRegion, data);
exitTokenStack.Pop();
--outputFormatter.IndentationLevel;
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Property);
outputFormatter.NewLine();
return null;
}
public override object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data)
{
outputFormatter.Indent();
@ -2782,7 +2737,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2782,7 +2737,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
#endregion
void OutputModifier(ParameterModifiers modifier, Location position)
void OutputModifier(ParameterModifiers modifier)
{
if ((modifier & ParameterModifiers.Optional) == ParameterModifiers.Optional) {
outputFormatter.PrintToken(Tokens.Optional);
@ -2881,6 +2836,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2881,6 +2836,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
// not required in VB
}
if ((modifier & Modifiers.Default) == Modifiers.Default) {
outputFormatter.PrintToken(Tokens.Default);
outputFormatter.Space();
}
if ((modifier & Modifiers.Volatile) == Modifiers.Volatile) {
Error("'Volatile' modifier not convertable", Location.Empty);
}

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

@ -546,31 +546,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -546,31 +546,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return null;
}
public virtual object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) {
Debug.Assert((indexerDeclaration != null));
Debug.Assert((indexerDeclaration.Attributes != null));
Debug.Assert((indexerDeclaration.Parameters != null));
Debug.Assert((indexerDeclaration.InterfaceImplementations != null));
Debug.Assert((indexerDeclaration.TypeReference != null));
Debug.Assert((indexerDeclaration.GetRegion != null));
Debug.Assert((indexerDeclaration.SetRegion != null));
foreach (AttributeSection o in indexerDeclaration.Attributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
foreach (ParameterDeclarationExpression o in indexerDeclaration.Parameters) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
foreach (InterfaceImplementation o in indexerDeclaration.InterfaceImplementations) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
indexerDeclaration.TypeReference.AcceptVisitor(this, data);
indexerDeclaration.GetRegion.AcceptVisitor(this, data);
return indexerDeclaration.SetRegion.AcceptVisitor(this, data);
}
public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
Debug.Assert((indexerExpression != null));
Debug.Assert((indexerExpression.TargetObject != null));

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

@ -984,59 +984,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -984,59 +984,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return null;
}
public virtual object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) {
Debug.Assert((indexerDeclaration != null));
Debug.Assert((indexerDeclaration.Attributes != null));
Debug.Assert((indexerDeclaration.Parameters != null));
Debug.Assert((indexerDeclaration.InterfaceImplementations != null));
Debug.Assert((indexerDeclaration.TypeReference != null));
Debug.Assert((indexerDeclaration.GetRegion != null));
Debug.Assert((indexerDeclaration.SetRegion != null));
for (int i = 0; i < indexerDeclaration.Attributes.Count; i++) {
AttributeSection o = indexerDeclaration.Attributes[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (AttributeSection)nodeStack.Pop();
if (o == null)
indexerDeclaration.Attributes.RemoveAt(i--);
else
indexerDeclaration.Attributes[i] = o;
}
for (int i = 0; i < indexerDeclaration.Parameters.Count; i++) {
ParameterDeclarationExpression o = indexerDeclaration.Parameters[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (ParameterDeclarationExpression)nodeStack.Pop();
if (o == null)
indexerDeclaration.Parameters.RemoveAt(i--);
else
indexerDeclaration.Parameters[i] = o;
}
for (int i = 0; i < indexerDeclaration.InterfaceImplementations.Count; i++) {
InterfaceImplementation o = indexerDeclaration.InterfaceImplementations[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (InterfaceImplementation)nodeStack.Pop();
if (o == null)
indexerDeclaration.InterfaceImplementations.RemoveAt(i--);
else
indexerDeclaration.InterfaceImplementations[i] = o;
}
nodeStack.Push(indexerDeclaration.TypeReference);
indexerDeclaration.TypeReference.AcceptVisitor(this, data);
indexerDeclaration.TypeReference = ((TypeReference)(nodeStack.Pop()));
nodeStack.Push(indexerDeclaration.GetRegion);
indexerDeclaration.GetRegion.AcceptVisitor(this, data);
indexerDeclaration.GetRegion = ((PropertyGetRegion)(nodeStack.Pop()));
nodeStack.Push(indexerDeclaration.SetRegion);
indexerDeclaration.SetRegion.AcceptVisitor(this, data);
indexerDeclaration.SetRegion = ((PropertySetRegion)(nodeStack.Pop()));
return null;
}
public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
Debug.Assert((indexerExpression != null));
Debug.Assert((indexerExpression.TargetObject != null));

11
src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs

@ -395,13 +395,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -395,13 +395,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return result;
}
public sealed override object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) {
this.BeginVisit(indexerDeclaration);
object result = this.TrackedVisitIndexerDeclaration(indexerDeclaration, data);
this.EndVisit(indexerDeclaration);
return result;
}
public sealed override object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
this.BeginVisit(indexerExpression);
object result = this.TrackedVisitIndexerExpression(indexerExpression, data);
@ -1107,10 +1100,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1107,10 +1100,6 @@ namespace ICSharpCode.NRefactory.Visitors {
return base.VisitIfElseStatement(ifElseStatement, data);
}
public virtual object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) {
return base.VisitIndexerDeclaration(indexerDeclaration, data);
}
public virtual object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data) {
return base.VisitIndexerExpression(indexerExpression, data);
}

4
src/Libraries/NRefactory/Project/Src/Visitors/NotImplementedAstVisitor.cs

@ -226,10 +226,6 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -226,10 +226,6 @@ namespace ICSharpCode.NRefactory.Visitors {
throw new global::System.NotImplementedException("IfElseStatement");
}
public virtual object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) {
throw new global::System.NotImplementedException("IndexerDeclaration");
}
public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
throw new global::System.NotImplementedException("IndexerExpression");
}

4
src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

@ -309,6 +309,10 @@ namespace ICSharpCode.NRefactory.Visitors @@ -309,6 +309,10 @@ namespace ICSharpCode.NRefactory.Visitors
{
if (!IsClassType(ClassType.Interface) && (propertyDeclaration.Modifier & Modifiers.Visibility) == 0)
propertyDeclaration.Modifier |= Modifiers.Private;
if (propertyDeclaration.IsIndexer)
propertyDeclaration.Modifier |= Modifiers.Default;
base.VisitPropertyDeclaration(propertyDeclaration, data);
ToVBNetRenameConflictingVariablesVisitor.RenameConflicting(propertyDeclaration);

9
src/Libraries/NRefactory/Test/Parser/TypeLevel/IndexerDeclarationTests.cs

@ -18,19 +18,21 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -18,19 +18,21 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpIndexerDeclarationTest()
{
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int this[int a, string b] { get { } set { } }");
PropertyDeclaration id = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int this[int a, string b] { get { } set { } }");
Assert.AreEqual(2, id.Parameters.Count);
Assert.IsTrue(id.HasGetRegion, "No get region found!");
Assert.IsTrue(id.HasSetRegion, "No set region found!");
Assert.IsTrue(id.IsIndexer, "No Default modifier set!");
}
[Test]
public void CSharpIndexerImplementingInterfaceTest()
{
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface.this[int a, string b] { get { } set { } }");
PropertyDeclaration id = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface.this[int a, string b] { get { } set { } }");
Assert.AreEqual(2, id.Parameters.Count);
Assert.IsTrue(id.HasGetRegion, "No get region found!");
Assert.IsTrue(id.HasSetRegion, "No set region found!");
Assert.IsTrue(id.IsIndexer, "No Default modifier set!");
Assert.AreEqual("MyInterface", id.InterfaceImplementations[0].InterfaceType.Type);
}
@ -38,10 +40,11 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -38,10 +40,11 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void CSharpIndexerImplementingGenericInterfaceTest()
{
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface<string>.this[int a, string b] { get { } set { } }");
PropertyDeclaration id = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface<string>.this[int a, string b] { get { } set { } }");
Assert.AreEqual(2, id.Parameters.Count);
Assert.IsTrue(id.HasGetRegion, "No get region found!");
Assert.IsTrue(id.HasSetRegion, "No set region found!");
Assert.IsTrue(id.IsIndexer, "No Default modifier set!");
Assert.AreEqual("MyInterface", id.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", id.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);

41
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -715,45 +715,26 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -715,45 +715,26 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes);
ConvertAttributes(propertyDeclaration, property);
AddInterfaceImplementations(property, propertyDeclaration);
c.Properties.Add(property);
return null;
}
public override object VisitIndexerDeclaration(AST.IndexerDeclaration indexerDeclaration, object data)
{
DomRegion region = GetRegion(indexerDeclaration.StartLocation, indexerDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart, indexerDeclaration.BodyEnd);
DefaultProperty i = new DefaultProperty("Item", CreateReturnType(indexerDeclaration.TypeReference), ConvertModifier(indexerDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
i.IsIndexer = true;
if (indexerDeclaration.HasGetRegion) {
i.GetterRegion = GetRegion(indexerDeclaration.GetRegion.StartLocation, indexerDeclaration.GetRegion.EndLocation);
i.CanGet = true;
i.GetterModifiers = ConvertModifier(indexerDeclaration.GetRegion.Modifier, ModifierEnum.None);
}
if (indexerDeclaration.HasSetRegion) {
i.SetterRegion = GetRegion(indexerDeclaration.SetRegion.StartLocation, indexerDeclaration.SetRegion.EndLocation);
i.CanSet = true;
i.SetterModifiers = ConvertModifier(indexerDeclaration.SetRegion.Modifier, ModifierEnum.None);
}
i.Documentation = GetDocumentation(region.BeginLine, indexerDeclaration.Attributes);
ConvertAttributes(indexerDeclaration, i);
if (indexerDeclaration.Parameters != null) {
foreach (AST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) {
i.Parameters.Add(CreateParameter(par));
property.IsIndexer = propertyDeclaration.IsIndexer;
if (propertyDeclaration.Parameters != null) {
foreach (AST.ParameterDeclarationExpression par in propertyDeclaration.Parameters) {
property.Parameters.Add(CreateParameter(par));
}
}
// If an IndexerNameAttribute is specified, use the specified name
// for the indexer instead of the default name.
IAttribute indexerNameAttribute = i.Attributes.LastOrDefault(this.IsIndexerNameAttribute);
IAttribute indexerNameAttribute = property.Attributes.LastOrDefault(this.IsIndexerNameAttribute);
if (indexerNameAttribute != null && indexerNameAttribute.PositionalArguments.Count > 0) {
string name = indexerNameAttribute.PositionalArguments[0] as string;
if (!String.IsNullOrEmpty(name)) {
i.FullyQualifiedName = String.Concat(i.DeclaringType.FullyQualifiedName, ".", name);
property.FullyQualifiedName = String.Concat(property.DeclaringType.FullyQualifiedName, ".", name);
}
}
DefaultClass c = GetCurrentClass();
c.Properties.Add(i);
AddInterfaceImplementations(property, propertyDeclaration);
c.Properties.Add(property);
return null;
}

57
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs

@ -264,37 +264,23 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -264,37 +264,23 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
throw new ArgumentException("Unknown member: " + m.GetType().FullName);
}
public static AttributedNode ConvertMember(IProperty p, ClassFinder targetContext)
{
if (p.IsIndexer) {
IndexerDeclaration md;
md = new IndexerDeclaration(ConvertType(p.ReturnType, targetContext),
ConvertParameters(p.Parameters, targetContext),
ConvertModifier(p.Modifiers, targetContext),
ConvertAttributes(p.Attributes, targetContext));
md.Parameters = ConvertParameters(p.Parameters, targetContext);
if (p.CanGet) md.GetRegion = new PropertyGetRegion((p.Modifiers.HasFlag(ModifierEnum.Abstract) || p.Modifiers.HasFlag(ModifierEnum.Extern)) ? null : CreateNotImplementedBlock(), null);
if (p.CanSet) md.SetRegion = new PropertySetRegion((p.Modifiers.HasFlag(ModifierEnum.Abstract) || p.Modifiers.HasFlag(ModifierEnum.Extern)) ? null : CreateNotImplementedBlock(), null);
md.InterfaceImplementations = ConvertInterfaceImplementations(p.InterfaceImplementations, targetContext);
return md;
} else {
PropertyDeclaration md;
md = new PropertyDeclaration(ConvertModifier(p.Modifiers, targetContext),
ConvertAttributes(p.Attributes, targetContext),
p.Name,
ConvertParameters(p.Parameters, targetContext));
md.TypeReference = ConvertType(p.ReturnType, targetContext);
md.InterfaceImplementations = ConvertInterfaceImplementations(p.InterfaceImplementations, targetContext);
if (p.CanGet) {
md.GetRegion = new PropertyGetRegion((p.Modifiers.HasFlag(ModifierEnum.Abstract) || p.Modifiers.HasFlag(ModifierEnum.Extern)) ? null : CreateNotImplementedBlock(), null);
md.GetRegion.Modifier = ConvertModifier(p.GetterModifiers, null);
}
if (p.CanSet) {
md.SetRegion = new PropertySetRegion((p.Modifiers.HasFlag(ModifierEnum.Abstract) || p.Modifiers.HasFlag(ModifierEnum.Extern)) ? null : CreateNotImplementedBlock(), null);
md.SetRegion.Modifier = ConvertModifier(p.SetterModifiers, null);
}
return md;
public static PropertyDeclaration ConvertMember(IProperty p, ClassFinder targetContext)
{
PropertyDeclaration md = new PropertyDeclaration(ConvertModifier(p.Modifiers, targetContext),
ConvertAttributes(p.Attributes, targetContext),
p.Name,
ConvertParameters(p.Parameters, targetContext));
md.TypeReference = ConvertType(p.ReturnType, targetContext);
md.InterfaceImplementations = ConvertInterfaceImplementations(p.InterfaceImplementations, targetContext);
if (p.CanGet) {
md.GetRegion = new PropertyGetRegion((p.Modifiers.HasFlag(ModifierEnum.Abstract) || p.Modifiers.HasFlag(ModifierEnum.Extern)) ? null : CreateNotImplementedBlock(), null);
md.GetRegion.Modifier = ConvertModifier(p.GetterModifiers, null);
}
if (p.CanSet) {
md.SetRegion = new PropertySetRegion((p.Modifiers.HasFlag(ModifierEnum.Abstract) || p.Modifiers.HasFlag(ModifierEnum.Extern)) ? null : CreateNotImplementedBlock(), null);
md.SetRegion.Modifier = ConvertModifier(p.SetterModifiers, null);
}
return md;
}
public static FieldDeclaration ConvertMember(IField f, ClassFinder targetContext)
@ -364,11 +350,6 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -364,11 +350,6 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
node.GetRegion.Block = null;
node.SetRegion.Block = null;
}
foreach (IndexerDeclaration node in members.OfType<IndexerDeclaration>()) {
node.Modifier &= ~(Modifiers.Public | Modifiers.Private | Modifiers.Protected | Modifiers.Internal);
node.GetRegion.Block = null;
node.SetRegion.Block = null;
}
foreach (EventDeclaration node in members.OfType<EventDeclaration>()) {
node.Modifier &= ~(Modifiers.Public | Modifiers.Private | Modifiers.Protected | Modifiers.Internal);
}
@ -710,11 +691,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -710,11 +691,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
pd.Attributes.Clear();
if (explicitImpl || requireAlternativeImplementation) {
InterfaceImplementation impl = CreateInterfaceImplementation(p, context);
if (pd is IndexerDeclaration) {
((IndexerDeclaration)pd).InterfaceImplementations.Add(impl);
} else {
((PropertyDeclaration)pd).InterfaceImplementations.Add(impl);
}
((PropertyDeclaration)pd).InterfaceImplementations.Add(impl);
targetClassProperties.Add(CloneAndAddExplicitImpl(p, targetClass));
pd.Modifier = explicitImplModifier;
} else {

Loading…
Cancel
Save