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


C# Refactoring.TypeSystemAstBuilder类代码示例

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


TypeSystemAstBuilder类属于ICSharpCode.NRefactory.CSharp.Refactoring命名空间,在下文中一共展示了TypeSystemAstBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GeneratePartialClassContextStub

		static string GeneratePartialClassContextStub(DebuggerCompletionContext context)
		{
			var compilation = SD.ParserService.GetCompilationForFile(context.FileName);
			var file = SD.ParserService.GetExistingUnresolvedFile(context.FileName);
			if (compilation == null || file == null)
				return "";
			var unresolvedMember = file.GetMember(context.Location);
			if (unresolvedMember == null)
				return "";
			var member = unresolvedMember.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
			if (member == null)
				return "";
			var builder = new TypeSystemAstBuilder();
			MethodDeclaration decl;
			if (unresolvedMember is IMethod) {
				// If it's a method, convert it directly (including parameters + type parameters)
				decl = (MethodDeclaration)builder.ConvertEntity(member);
			} else {
				// Otherwise, create a method anyways, and copy the parameters
				decl = new MethodDeclaration();
				if (member is IParameterizedMember) {
					foreach (var p in ((IParameterizedMember)member).Parameters) {
						decl.Parameters.Add(builder.ConvertParameter(p));
					}
				}
			}
			decl.Name = "__DebuggerStub__";
			decl.ReturnType = builder.ConvertType(member.ReturnType);
			decl.Modifiers = unresolvedMember.IsStatic ? Modifiers.Static : Modifiers.None;
			// Make the method look like an explicit interface implementation so that it doesn't appear in CC
			decl.PrivateImplementationType = new SimpleType("__DummyType__");
			decl.Body = GenerateBodyFromContext(builder, context);
			return WrapInType(unresolvedMember.DeclaringTypeDefinition, decl).ToString();
		}
开发者ID:dgrunwald,项目名称:SharpDevelop,代码行数:34,代码来源:DebuggerDotCompletion.cs

示例2: VisitForeachStatement

 public override void VisitForeachStatement(ForeachStatement foreachStatement)
 {
     base.VisitForeachStatement(foreachStatement);
     var rr = ctx.Resolve(foreachStatement) as ForEachResolveResult;
     if (rr == null)
         return;
     if (rr.ElementType.Kind == TypeKind.Unknown)
         return;
     if (ReflectionHelper.GetTypeCode(rr.ElementType) == TypeCode.Object)
         return;
     if (conversions == null) {
         conversions = CSharpConversions.Get(ctx.Compilation);
     }
     Conversion c = conversions.ImplicitConversion(rr.ElementType, rr.ElementVariable.Type);
     if (c.IsValid)
         return;
     var csResolver = ctx.GetResolverStateBefore(foreachStatement);
     var builder = new TypeSystemAstBuilder(csResolver);
     AstType elementType = builder.ConvertType(rr.ElementType);
     AstType variableType = foreachStatement.VariableType;
     string issueText = ctx.TranslateString("Collection element type '{0}' is not implicitly convertible to '{1}'");
     string fixText = ctx.TranslateString("Use type '{0}'");
     AddIssue(variableType, string.Format(issueText, elementType.GetText(), variableType.GetText()),
              new CodeAction(string.Format(fixText, elementType.GetText()),
                             script => script.Replace(variableType, elementType)));
 }
开发者ID:artifexor,项目名称:NRefactory,代码行数:26,代码来源:ExplicitConversionInForEachIssue.cs

