예제 #1
0
        public static List <MethodDeclarationSyntax> SearchForMethod(this ClassDeclarationSyntax classDeclaration,
                                                                     MethodMatch methodMatch)
        {
            if (Program.Debug)
            {
                Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullMemberTag(methodMatch)}}}");
                Program.IndentLevel++;
            }

            List <MethodDeclarationSyntax> s = Registry.GetMatchedMember(methodMatch);

            if (!Program.SkipOne)
            {
                Program.WriteLine(ConsoleColor.Red, "Skipping for speed");
                s = classDeclaration.Members.OfType <MethodDeclarationSyntax>().Where(methodMatch.Matches)
                    .ToList();
            }

            if (Program.Debug)
            {
                Program.IndentLevel--;
            }

            return(s);
        }
예제 #2
0
        public static List <EnumDeclarationSyntax> SearchForEnum(EnumMatch enumMatch)
        {
            if (Program.Debug)
            {
                Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullTypeTag(enumMatch)}}}");
                Program.IndentLevel++;
            }

            List <EnumDeclarationSyntax> ls = Registry.GetMatchedType(enumMatch);

            if (!Program.SkipOne)
            {
                ls = Registry.AssemblyCs.Values.Where(c => c is EnumDeclarationSyntax e && enumMatch.Matches(e))
                     .Cast <EnumDeclarationSyntax>().ToList();
            }

            foreach (var enumDeclarationSyntax in ls)
            {
                Registry.AddMatchedType(enumMatch, enumDeclarationSyntax);
            }

            if (Program.Debug)
            {
                Program.IndentLevel--;
            }

            return(ls);
        }
        protected override async Task <UsingDirective> AssignUpsertedReferences(UsingDirective record)
        {
            record.Identifier = await _identifiers.UpsertAsync(record.Identifier);

            record.IdentifierId = record.Identifier?.IdentifierId ?? record.IdentifierId;
            return(record);
        }
예제 #4
0
        public void AddUsing(UsingDirective u)
        {
            this.FileUsings.Add(u);
            this.namespaceSearchPrefixes = null;
            bool isLinq = string.Join('.', u.Path.Select(token => token.Value)) == "System.Linq";

            this.HasLinq = this.HasLinq || isLinq;
        }
        public void CSharpCodeGenerator_UsingDirective()
        {
            var directive = new UsingDirective("System");

            var generator = new CSharpCodeGenerator();
            var result    = generator.Write(directive);

            Assert.That.StringEquals("using System;", result);
        }
