static bool CheckBody(EntityDeclaration node) { var custom = node as CustomEventDeclaration; if (custom != null && !(IsValidBody(custom.AddAccessor.Body) || IsValidBody(custom.RemoveAccessor.Body))) { return(false); } if (node is PropertyDeclaration || node is IndexerDeclaration) { var setter = node.GetChildByRole(PropertyDeclaration.SetterRole); var getter = node.GetChildByRole(PropertyDeclaration.GetterRole); return(IsValidBody(setter.Body) && IsValidBody(getter.Body)); } return(IsValidBody(node.GetChildByRole(Roles.Body))); }
static ThrowStatement ImplementStub(RefactoringContext context, EntityDeclaration newNode) { ThrowStatement throwStatement = null; if (newNode is PropertyDeclaration || newNode is IndexerDeclaration) { var setter = newNode.GetChildByRole(PropertyDeclaration.SetterRole); if (!setter.IsNull) { setter.AddChild(CreateNotImplementedBody(context, out throwStatement), Roles.Body); } var getter = newNode.GetChildByRole(PropertyDeclaration.GetterRole); if (!getter.IsNull) { getter.AddChild(CreateNotImplementedBody(context, out throwStatement), Roles.Body); } } else { newNode.AddChild(CreateNotImplementedBody(context, out throwStatement), Roles.Body); } return(throwStatement); }
void VisitParameterizedEntityDeclaration(string memberType, EntityDeclaration entityDeclaration, AstNodeCollection <ParameterDeclaration> parameters) { // Ignore explicit interface implementations (those should have no optional parameters as there can't be any direct calls) if (!entityDeclaration.GetChildByRole(EntityDeclaration.PrivateImplementationTypeRole).IsNull) { return; } //Override is not strictly necessary because methodDeclaration //might still implement an interface member var memberResolveResult = ctx.Resolve(entityDeclaration) as MemberResolveResult; if (memberResolveResult == null) { return; } var member = (IParameterizedMember)memberResolveResult.Member; var baseMembers = InheritanceHelper.GetBaseMembers(member, true).ToList(); foreach (IParameterizedMember baseMember in baseMembers) { if (baseMember.IsOverride || baseMember.DeclaringType.Kind == TypeKind.Interface) { continue; } CompareMethods(memberType, parameters, member, baseMember); return; } // only check 1 interface method -> multiple interface implementations could lead to deault value conflicts // possible other solutions: Skip the interface check entirely var interfaceBaseMethods = baseMembers.Where(b => b.DeclaringType.Kind == TypeKind.Interface).ToList(); if (interfaceBaseMethods.Count == 1) { foreach (IParameterizedMember baseMember in interfaceBaseMethods) { if (baseMember.DeclaringType.Kind == TypeKind.Interface) { CompareMethods(memberType, parameters, member, baseMember); } } } }
public void ConvertEntity(IEntity entity, IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy) { if (entity == null) { throw new ArgumentNullException("entity"); } if (formatter == null) { throw new ArgumentNullException("formatter"); } if (formattingPolicy == null) { throw new ArgumentNullException("options"); } TypeSystemAstBuilder astBuilder = CreateAstBuilder(); EntityDeclaration node = astBuilder.ConvertEntity(entity); PrintModifiers(node.Modifiers, formatter); if ((ConversionFlags & ConversionFlags.ShowDefinitionKeyword) == ConversionFlags.ShowDefinitionKeyword) { if (node is TypeDeclaration) { switch (((TypeDeclaration)node).ClassType) { case ClassType.Class: formatter.WriteKeyword("class"); break; case ClassType.Struct: formatter.WriteKeyword("struct"); break; case ClassType.Interface: formatter.WriteKeyword("interface"); break; case ClassType.Enum: formatter.WriteKeyword("enum"); break; default: throw new Exception("Invalid value for ClassType"); } formatter.Space(); } else if (node is DelegateDeclaration) { formatter.WriteKeyword("delegate"); formatter.Space(); } else if (node is EventDeclaration) { formatter.WriteKeyword("event"); formatter.Space(); } } if ((ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) { var rt = node.GetChildByRole(Roles.Type); if (!rt.IsNull) { rt.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy)); formatter.Space(); } } if (entity is ITypeDefinition) { WriteTypeDeclarationName((ITypeDefinition)entity, formatter, formattingPolicy); } else { WriteMemberDeclarationName((IMember)entity, formatter, formattingPolicy); } if ((ConversionFlags & ConversionFlags.ShowParameterList) == ConversionFlags.ShowParameterList && HasParameters(entity)) { formatter.WriteToken(entity.EntityType == EntityType.Indexer ? "[" : "("); bool first = true; foreach (var param in node.GetChildrenByRole(Roles.Parameter)) { if (first) { first = false; } else { formatter.WriteToken(","); formatter.Space(); } param.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy)); } formatter.WriteToken(entity.EntityType == EntityType.Indexer ? "]" : ")"); } if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration)) { IProperty property = entity as IProperty; if (property != null) { formatter.Space(); formatter.WriteToken("{"); formatter.Space(); if (property.CanGet) { formatter.WriteKeyword("get"); formatter.WriteToken(";"); formatter.Space(); } if (property.CanSet) { formatter.WriteKeyword("set"); formatter.WriteToken(";"); formatter.Space(); } formatter.WriteToken("}"); } else { formatter.WriteToken(";"); } } }
public static BlockStatement GetDefinition(this EntityDeclaration decl) { return(decl.GetChildByRole <BlockStatement>(Roles.Body)); }