Пример #1
0
        public bool CheckNamespace(ICS.NamespaceDeclaration node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Namespace) == 0))
            {
                return(false);
            }

            string name = node.Name;

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

            data.Add(GetFixableResult(node.Identifiers.First().StartLocation, null, name));
            return(true);
        }
Пример #2
0
        private string GetMethodContentsFor(SyntaxTree syntaxTree, StringBuilderDocument document, string methodName, out bool wasFound)
        {
            ICSharpCode.NRefactory.CSharp.NamespaceDeclaration namespaceDecl = null;
            TypeDeclaration   classDecl      = null;
            MethodDeclaration methodDecl     = null;
            BlockStatement    blockStatement = null;
            string            toReturn       = null;

            ICSharpCode.NRefactory.TextLocation?start = null;
            ICSharpCode.NRefactory.TextLocation?end   = null;


            foreach (var child in syntaxTree.Children)
            {
                if (child is ICSharpCode.NRefactory.CSharp.NamespaceDeclaration)
                {
                    namespaceDecl = child as NamespaceDeclaration;
                    break;
                }
            }

            if (namespaceDecl != null)
            {
                foreach (var child in namespaceDecl.Children)
                {
                    if (child is TypeDeclaration)
                    {
                        classDecl = child as TypeDeclaration;
                        break;
                    }
                }
            }
            if (classDecl != null)
            {
                foreach (var child in classDecl.Children)
                {
                    if (child is MethodDeclaration && (child as MethodDeclaration).Name == "On" + methodName)
                    {
                        methodDecl = child as MethodDeclaration;
                        break;
                    }
                }
            }

            if (methodDecl != null)
            {
                foreach (var child in methodDecl.Children)
                {
                    if (child is BlockStatement)
                    {
                        blockStatement = child as BlockStatement;
                        break;
                    }
                }
            }

            if (blockStatement != null)
            {
                foreach (var child in blockStatement.Children)
                {
                    if ((child is CSharpTokenNode) == false)
                    {
                        if (start == null)
                        {
                            start = child.StartLocation;
                        }
                        end = child.EndLocation;
                    }
                }
            }

            if (start.HasValue)
            {
                int offset = document.GetOffset(start.Value);
                int length = document.GetOffset(end.Value) - offset;
                wasFound = true;
                return(document.GetText(offset, length));
            }
            else if (blockStatement != null)
            {
                // we found a pure empty method
                wasFound = true;
                return("");
            }
            else
            {
                wasFound = false;
                return(null);
            }
        }
Пример #3
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            NamespaceDeclaration o = other as NamespaceDeclaration;

            return(o != null && MatchString(this.Name, o.Name) && this.Members.DoMatch(o.Members, match));
        }
 void IAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
 {
     Visit(EnterNamespaceDeclaration, LeaveNamespaceDeclaration, namespaceDeclaration);
 }
Пример #5
0
        public override void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
        {
            FixOpenBrace(policy.NamespaceBraceStyle, namespaceDeclaration.LBraceToken);
            if (policy.IndentNamespaceBody)
            {
                curIndent.Push(IndentType.Block);
            }

            bool first       = true;
            bool startFormat = false;

            VisitChildrenToFormat(namespaceDeclaration, child => {
                if (first)
                {
                    startFormat = child.StartLocation > namespaceDeclaration.LBraceToken.StartLocation;
                }
                if (child.Role == Roles.LBrace)
                {
                    var next       = child.GetNextSibling(NoWhitespacePredicate);
                    var blankLines = 1;
                    if (next is UsingDeclaration || next is UsingAliasDeclaration)
                    {
                        blankLines += policy.BlankLinesBeforeUsings;
                    }
                    else
                    {
                        blankLines += policy.BlankLinesBeforeFirstDeclaration;
                    }
                    EnsureNewLinesAfter(child, blankLines);
                    startFormat = true;
                    return;
                }
                if (child.Role == Roles.RBrace)
                {
                    startFormat = false;
                    return;
                }
                if (!startFormat || !NoWhitespacePredicate(child))
                {
                    return;
                }
                if (first && (child is UsingDeclaration || child is UsingAliasDeclaration))
                {
                    // TODO: policy.BlankLinesBeforeUsings
                    first = false;
                }
                if (NoWhitespacePredicate(child))
                {
                    FixIndentationForceNewLine(child);
                }
                child.AcceptVisitor(this);
                if (NoWhitespacePredicate(child))
                {
                    EnsureNewLinesAfter(child, GetGlobalNewLinesFor(child));
                }
            });

            if (policy.IndentNamespaceBody)
            {
                curIndent.Pop();
            }

            FixClosingBrace(policy.NamespaceBraceStyle, namespaceDeclaration.RBraceToken);
        }
Пример #6
0
 public virtual S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data)
 {
     return(VisitChildren(namespaceDeclaration, data));
 }
 public virtual S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data)
 {
     throw new NotImplementedException();
 }