예제 #6
0
        /// <summary>
        /// Compares the order of two using directives.
        /// </summary>
        /// <param name="firstUsing">The first using directive.</param>
        /// <param name="secondUsing">The second using directive.</param>
        /// <returns>Returns false if the elements are out of order.</returns>
        private bool CompareOrderOfUsingDirectives(UsingDirective firstUsing, UsingDirective secondUsing)
        {
            Param.AssertNotNull(firstUsing, "firstUsing");
            Param.AssertNotNull(secondUsing, "secondUsing");

            if (string.IsNullOrEmpty(firstUsing.Alias))
            {
                if (string.IsNullOrEmpty(secondUsing.Alias))
                {
                    bool isFirstSystem  = firstUsing.NamespaceType.StartsWith("System", StringComparison.Ordinal) || firstUsing.NamespaceType.StartsWith("System.", StringComparison.Ordinal);
                    bool isSecondSystem = secondUsing.NamespaceType.Equals("System", StringComparison.Ordinal) || secondUsing.NamespaceType.StartsWith("System.", StringComparison.Ordinal);

                    // Neither of the usings is an alias. First, ensure that System namespaces are placed above all
                    // non-System namespaces.
                    if (isSecondSystem && !isFirstSystem)
                    {
                        this.AddViolation(secondUsing, Rules.SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives);
                        return(false);
                    }
                    else if ((isFirstSystem && isSecondSystem) || (!isFirstSystem && !isSecondSystem))
                    {
                        if (!CheckNamespaceOrdering(firstUsing.NamespaceType, secondUsing.NamespaceType))
                        {
                            // The usings are not in alphabetical order by namespace.
                            this.AddViolation(firstUsing, Rules.UsingDirectivesMustBeOrderedAlphabeticallyByNamespace);
                            return(false);
                        }
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(secondUsing.Alias))
                {
                    // The first using is an alias, but the second is not. They are in the wrong order.
                    this.AddViolation(firstUsing, Rules.UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives);
                    return(false);
                }
                else
                {
                    // Both of the usings are aliases. Verify that they are sorted alphabetically by the alias name.
                    if (string.Compare(firstUsing.Alias, secondUsing.Alias, StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        // The usings are not sorted alphabetically by the alias.
                        this.AddViolation(firstUsing, Rules.UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName);
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #7
0
        /// <summary>
        /// Adds a new using directive with the specified namespace.
        ///
        /// <param name="ns">reference to namespace</param>
        /// </summary>
        public void add_using_directive(UsingDirective ns)
        {
            // do not modify current_using_directives, it should be considered immutable
            // for correct symbol resolving
            var old_using_directives = current_using_directives;

            current_using_directives = new List <UsingDirective>();
            foreach (var using_directive in old_using_directives)
            {
                current_using_directives.Add(using_directive);
            }
            current_using_directives.Add(ns);
        }
예제 #8
0
        public void ReturnsNull()
        {
            var d1 = new UsingDirective {
                Namespace = "System"
            };
            var d2 = new UsingDirective {
                Namespace = "System.Linq"
            };
            var required = new[] { d1, d2 };
            var current  = new[] { d1, d2 };

            Assert.IsNull(OrderChecker.GetNextUsingToMove(required, current));
        }
예제 #9
0
 private void Add(UsingBlock usingSection, UsingDirective usingEntry)
 {
     if (usingSection.VMembers.Children.Count == 1 &&
         usingSection.FirstUsing != null &&
         usingSection.FirstUsing.Text == "")
     {
         usingSection.VMembers.Children.Replace(usingSection.FirstUsing, usingEntry);
     }
     else
     {
         usingSection.VMembers.Children.Add(usingEntry);
     }
 }
예제 #10
0
        public static UstNode GetObject(string type)
        {
            UstNode ustNode = null;

            switch (type)
            {
            case IdConstants.RootIdName:
                ustNode = new RootUstNode();
                break;

            case IdConstants.UsingDirectiveIdName:
                ustNode = new UsingDirective();
                break;

            case IdConstants.NamespaceIdName:
                ustNode = new NamespaceDeclaration();
                break;

            case IdConstants.ClassIdName:
                ustNode = new ClassDeclaration();
                break;

            case IdConstants.InterfaceIdName:
                ustNode = new InterfaceDeclaration();
                break;

            case IdConstants.BodyIdName:
                ustNode = new BlockStatement();
                break;

            case IdConstants.ObjectCreationIdName:
                ustNode = new ObjectCreationExpression();
                break;

            case IdConstants.InvocationIdName:
                ustNode = new InvocationExpression();
                break;

            case IdConstants.LiteralIdName:
                ustNode = new LiteralExpression();
                break;

            case IdConstants.MethodIdName:
                ustNode = new MethodDeclaration();
                break;

            default: break;
            }

            return(ustNode);
        }
예제 #11
0
        public static List <ClassDeclarationSyntax> SearchForClass(ClassMatch classMatch)
        {
            if (Program.Debug)
            {
                Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullTypeTag(classMatch)}}}");
                Program.IndentLevel++;
            }


            List <ClassDeclarationSyntax> ls = Registry.GetMatchedType(classMatch);

            if (!Program.SkipOne)
            {
                ls = Registry.AssemblyCs.Values.Where(c => c is ClassDeclarationSyntax cl && classMatch.Matches(cl))
                     .Cast <ClassDeclarationSyntax>().ToList();
            }

            List <ClassDeclarationSyntax> toRemove = new();

            foreach (var classDeclarationSyntax in ls)
            {
                if (Registry.Fullmatches.Contains(classDeclarationSyntax))
                {
                    toRemove.Add(classDeclarationSyntax);
                }
                else
                {
                    Registry.AddMatchedType(classMatch, classDeclarationSyntax);
                }
            }

            foreach (var torm in toRemove)
            {
                ls.Remove(torm);
            }

            if (ls.Count == 1)
            {
                Registry.Fullmatches.Add(ls[0]);
            }



            if (Program.Debug)
            {
                Program.IndentLevel--;
            }

            return(ls);
        }
예제 #12
0
        public override void visit_using_directive(UsingDirective ns)
        {
            var unresolved_symbol = ns.namespace_symbol as UnresolvedSymbol;

            if (unresolved_symbol != null)
            {
                ns.namespace_symbol = resolve_symbol(unresolved_symbol);
                if (!(ns.namespace_symbol is Namespace))
                {
                    ns.error = true;
                    Report.error(ns.source_reference, "The namespace name `%s' could not be found".printf(unresolved_symbol.ToString()));
                    return;
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Checks the order of the using directives in the given list.
        /// </summary>
        /// <param name="usings">The list of using directives.</param>
        private void CheckOrderOfUsingDirectivesInList(List <UsingDirective> usings)
        {
            Param.AssertNotNull(usings, "usings");

            for (int i = 0; i < usings.Count; ++i)
            {
                UsingDirective firstUsing = usings[i];

                for (int j = i + 1; j < usings.Count; ++j)
                {
                    UsingDirective secondUsing = usings[j];

                    if (!this.CompareOrderOfUsingDirectives(firstUsing, secondUsing))
                    {
                        break;
                    }
                }
            }
        }
예제 #14
0
        internal void Verify(UsingDirective[] directivesIn, params UsingDirective[][] expectedGroups)
        {
            foreach (var permutation in AllOrderings(directivesIn))
            {
                var results = OrderAndSpacingGenerator.DetermineOrderAndSpacing(
                    permutation, Configuration);

                Assert.AreEqual(expectedGroups.Length, results.Count);
                for (int i = 0; i < expectedGroups.Length; ++i)
                {
                    Assert.AreEqual(results[i].Count, expectedGroups[i].Length, "Item count in group " + i);
                    for (int j = 0; j < expectedGroups[i].Length; ++j)
                    {
                        UsingDirective expectedUsing = expectedGroups[i][j];
                        UsingDirective actualUsing   = results[i][j];
                        string         message       = string.Format(
                            "Expected {0} at {1},{2}, found {3}", expectedUsing, i, j, actualUsing);
                        Assert.AreSame(expectedUsing, actualUsing, message);
                    }
                }
            }
        }
예제 #15
0
        public static List <EnumMemberDeclarationSyntax> SearchForEnumValue(this EnumDeclarationSyntax enumDeclaration,
                                                                            EnumValueMatch valueMatch)
        {
            if (Program.Debug)
            {
                Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullMemberTag(valueMatch)}}}");
                Program.IndentLevel++;
            }

            List <EnumMemberDeclarationSyntax> s = Registry.GetMatchedMember(valueMatch);

            if (!Program.SkipOne)
            {
                s = enumDeclaration.Members.Where(m => valueMatch.Matches(m))
                    .ToList();
            }

            if (Program.Debug)
            {
                Program.IndentLevel--;
            }

            return(s);
        }
예제 #16
0
        public static List <FieldDeclarationSyntax> SearchForField(this ClassDeclarationSyntax type, FieldMatch fieldMatch)
        {
            if (Program.Debug)
            {
                Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullMemberTag(fieldMatch)}}}");
                Program.IndentLevel++;
            }

            List <FieldDeclarationSyntax> s = Registry.GetMatchedMember(fieldMatch);

            if (!Program.SkipOne)
            {
                s = type.Members.OfType <FieldDeclarationSyntax>().Where(fieldMatch.Matches)
                    .ToList();
            }


            if (Program.Debug)
            {
                Program.IndentLevel--;
            }

            return(s);
        }
