public void GenerateSignatureXML()
        {
            using (FileStream fs = File.OpenRead(".\\TestInput\\SystemSignatures.txt"))
            {
                ApexLexer   scanner = new ApexLexer(fs);
                ApexParser  parser  = new ApexParser(scanner);
                ParseResult result  = parser.ParseApex();

                if (result.Errors.Length > 0)
                {
                    foreach (LanguageError err in result.Errors)
                    {
                        Console.WriteLine(err.ToString());
                    }
                    Assert.Fail("Errors in text.");
                }
                else
                {
                    PropertyInfo nameInfo = typeof(Symbol).GetProperty("Name");
                    FieldInfo    fi       = typeof(TypedSymbol).GetField("_type", BindingFlags.NonPublic | BindingFlags.Instance);
                    PropertyInfo pi       = typeof(SymbolTable).GetProperty("TableType");

                    List <SymbolTable> symbols = new List <SymbolTable>();
                    foreach (SymbolTable symbol in result.Symbols.InnerClasses)
                    {
                        if (symbol.Name == "trigger")
                        {
                            fi.SetValue(symbol, "System.Trigger");
                            nameInfo.SetValue(symbol, "Trigger");
                        }
                        else
                        {
                            fi.SetValue(symbol, String.Format("System.{0}", symbol.Name));
                        }

                        if (symbol.InnerClasses.Length > 0 &&
                            symbol.Fields.Length == 0 &&
                            symbol.Constructors.Length == 0 &&
                            symbol.Properties.Length == 0 &&
                            symbol.Methods.Length == 0 &&
                            symbol.Interfaces.Length == 0 &&
                            String.IsNullOrWhiteSpace(symbol.Extends))
                        {
                            pi.SetValue(symbol, SymbolTableType.Namespace);
                        }
                        symbols.Add(symbol);
                    }

                    XmlSerializer ser = new XmlSerializer(typeof(SymbolTable[]));
                    StringBuilder sb  = new StringBuilder();
                    using (StringWriter sw = new StringWriter(sb))
                    {
                        ser.Serialize(sw, symbols.ToArray());
                        Console.Write(sb.ToString());
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Parse the given text for an apex document.
        /// </summary>
        /// <param name="stream">The stream to read text from to parse.</param>
        /// <param name="replace">If true, existing symbols will be replaced.  If false, existing symbols will not be replaced.</param>
        /// <param name="save">If set to true the symbols will be saved to file if a SymbolsFolder has been set.</param>
        /// <param name="merge">If set to true, inner classes will be merged into existing classes when available.</param>
        /// <returns>The result of the parse.</returns>
        public ParseResult ParseApex(Stream stream, bool replace, bool save, bool merge)
        {
            if (stream == null)
            {
                return(new ParseResult(null, null, new LanguageError[0]));
            }

            ApexParser parser = new ApexParser(new ApexLexer(stream));

            ParseResult result = parser.ParseApex();

            if (result.Symbols != null)
            {
                UpdateSymbols(new SymbolTable[] { result.Symbols }, replace, save, merge);
            }

            return(result);
        }
Exemple #3
0
        public void ApexParser_ParseApex()
        {
            foreach (string file in Directory.GetFiles(".\\TestInput", "apexTest*.txt"))
            {
                Console.WriteLine("File: " + file);

                using (FileStream fs = File.OpenRead(file))
                {
                    ApexLexer   scanner = new ApexLexer(fs);
                    ApexParser  parser  = new ApexParser(scanner);
                    ParseResult result  = parser.ParseApex();

                    foreach (LanguageError err in result.Errors)
                    {
                        Console.WriteLine(err.ToString());
                    }

                    Assert.AreEqual(0, result.Errors.Length, "Errors occured parsing: " + file);
                }

                Console.WriteLine();
            }
        }