当前位置: 首页>>代码示例>>C#>>正文


C# CSharpParser.AcceptVisitor方法代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.CSharpParser.AcceptVisitor方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpParser.AcceptVisitor方法的具体用法?C# CSharpParser.AcceptVisitor怎么用?C# CSharpParser.AcceptVisitor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.NRefactory.CSharp.CSharpParser的用法示例。


在下文中一共展示了CSharpParser.AcceptVisitor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseAndWrite

        public void ParseAndWrite(PARSE_TYPE type, string inputText)
        {
            // parse through framework
            SyntaxTree tree = new N.CSharpParser().Parse(inputText);

            // dispatch to visitor
            var defaultVisitor = new NRefactoryVisitor();
            tree.AcceptVisitor(defaultVisitor);

            IEnumerable<CLRType> CLRTypesDetected = defaultVisitor.CLRTypes;
            switch (type)
            {
                case PARSE_TYPE.FIELDS:
                    CLRTypesDetected.ToList().ForEach(clrType => clrType.WriteFieldsUML(m_richSb));
                    break;

                case PARSE_TYPE.PROPERTIES:
                    CLRTypesDetected.ToList().ForEach(clrType => clrType.WritePropertiesUML(m_richSb));
                    break;

                case PARSE_TYPE.METHODS:
                    CLRTypesDetected.ToList().ForEach(clrType => clrType.WriteMethodsUML(m_richSb));
                    break;

                case PARSE_TYPE.ALL:
                    CLRTypesDetected.ToList().ForEach(clrType => clrType.Design(m_richSb));
                    break;

                default:
                    throw new NotSupportedException();

            }
        }
开发者ID:goncalod,项目名称:csharp,代码行数:33,代码来源:NRefactoryCom.cs