예제 #17
0
 internal static void using_directive_location(this TextWriter trapFile, UsingDirective @using, Location location)
 {
     trapFile.WriteTuple("using_directive_location", @using, location);
 }
예제 #18
0
 internal static void using_namespace_directives(this TextWriter trapFile, UsingDirective @using, Namespace ns)
 {
     trapFile.WriteTuple("using_namespace_directives", @using, ns);
 }
 protected override Expression <Func <UsingDirective, bool> > FindExisting(UsingDirective record)
 => existing => existing.IdentifierId == record.IdentifierId;
 protected override IEnumerable <object> EnumerateReferences(UsingDirective record)
 {
     yield return(record.Identifier);
 }
예제 #21
0
        private void Process_Using_Directive(UsingDirective node)
        {
            if (node == null) throw new ArgumentNullException("node");

            UsingStatement usingDirective = new UsingStatement(controller);
            usingDirective.Alias = node.Alias ?? "";
            usingDirective.Value = node.NamespaceName.Text;

            SetupBaseConstruct(node.StartOffset, node.EndOffset, "", usingDirective, null);
        }
예제 #22
0
 internal static Tuple using_static_directives(UsingDirective @using, Type type) => new Tuple("using_static_directives", @using, type);
 public AliasAndUsingDirective(AliasSymbol alias, UsingDirective usingDirective)
 {
     this.Alias          = alias;
     this.UsingDirective = usingDirective;
 }
