示例#1
0
        public void SetupFixture()
        {
            // Add forms designer addin to the AddInTree.
            bool formsDesignerAddInExists = false;

            foreach (AddIn addIn in AddInTree.AddIns)
            {
                if (addIn.Manifest.Identities.ContainsKey("ICSharpCode.FormsDesigner"))
                {
                    formsDesignerAddInExists = true;
                    break;
                }
            }

            if (!formsDesignerAddInExists)
            {
                formsDesignerAddIn         = AddIn.Load(new StringReader(GetFormsDesignerAddInFile()));
                formsDesignerAddIn.Enabled = true;

                string codeBase = typeof(PythonSyntaxModeTestFixture).Assembly.CodeBase.Replace("file:///", String.Empty);
                string folder   = Path.GetDirectoryName(codeBase);

                Type      type      = formsDesignerAddIn.GetType();
                FieldInfo fieldInfo = type.GetField("addInFileName", BindingFlags.NonPublic | BindingFlags.Instance);
                fieldInfo.SetValue(formsDesignerAddIn, Path.Combine(folder, "FormsDesigner.addin"));
                AddInTree.InsertAddIn(formsDesignerAddIn);
            }

            using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
                addin = AddIn.Load(reader, String.Empty);

                // Get syntax mode codon.
                syntaxModeCodon = null;
                ExtensionPath path = addin.Paths[SyntaxModePath];
                foreach (Codon codon in path.Codons)
                {
                    if (codon.Id == "Python.SyntaxMode")
                    {
                        syntaxModeCodon = codon;
                        break;
                    }
                }

                // Get syntax mode.
                highlightingStrategy = null;
                if (syntaxModeCodon != null)
                {
                    SyntaxModeDoozer    doozer     = new SyntaxModeDoozer();
                    AddInTreeSyntaxMode syntaxMode = (AddInTreeSyntaxMode)doozer.BuildItem(null, syntaxModeCodon, null);
                    highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, syntaxMode.CreateTextReader());

                    // Load Python syntax file into XML document since
                    // we cannot get all the information stored in this
                    // document through the HighlightRuleSet class. For
                    // example KeyWords are only accessible through a
                    // LookupTable does not have a getter which is easy
                    // to use.
                    syntaxModeDocument = new XmlDocument();
                    syntaxModeDocument.Load(syntaxMode.CreateTextReader());

                    // Get default ruleset.
                    foreach (HighlightRuleSet ruleSet in highlightingStrategy.Rules)
                    {
                        if (String.IsNullOrEmpty(ruleSet.Name))
                        {
                            defaultRuleSet = ruleSet;
                            break;
                        }
                    }

                    // Get keywords elements.
                    importsKeyWordsElement             = GetKeyWordsElement("Imports");
                    iterationStatementsKeyWordsElement = GetKeyWordsElement("IterationStatements");
                    jumpStatementsKeyWordsElement      = GetKeyWordsElement("JumpStatements");
                    operatorStatementsKeyWordsElement  = GetKeyWordsElement("OperatorStatements");
                    selectionStatementsKeyWordsElement = GetKeyWordsElement("SelectionStatements");
                    functionDefinitionKeyWordsElement  = GetKeyWordsElement("FunctionDefinition");
                    exceptionHandlingKeyWordsElement   = GetKeyWordsElement("ExceptionHandlingStatements");
                    withStatementKeyWordsElement       = GetKeyWordsElement("WithStatement");
                    passStatementKeyWordsElement       = GetKeyWordsElement("PassStatement");
                    classStatementKeyWordsElement      = GetKeyWordsElement("ClassStatement");
                    builtInStatementsKeyWordsElement   = GetKeyWordsElement("BuiltInStatements");

                    // Get mark previous.
                    markPreviousElement = syntaxModeDocument.SelectSingleNode("//MarkPrevious") as XmlElement;
                }

                // Get line comment span.
                if (defaultRuleSet != null)
                {
                    foreach (Span s in defaultRuleSet.Spans)
                    {
                        if (s.Name == "LineComment")
                        {
                            lineCommentSpan = s;
                        }
                        else if (s.Name == "String")
                        {
                            stringSpan = s;
                        }
                        else if (s.Name == "Char")
                        {
                            charSpan = s;
                        }
                        else if (s.Name == "DocComment")
                        {
                            docCommentSpan = s;
                        }
                        else if (s.Name == "SingleQuoteDocComment")
                        {
                            singleQuoteDocCommentSpan = s;
                        }
                    }
                }
            }
        }