protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, Accessor accessor, bool setter) { if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null) { XmlToJsDoc.EmitComment(this, this.IndexerDeclaration); var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter); string name = overloads.GetOverloadName(); this.Write((setter ? "set" : "get") + name); this.EmitMethodParameters(indexerDeclaration.Parameters, indexerDeclaration, setter); if (setter) { this.Write(", value"); this.WriteColon(); name = BridgeTypes.ToTypeScriptName(indexerDeclaration.ReturnType, this.Emitter); this.Write(name); this.WriteCloseParentheses(); this.WriteColon(); this.Write("void"); } else { this.WriteColon(); name = BridgeTypes.ToTypeScriptName(indexerDeclaration.ReturnType, this.Emitter); this.Write(name); } this.WriteSemiColon(); this.WriteNewLine(); } }
/// <summary> /// Adds the elements of an array to the end of this IndexerDeclarationCollection. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the end of this IndexerDeclarationCollection. /// </param> public virtual void AddRange(IndexerDeclaration[] items) { foreach (IndexerDeclaration item in items) { this.List.Add(item); } }
static void AddImplementation(RefactoringContext context, TypeDeclaration result, ICSharpCode.NRefactory.TypeSystem.IType guessedType) { foreach (var property in guessedType.GetProperties ()) { if (!property.IsAbstract) continue; if (property.IsIndexer) { var indexerDecl = new IndexerDeclaration() { ReturnType = context.CreateShortType(property.ReturnType), Modifiers = GetModifiers(property), Name = property.Name }; indexerDecl.Parameters.AddRange(ConvertParameters(context, property.Parameters)); if (property.CanGet) indexerDecl.Getter = new Accessor(); if (property.CanSet) indexerDecl.Setter = new Accessor(); result.AddChild(indexerDecl, Roles.TypeMemberRole); continue; } var propDecl = new PropertyDeclaration() { ReturnType = context.CreateShortType(property.ReturnType), Modifiers = GetModifiers (property), Name = property.Name }; if (property.CanGet) propDecl.Getter = new Accessor(); if (property.CanSet) propDecl.Setter = new Accessor(); result.AddChild(propDecl, Roles.TypeMemberRole); } foreach (var method in guessedType.GetMethods ()) { if (!method.IsAbstract) continue; var decl = new MethodDeclaration() { ReturnType = context.CreateShortType(method.ReturnType), Modifiers = GetModifiers (method), Name = method.Name, Body = new BlockStatement() { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }; decl.Parameters.AddRange(ConvertParameters(context, method.Parameters)); result.AddChild(decl, Roles.TypeMemberRole); } foreach (var evt in guessedType.GetEvents ()) { if (!evt.IsAbstract) continue; var decl = new EventDeclaration() { ReturnType = context.CreateShortType(evt.ReturnType), Modifiers = GetModifiers (evt), Name = evt.Name }; result.AddChild(decl, Roles.TypeMemberRole); } }
public static OverloadsCollection Create(IEmitter emitter, IndexerDeclaration indexerDeclaration, bool isSetter = false) { string key = indexerDeclaration.GetHashCode().ToString() + isSetter.GetHashCode().ToString(); if (emitter.OverloadsCache.ContainsKey(key)) { return emitter.OverloadsCache[key]; } return new OverloadsCollection(emitter, indexerDeclaration, isSetter); }
protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, Accessor accessor, bool setter) { if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null) { this.EnsureComma(); this.ResetLocals(); var prevMap = this.BuildLocalsMap(); var prevNamesMap = this.BuildLocalsNamesMap(); if (setter) { this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration { Name = "value" } }, accessor.Body); } XmlToJsDoc.EmitComment(this, this.IndexerDeclaration); var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter); string name = overloads.GetOverloadName(); this.Write((setter ? "set" : "get") + name); this.WriteColon(); this.WriteFunction(); this.EmitMethodParameters(indexerDeclaration.Parameters, indexerDeclaration, setter); if (setter) { this.Write(", value)"); } this.WriteSpace(); var script = this.Emitter.GetScript(accessor); if (script == null) { accessor.Body.AcceptVisitor(this.Emitter); } else { this.BeginBlock(); foreach (var line in script) { this.Write(line); this.WriteNewLine(); } this.EndBlock(); } this.ClearLocalsMap(prevMap); this.ClearLocalsNamesMap(prevNamesMap); this.Emitter.Comma = true; } }
/// <summary> /// Adds an instance of type IndexerDeclaration to the end of this IndexerDeclarationCollection. /// </summary> /// <param name="value"> /// The IndexerDeclaration to be added to the end of this IndexerDeclarationCollection. /// </param> public virtual void Add(IndexerDeclaration value) { this.List.Add(value); }
/// <summary> /// Removes the first occurrence of a specific IndexerDeclaration from this IndexerDeclarationCollection. /// </summary> /// <param name="value"> /// The IndexerDeclaration value to remove from this IndexerDeclarationCollection. /// </param> public virtual void Remove(IndexerDeclaration value) { this.List.Remove(value); }
/// <summary> /// Return the zero-based index of the first occurrence of a specific value /// in this IndexerDeclarationCollection /// </summary> /// <param name="value"> /// The IndexerDeclaration value to locate in the IndexerDeclarationCollection. /// </param> /// <returns> /// The zero-based index of the first occurrence of the _ELEMENT value if found; /// -1 otherwise. /// </returns> public virtual int IndexOf(IndexerDeclaration value) { return this.List.IndexOf(value); }
public ClassDeclaration AddClass(NamespaceDeclaration ns) { ClassDeclaration col = ns.AddClass(this.Name); // set base class as CollectionBase col.Parent = new TypeTypeDeclaration(typeof(DictionaryBase)); // default constructor col.AddConstructor(); // add indexer if (this.ItemGet || this.ItemSet) { IndexerDeclaration index = col.AddIndexer( this.ValueType ); ParameterDeclaration pindex = index.Signature.AddParam(KeyType, "key", false); // get body if (this.ItemGet) { index.Get.Return( (Expr.This.Prop("Dictionary").Item(Expr.Arg(pindex)).Cast(this.ValueType) ) ); } // set body if (this.ItemSet) { index.Set.Add( Stm.Assign( Expr.This.Prop("Dictionary").Item(Expr.Arg(pindex)), Expr.Value ) ); } } // add method if (this.Add) { MethodDeclaration add = col.AddMethod("Add"); ParameterDeclaration pKey = add.Signature.AddParam(this.KeyType, "key", true); ParameterDeclaration pValue = add.Signature.AddParam(this.ValueType, "value", true); add.Body.Add( Expr.This.Prop("Dictionary").Method("Add").Invoke(pKey, pValue) ); } // contains method if (this.Contains) { MethodDeclaration contains = col.AddMethod("Contains"); contains.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool)); ParameterDeclaration pKey = contains.Signature.AddParam(this.KeyType, "key", true); contains.Body.Return( Expr.This.Prop("Dictionary").Method("Contains").Invoke(pKey) ); } // remove method if (this.Remove) { MethodDeclaration remove = col.AddMethod("Remove"); ParameterDeclaration pKey = remove.Signature.AddParam(this.KeyType, "key", true); remove.Body.Add( Expr.This.Prop("Dictionary").Method("Remove").Invoke(pKey) ); } return(col); }
public VisitorIndexerBlock(IEmitter emitter, IndexerDeclaration indexerDeclaration) : base(emitter, indexerDeclaration) { Emitter = emitter; IndexerDeclaration = indexerDeclaration; }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { FixAttributesAndDocComment(indexerDeclaration); ForceSpacesBefore(indexerDeclaration.LBracketToken, policy.SpaceBeforeIndexerDeclarationBracket); ForceSpacesAfter(indexerDeclaration.LBracketToken, policy.SpaceWithinIndexerDeclarationBracket); FormatArguments(indexerDeclaration); bool oneLine = false; bool fixClosingBrace = false; switch (policy.SimplePropertyFormatting) { case PropertyFormatting.AllowOneLine: bool isSimple = IsSimpleAccessor(indexerDeclaration.Getter) && IsSimpleAccessor(indexerDeclaration.Setter); int accessorLine = indexerDeclaration.RBraceToken.StartLocation.Line; if (!indexerDeclaration.Getter.IsNull && indexerDeclaration.Setter.IsNull) { accessorLine = indexerDeclaration.Getter.StartLocation.Line; } else if (indexerDeclaration.Getter.IsNull && !indexerDeclaration.Setter.IsNull) { accessorLine = indexerDeclaration.Setter.StartLocation.Line; } else { var acc = indexerDeclaration.Getter.StartLocation < indexerDeclaration.Setter.StartLocation ? indexerDeclaration.Getter : indexerDeclaration.Setter; accessorLine = acc.StartLocation.Line; } if (!isSimple || indexerDeclaration.LBraceToken.StartLocation.Line != accessorLine) { fixClosingBrace = true; FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken); } else { ForceSpacesBefore(indexerDeclaration.Getter, true); ForceSpacesBefore(indexerDeclaration.Setter, true); ForceSpacesBeforeRemoveNewLines(indexerDeclaration.RBraceToken, true); oneLine = true; } break; case PropertyFormatting.ForceNewLine: fixClosingBrace = true; FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken); break; case PropertyFormatting.ForceOneLine: isSimple = IsSimpleAccessor(indexerDeclaration.Getter) && IsSimpleAccessor(indexerDeclaration.Setter); if (isSimple) { int offset = this.document.GetOffset(indexerDeclaration.LBraceToken.StartLocation); int start = SearchWhitespaceStart(offset); int end = SearchWhitespaceEnd(offset); AddChange(start, offset - start, " "); AddChange(offset + 1, end - offset - 2, " "); offset = this.document.GetOffset(indexerDeclaration.RBraceToken.StartLocation); start = SearchWhitespaceStart(offset); AddChange(start, offset - start, " "); oneLine = true; } else { fixClosingBrace = true; FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken); } break; } if (policy.IndentPropertyBody) curIndent.Push(IndentType.Block); FormatAccessor(indexerDeclaration.Getter, policy.PropertyGetBraceStyle, policy.SimpleGetBlockFormatting, oneLine); FormatAccessor(indexerDeclaration.Setter, policy.PropertySetBraceStyle, policy.SimpleSetBlockFormatting, oneLine); if (policy.IndentPropertyBody) curIndent.Pop(); if (fixClosingBrace) FixClosingBrace(policy.PropertyBraceStyle, indexerDeclaration.RBraceToken); }
public virtual void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { if (this.ThrowException) { throw (Exception)this.CreateException(indexerDeclaration); } }
protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, IProperty prop, Accessor accessor, IMethod propAccessor, bool setter) { var isIgnore = propAccessor != null && this.Emitter.Validator.IsExternalType(propAccessor); if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null && !isIgnore) { this.EnsureComma(); this.ResetLocals(); var prevMap = this.BuildLocalsMap(); var prevNamesMap = this.BuildLocalsNamesMap(); if (setter) { this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration { Name = "value" } }, accessor.Body); } else { this.AddLocals(new ParameterDeclaration[0], accessor.Body); } XmlToJsDoc.EmitComment(this, this.IndexerDeclaration, !setter); string accName = null; if (prop != null) { accName = this.Emitter.GetEntityNameFromAttr(prop, setter); if (string.IsNullOrEmpty(accName)) { var member_rr = (MemberResolveResult)this.Emitter.Resolver.ResolveNode(indexerDeclaration, this.Emitter); var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter); accName = overloads.GetOverloadName(false, Helpers.GetSetOrGet(setter), OverloadsCollection.ExcludeTypeParameterForDefinition(member_rr)); } } this.Write(accName); this.WriteColon(); this.WriteFunction(); var nm = Helpers.GetFunctionName(this.Emitter.AssemblyInfo.NamedFunctions, prop, this.Emitter, setter); if (nm != null) { this.Write(nm); } this.EmitMethodParameters(indexerDeclaration.Parameters, null, indexerDeclaration, setter); if (setter) { this.Write(", value)"); } this.WriteSpace(); var script = this.Emitter.GetScript(accessor); if (script == null) { if (YieldBlock.HasYield(accessor.Body)) { new GeneratorBlock(this.Emitter, accessor).Emit(); } else { accessor.Body.AcceptVisitor(this.Emitter); } } else { this.BeginBlock(); this.WriteLines(script); this.EndBlock(); } this.ClearLocalsMap(prevMap); this.ClearLocalsNamesMap(prevNamesMap); this.Emitter.Comma = true; } }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { new VisitorIndexerBlock(this, indexerDeclaration).Emit(); }
public virtual Node VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { throw new System.NotImplementedException(); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { FindIssuesInNode(indexerDeclaration.Setter, indexerDeclaration.Setter.Body); }
public JsNode VisitIndexerDeclaration(IndexerDeclaration node) { throw new NotImplementedException(); }
protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, IProperty prop, Accessor accessor, IMethod propAccessor, bool setter) { var isIgnore = propAccessor != null && this.Emitter.Validator.IsIgnoreType(propAccessor); if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null && !isIgnore) { this.EnsureComma(); this.ResetLocals(); var prevMap = this.BuildLocalsMap(); var prevNamesMap = this.BuildLocalsNamesMap(); if (setter) { this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration { Name = "value" } }, accessor.Body); } XmlToJsDoc.EmitComment(this, this.IndexerDeclaration); string accName = null; if (prop != null) { accName = this.Emitter.GetEntityNameFromAttr(prop, setter); if (string.IsNullOrEmpty(accName)) { var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter); accName = (setter ? "set" : "get") + overloads.GetOverloadName(); } } this.Write(accName); this.WriteColon(); this.WriteFunction(); this.EmitMethodParameters(indexerDeclaration.Parameters, null, indexerDeclaration, setter); if (setter) { this.Write(", value)"); } this.WriteSpace(); var script = this.Emitter.GetScript(accessor); if (script == null) { accessor.Body.AcceptVisitor(this.Emitter); } else { this.BeginBlock(); foreach (var line in script) { this.Write(line); this.WriteNewLine(); } this.EndBlock(); } this.ClearLocalsMap(prevMap); this.ClearLocalsNamesMap(prevNamesMap); this.Emitter.Comma = true; } }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { base.VisitIndexerDeclaration(indexerDeclaration); if (!indexerDeclaration.HasModifier(Modifiers.Override)) { return; } bool hasGetter = !indexerDeclaration.Getter.IsNull; bool hasSetter = !indexerDeclaration.Setter.IsNull; if (!hasGetter && !hasSetter) { return; } if (hasGetter && indexerDeclaration.Getter.Body.Statements.Count != 1) { return; } if (hasSetter && indexerDeclaration.Setter.Body.Statements.Count != 1) { return; } var resultIndexer = ctx.Resolve(indexerDeclaration) as MemberResolveResult; var basetype = resultIndexer.Member.DeclaringType.DirectBaseTypes.First(); if (basetype == null) { return; } var baseIndexer = basetype.GetMembers(f => f.Name == "Item").FirstOrDefault(); if (baseIndexer == null) { return; } bool hasBaseGetter = ((baseIndexer as IProperty).Getter != null); bool hasBaseSetter = ((baseIndexer as IProperty).Setter != null); if (hasBaseGetter) { if (hasGetter) { var expr = indexerDeclaration.Getter.Body.Statements.FirstOrNullObject() as ReturnStatement; if (expr == null) { return; } Expression indexerExpression = expr.Expression; if (indexerExpression == null || !(indexerExpression.FirstChild is BaseReferenceExpression)) { return; } } } if (hasBaseSetter) { if (hasSetter) { var expr = indexerDeclaration.Setter.Body.Statements.FirstOrNullObject(); if (expr == null || !(expr.FirstChild is AssignmentExpression)) { return; } Expression memberReferenceExpression = (expr.FirstChild as AssignmentExpression).Left; if (memberReferenceExpression == null || !(memberReferenceExpression.FirstChild is BaseReferenceExpression)) { return; } } } var title = ctx.TranslateString("Redundant indexer override"); AddIssue(indexerDeclaration, title, ctx.TranslateString("Remove redundant indexer override"), script => { script.Remove(indexerDeclaration); }); }
public override IEnumerable<CodeAction> GetActions(RefactoringContext context) { var indexer = context.GetNode<IndexerExpression>(); if (indexer == null) yield break; if (!(context.Resolve(indexer).IsError)) yield break; var state = context.GetResolverStateBefore(indexer); if (state.CurrentTypeDefinition == null) yield break; var guessedType = CreateFieldAction.GuessAstType(context, indexer); bool createInOtherType = false; ResolveResult targetResolveResult = null; targetResolveResult = context.Resolve(indexer.Target); createInOtherType = !state.CurrentTypeDefinition.Equals(targetResolveResult.Type.GetDefinition()); bool isStatic; if (createInOtherType) { if (targetResolveResult.Type.GetDefinition() == null || targetResolveResult.Type.GetDefinition().Region.IsEmpty) yield break; isStatic = targetResolveResult is TypeResolveResult; if (isStatic && targetResolveResult.Type.Kind == TypeKind.Interface || targetResolveResult.Type.Kind == TypeKind.Enum) yield break; } else { isStatic = indexer.Target is IdentifierExpression && state.CurrentMember.IsStatic; } yield return new CodeAction(context.TranslateString("Create indexer"), script => { var decl = new IndexerDeclaration() { ReturnType = guessedType, Getter = new Accessor() { Body = new BlockStatement() { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }, Setter = new Accessor() { Body = new BlockStatement() { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }, }; decl.Parameters.AddRange(CreateMethodDeclarationAction.GenerateParameters(context, indexer.Arguments)); if (isStatic) decl.Modifiers |= Modifiers.Static; if (createInOtherType) { if (targetResolveResult.Type.Kind == TypeKind.Interface) { decl.Getter.Body = null; decl.Setter.Body = null; decl.Modifiers = Modifiers.None; } else { decl.Modifiers |= Modifiers.Public; } script.InsertWithCursor(context.TranslateString("Create indexer"), targetResolveResult.Type.GetDefinition(), (s, c) => decl); return; } script.InsertWithCursor(context.TranslateString("Create indexer"), Script.InsertPosition.Before, decl); }, indexer); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { if (indexerDeclaration.HasModifier(Modifiers.Abstract)) { return; } IDictionary<string, List<EntityDeclaration>> dict = CurrentType.InstanceProperties; var key = indexerDeclaration.Name; if (dict.ContainsKey(key)) { dict[key].Add(indexerDeclaration); } else { dict.Add(key, new List<EntityDeclaration>(new[] { indexerDeclaration })); } }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { CheckVirtual(indexerDeclaration); base.VisitIndexerDeclaration(indexerDeclaration); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { base.VisitIndexerDeclaration(indexerDeclaration); if (!indexerDeclaration.HasModifier(Modifiers.Override)) { return; } bool hasGetter = !indexerDeclaration.Getter.IsNull; bool hasSetter = !indexerDeclaration.Setter.IsNull; if (!hasGetter && !hasSetter) { return; } if (hasGetter && indexerDeclaration.Getter.Body.Statements.Count != 1) { return; } if (hasSetter && indexerDeclaration.Setter.Body.Statements.Count != 1) { return; } var resultIndexer = ctx.Resolve(indexerDeclaration) as MemberResolveResult; if (resultIndexer == null) { return; } var baseIndexer = InheritanceHelper.GetBaseMember(resultIndexer.Member) as IProperty; if (baseIndexer == null) { return; } bool hasBaseGetter = (baseIndexer.Getter != null); bool hasBaseSetter = (baseIndexer.Setter != null); if (hasBaseGetter) { if (hasGetter) { var expr = indexerDeclaration.Getter.Body.Statements.FirstOrNullObject() as ReturnStatement; if (expr == null) { return; } Expression indexerExpression = expr.Expression; if (indexerExpression == null || !(indexerExpression.FirstChild is BaseReferenceExpression)) { return; } } } if (hasBaseSetter) { if (hasSetter) { var match = setterPattern.Match(indexerDeclaration.Setter.Body.Statements.FirstOrNullObject()); if (!match.Success) { return; } var memberReferenceExpression = match.Get("left").Single() as IndexerExpression; if (memberReferenceExpression == null || !(memberReferenceExpression.FirstChild is BaseReferenceExpression)) { return; } } } var title = ctx.TranslateString("Redundant indexer override"); AddIssue(new CodeIssue(indexerDeclaration, title, ctx.TranslateString("Remove redundant indexer override"), script => script.Remove(indexerDeclaration)) { IssueMarker = IssueMarker.GrayOut }); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { VisitXmlChildren(indexerDeclaration); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { CheckNode(indexerDeclaration); }
public virtual object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { throw new global::System.NotImplementedException("IndexerDeclaration"); }
static void AddImplementation(RefactoringContext context, TypeDeclaration result, IType guessedType) { foreach (var property in guessedType.GetProperties()) { if (!property.IsAbstract) { continue; } if (property.IsIndexer) { var indexerDecl = new IndexerDeclaration { ReturnType = context.CreateShortType(property.ReturnType), Modifiers = GetModifiers(property), Name = property.Name }; indexerDecl.Parameters.AddRange(ConvertParameters(context, property.Parameters)); if (property.CanGet) { indexerDecl.Getter = new Accessor(); } if (property.CanSet) { indexerDecl.Setter = new Accessor(); } result.AddChild(indexerDecl, Roles.TypeMemberRole); continue; } var propDecl = new PropertyDeclaration { ReturnType = context.CreateShortType(property.ReturnType), Modifiers = GetModifiers(property), Name = property.Name }; if (property.CanGet) { propDecl.Getter = new Accessor(); } if (property.CanSet) { propDecl.Setter = new Accessor(); } result.AddChild(propDecl, Roles.TypeMemberRole); } foreach (var method in guessedType.GetMethods()) { if (!method.IsAbstract) { continue; } var decl = new MethodDeclaration { ReturnType = context.CreateShortType(method.ReturnType), Modifiers = GetModifiers(method), Name = method.Name, Body = new BlockStatement { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }; decl.Parameters.AddRange(ConvertParameters(context, method.Parameters)); result.AddChild(decl, Roles.TypeMemberRole); } foreach (var evt in guessedType.GetEvents()) { if (!evt.IsAbstract) { continue; } var decl = new EventDeclaration { ReturnType = context.CreateShortType(evt.ReturnType), Modifiers = GetModifiers(evt), Variables = { new VariableInitializer { Name = evt.Name } } }; decl.Variables.Add(new VariableInitializer(evt.Name)); result.AddChild(decl, Roles.TypeMemberRole); } }
/// <summary> /// Determines whether a specfic IndexerDeclaration value is in this IndexerDeclarationCollection. /// </summary> /// <param name="value"> /// The IndexerDeclaration value to locate in this IndexerDeclarationCollection. /// </param> /// <returns> /// true if value is found in this IndexerDeclarationCollection; /// false otherwise. /// </returns> public virtual bool Contains(IndexerDeclaration value) { return this.List.Contains(value); }
public RedILNode VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, State data) { throw new System.NotImplementedException(); }
/// <summary> /// Inserts an element into the IndexerDeclarationCollection at the specified index /// </summary> /// <param name="index"> /// The index at which the IndexerDeclaration is to be inserted. /// </param> /// <param name="value"> /// The IndexerDeclaration to insert. /// </param> public virtual void Insert(int index, IndexerDeclaration value) { this.List.Insert(index, value); }
public VisitorIndexerBlock(IEmitter emitter, IndexerDeclaration indexerDeclaration) { this.Emitter = emitter; this.IndexerDeclaration = indexerDeclaration; }
/// <summary> /// Initializes a new instance of the IndexerDeclarationCollection class, containing elements /// copied from an array. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the new IndexerDeclarationCollection. /// </param> public IndexerDeclarationCollection(IndexerDeclaration[] items) { this.AddRange(items); }
public ClassDeclaration AddClass(NamespaceDeclaration ns) { ClassDeclaration col = ns.AddClass(this.Name); // set base class as CollectionBase col.Parent = new TypeTypeDeclaration(typeof(CollectionBase)); // default constructor col.AddConstructor(); // add indexer if (this.ItemGet || this.ItemSet) { IndexerDeclaration index = col.AddIndexer( this.Type ); ParameterDeclaration pindex = index.Signature.AddParam(typeof(int), "index", false); // get body if (this.ItemGet) { index.Get.Return( (Expr.This.Prop("List").Item(Expr.Arg(pindex)).Cast(this.Type) ) ); } // set body if (this.ItemSet) { index.Set.Add( Stm.Assign( Expr.This.Prop("List").Item(Expr.Arg(pindex)), Expr.Value ) ); } } string pname = ns.Conformer.ToCamel(this.Type.Name); // add method if (this.Add) { MethodDeclaration add = col.AddMethod("Add"); ParameterDeclaration para = add.Signature.AddParam(this.Type, pname, true); add.Body.Add( Expr.This.Prop("List").Method("Add").Invoke(para) ); } if (this.AddRange) { MethodDeclaration add = col.AddMethod("AddRange"); ParameterDeclaration para = add.Signature.AddParam(col, pname, true); ForEachStatement fe = Stm.ForEach( this.Type, "item", Expr.Arg(para), false ); fe.Body.Add( Expr.This.Prop("List").Method("Add").Invoke(fe.Local) ); add.Body.Add(fe); } // contains method if (this.Contains) { MethodDeclaration contains = col.AddMethod("Contains"); contains.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool)); ParameterDeclaration para = contains.Signature.AddParam(this.Type, pname, true); contains.Body.Return( Expr.This.Prop("List").Method("Contains").Invoke(para) ); } // remove method if (this.Remove) { MethodDeclaration remove = col.AddMethod("Remove"); ParameterDeclaration para = remove.Signature.AddParam(this.Type, pname, true); remove.Doc.Summary.AddText("Removes the first occurrence of a specific ParameterDeclaration from this ParameterDeclarationCollection."); remove.Body.Add( Expr.This.Prop("List").Method("Remove").Invoke(para) ); } // insert if (this.Insert) { MethodDeclaration insert = col.AddMethod("Insert"); ParameterDeclaration index = insert.Signature.AddParam(typeof(int), "index", true); ParameterDeclaration para = insert.Signature.AddParam(this.Type, pname, true); insert.Body.Add( Expr.This.Prop("List").Method("Insert").Invoke(index, para) ); } // indexof if (this.IndexOf) { MethodDeclaration indexof = col.AddMethod("IndexOf"); ParameterDeclaration para = indexof.Signature.AddParam(this.Type, pname, true); indexof.Signature.ReturnType = new TypeTypeDeclaration(typeof(int)); indexof.Body.Return( Expr.This.Prop("List").Method("IndexOf").Invoke(para) ); } if (this.Enumerator) { // create subclass ClassDeclaration en = col.AddClass("Enumerator"); // add wrapped field FieldDeclaration wrapped = en.AddField( typeof(IEnumerator), "wrapped" ); // add IEnumerator en.Interfaces.Add(typeof(IEnumerator)); // add constructor ConstructorDeclaration cs = en.AddConstructor(); ParameterDeclaration collection = cs.Signature.AddParam(col, "collection", true); cs.Body.Add( Stm.Assign( Expr.This.Field(wrapped), Expr.Arg(collection).Cast(typeof(CollectionBase)).Method("GetEnumerator").Invoke() ) ); // add current PropertyDeclaration current = en.AddProperty(this.Type, "Current"); current.Get.Return( (Expr.This.Field(wrapped).Prop("Current")).Cast(this.Type) ); // add explicit interface implementation PropertyDeclaration currentEn = en.AddProperty(typeof(Object), "Current"); currentEn.Get.Return(Expr.This.Prop(current)); currentEn.PrivateImplementationType = wrapped.Type; // add reset MethodDeclaration reset = en.AddMethod("Reset"); reset.ImplementationTypes.Add(wrapped.Type); reset.Body.Add(Expr.This.Field(wrapped).Method("Reset").Invoke()); // add movenext MethodDeclaration movenext = en.AddMethod("MoveNext"); movenext.ImplementationTypes.Add(wrapped.Type); movenext.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool)); movenext.Body.Return(Expr.This.Field(wrapped).Method("MoveNext").Invoke()); // add get enuemrator MethodDeclaration geten = col.AddMethod("GetEnumerator"); geten.Attributes |= MemberAttributes.New; geten.ImplementationTypes.Add(new TypeTypeDeclaration(typeof(IEnumerable))); geten.Signature.ReturnType = en; geten.Body.Return(Expr.New(en, Expr.This)); } return(col); }
IndexerDeclaration ConvertPropertyToIndexer(PropertyDeclaration astProp, PropertyDefinition propDef) { var astIndexer = new IndexerDeclaration(); astIndexer.Name = astProp.Name; astIndexer.CopyAnnotationsFrom(astProp); astProp.Attributes.MoveTo(astIndexer.Attributes); astIndexer.Modifiers = astProp.Modifiers; astIndexer.PrivateImplementationType = astProp.PrivateImplementationType.Detach(); astIndexer.ReturnType = astProp.ReturnType.Detach(); astIndexer.Getter = astProp.Getter.Detach(); astIndexer.Setter = astProp.Setter.Detach(); astIndexer.Parameters.AddRange(MakeParameters(propDef.Parameters)); return astIndexer; }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { ForceSpacesBefore(indexerDeclaration.LBracketToken, policy.SpaceBeforeIndexerDeclarationBracket); ForceSpacesAfter(indexerDeclaration.LBracketToken, policy.SpaceWithinIndexerDeclarationBracket); ForceSpacesBefore(indexerDeclaration.RBracketToken, policy.SpaceWithinIndexerDeclarationBracket); FormatCommas(indexerDeclaration, policy.SpaceBeforeIndexerDeclarationParameterComma, policy.SpaceAfterIndexerDeclarationParameterComma); FormatAttributedNode(indexerDeclaration); EnforceBraceStyle(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken, indexerDeclaration.RBraceToken); if (policy.IndentPropertyBody) { curIndent.Push(IndentType.Block); } if (!indexerDeclaration.Getter.IsNull) { FixIndentation(indexerDeclaration.Getter.StartLocation); if (!indexerDeclaration.Getter.Body.IsNull) { if (!policy.AllowPropertyGetBlockInline || indexerDeclaration.Getter.Body.LBraceToken.StartLocation.Line != indexerDeclaration.Getter.Body.RBraceToken.StartLocation.Line) { EnforceBraceStyle(policy.PropertyGetBraceStyle, indexerDeclaration.Getter.Body.LBraceToken, indexerDeclaration.Getter.Body.RBraceToken); } else { nextStatementIndent = " "; } VisitBlockWithoutFixingBraces(indexerDeclaration.Getter.Body, policy.IndentBlocks); } } if (!indexerDeclaration.Setter.IsNull) { FixIndentation(indexerDeclaration.Setter.StartLocation); if (!indexerDeclaration.Setter.Body.IsNull) { if (!policy.AllowPropertySetBlockInline || indexerDeclaration.Setter.Body.LBraceToken.StartLocation.Line != indexerDeclaration.Setter.Body.RBraceToken.StartLocation.Line) { EnforceBraceStyle(policy.PropertySetBraceStyle, indexerDeclaration.Setter.Body.LBraceToken, indexerDeclaration.Setter.Body.RBraceToken); } else { nextStatementIndent = " "; } VisitBlockWithoutFixingBraces(indexerDeclaration.Setter.Body, policy.IndentBlocks); } } if (policy.IndentPropertyBody) { curIndent.Pop (); } if (IsMember(indexerDeclaration.NextSibling)) { EnsureBlankLinesAfter(indexerDeclaration, policy.BlankLinesBetweenMembers); } }
public void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { throw new NotImplementedException(); }
private bool IsMatch(IndexerDeclaration left, IndexerDeclaration data) { return(true); }
public override IEnumerable <CodeAction> GetActions(RefactoringContext context) { var indexer = context.GetNode <IndexerExpression>(); if (indexer == null) { yield break; } if (!(context.Resolve(indexer).IsError)) { yield break; } var state = context.GetResolverStateBefore(indexer); if (state.CurrentTypeDefinition == null) { yield break; } var guessedType = TypeGuessing.GuessAstType(context, indexer); bool createInOtherType = false; ResolveResult targetResolveResult = null; targetResolveResult = context.Resolve(indexer.Target); createInOtherType = !state.CurrentTypeDefinition.Equals(targetResolveResult.Type.GetDefinition()); bool isStatic; if (createInOtherType) { if (targetResolveResult.Type.GetDefinition() == null || targetResolveResult.Type.GetDefinition().Region.IsEmpty) { yield break; } isStatic = targetResolveResult is TypeResolveResult; if (isStatic && targetResolveResult.Type.Kind == TypeKind.Interface || targetResolveResult.Type.Kind == TypeKind.Enum) { yield break; } } else { isStatic = indexer.Target is IdentifierExpression && state.CurrentMember.IsStatic; } yield return(new CodeAction(context.TranslateString("Create indexer"), script => { var decl = new IndexerDeclaration() { ReturnType = guessedType, Getter = new Accessor() { Body = new BlockStatement() { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }, Setter = new Accessor() { Body = new BlockStatement() { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }, }; decl.Parameters.AddRange(CreateMethodDeclarationAction.GenerateParameters(context, indexer.Arguments)); if (isStatic) { decl.Modifiers |= Modifiers.Static; } if (createInOtherType) { if (targetResolveResult.Type.Kind == TypeKind.Interface) { decl.Getter.Body = null; decl.Setter.Body = null; decl.Modifiers = Modifiers.None; } else { decl.Modifiers |= Modifiers.Public; } script.InsertWithCursor(context.TranslateString("Create indexer"), targetResolveResult.Type.GetDefinition(), (s, c) => decl); return; } script.InsertWithCursor(context.TranslateString("Create indexer"), Script.InsertPosition.Before, decl); }, indexer) { Severity = ICSharpCode.NRefactory.Refactoring.Severity.Error }); }
public IndexerBlock(IEmitter emitter, IndexerDeclaration indexerDeclaration) : base(emitter, indexerDeclaration) { this.Emitter = emitter; this.IndexerDeclaration = indexerDeclaration; }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { FindIssuesInNode(indexerDeclaration.Setter, indexerDeclaration.Setter.Body); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { var resolveResult = _resolver.Resolve(indexerDeclaration); if (!(resolveResult is MemberResolveResult)) { _errorReporter.Region = indexerDeclaration.GetRegion(); _errorReporter.InternalError("Event declaration " + indexerDeclaration.Name + " does not resolve to a member."); return; } var prop = ((MemberResolveResult)resolveResult).Member as IProperty; if (prop == null) { _errorReporter.Region = indexerDeclaration.GetRegion(); _errorReporter.InternalError("Event declaration " + indexerDeclaration.Name + " does not resolve to a property (resolves to " + resolveResult.ToString() + ")"); return; } var jsClass = GetJsClass(prop.DeclaringTypeDefinition); if (jsClass == null) return; var impl = _metadataImporter.GetPropertySemantics(prop); switch (impl.Type) { case PropertyScriptSemantics.ImplType.GetAndSetMethods: { if (!indexerDeclaration.Getter.IsNull) MaybeCompileAndAddMethodToType(jsClass, indexerDeclaration.Getter, indexerDeclaration.Getter.Body, prop.Getter, impl.GetMethod); if (!indexerDeclaration.Setter.IsNull) MaybeCompileAndAddMethodToType(jsClass, indexerDeclaration.Setter, indexerDeclaration.Setter.Body, prop.Setter, impl.SetMethod); break; } case PropertyScriptSemantics.ImplType.NotUsableFromScript: break; default: throw new InvalidOperationException("Invalid indexer implementation type " + impl.Type); } }
public override void Visit(Indexer i) { var newIndexer = new IndexerDeclaration(); AddAttributeSection(newIndexer, i); var location = LocationsBag.GetMemberLocation(i); AddModifiers(newIndexer, location); newIndexer.AddChild(ConvertToType(i.TypeExpression), Roles.Type); AddExplicitInterface(newIndexer, i.MemberName); var name = i.MemberName; newIndexer.AddChild(new CSharpTokenNode(Convert(name.Location), IndexerDeclaration.ThisKeywordRole), IndexerDeclaration.ThisKeywordRole); if (location != null && location.Count > 0) newIndexer.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LBracket), Roles.LBracket); AddParameter(newIndexer, i.ParameterInfo); if (location != null && location.Count > 1) newIndexer.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RBracket), Roles.RBracket); if (location != null && location.Count > 2) newIndexer.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.LBrace), Roles.LBrace); if (i.Get != null) { var getAccessor = new Accessor(); var getLocation = LocationsBag.GetMemberLocation(i.Get); AddAttributeSection(getAccessor, i.Get); AddModifiers(getAccessor, getLocation); if (getLocation != null) getAccessor.AddChild(new CSharpTokenNode(Convert(i.Get.Location), PropertyDeclaration.GetKeywordRole), PropertyDeclaration.GetKeywordRole); if (i.Get.Block != null) { getAccessor.AddChild((BlockStatement)i.Get.Block.Accept(this), Roles.Body); } else { if (getLocation != null && getLocation.Count > 0) newIndexer.AddChild(new CSharpTokenNode(Convert(getLocation [0]), Roles.Semicolon), Roles.Semicolon); } newIndexer.AddChild(getAccessor, PropertyDeclaration.GetterRole); } if (i.Set != null) { var setAccessor = new Accessor(); var setLocation = LocationsBag.GetMemberLocation(i.Set); AddAttributeSection(setAccessor, i.Set); AddModifiers(setAccessor, setLocation); if (setLocation != null) setAccessor.AddChild(new CSharpTokenNode(Convert(i.Set.Location), PropertyDeclaration.SetKeywordRole), PropertyDeclaration.SetKeywordRole); if (i.Set.Block != null) { setAccessor.AddChild((BlockStatement)i.Set.Block.Accept(this), Roles.Body); } else { if (setLocation != null && setLocation.Count > 0) newIndexer.AddChild(new CSharpTokenNode(Convert(setLocation [0]), Roles.Semicolon), Roles.Semicolon); } newIndexer.AddChild(setAccessor, PropertyDeclaration.SetterRole); } if (location != null) { if (location.Count > 3) newIndexer.AddChild(new CSharpTokenNode(Convert(location [3]), Roles.RBrace), Roles.RBrace); } else { // parser error, set end node to max value. newIndexer.AddChild(new ErrorNode(), Roles.Error); } typeStack.Peek().AddChild(newIndexer, Roles.TypeMemberRole); }
IndexerDeclaration ConvertIndexer(IProperty indexer) { IndexerDeclaration decl = new IndexerDeclaration(); decl.Modifiers = GetMemberModifiers(indexer); decl.ReturnType = ConvertType(indexer.ReturnType); foreach (IParameter p in indexer.Parameters) { decl.Parameters.Add(ConvertParameter(p)); } decl.Getter = ConvertAccessor(indexer.Getter, indexer.Accessibility); decl.Setter = ConvertAccessor(indexer.Setter, indexer.Accessibility); return decl; }
public override void Visit (Indexer indexer) { IndexerDeclaration newIndexer = new IndexerDeclaration (); var location = LocationsBag.GetMemberLocation (indexer); AddModifiers (newIndexer, location); newIndexer.AddChild ((INode)indexer.TypeName.Accept (this), AbstractNode.Roles.ReturnType); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket); AddParameter (newIndexer, indexer.Parameters); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IndexerDeclaration.Roles.RBracket); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[2]), 1), IndexerDeclaration.Roles.LBrace); if (indexer.Get != null) { MonoDevelop.CSharp.Dom.Accessor getAccessor = new MonoDevelop.CSharp.Dom.Accessor (); var getLocation = LocationsBag.GetMemberLocation (indexer.Get); AddModifiers (getAccessor, getLocation); if (getLocation != null) getAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Get.Location), "get".Length), PropertyDeclaration.Roles.Keyword); if (indexer.Get.Block != null) { getAccessor.AddChild ((INode)indexer.Get.Block.Accept (this), MethodDeclaration.Roles.Body); } else { if (getLocation != null && getLocation.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (getLocation[0]), 1), MethodDeclaration.Roles.Semicolon); } newIndexer.AddChild (getAccessor, PropertyDeclaration.PropertyGetRole); } if (indexer.Set != null) { MonoDevelop.CSharp.Dom.Accessor setAccessor = new MonoDevelop.CSharp.Dom.Accessor (); var setLocation = LocationsBag.GetMemberLocation (indexer.Set); AddModifiers (setAccessor, setLocation); if (setLocation != null) setAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Set.Location), "set".Length), PropertyDeclaration.Roles.Keyword); if (indexer.Set.Block != null) { setAccessor.AddChild ((INode)indexer.Set.Block.Accept (this), MethodDeclaration.Roles.Body); } else { if (setLocation != null && setLocation.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (setLocation[0]), 1), MethodDeclaration.Roles.Semicolon); } newIndexer.AddChild (setAccessor, PropertyDeclaration.PropertySetRole); } if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[3]), 1), IndexerDeclaration.Roles.RBrace); typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.Roles.Member); }
public override void Visit (Indexer indexer) { IndexerDeclaration newIndexer = new IndexerDeclaration (); AddAttributeSection (newIndexer, indexer); var location = LocationsBag.GetMemberLocation (indexer); AddModifiers (newIndexer, location); newIndexer.AddChild (ConvertToType (indexer.TypeName), IndexerDeclaration.Roles.Type); var name = indexer.MemberName; if (name.Left != null) { newIndexer.AddChild (ConvertToType (name.Left), IndexerDeclaration.PrivateImplementationTypeRole); var privateImplTypeLoc = LocationsBag.GetLocations (name.Left); if (privateImplTypeLoc != null) newIndexer.AddChild (new CSharpTokenNode (Convert (privateImplTypeLoc[0]), 1), MethodDeclaration.Roles.Dot); } newIndexer.AddChild (Identifier.Create ("this", Convert (name.Location)), IndexerDeclaration.Roles.Identifier); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location [0]), 1), IndexerDeclaration.Roles.LBracket); AddParameter (newIndexer, indexer.ParameterInfo); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IndexerDeclaration.Roles.RBracket); if (location != null) newIndexer.AddChild (new CSharpTokenNode (Convert (location[2]), 1), IndexerDeclaration.Roles.LBrace); if (indexer.Get != null) { Accessor getAccessor = new Accessor (); var getLocation = LocationsBag.GetMemberLocation (indexer.Get); AddAttributeSection (getAccessor, indexer.Get); AddModifiers (getAccessor, getLocation); if (getLocation != null) getAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Get.Location), "get".Length), PropertyDeclaration.Roles.Keyword); if (indexer.Get.Block != null) { getAccessor.AddChild ((BlockStatement)indexer.Get.Block.Accept (this), MethodDeclaration.Roles.Body); } else { if (getLocation != null && getLocation.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (getLocation[0]), 1), MethodDeclaration.Roles.Semicolon); } newIndexer.AddChild (getAccessor, PropertyDeclaration.GetterRole); } if (indexer.Set != null) { Accessor setAccessor = new Accessor (); var setLocation = LocationsBag.GetMemberLocation (indexer.Set); AddAttributeSection (setAccessor, indexer.Set); AddModifiers (setAccessor, setLocation); if (setLocation != null) setAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Set.Location), "set".Length), PropertyDeclaration.Roles.Keyword); if (indexer.Set.Block != null) { setAccessor.AddChild ((BlockStatement)indexer.Set.Block.Accept (this), MethodDeclaration.Roles.Body); } else { if (setLocation != null && setLocation.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (setLocation[0]), 1), MethodDeclaration.Roles.Semicolon); } newIndexer.AddChild (setAccessor, PropertyDeclaration.SetterRole); } if (location != null) { newIndexer.AddChild (new CSharpTokenNode (Convert (location[3]), 1), IndexerDeclaration.Roles.RBrace); } else { // parser error, set end node to max value. newIndexer.AddChild (new ErrorNode (), AstNode.Roles.Error); } typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.MemberRole); }
public override object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { CheckNode(indexerDeclaration); return(base.VisitIndexerDeclaration(indexerDeclaration, data)); }
public override void VisitIndexerDeclaration (IndexerDeclaration indexerDeclaration) { if (!indexerDeclaration.LBraceToken.IsNull) AddFolding (GetEndOfPrev(indexerDeclaration.LBraceToken), indexerDeclaration.RBraceToken.EndLocation, true); base.VisitIndexerDeclaration (indexerDeclaration); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { if (indexerDeclaration.Modifiers.HasFlag(Modifiers.Override)) { var rr = ctx.Resolve (indexerDeclaration) as MemberResolveResult; if (rr == null) return; var baseType = rr.Member.DeclaringType.DirectBaseTypes.FirstOrDefault (t => t.Kind != TypeKind.Interface); var method = baseType != null ? baseType.GetProperties (m => m.IsIndexer && m.IsOverridable && m.Parameters.Count == indexerDeclaration.Parameters.Count).FirstOrDefault () : null; if (method == null) return; int i = 0; foreach (var par in indexerDeclaration.Parameters) { if (method.Parameters[i++].Name != par.Name) { par.AcceptVisitor (this); } } return; } base.VisitIndexerDeclaration(indexerDeclaration); }
public virtual void VisitIndexerDeclaration (IndexerDeclaration indexerDeclaration) { VisitChildren (indexerDeclaration); }
public static string GetPropertyRef(IndexerDeclaration property, IEmitter emitter, bool isSetter = false, bool noOverload = false, bool ignoreInterface = false) { var name = emitter.GetEntityName(property, true, ignoreInterface); if (!noOverload) { var overloads = OverloadsCollection.Create(emitter, property, isSetter); name = overloads.HasOverloads ? overloads.GetOverloadName() : name; noOverload = !overloads.HasOverloads; } return (isSetter ? "set" : "get") + name; }
public void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { StartNode(indexerDeclaration); WriteAttributes(indexerDeclaration.Attributes); WriteModifiers(indexerDeclaration.ModifierTokens); indexerDeclaration.ReturnType.AcceptVisitor(this); Space(); WritePrivateImplementationType(indexerDeclaration.PrivateImplementationType); WriteKeyword(IndexerDeclaration.ThisKeywordRole); Space(policy.SpaceBeforeMethodDeclarationParentheses); WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); OpenBrace(policy.PropertyBraceStyle); // output get/set in their original order foreach (AstNode node in indexerDeclaration.Children) { if (node.Role == IndexerDeclaration.GetterRole || node.Role == IndexerDeclaration.SetterRole) { node.AcceptVisitor(this); } } CloseBrace(policy.PropertyBraceStyle); NewLine(); EndNode(indexerDeclaration); }
public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) { VisitParameterizedEntityDeclaration("indexer", indexerDeclaration, indexerDeclaration.Parameters); }