private static bool IsModuleClass(BaseTypeSyntax baseType, SemanticModel model, INamedTypeSymbol moduleType) { var typeInfo = model.GetTypeInfo(baseType.Type); return(SymbolEqualityComparer.Default.Equals(typeInfo.Type, moduleType)); }
private static async Task<Document> ApplyFix( Document document , BaseTypeSyntax derivingClass , BasePropertyDeclarationSyntax viewModelProperty , CancellationToken cancellationToken) { var genericClassDeclaration = SyntaxFactory.SimpleBaseType( SyntaxFactory.GenericName( SyntaxFactory.Identifier( derivingClass.Type.ToString() ) ) .WithTypeArgumentList( SyntaxFactory.TypeArgumentList( SyntaxFactory.SingletonSeparatedList(viewModelProperty.Type) ) ) ).WithAdditionalAnnotations(Formatter.Annotation); var editor = await DocumentEditor.CreateAsync(document, cancellationToken); editor.RemoveNode(viewModelProperty); editor.ReplaceNode(derivingClass, genericClassDeclaration); return editor.GetChangedDocument(); }
public void TypeFullNameRenderingSemanticModel() { var tree = CSharpSyntaxTree.ParseText(@" using System; public class MyClass : IDisposable { public void Dispose() { } } "); var node = new NodeLocator(tree).LocateLast(typeof(ClassDeclarationSyntax)); Assert.IsNotNull(node, string.Format("Node of type `{0}` should be found!", typeof(ClassDeclarationSyntax).Name)); // Loading MSCoreLib var compilation = CSharpCompilation.Create("TestAssembly") .AddReferences( MetadataReference.CreateFromFile( typeof(object).Assembly.Location)) .AddSyntaxTrees(tree); var semanticModel = compilation.GetSemanticModel(tree); ClassDeclarationSyntax classDeclarationNode = node as ClassDeclarationSyntax; BaseTypeSyntax baseTypeNode = classDeclarationNode.BaseList.Types.FirstOrDefault(); TestRetrieveTypeName(baseTypeNode, null, "IDisposable"); TestRetrieveTypeName(baseTypeNode, semanticModel, "IDisposable"); TestRetrieveTypeFullName(baseTypeNode, null, "IDisposable"); TestRetrieveTypeFullName(baseTypeNode, semanticModel, "System.IDisposable"); }
public static Task <Document> RefactorAsync( Document document, BaseTypeSyntax baseType, CancellationToken cancellationToken) { SyntaxRemoveOptions removeOptions = RemoveHelper.DefaultRemoveOptions; if (baseType.GetLeadingTrivia().All(f => f.IsWhitespaceTrivia())) { removeOptions &= ~SyntaxRemoveOptions.KeepLeadingTrivia; } if (baseType.GetTrailingTrivia().All(f => f.IsWhitespaceTrivia())) { var baseList = (BaseListSyntax)baseType.Parent; if (baseList.Types.IsLast(baseType) && !GenericSyntax.HasConstraintClauses(baseList.Parent)) { removeOptions &= ~SyntaxRemoveOptions.KeepTrailingTrivia; } } return(document.RemoveNodeAsync(baseType, removeOptions, cancellationToken)); }
private static void Analyze( SyntaxNodeAnalysisContext context, SymbolInterfaceInfo interfaceInfo, SymbolInterfaceInfo interfaceInfo2, INamedTypeSymbol typeSymbol = null) { foreach (INamedTypeSymbol interfaceSymbol in interfaceInfo2.Interfaces) { if (interfaceInfo.Symbol.Equals(interfaceSymbol)) { if (typeSymbol == null || !typeSymbol.IsAnyInterfaceMemberExplicitlyImplemented(interfaceInfo.Symbol)) { BaseTypeSyntax baseType = interfaceInfo.BaseType; context.ReportDiagnostic( DiagnosticDescriptors.RemoveRedundantBaseInterface, baseType, SymbolDisplay.GetMinimalString(interfaceInfo.Symbol, context.SemanticModel, baseType.SpanStart), SymbolDisplay.GetMinimalString(interfaceInfo2.Symbol, context.SemanticModel, baseType.SpanStart)); return; } } } }
public static ClassDeclarationSyntax Create(string name, BaseTypeSyntax[] baseTypes, ConstructorDeclarationSyntax constructor, MemberDeclarationSyntax[] body) { return SyntaxFactory.ClassDeclaration(name) .AddBaseListTypes(baseTypes) .AddMembers(constructor) .AddMembers(body); }
private static async Task <Document> ApplyFix( Document document , BaseTypeSyntax derivingClass , BasePropertyDeclarationSyntax viewModelProperty , CancellationToken cancellationToken) { var genericClassDeclaration = SyntaxFactory.SimpleBaseType( SyntaxFactory.GenericName( SyntaxFactory.Identifier( derivingClass.Type.ToString() ) ) .WithTypeArgumentList( SyntaxFactory.TypeArgumentList( SyntaxFactory.SingletonSeparatedList(viewModelProperty.Type) ) ) ).WithAdditionalAnnotations(Formatter.Annotation); var editor = await DocumentEditor.CreateAsync(document, cancellationToken); editor.RemoveNode(viewModelProperty); editor.ReplaceNode(derivingClass, genericClassDeclaration); return(editor.GetChangedDocument()); }
private static void ComputeRefactoring( RefactoringContext context, MemberDeclarationSyntax memberDeclaration, BaseTypeSyntax baseType, ITypeSymbol explicitInterfaceSymbol, ISymbol memberSymbol, SemanticModel semanticModel) { TypeSyntax type = baseType.Type; if (type == null) { return; } var interfaceSymbol = semanticModel.GetTypeSymbol(type, context.CancellationToken) as INamedTypeSymbol; if (interfaceSymbol?.TypeKind != TypeKind.Interface) { return; } interfaceSymbol = interfaceSymbol.OriginalDefinition; if (!(interfaceSymbol.GetSyntaxOrDefault(context.CancellationToken) is InterfaceDeclarationSyntax interfaceDeclaration)) { return; } if (interfaceSymbol.Equals(explicitInterfaceSymbol)) { return; } ImmutableArray <ISymbol> members = interfaceSymbol.GetMembers(); SyntaxKind kind = memberDeclaration.Kind(); for (int i = 0; i < members.Length; i++) { if (CheckKind(members[i], kind)) { ISymbol symbol = memberSymbol.ContainingType.FindImplementationForInterfaceMember(members[i]); if (memberSymbol.OriginalDefinition.Equals(symbol?.OriginalDefinition) && CheckTypeParameters(memberDeclaration, interfaceSymbol)) { return; } } } string displayName = SymbolDisplay.GetMinimalString(interfaceSymbol, semanticModel, type.SpanStart); context.RegisterRefactoring( $"Add to interface '{displayName}'", cancellationToken => RefactorAsync(context.Document, memberDeclaration, interfaceDeclaration, cancellationToken), RefactoringIdentifiers.AddMemberToInterface + "." + displayName); }
private LuaExpressionSyntax BuildBaseTypeName(BaseTypeSyntax baseType) { ++baseNameNodeCounter_; var baseTypeName = (LuaExpressionSyntax)baseType.Accept(this); --baseNameNodeCounter_; return(baseTypeName); }
private INamedTypeSymbol GetTypeSymbolForArgument(string source) { BaseTypeSyntax b = GetNode <BaseTypeSyntax>(source); SemanticModel semanticModel = Compilation.CurrentCompilation.GetSemanticModel(b.SyntaxTree); TypeInfo info = semanticModel.GetTypeInfo(b.Type); return((info.Type as INamedTypeSymbol) !); }
private ApexTypeSyntax ConvertBaseType(BaseTypeSyntax csharpType) { if (csharpType != null) { return(new ApexTypeSyntax(csharpType.ToString())); } return(null); }
public static SimpleNameSyntax GetSimpleName(this BaseTypeSyntax baseType) { if (baseType is SimpleBaseTypeSyntax simpleBaseType && simpleBaseType.Type is SimpleNameSyntax simpleName) { return(simpleName); } return(null); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { if (!Settings.IsCodeFixEnabled(CodeFixIdentifiers.MoveBaseClassBeforeAnyInterface)) { return; } SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); BaseListSyntax baseList = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <BaseListSyntax>(); Debug.Assert(baseList != null, $"{nameof(baseList)} is null"); if (baseList == null || baseList.ContainsDiagnostics) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case CompilerDiagnosticIdentifiers.BaseClassMustComeBeforeAnyInterface: { SeparatedSyntaxList <BaseTypeSyntax> types = baseList.Types; if (types.Count > 1) { BaseTypeSyntax baseType = types.First(f => context.Span.Contains(f.Span)); CodeAction codeAction = CodeAction.Create( $"Move '{baseType.Type}' before any interface", cancellationToken => { BaseTypeSyntax firstType = types[0]; SeparatedSyntaxList <BaseTypeSyntax> newTypes = types .Replace(baseType, firstType.WithTriviaFrom(baseType)) .ReplaceAt(0, baseType.WithTriviaFrom(firstType)); BaseListSyntax newBaseList = baseList.WithTypes(newTypes); return(context.Document.ReplaceNodeAsync(baseList, newBaseList, context.CancellationToken)); }, GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); } break; } } } }
private static SyntaxNode GetNodeToRemove(BaseTypeSyntax baseType, BaseListSyntax baseList) { if (baseList.Types.Count == 1) { return(baseList); } return(baseType); }
public static void Analyze(SyntaxNodeAnalysisContext context, EnumDeclarationSyntax enumDeclaration) { BaseTypeSyntax baseType = GetRedundantBaseType(context, enumDeclaration); if (baseType != null) { context.ReportDiagnostic(DiagnosticDescriptors.RemoveEnumDefaultUnderlyingType, baseType.GetLocation()); } }
internal bool IsBaseType(BaseTypeSyntax type) { var syntaxTree = type.SyntaxTree; SemanticModel semanticModel = GetSemanticModel(syntaxTree); var symbol = semanticModel.GetTypeInfo(type.Type).Type; Contract.Assert(symbol != null); return(symbol.TypeKind != TypeKind.Interface); }
private static StructDeclarationSyntax AddBaseType(StructDeclarationSyntax structDeclaration, BaseTypeSyntax baseType) { BaseListSyntax baseList = structDeclaration.BaseList; if (baseList == null) { baseList = BaseList(baseType); TypeParameterListSyntax typeParameterList = structDeclaration.TypeParameterList; if (typeParameterList != null) { return(structDeclaration .WithTypeParameterList(typeParameterList.WithoutTrailingTrivia()) .WithBaseList(baseList.WithTrailingTrivia(typeParameterList.GetTrailingTrivia()))); } else { SyntaxToken identifier = structDeclaration.Identifier; return(structDeclaration .WithIdentifier(identifier.WithoutTrailingTrivia()) .WithBaseList(baseList.WithTrailingTrivia(identifier.TrailingTrivia))); } } else { SeparatedSyntaxList <BaseTypeSyntax> types = baseList.Types; BaseTypeSyntax lastType = types.LastOrDefault(); if (lastType == null || (types.Count == 1 && types[0].IsMissing)) { SyntaxToken colonToken = baseList.ColonToken; baseType = baseType .WithLeadingTrivia(Space) .WithTrailingTrivia(colonToken.TrailingTrivia); baseList = baseList .WithColonToken(colonToken.WithoutTrailingTrivia()) .WithTypes(SingletonSeparatedList(baseType)); return(structDeclaration.WithBaseList(baseList)); } else { types = types .Replace(lastType, lastType.WithoutTrailingTrivia()) .Add(baseType.WithTrailingTrivia(lastType.GetTrailingTrivia())); return(structDeclaration.WithBaseList(baseList.WithTypes(types))); } } }
protected override Location GetUnboundDacFieldLocation(ClassDeclarationSyntax keyNode, ITypeSymbol unboundDacFieldInKey) { if (keyNode.BaseList.Types.Count == 0) { return(null); } BaseTypeSyntax baseTypeNode = keyNode.BaseList.Types[0]; if (!(baseTypeNode.Type is QualifiedNameSyntax fullBaseTypeQualifiedName) || !(fullBaseTypeQualifiedName.Right is GenericNameSyntax byOrWithTablesOfNode)) { return(null); } if (byOrWithTablesOfNode.Identifier.Text == ReferentialIntegrity.By_TypeName) { var byTypeNode = byOrWithTablesOfNode; return(GetUnboundDacFieldLocationFromTypeArguments(byTypeNode, unboundDacFieldInKey)); } else if (byOrWithTablesOfNode.Identifier.Text == ReferentialIntegrity.WithTablesOf_TypeName) { switch (fullBaseTypeQualifiedName.Left) { //AsSimpleKey case case QualifiedNameSyntax partialBaseTypeQualifiedName //Case of Field<>.IsRelatedTo<> AsSimpleKey.WithTablesOf<,> when partialBaseTypeQualifiedName.Right is IdentifierNameSyntax { Identifier: { Text : ReferentialIntegrity.AsSimpleKeyName } } asSimpleKeyNode : return(GetUnboundDacFieldLocationFromAsSimpleKeyNode(partialBaseTypeQualifiedName.Left as QualifiedNameSyntax, unboundDacFieldInKey)); //CompositeKey cases case GenericNameSyntax { Identifier: { Text : ReferentialIntegrity.CompositeKey } } compositeKeyNode : //Case of CompositeKey<,...,>.WithTablesOf<,> return(GetUnboundDacFieldLocationFromCompositeKeyNode(compositeKeyNode, unboundDacFieldInKey)); case QualifiedNameSyntax compositeKeyNodeWithNamespace //Case of Namespace.CompositeKey<,...,> and Alias::Namespace.CompositeKey<,...,> when compositeKeyNodeWithNamespace.Right is GenericNameSyntax { Identifier: { Text : ReferentialIntegrity.CompositeKey } } compositeKeyNode : return(GetUnboundDacFieldLocationFromCompositeKeyNode(compositeKeyNode, unboundDacFieldInKey)); case AliasQualifiedNameSyntax compositeKeyNodeWithAlias when compositeKeyNodeWithAlias.Name is GenericNameSyntax { Identifier: { Text : ReferentialIntegrity.CompositeKey } } compositeKeyNode : return(GetUnboundDacFieldLocationFromCompositeKeyNode(compositeKeyNode, unboundDacFieldInKey)); } } return(null); }
/// <summary> /// Tries all possible ways to retrieve the full name using the semantic model. /// </summary> /// <param name="node"></param> /// <param name="semanticModel"></param> /// <returns></returns> /// <exception cref="SymbolNotFoundException"></exception> internal static string GetTypeSymbolFullName(BaseTypeSyntax node, SemanticModel semanticModel) { var value = TryGetTypeSymbolFullName(node, semanticModel); if (value != null) { return(value); } throw new SymbolNotFoundException(node, semanticModel); }
private static bool IsOrImplementsIDisposable(BaseTypeSyntax baseType, SemanticModel semanticModel) { if (baseType?.Type == null) { return(false); } var typeSymbol = semanticModel.GetSymbolInfo(baseType.Type).Symbol as INamedTypeSymbol; return(typeSymbol != null && typeSymbol.IsInterface() && IsOrImplementsIDisposable(typeSymbol)); }
public static MemberDeclarationSyntax Class(string name, IEnumerable <string> implements, IEnumerable <SyntaxKind> accessModifiers, Func <SyntaxList <MemberDeclarationSyntax> > members, bool abstractClass = false, string inherits = null) { BaseTypeSyntax baseType = null; if (!string.IsNullOrEmpty(inherits)) { baseType = SyntaxFactory.SimpleBaseType(SyntaxFactory.IdentifierName(inherits)); } return(Class(name, implements, accessModifiers, members, baseType, abstractClass)); }
public void InterfaceTypeNameFromBaseList() { SyntaxNode node = new NodeLocator(Class3SyntaxTree).LocateLast(typeof(ClassDeclarationSyntax)); Assert.IsNotNull(node, string.Format("Node of type `{0}` should be found!", typeof(ClassDeclarationSyntax).Name)); ClassDeclarationSyntax classDeclarationNode = node as ClassDeclarationSyntax; BaseTypeSyntax baseTypeNode = classDeclarationNode.BaseList.Types.FirstOrDefault(); TestRetrieveTypeName(baseTypeNode, TestSuite.Class3.Value["Interface1Name"]); }
private static void TestRetrieveTypeName(BaseTypeSyntax baseTypeNode, string expected) { Assert.IsNotNull(baseTypeNode, "Found node should be of type `{0}`!", typeof(BaseTypeSyntax).Name); BaseTypeReference baseTypeReference = new BaseTypeReference(baseTypeNode); string name = baseTypeReference.Name; Assert.IsNotNull(name, "Type name should not be null!"); Assert.AreNotEqual(string.Empty, name, "Type name should not be empty!"); Assert.AreEqual(expected, name, "Type name is not the one in source!"); }
private bool checkBaseTypeIsInterface(BaseTypeSyntax syntax) { if (syntax is SimpleBaseTypeSyntax) { var s = syntax as SimpleBaseTypeSyntax; return checkTypeIsInterface(s.Type); } else { throw new Exception("Unknown type : " + syntax.GetType()); } }
private static string GetStringForBaseTypeComparison(BaseTypeSyntax baseType) { if (baseType.Type.IsKind(SyntaxKind.GenericName)) { GenericNameSyntax genericType = ((GenericNameSyntax)baseType.Type); return(String.Concat(genericType.Identifier.Text, "`", genericType.TypeArgumentList.Arguments.Count)); } else { return(baseType.Type.ToString()); } }
private static void TestRetrieveTypeName(BaseTypeSyntax baseTypeNode, string expected) { Assert.IsNotNull(baseTypeNode, "Found node should be of type `{0}`!", typeof(BaseTypeSyntax).Name); BaseTypeReference baseTypeReference = new BaseTypeReference(baseTypeNode); string name = baseTypeReference.Name; Assert.IsNotNull(name, "Type name should not be null!"); Assert.AreNotEqual(string.Empty, name, "Type name should not be empty!"); Assert.AreEqual(expected, name, "Type name is not the one in source!"); }
/// <summary> /// Guesses the base type kind basing on name. /// </summary> /// <param name="baseType"></param> /// <returns></returns> public static Roslyn.TypeKind GuessBaseTypeKindFromName(BaseTypeSyntax baseType) { var helper = new BaseTypeReference(baseType); var name = helper.Name; var firstLetter = name[0]; if (firstLetter == 'I') { return Roslyn.TypeKind.Interface; } return Roslyn.TypeKind.Class; }
public void ReplaceBaseClass(ClassDeclarationSyntax classDeclaration, string baseType) { InitIfNeeded(); IdentifierNameSyntax identifierName = SyntaxFactory.IdentifierName(baseType); BaseTypeSyntax baseTypeSyntax = SyntaxFactory.SimpleBaseType(identifierName); SeparatedSyntaxList <BaseTypeSyntax> separatedSyntaxList = new SeparatedSyntaxList <BaseTypeSyntax>(); separatedSyntaxList = separatedSyntaxList.Add(baseTypeSyntax); BaseListSyntax baseSyntaxList = SyntaxFactory.BaseList(separatedSyntaxList); _formRoot = _formRoot.ReplaceNode(classDeclaration, classDeclaration.WithBaseList(baseSyntaxList)); _formTree = _formTree.WithRootAndOptions(_formRoot, _formTree.Options); }
/// <summary> /// Guesses the base type kind basing on name. /// </summary> /// <param name="baseType"></param> /// <returns></returns> public static Roslyn.TypeKind GuessBaseTypeKindFromName(BaseTypeSyntax baseType) { var helper = new BaseTypeReference(baseType); var name = helper.Name; var firstLetter = name[0]; if (firstLetter == 'I') { return(Roslyn.TypeKind.Interface); } return(Roslyn.TypeKind.Class); }
/// <inheritdoc /> public override async Task RegisterCodeFixesAsync(CodeFixContext context) { Diagnostic diagnostic = context.Diagnostics.First(); SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); BaseTypeSyntax baseTypeSyntax = root.FindNode(diagnostic.Location.SourceSpan).FirstAncestorOrSelf <BaseTypeSyntax>(); ClassDeclarationSyntax classDeclarationSyntax = baseTypeSyntax.FirstAncestorOrSelf <ClassDeclarationSyntax>(); context.RegisterCodeFix( CodeAction.Create("Convert to async package", ct => this.ConvertToAsyncPackageAsync(context, diagnostic, ct), "only one"), diagnostic); }
public BaseObject(ObjectType childObjectType, BaseTypeSyntax baseType, SemanticModel semanticModel) { this.childObjectType = childObjectType; this.baseType = baseType; typeInfo = semanticModel.GetTypeInfo(baseType.Type); var symbol = typeInfo.Type; name = Tools.GetTypeName(symbol); fullName = Tools.GetFullTypeName(symbol); fullNameFlat = Tools.GetFullTypeNameFlat(symbol); isPrimitive = symbol.SpecialType != SpecialType.None; }
public static Task <Document> RefactorAsync( Document document, BaseTypeSyntax baseType, CancellationToken cancellationToken) { var baseList = (BaseListSyntax)baseType.Parent; var enumDeclaration = (EnumDeclarationSyntax)baseList.Parent; EnumDeclarationSyntax newEnumDeclaration = enumDeclaration .RemoveNode(GetNodeToRemove(baseType, baseList), SyntaxRemoveOptions.KeepExteriorTrivia) .WithFormatterAnnotation(); return(document.ReplaceNodeAsync(enumDeclaration, newEnumDeclaration, cancellationToken)); }
public static IReadOnlyCollection <BaseTypeSyntax> GetInterfaceBaseTypes(this TypeWrapper type, Nullability nullableContext, Nullability[] nullable) { var interfaces = type.InterfaceImplementations; var bases = new BaseTypeSyntax[interfaces.Count]; int i = 0; foreach (var interfaceType in interfaces) { bases[i] = SimpleBaseType(interfaceType.GetTypeSyntax(type, nullableContext, nullable)); i++; } return(bases); }
protected override Location GetUnboundDacFieldLocation(ClassDeclarationSyntax keyNode, ITypeSymbol unboundDacFieldInKey) { if (keyNode.BaseList.Types.Count == 0) { return(null); } BaseTypeSyntax baseTypeNode = keyNode.BaseList.Types[0]; if (!(baseTypeNode.Type is QualifiedNameSyntax qualifiedName) || !(qualifiedName.Right is GenericNameSyntax byTypeNode)) { return(null); } return(GetUnboundDacFieldLocationFromTypeArguments(byTypeNode, unboundDacFieldInKey)); }
private static async Task <Document> RemoveDefaultUnderlyingTypeAsync( Document document, BaseTypeSyntax baseType, CancellationToken cancellationToken) { SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var baseList = (BaseListSyntax)baseType.Parent; var enumDeclaration = (EnumDeclarationSyntax)baseList.Parent; EnumDeclarationSyntax newEnumDeclaration = enumDeclaration .RemoveNode(GetNodeToRemove(baseType, baseList), SyntaxRemoveOptions.KeepExteriorTrivia) .WithFormatterAnnotation(); SyntaxNode newRoot = root.ReplaceNode(enumDeclaration, newEnumDeclaration); return(document.WithSyntaxRoot(newRoot)); }
/// <summary> /// Initializes a new instance of the <see cref="BaseTypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="kind"></param> /// <remarks> /// When providing the semantic model, some properites will be devised from that. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, SemanticModel semanticModel) : base(baseTypeSyntaxNode, semanticModel) { this.kind = null; }
public bool IsBaseClass(BaseTypeSyntax syntax) { return _repositoryModelClasses.Any(c => c.Identifier.Text == syntax.Type.ToString()); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="semanticModel"></param> /// <param name="typeKind"></param> /// <returns></returns> protected override Rosetta.AST.Helpers.BaseTypeReference CreateBaseTypeReferenceHelper(BaseTypeSyntax node, SemanticModel semanticModel, TypeKind typeKind) { return new BaseTypeReference(node, semanticModel, typeKind); }
/// <summary> /// Initializes a new instance of the <see cref="TypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="semanticModel"></param> /// <param name="kind"></param> /// <remarks> /// Type kind will be stored statically. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, SemanticModel semanticModel, Microsoft.CodeAnalysis.TypeKind kind) : base(baseTypeSyntaxNode, semanticModel) { this.kind = kind; }
/// <summary> /// Tries all possible ways to retrieve the full name using the semantic model. /// </summary> /// <param name="node"></param> /// <param name="semanticModel"></param> /// <returns></returns> /// <exception cref="SymbolNotFoundException"></exception> internal static string GetTypeSymbolFullName(BaseTypeSyntax node, SemanticModel semanticModel) { var value = TryGetTypeSymbolFullName(node, semanticModel); if (value != null) { return value; } throw new SymbolNotFoundException(node, semanticModel); }
/// <summary> /// Initializes a new instance of the <see cref="BaseTypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="kind"></param> /// <remarks> /// When providing the semantic model, some properites will be devised from that. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, SemanticModel semanticModel) : this(baseTypeSyntaxNode, semanticModel, Microsoft.CodeAnalysis.TypeKind.Unknown) { }
/// <summary> /// Initializes a new instance of the <see cref="TypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="kind"></param> /// <remarks> /// Type kind will be stored statically. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, Microsoft.CodeAnalysis.TypeKind kind) : this(baseTypeSyntaxNode, null, kind) { }
public BaseTypeTranslation(BaseTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { Type = syntax.Type.Get<TypeTranslation>(this); }
// TODO: Revise this contruction logic, it is odd and not consistent! /// <summary> /// Initializes a new instance of the <see cref="BaseTypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <remarks> /// This is a minimal constructor, some properties might be unavailable. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode) : this(baseTypeSyntaxNode, null, Microsoft.CodeAnalysis.TypeKind.Unknown) { }
/// <summary> /// Tries all possible ways to retrieve the full name using the semantic model. /// </summary> /// <param name="node"></param> /// <param name="semanticModel"></param> /// <returns></returns> internal static string TryGetTypeSymbolFullName(BaseTypeSyntax node, SemanticModel semanticModel) { var displayFormat = new SymbolDisplayFormat(typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces); // Symbol can be found via Symbol ISymbol symbol = semanticModel.GetSymbolInfo(node.Type).Symbol; if (symbol != null) { return symbol.ToDisplayString(displayFormat); } // Symbol can be found via TypeSymbol ITypeSymbol type = semanticModel.GetTypeInfo(node.Type).Type; if (type != null) { return type.ToDisplayString(displayFormat); } // Could not find symbol return null; }
/// <summary> /// Initializes a new instance of the <see cref="BaseTypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <remarks> /// This is a minimal constructor, some properties might be unavailable. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode) : this(baseTypeSyntaxNode, null) { }
/// <summary> /// Initializes a new instance of the <see cref="TypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="semanticModel"></param> /// <param name="kind"></param> /// <remarks> /// Type kind will be stored statically. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, SemanticModel semanticModel, TypeKind kind) : base(baseTypeSyntaxNode, semanticModel, kind) { }
public static EnumDeclarationSyntax WithBaseClass(this EnumDeclarationSyntax @this, BaseTypeSyntax @classTypeSyntax) { return @this.WithBaseList( SyntaxFactory.BaseList()) .AddBaseListTypes(@classTypeSyntax); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="semanticModel"></param> /// <param name="typeKind"></param> /// <returns></returns> protected virtual BaseTypeReference CreateBaseTypeReferenceHelper(BaseTypeSyntax node, SemanticModel semanticModel, Roslyn.TypeKind typeKind) { return new BaseTypeReference(node, semanticModel, typeKind); }
/// <summary> /// Initializes a new instance of the <see cref="TypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="kind"></param> /// <remarks> /// Type kind will be stored statically. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, Microsoft.CodeAnalysis.TypeKind kind) : this(baseTypeSyntaxNode) { this.kind = kind; }
/// <summary> /// Initializes a new instance of the <see cref="TypeReference"/> class. /// </summary> /// <param name="baseTypeSyntaxNode"></param> /// <param name="semanticModel"></param> /// <param name="kind"></param> /// <remarks> /// Type kind will be stored statically. /// </remarks> public BaseTypeReference(BaseTypeSyntax baseTypeSyntaxNode, SemanticModel semanticModel) : this(baseTypeSyntaxNode, semanticModel, TypeKind.Unknown) { }