示例2: TestCollectNodes

		public void TestCollectNodes()
		{
			var cu = new CSharpParser().Parse("using System;\nclass Test {\n  int field; // comment\n}");
			CollectNodesVisitor v = new CollectNodesVisitor();
			cu.AcceptVisitor(v);
			Assert.AreEqual(cu.DescendantsAndSelf.ToList(), v.nodes);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:7,代码来源:DepthFirstVisitorTests.cs

示例3: Parse

        public string Parse(PARSE_TYPE type, string inputText)
        {
            // parse through framework
            SyntaxTree tree = new N.CSharpParser().Parse(inputText);

            // dispatch to visitor
            var defaultVisitor = new NRefactoryVisitor();
            tree.AcceptVisitor(defaultVisitor);

            IEnumerable<CLRType> inputTextTypes = defaultVisitor.CLRTypes;
            switch (type)
            {
                case PARSE_TYPE.FIELDS:
                    return inputTextTypes.Aggregate(new StringBuilder(), (sb, clr) => sb.AppendLine(clr.GetFieldsUML())).ToString();

                case PARSE_TYPE.PROPERTIES:
                    return inputTextTypes.Aggregate(new StringBuilder(), (sb, clr) => sb.AppendLine(clr.GetPropertiesUML())).ToString();

                case PARSE_TYPE.METHODS:
                    return inputTextTypes.Aggregate(new StringBuilder(), (sb, clr) => sb.AppendLine(clr.GetMethodsUML())).ToString();

                case PARSE_TYPE.ALL:
                    return inputTextTypes.Aggregate(new StringBuilder(), (sb, clr) => sb.AppendLine(clr.Design())).ToString();

                default:
                    throw new NotSupportedException();

            }
        }
开发者ID:goncalod,项目名称:csharp,代码行数:29,代码来源:NRefactoryCom+(ASUSK550's+conflicted+copy+2015-07-29).cs

示例4: Format

 /// <summary>
 /// Formats the specified part of the document.
 /// </summary>
 public static void Format(IDocument document, int offset, int length, CSharpFormattingOptions options)
 {
     var syntaxTree = new CSharpParser().Parse(document);
     var fv = new AstFormattingVisitor(options, document);
     fv.FormattingRegion = new DomRegion(document.GetLocation(offset), document.GetLocation(offset + length));
     syntaxTree.AcceptVisitor(fv);
     fv.ApplyChanges(offset, length);
 }
开发者ID:sentientpc,项目名称:SharpSnippetCompiler-v5,代码行数:11,代码来源:CSharpFormatter.cs

示例5: GetResult

        protected static IDocument GetResult(CSharpFormattingOptions policy, string input)
        {
            var adapter = new ReadOnlyDocument (input);
            var visitor = new AstFormattingVisitor (policy, adapter, factory);

            var compilationUnit = new CSharpParser ().Parse (new StringReader (input), "test.cs");
            compilationUnit.AcceptVisitor (visitor, null);

            return new ReadOnlyDocument (ApplyChanges (input, visitor.Changes));
        }
开发者ID:holmak,项目名称:NRefactory,代码行数:10,代码来源:TextEditorTestAdapter.cs

示例6: Continue

        protected static void Continue(CSharpFormattingOptions policy, IDocument document, string expectedOutput)
        {
            var visitior = new AstFormattingVisitor (policy, document, factory);

            var compilationUnit = new CSharpParser ().Parse (new StringReader (document.Text), "test.cs");
            compilationUnit.AcceptVisitor (visitior, null);
            string newText = ApplyChanges (document.Text, visitior.Changes);
            if (expectedOutput != newText) {
                Console.WriteLine (newText);
            }
            Assert.AreEqual (expectedOutput, newText);
        }
开发者ID:holmak,项目名称:NRefactory,代码行数:12,代码来源:TextEditorTestAdapter.cs

示例7: StringBuilder

		/*public static string ApplyChanges (string text, List<TextReplaceAction> changes)
		{
			changes.Sort ((x, y) => y.Offset.CompareTo (x.Offset));
			StringBuilder b = new StringBuilder(text);
			foreach (var change in changes) {
				//Console.WriteLine ("---- apply:" + change);
//				Console.WriteLine (adapter.Text);
				if (change.Offset > b.Length)
					continue;
				b.Remove(change.Offset, change.RemovedChars);
				b.Insert(change.Offset, change.InsertedText);
			}
//			Console.WriteLine ("---result:");
//			Console.WriteLine (adapter.Text);
			return b.ToString();
		}*/
		
		protected static IDocument GetResult (CSharpFormattingOptions policy, string input, FormattingMode mode = FormattingMode.OnTheFly)
		{
			input = NormalizeNewlines (input);
			var document = new StringBuilderDocument (input);
			var options = new TextEditorOptions ();
			options.EolMarker = "\n";
			var visitor = new AstFormattingVisitor (policy, document, options);
			visitor.FormattingMode = mode;
			var compilationUnit = new CSharpParser ().Parse (document, "test.cs");
			compilationUnit.AcceptVisitor (visitor);
			visitor.ApplyChanges();
			return document;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:30,代码来源:TextEditorTestAdapter.cs

示例8: StringBuilder

		/*public static string ApplyChanges (string text, List<TextReplaceAction> changes)
		{
			changes.Sort ((x, y) => y.Offset.CompareTo (x.Offset));
			StringBuilder b = new StringBuilder(text);
			foreach (var change in changes) {
				//Console.WriteLine ("---- apply:" + change);
//				Console.WriteLine (adapter.Text);
				if (change.Offset > b.Length)
					continue;
				b.Remove(change.Offset, change.RemovedChars);
				b.Insert(change.Offset, change.InsertedText);
			}
//			Console.WriteLine ("---result:");
//			Console.WriteLine (adapter.Text);
			return b.ToString();
		}*/
		
		protected static IDocument GetResult(CSharpFormattingOptions policy, string input, FormattingMode mode = FormattingMode.Intrusive)
		{
			input = NormalizeNewlines(input);
			var document = new StringBuilderDocument(input);
			var options = new TextEditorOptions();
			options.EolMarker = "\n";
			options.WrapLineLength = 80;
			var visitor = new AstFormattingVisitor (policy, document, options);
			visitor.FormattingMode = mode;
			var syntaxTree = new CSharpParser ().Parse (document, "test.cs");
			syntaxTree.AcceptVisitor (visitor);
			visitor.ApplyChanges();
			return document;
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:31,代码来源:TextEditorTestAdapter.cs

示例9: Format

 public CodeFormatResponse Format(CodeFormatRequest request)
 {
     var document = new StringBuilderDocument(request.Buffer);
     var options = new TextEditorOptions();
     options.EolMarker = Environment.NewLine;
     options.WrapLineLength = 80;
     options.TabsToSpaces = request.ExpandTab;
     var policy = FormattingOptionsFactory.CreateAllman();
     var visitor = new AstFormattingVisitor(policy, document, options);
     visitor.FormattingMode = FormattingMode.Intrusive;
     var syntaxTree = new CSharpParser().Parse(document, request.FileName);
     syntaxTree.AcceptVisitor(visitor);
     visitor.ApplyChanges();
     return new CodeFormatResponse(document.Text);
 }
开发者ID:dykim07,项目名称:vim-ide,代码行数:15,代码来源:CodeFormatHandler.cs

示例10: Continue

		protected static void Continue (CSharpFormattingOptions policy, IDocument document, string expectedOutput, FormattingMode formattingMode = FormattingMode.OnTheFly)
		{
			expectedOutput = NormalizeNewlines (expectedOutput);
			var options = new TextEditorOptions ();
			options.EolMarker = "\n";
			var visitior = new AstFormattingVisitor (policy, document, options);
			visitior.FormattingMode = formattingMode;
			var syntaxTree = new CSharpParser ().Parse (document, "test.cs");
			syntaxTree.AcceptVisitor (visitior);
			visitior.ApplyChanges();
			string newText = document.Text;
			if (expectedOutput != newText) {
				Console.WriteLine (newText);
			}
			Assert.AreEqual (expectedOutput, newText);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:16,代码来源:TextEditorTestAdapter.cs

示例11: Evaluate

		public override ValueReference Evaluate (EvaluationContext ctx, string expression, object expectedType)
		{
			expression = expression.TrimStart ();

			if (expression.Length > 0 && expression[0] == '?')
				expression = expression.Substring (1).Trim ();

			if (expression.StartsWith ("var", StringComparison.Ordinal) && char.IsWhiteSpace (expression[3])) {
				expression = expression.Substring (4).Trim (' ', '\t');
				string variable = null;

				for (int n = 0; n < expression.Length; n++) {
					if (!char.IsLetterOrDigit (expression[n]) && expression[n] != '_') {
						variable = expression.Substring (0, n);
						if (!expression.Substring (n).Trim (' ', '\t').StartsWith ("=", StringComparison.Ordinal))
							variable = null;
						break;
					}

					if (n == expression.Length - 1) {
						variable = expression;
						expression = null;
						break;
					}
				}

				if (!string.IsNullOrEmpty (variable))
					userVariables[variable] = new UserVariableReference (ctx, variable);

				if (expression == null)
					return null;
			}

			expression = ReplaceExceptionTag (expression, ctx.Options.CurrentExceptionTag);

			var expr = new CSharpParser ().ParseExpression (expression);
			if (expr == null)
				throw new EvaluatorException ("Could not parse expression '{0}'", expression);

			var evaluator = new NRefactoryExpressionEvaluatorVisitor (ctx, expression, expectedType, userVariables);
			return expr.AcceptVisitor<ValueReference> (evaluator);
		}
开发者ID:IBBoard,项目名称:monodevelop,代码行数:42,代码来源:NRefactoryExpressionEvaluator.cs

示例12: ParseAndWrite

        public void ParseAndWrite(PARSE_TYPE type, string inputText)
        {
            // parse through framework
            SyntaxTree tree = new N.CSharpParser().Parse(inputText);

            // dispatch to visitor
            var defaultVisitor = new NRefactoryVisitorV2();
            tree.AcceptVisitor(defaultVisitor);

            IEnumerable<Declaration> CLRDeclarations = defaultVisitor.Declarations;
            switch (type)
            {
                case PARSE_TYPE.FIELDS:
                    CLRDeclarations.OfType<ClassesAndStructs>().ToList().ForEach(cs =>
                        cs.Fields.OrderByDescending(x => !x.Static).ToList().ForEach(f => f.Design(m_richSb).WriteLine()));
                    break;

                case PARSE_TYPE.PROPERTIES:
                    CLRDeclarations.OfType<ClassesAndStructsAndInterfaces>().ToList().ForEach(csi => csi.Properties.OrderByDescending(x => !x.Static).ToList().ForEach(p => p.Design(m_richSb).WriteLine()));
                    break;

                case PARSE_TYPE.METHODS:
                    CLRDeclarations.OfType<ClassesAndStructsAndInterfaces>().ToList().ForEach(csi =>
                        csi.Methods.OrderByDescending(x => !x.Static).ToList().Aggregate(new List<Method>(), (l, m) =>
                        {
                            l.Insert((m.Ctor && m.Static) ? 0 : l.Count, m);
                            return l;
                        })
                        .ForEach(m => m.Design(m_richSb).WriteLine())
                     );
                    break;

                case PARSE_TYPE.ALL:
                    CLRDeclarations.OfType<ITypeDeclaration>().ToList().ForEach(clrType => clrType.DesignType(m_richSb));
                    break;

                default:
                    throw new NotSupportedException();

            }
        }
开发者ID:goncalod,项目名称:csharp,代码行数:41,代码来源:NRefactoryCom2.cs

示例13: Resolve

		string Resolve (DebuggerSession session, SourceLocation location, string expression, bool tryTypeOf)
		{
			expression = expression.TrimStart ();

			if (expression.Length > 0 && expression[0] == '?')
				return "?" + Resolve (session, location, expression.Substring (1).Trim ());

			if (expression.StartsWith ("var", StringComparison.Ordinal) && char.IsWhiteSpace (expression[3]))
				return "var " + Resolve (session, location, expression.Substring (4).Trim (' ', '\t'));

			expression = ReplaceExceptionTag (expression, session.Options.EvaluationOptions.CurrentExceptionTag);

			Expression expr = new CSharpParser ().ParseExpression (expression);
			if (expr == null)
				return expression;

			var resolver = new NRefactoryExpressionResolverVisitor (session, location, expression);
			expr.AcceptVisitor (resolver);

			string resolved = resolver.GetResolvedExpression ();
			if (resolved == expression && !tryTypeOf && (expr is BinaryOperatorExpression) && IsTypeName (expression)) {
				// This is a hack to be able to parse expressions such as "List<string>". The NRefactory parser
				// can parse a single type name, so a solution is to wrap it around a typeof(). We do it if
				// the evaluation fails.
				string res = Resolve (session, location, "typeof(" + expression + ")", true);
				return res.Substring (7, res.Length - 8);
			}

			return resolved;
		}
开发者ID:IBBoard,项目名称:monodevelop,代码行数:30,代码来源:NRefactoryExpressionEvaluator.cs

示例14: Continue

		protected static void Continue (CSharpFormattingPolicy policy, ITextEditorAdapter adapter, string expectedOutput)
		{
			var visitior = new AstFormattingVisitor (policy, adapter);
			
			var compilationUnit = new CSharpParser ().Parse (new StringReader (adapter.Text));
			compilationUnit.AcceptVisitor (visitior, null);
			((TextEditorTestAdapter)adapter).ApplyChanges (visitior.Changes);
			Assert.AreEqual (expectedOutput, adapter.Text);
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:9,代码来源:TextEditorTestAdapter.cs

示例15: Continue

		protected static void Continue (CSharpFormattingOptions policy, ITextEditorAdapter adapter, string expectedOutput)
		{
			var visitior = new AstFormattingVisitor (policy, adapter, factory);
			
			var compilationUnit = new CSharpParser ().Parse (new StringReader (adapter.Text));
			compilationUnit.AcceptVisitor (visitior, null);
			ApplyChanges (((TextEditorTestAdapter)adapter), visitior.Changes);
			if (expectedOutput != adapter.Text) {
				Console.WriteLine (adapter.Text);
			}
			Assert.AreEqual (expectedOutput, adapter.Text);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:12,代码来源:TextEditorTestAdapter.cs


注:本文中的ICSharpCode.NRefactory.CSharp.CSharpParser.AcceptVisitor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。