示例3: CreateShortType

		public override AstType CreateShortType (IType fullType)
		{
			AstNode node = Unit.GetNodeAt(Location);
			CSharpResolver csResolver = resolver.GetResolverStateBefore(node);
			var builder = new TypeSystemAstBuilder (csResolver);
			return builder.ConvertType (fullType);
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:7,代码来源:TestRefactoringContext.cs

示例4: EnumMemberCompletionData

		public EnumMemberCompletionData(IType enumType, IEntity member, TypeSystemAstBuilder builder) : base(enumType.Name + "." + member.Name)
		{
			this.enumType = enumType;
			this.member = member;
			this.Image = ClassBrowserIconService.Const;
			this.CompletionText = builder.ConvertType(enumType).ToString() + "." + member.Name;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:7,代码来源:EnumMemberCompletionData.cs

示例5: GetShortType

		protected string GetShortType (IType type)
		{
			if (builder == null) {
				var ctx = ext.CSharpUnresolvedFile.GetTypeResolveContext (ext.UnresolvedFileCompilation, ext.Document.Editor.Caret.Location) as CSharpTypeResolveContext;
				var state = new CSharpResolver (ctx);
				builder = new TypeSystemAstBuilder (state);
				var dt = state.CurrentTypeDefinition;
				var declaring = ctx.CurrentTypeDefinition != null ? ctx.CurrentTypeDefinition.DeclaringTypeDefinition : null;
				if (declaring != null) {
					while (dt != null) {
						if (dt.Equals (declaring)) {
							builder.AlwaysUseShortTypeNames = true;
							break;
						}
						dt = dt.DeclaringTypeDefinition;
					}
				}
			}
			try {
				return GLib.Markup.EscapeText (builder.ConvertType(type).ToString (ext.FormattingPolicy.CreateOptions ()));
			} catch (Exception e) {
				LoggingService.LogError ("Exception while getting short type.", e);
				return "";
			}
		}
开发者ID:segaman,项目名称:monodevelop,代码行数:25,代码来源:AbstractParameterDataProvider.cs

示例6: GeneratePartialClassContextStub

		static string GeneratePartialClassContextStub(ICodeContext context)
		{
			var member = context.CurrentMember;
			if (member == null)
				return "";
			var builder = new TypeSystemAstBuilder();
			MethodDeclaration decl;
			if (member is IMethod) {
				// If it's a method, convert it directly (including parameters + type parameters)
				decl = (MethodDeclaration)builder.ConvertEntity(member);
			} else {
				// Otherwise, create a method anyways, and copy the parameters
				decl = new MethodDeclaration();
				if (member is IParameterizedMember) {
					foreach (var p in ((IParameterizedMember)member).Parameters) {
						decl.Parameters.Add(builder.ConvertParameter(p));
					}
				}
			}
			decl.Name = "__DebuggerStub__";
			decl.ReturnType = builder.ConvertType(member.ReturnType);
			decl.Modifiers = member.IsStatic ? Modifiers.Static : Modifiers.None;
			// Make the method look like an explicit interface implementation so that it doesn't appear in CC
			decl.PrivateImplementationType = new SimpleType("__DummyType__");
			decl.Body = GenerateBodyFromContext(builder, context.LocalVariables.ToArray());
			return WrapInType(context.CurrentTypeDefinition, decl).ToString();
		}
开发者ID:kinpro,项目名称:SharpDevelop,代码行数:27,代码来源:CSharpLanguageBinding.cs

示例7: Complete

		public override void Complete(CompletionContext context)
		{
			if (declarationBegin > context.StartOffset) {
				base.Complete(context);
				return;
			}
			
			TypeSystemAstBuilder b = new TypeSystemAstBuilder(contextAtCaret);
			b.ShowTypeParameterConstraints = false;
			b.GenerateBody = true;
			
			var entityDeclaration = b.ConvertEntity(this.Entity);
			entityDeclaration.Modifiers &= ~(Modifiers.Virtual | Modifiers.Abstract);
			entityDeclaration.Modifiers |= Modifiers.Override;
			
			if (!this.Entity.IsAbstract) {
				// modify body to call the base method
				if (this.Entity.SymbolKind == SymbolKind.Method) {
					var baseCall = new BaseReferenceExpression().Invoke(this.Entity.Name, ParametersToExpressions(this.Entity));
					var body = entityDeclaration.GetChildByRole(Roles.Body);
					body.Statements.Clear();
					if (((IMethod)this.Entity).ReturnType.IsKnownType(KnownTypeCode.Void))
						body.Statements.Add(new ExpressionStatement(baseCall));
					else
						body.Statements.Add(new ReturnStatement(baseCall));
				} else if (this.Entity.SymbolKind == SymbolKind.Indexer || this.Entity.SymbolKind == SymbolKind.Property) {
					Expression baseCall;
					if (this.Entity.SymbolKind == SymbolKind.Indexer)
						baseCall = new BaseReferenceExpression().Indexer(ParametersToExpressions(this.Entity));
					else
						baseCall = new BaseReferenceExpression().Member(this.Entity.Name);
					var getterBody = entityDeclaration.GetChildByRole(PropertyDeclaration.GetterRole).Body;
					if (!getterBody.IsNull) {
						getterBody.Statements.Clear();
						getterBody.Add(new ReturnStatement(baseCall.Clone()));
					}
					var setterBody = entityDeclaration.GetChildByRole(PropertyDeclaration.SetterRole).Body;
					if (!setterBody.IsNull) {
						setterBody.Statements.Clear();
						setterBody.Add(new AssignmentExpression(baseCall.Clone(), new IdentifierExpression("value")));
					}
				}
			}
			
			var document = context.Editor.Document;
			StringWriter w = new StringWriter();
			var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
			var segmentDict = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, context.Editor.Options);
			
			using (document.OpenUndoGroup()) {
				string newText = w.ToString().TrimEnd();
				document.Replace(declarationBegin, context.EndOffset - declarationBegin, newText);
				var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement);
				if (throwStatement != null) {
					var segment = segmentDict[throwStatement];
					context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
				}
				CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions);
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:60,代码来源:OverrideCompletionData.cs

示例8: Complete

		public override void Complete(CompletionContext context)
		{
			if (declarationBegin > context.StartOffset) {
				base.Complete(context);
				return;
			}
			
			TypeSystemAstBuilder b = new TypeSystemAstBuilder(contextAtCaret);
			b.GenerateBody = true;
			
			var entityDeclaration = b.ConvertEntity(this.Entity);
			entityDeclaration.Modifiers &= ~Modifiers.VisibilityMask; // remove visiblity
			entityDeclaration.Modifiers |= Modifiers.Partial;
			
			var document = context.Editor.Document;
			StringWriter w = new StringWriter();
			var formattingOptions = CSharpFormattingPolicies.Instance.GetProjectOptions(contextAtCaret.Compilation.GetProject());
			var segmentDict = SegmentTrackingOutputFormatter.WriteNode(
				w, entityDeclaration, formattingOptions.OptionsContainer.GetEffectiveOptions(), context.Editor.Options);
			
			using (document.OpenUndoGroup()) {
				string newText = w.ToString().TrimEnd();
				document.Replace(declarationBegin, context.EndOffset - declarationBegin, newText);
				var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement);
				if (throwStatement != null) {
					var segment = segmentDict[throwStatement];
					context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
				}
				CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions.OptionsContainer);
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:31,代码来源:PartialCompletionData.cs

示例9: CSharpCompletionDataFactory

		public CSharpCompletionDataFactory(CSharpCompletionContext completionContext, CSharpResolver contextAtCaret)
		{
			Debug.Assert(completionContext != null);
			Debug.Assert(contextAtCaret != null);
			this.completionContext = completionContext;
			this.contextAtCaret = contextAtCaret;
			this.builder = new TypeSystemAstBuilder(contextAtCaret);
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:8,代码来源:CSharpCompletionDataFactory.cs

示例10: CSharpResolver

        public static string GetOverrideTargetName
            (IMember m, CSharpTypeResolveContext resolveContext) {
            var builder = new TypeSystemAstBuilder
                (new CSharpResolver(resolveContext));

			return builder.ConvertEntity(m).ToString()
                // Builder automatically adds a trailing newline
                .TrimEnd(Environment.NewLine.ToCharArray());
        }
开发者ID:jcd-as,项目名称:omnisharp-server,代码行数:9,代码来源:GetOverrideTargetsResponse.cs

示例11: SignatureMarkupCreator

		public SignatureMarkupCreator (CSharpResolver resolver, CSharpFormattingOptions formattingOptions)
		{
			this.colorStyle = SyntaxModeService.GetColorStyle (MonoDevelop.Ide.IdeApp.Preferences.ColorScheme);

			this.resolver = resolver;
			this.astBuilder = new TypeSystemAstBuilder (resolver) {
				ConvertUnboundTypeArguments = true,
				UseAliases = false
			};
			this.formattingOptions = formattingOptions;
		}
开发者ID:Chertolom,项目名称:monodevelop,代码行数:11,代码来源:SignatureMarkupCreator.cs

示例12: ImportCompletionData

		public ImportCompletionData(ITypeDefinition typeDef, CSharpResolver contextAtCaret, bool useFullName)
			: base(typeDef)
		{
			this.Description = "using " + typeDef.Namespace + ";";
			if (useFullName) {
				var astBuilder = new TypeSystemAstBuilder(contextAtCaret);
				insertionText = astBuilder.ConvertType(typeDef).ToString();
			} else {
				insertionText = typeDef.Name;
				insertUsing = typeDef.Namespace;
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:12,代码来源:ImportCompletionData.cs

示例13: MemberCompletionData

            public MemberCompletionData(IType type, IEntity member, TypeSystemAstBuilder builder)
            {
                DeclarationCategory = DeclarationCategory.Enumeration_Member;

                Type = type;
                Member = member;

                string typeName = builder.ConvertType(type).GetText();
                SetDefaultText(typeName + "." + member.Name);

                Documentation = member.Documentation;
            }
开发者ID:uluhonolulu,项目名称:QCCodingServices.NET,代码行数:12,代码来源:MemberCompletionData.cs

示例14: InsertEventHandler

		public override void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo)
		{
			IUnresolvedTypeDefinition match = null;
			
			foreach (var part in target.Parts) {
				if (match == null || EntityModelContextUtils.IsBetterPart(part, match, ".cs"))
					match = part;
			}
			
			if (match == null) return;
			
			var view = SD.FileService.OpenFile(new FileName(match.Region.FileName), jumpTo);
			var editor = view.GetRequiredService<ITextEditor>();
			var last = match.Members.LastOrDefault() ?? (IUnresolvedEntity)match;
			editor.Caret.Location = last.BodyRegion.End;
			var context = SDRefactoringContext.Create(editor, CancellationToken.None);
			
			var node = context.RootNode.GetNodeAt<EntityDeclaration>(last.Region.Begin);
			var resolver = context.GetResolverStateAfter(node);
			var builder = new TypeSystemAstBuilder(resolver);
			var delegateDecl = builder.ConvertEntity(eventDefinition.ReturnType.GetDefinition()) as DelegateDeclaration;
			if (delegateDecl == null) return;
			var throwStmt = new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")));
			var decl = new MethodDeclaration() {
				ReturnType = delegateDecl.ReturnType.Clone(),
				Name = name,
				Body = new BlockStatement() {
					throwStmt
				}
			};
			var param = delegateDecl.Parameters.Select(p => p.Clone()).OfType<ParameterDeclaration>().ToArray();
			decl.Parameters.AddRange(param);
			
			using (Script script = context.StartScript()) {
				// FIXME : will not work properly if there are no members.
				if (last == match) {
					throw new NotImplementedException();
					// TODO InsertWithCursor not implemented!
					//script.InsertWithCursor("Insert event handler", Script.InsertPosition.End, decl).RunSynchronously();
				} else {
					// TODO does not jump correctly...
					script.InsertAfter(node, decl);
					editor.JumpTo(throwStmt.StartLocation.Line, throwStmt.StartLocation.Column);
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:46,代码来源:CSharpCodeGenerator.cs

示例15: TypeCompletionData

            public TypeCompletionData(ICSharpCode.NRefactory.TypeSystem.IType type, bool fullName, bool isInAttributeContext, TypeSystemAstBuilder builder, bool addForTypeCreation)
            {
                Type = type;
                FullName = fullName;
                IsInAttributeContext = isInAttributeContext;

                // Confirm that this doesn't also include other types, such as enums, structs, etc.
                //DeclarationCategory = DeclarationCategory.Class;
                DeclarationCategory = type.Kind.ResolveDeclarationCategoryFromTypeKind();

                string typeName = fullName ? builder.ConvertType(type).GetText() : type.Name;
                if (isInAttributeContext && typeName.EndsWith("Attribute") && typeName.Length > "Attribute".Length)
                {
                    typeName = typeName.Substring(0, typeName.Length - "Attribute".Length);
                }
                SetDefaultText(typeName);

                // for documentation, see type.GetDefinition().Documentation
                Documentation = type.GetDefinition().Documentation;
            }
开发者ID:uluhonolulu,项目名称:QCCodingServices.NET,代码行数:20,代码来源:TypeCompletionData.cs


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