예제 #24
0
 internal static Tuple using_namespace_directives(UsingDirective @using, Namespace ns) => new Tuple("using_namespace_directives", @using, ns);
예제 #25
0
 private void MarkImportDirective(UsingDirective directive, bool callerIsSemanticModel)
 {
     MarkImportDirective(_compilation, directive.SyntaxNode, callerIsSemanticModel);
 }
예제 #26
0
 public NamespaceOrTypeAndUsingDirective(NamespaceOrTypeSymbol namespaceOrType, UsingDirective usingDirective)
 {
     this.NamespaceOrType = namespaceOrType;
     this.UsingDirective  = usingDirective;
 }
예제 #27
0
파일: Parser.cs 프로젝트: chenzuo/blue
//-----------------------------------------------------------------------------
// Parse and return an array of using declarations 
// ** rules **
// UsingDirective -> 'using' id:name '=' id_list ';'      // for aliasing
// UsingDirective -> 'using' id_list ';'                  // for namespaces
//-----------------------------------------------------------------------------
    protected UsingDirective[] ParseUsingDirectives()
    {
        Token t;
                       
        t = m_lexer.PeekNextToken();

        ArrayList a = new ArrayList();

        while( t.TokenType == Token.Type.cUsing)
        {
            ConsumeNextToken();
            Exp o = ParseDottedIdList();

            UsingDirective node;

            FileRange f = this.BeginRange();        
            t = m_lexer.PeekNextToken();
            if (t.TokenType == Token.Type.cAssign)
            {
                ConsumeNextToken();
                // o had better be a single identifier
                SimpleObjExp s = o as SimpleObjExp;
                Debug.Assert(s != null);
                string stAlias = s.Name.Text;

                Exp o2 = ParseDottedIdList();
                node = new UsingDirective(stAlias, o2);
            } 
            else 
            {
                node = new UsingDirective(o);
            }
            ReadExpectedToken(Token.Type.cSemi);

            Debug.Assert(node != null);
            node.SetLocation(this.EndRange(f));
            a.Add(node);
            t = m_lexer.PeekNextToken();
        }


        UsingDirective[] arNodes = (UsingDirective[]) a.ToArray(typeof(UsingDirective));
        
        return arNodes;
    }
예제 #28
0
 internal static void using_static_directives(this TextWriter trapFile, UsingDirective @using, Type type)
 {
     trapFile.WriteTuple("using_static_directives", @using, type);
 }
예제 #29
0
 internal static Tuple using_directive_location(UsingDirective @using, Location location) => new Tuple("using_directive_location", @using, location);
        public void TestCaseEvaluation1()
        {
            var directive = new UsingDirective("BOO ? TO $", "BEER", TypeConverter);

            Assert.AreEqual("1", Evaluate("{BOO I TO 1}{I}{BEER}", directive));
        }
        public void TestCaseConstructor3()
        {
            var directive = new UsingDirective("SET $ TO BE ?", "TERMINATE", TypeConverter);

            Assert.AreEqual("{SET $ TO BE ?}...{TERMINATE}", directive.ToString());
        }
예제 #32
0
 private bool Equals(UsingDirective other)
 {
     return(Name == other.Name && Alias == other.Alias);
 }
예제 #33
0
 private void Add(UsingBlock usingSection, UsingDirective usingEntry)
 {
     if (usingSection.VMembers.Children.Count == 1
         && usingSection.FirstUsing != null
         && usingSection.FirstUsing.Text == "")
     {
         usingSection.VMembers.Children.Replace(usingSection.FirstUsing, usingEntry);
     }
     else
     {
         usingSection.VMembers.Children.Add(usingEntry);
     }
 }