Exemple #1
0
        public bool CheckType(ICS.TypeDeclaration node, InspectionData data)
        {
            if (MatchKind != 0)
            {
                switch (MatchKind)
                {
                case DeclarationKinds.Class:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Class)
                    {
                        return(false);
                    }
                    break;

                case DeclarationKinds.Enum:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Enum)
                    {
                        return(false);
                    }
                    break;

                case DeclarationKinds.Struct:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Struct)
                    {
                        return(false);
                    }
                    break;

                case DeclarationKinds.Interface:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Interface)
                    {
                        return(false);
                    }
                    break;

//				case DeclarationKinds.Delegate:
//					if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Delegate)
//						return false;
//					break;
                default:
                    return(false);
                }
            }

            if (!CheckAttributedNode(node, ICS.Modifiers.Internal))
            {
                return(false);
            }

            string name = node.Name;

            if (IsValid(name))
            {
                return(true);
            }

            data.Add(GetFixableResult(node.NameToken.StartLocation, null, name));
            return(true);
        }
Exemple #2
0
        public override IEntity VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            var td = currentTypeDefinition = CreateTypeDefinition(typeDeclaration.Name);

            td.ClassType  = typeDeclaration.ClassType;
            td.Region     = MakeRegion(typeDeclaration);
            td.BodyRegion = MakeBraceRegion(typeDeclaration);
            td.AddDefaultConstructorIfRequired = true;

            ConvertAttributes(td.Attributes, typeDeclaration.Attributes);
            ApplyModifiers(td, typeDeclaration.Modifiers);
            if (td.ClassType == ClassType.Interface)
            {
                td.IsAbstract = true;                 // interfaces are implicitly abstract
            }
            else if (td.ClassType == ClassType.Enum || td.ClassType == ClassType.Struct)
            {
                td.IsSealed = true;                 // enums/structs are implicitly sealed
            }
            ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints);

            foreach (AstType baseType in typeDeclaration.BaseTypes)
            {
                td.BaseTypes.Add(ConvertType(baseType));
            }

            foreach (AttributedNode member in typeDeclaration.Members)
            {
                member.AcceptVisitor(this, data);
            }

            td.HasExtensionMethods = td.Methods.Any(m => m.IsExtensionMethod);

            currentTypeDefinition = (DefaultTypeDefinition)currentTypeDefinition.DeclaringTypeDefinition;
            return(td);
        }
 void IAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration)
 {
     Visit(EnterTypeDeclaration, LeaveTypeDeclaration, typeDeclaration);
 }
 public virtual S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data)
 {
     return(VisitChildren(typeDeclaration, data));
 }
        public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
        {
            FixAttributesAndDocComment(typeDeclaration);
            BraceStyle braceStyle;
            bool       indentBody = false;

            switch (typeDeclaration.ClassType)
            {
            case ClassType.Class:
                braceStyle = policy.ClassBraceStyle;
                indentBody = policy.IndentClassBody;
                break;

            case ClassType.Struct:
                braceStyle = policy.StructBraceStyle;
                indentBody = policy.IndentStructBody;
                break;

            case ClassType.Interface:
                braceStyle = policy.InterfaceBraceStyle;
                indentBody = policy.IndentInterfaceBody;
                break;

            case ClassType.Enum:
                braceStyle = policy.EnumBraceStyle;
                indentBody = policy.IndentEnumBody;
                break;

            default:
                throw new InvalidOperationException("unsupported class type : " + typeDeclaration.ClassType);
            }

            foreach (var constraint in typeDeclaration.Constraints)
            {
                constraint.AcceptVisitor(this);
            }

            FixOpenBrace(braceStyle, typeDeclaration.LBraceToken);

            if (indentBody)
            {
                curIndent.Push(IndentType.Block);
            }
            bool startFormat = true;
            bool first       = true;

            VisitChildrenToFormat(typeDeclaration, child => {
                if (first)
                {
                    startFormat = child.StartLocation > typeDeclaration.LBraceToken.StartLocation;
                    first       = false;
                }
                if (child.Role == Roles.LBrace)
                {
                    startFormat = true;
                    if (braceStyle != BraceStyle.DoNotChange)
                    {
                        EnsureMinimumNewLinesAfter(child, GetTypeLevelNewLinesFor(child));
                    }
                    return;
                }
                if (child.Role == Roles.RBrace)
                {
                    startFormat = false;
                    return;
                }
                if (!startFormat || !NoWhitespacePredicate(child))
                {
                    return;
                }
                if (child.Role == Roles.Comma)
                {
                    ForceSpacesBeforeRemoveNewLines(child, false);
                    EnsureMinimumNewLinesAfter(child, 1);
                    return;
                }
                if (NoWhitespacePredicate(child))
                {
                    FixIndentationForceNewLine(child);
                }
                child.AcceptVisitor(this);
                if (NoWhitespacePredicate(child) && child.GetNextSibling(NoWhitespacePredicate).Role != Roles.Comma)
                {
                    EnsureMinimumNewLinesAfter(child, GetTypeLevelNewLinesFor(child));
                }
            });

            if (indentBody)
            {
                curIndent.Pop();
            }

            FixClosingBrace(braceStyle, typeDeclaration.RBraceToken);
        }
Exemple #6
0
            public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
            {
                if (typeDeclaration.ClassType == ClassType.Enum)
                {
                    return;
                }
                var entities = new List <EntityDeclaration> (typeDeclaration.Members);

                entities.Sort((x, y) =>
                {
                    int i1 = settings.CodeMemberOrder.IndexOf(GetCodeMemberCategory(x));
                    int i2 = settings.CodeMemberOrder.IndexOf(GetCodeMemberCategory(y));
                    if (i1 != i2)
                    {
                        return(i1.CompareTo(i2));
                    }
                    if (settings.SubOrderAlphabetical)
                    {
                        return((x.Name ?? "").CompareTo((y.Name ?? "")));
                    }
                    return(entities.IndexOf(x).CompareTo(entities.IndexOf(y)));
                });
                typeDeclaration.Members.Clear();
                typeDeclaration.Members.AddRange(entities);

                if (settings.GenerateCategoryComments)
                {
                    var curCat = GeneratedCodeMember.Unknown;
                    foreach (var mem in entities)
                    {
                        if (mem.NextSibling is EntityDeclaration)
                        {
                            mem.Parent.InsertChildAfter(mem, new UnixNewLine(), Roles.NewLine);
                        }

                        var cat = GetCodeMemberCategory(mem);
                        if (cat == curCat)
                        {
                            continue;
                        }
                        curCat = cat;
                        var label = settings.GetCategoryLabel(curCat);
                        if (string.IsNullOrEmpty(label))
                        {
                            continue;
                        }

                        var cmt  = new Comment("", CommentType.SingleLine);
                        var cmt2 = new Comment(" " + label, CommentType.SingleLine);
                        var cmt3 = new Comment("", CommentType.SingleLine);
                        mem.Parent.InsertChildBefore(mem, cmt, Roles.Comment);
                        mem.Parent.InsertChildBefore(mem, cmt2, Roles.Comment);
                        mem.Parent.InsertChildBefore(mem, cmt3, Roles.Comment);
                        if (cmt.PrevSibling is EntityDeclaration)
                        {
                            mem.Parent.InsertChildBefore(cmt, new UnixNewLine(), Roles.NewLine);
                        }

                        mem.Parent.InsertChildAfter(cmt3, new UnixNewLine(), Roles.NewLine);
                    }
                }
            }
 public virtual S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data)
 {
     throw new NotImplementedException();
 }