コード例 #1
0
ファイル: Symbol.cs プロジェクト: Samana/HlslTools
 internal Symbol(SymbolKind kind, string name, string documentation, Symbol parent)
 {
     Kind = kind;
     Name = name;
     Documentation = documentation;
     Parent = parent;
 }
コード例 #2
0
 /// <summary>
 /// Creates a new symbol information literal.
 ///
 /// @param name The name of the symbol.
 /// @param kind The kind of the symbol.
 /// @param range The range of the location of the symbol.
 /// @param uri The resource of the location of symbol, defaults to the current document.
 /// @param containerName The name of the symbol containg the symbol.
 /// </summary>
 public SymbolInformation(string name, SymbolKind kind, Range range, string uri, string containerName)
 {
     this.name = name;
     this.kind = kind;
     this.location = new Location(uri, range);
     this.containerName = containerName;
 }
コード例 #3
0
		public InlineCodeToken(TokenType type, string text = null, int index = -1, SymbolKind ownerType = default(SymbolKind), bool isExpandedParamArray = false) {
			Type   = type;
			_text  = text;
			_index = index;
			_ownerType = ownerType;
			_isExpandedParamArray = isExpandedParamArray;
		}
コード例 #4
0
ファイル: SymbolDefinition.cs プロジェクト: yonglehou/PSharp
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="symbol">ISymbol</param>
 /// <param name="dfgNode">DataFlowNode</param>
 internal SymbolDefinition(ISymbol symbol, DataFlowNode dfgNode)
 {
     this.DataFlowNode = dfgNode;
     this.Symbol = symbol;
     this.CandidateTypes = new HashSet<ITypeSymbol>();
     this.Kind = symbol.Kind;
     this.Name = $"[{this.DataFlowNode.Id},{this.Kind}]::{this.Symbol.Name}";
 }
コード例 #5
0
 public Symbol(string symType, string symName,
     SymbolKind symKind, string declaringClassName)
 {
     Type = symType;
     Name = symName;
     Kind = symKind;
     DeclaringClassName = declaringClassName;
 }
コード例 #6
0
        private string GetClass(SymbolKind kind)
        {
            if (kind == SymbolKind.TypeParameter)
            {
                return " t";
            }

            return "";
        }
コード例 #7
0
ファイル: Declaration.cs プロジェクト: bencz/Beryl
        public Declaration(Position position, string name, SymbolKind kind, AST.Type type)
            : base(position)
        {
            _name = name;

            _kind = kind;

            _type = type;
            _type.Parent = this;
        }
コード例 #8
0
        public SymbolMetadata(
			string id, 
			string fullName, 
			string[] filePathsOfDeclarations, 
			SymbolKind symbolKind)
        {
            Id = id;
            FullName = fullName;
            DeclarationFilesPaths = filePathsOfDeclarations;
            SymbolKind = symbolKind;
        }
コード例 #9
0
 public static object GetErrorReportingName(SymbolKind kind)
 {
     switch (kind)
     {
         case SymbolKind.Namespace:
             return MessageID.IDS_SK_NAMESPACE.Localize();
         default:
             // TODO: what is the right way to get these strings?
             return kind.ToString().ToLower();
     }
 }
コード例 #10
0
		/// <summary>
		/// Creates a type parameter reference.
		/// For common type parameter references, this method may return a shared instance.
		/// </summary>
		public static TypeParameterReference Create(SymbolKind ownerType, int index)
		{
			if (index >= 0 && index < 8 && (ownerType == SymbolKind.TypeDefinition || ownerType == SymbolKind.Method)) {
				TypeParameterReference[] arr = (ownerType == SymbolKind.TypeDefinition) ? classTypeParameterReferences : methodTypeParameterReferences;
				TypeParameterReference result = LazyInit.VolatileRead(ref arr[index]);
				if (result == null) {
					result = LazyInit.GetOrSet(ref arr[index], new TypeParameterReference(ownerType, index));
				}
				return result;
			} else {
				return new TypeParameterReference(ownerType, index);
			}
		}
コード例 #11
0
		public DefaultMemberReference(SymbolKind symbolKind, ITypeReference typeReference, string name, int typeParameterCount = 0, IList<ITypeReference> parameterTypes = null)
		{
			if (typeReference == null)
				throw new ArgumentNullException("typeReference");
			if (name == null)
				throw new ArgumentNullException("name");
			if (typeParameterCount != 0 && symbolKind != SymbolKind.Method)
				throw new ArgumentException("Type parameter count > 0 is only supported for methods.");
			this.symbolKind = symbolKind;
			this.typeReference = typeReference;
			this.name = name;
			this.typeParameterCount = typeParameterCount;
			this.parameterTypes = parameterTypes ?? EmptyList<ITypeReference>.Instance;
		}
コード例 #12
0
ファイル: InvocableSymbol.cs プロジェクト: Samana/HlslTools
        internal InvocableSymbol(SymbolKind kind, string name, string documentation, Symbol parent, TypeSymbol returnType, Func<InvocableSymbol, IEnumerable<ParameterSymbol>> lazyParameters = null)
            : base(kind, name, documentation, parent)
        {
            if (returnType == null)
                throw new ArgumentNullException(nameof(returnType));

            _parameters = new List<ParameterSymbol>();

            if (lazyParameters != null)
                foreach (var parameter in lazyParameters(this))
                    AddParameter(parameter);

            ReturnType = returnType;
        }
コード例 #13
0
            private static IEnumerable<ValueTuple<ISymbol, int>> EnumerateSymbols(
                Compilation compilation, ISymbol containingSymbol,
                SymbolKind kind, string localName,
                CancellationToken cancellationToken)
            {
                int ordinal = 0;

                foreach (var declaringLocation in containingSymbol.DeclaringSyntaxReferences)
                {
                    // This operation can potentially fail. If containingSymbol came from 
                    // a SpeculativeSemanticModel, containingSymbol.ContainingAssembly.Compilation
                    // may not have been rebuilt to reflect the trees used by the 
                    // SpeculativeSemanticModel to produce containingSymbol. In that case,
                    // asking the ContainingAssembly's complation for a SemanticModel based
                    // on trees for containingSymbol with throw an ArgumentException.
                    // Unfortunately, the best way to avoid this (currently) is to see if
                    // we're asking for a model for a tree that's part of the compilation.
                    // (There's no way to get back to a SemanticModel from a symbol).

                    // TODO (rchande): It might be better to call compilation.GetSemanticModel
                    // and catch the ArgumentException. The compilation internally has a 
                    // Dictionary<SyntaxTree, ...> that it uses to check if the SyntaxTree
                    // is applicable wheras the public interface requires us to enumerate
                    // the entire IEnumerable of trees in the Compilation.
                    if (!compilation.SyntaxTrees.Contains(declaringLocation.SyntaxTree))
                    {
                        continue;
                    }

                    var node = declaringLocation.GetSyntax(cancellationToken);
                    if (node.Language == LanguageNames.VisualBasic)
                    {
                        node = node.Parent;
                    }

                    var semanticModel = compilation.GetSemanticModel(node.SyntaxTree);

                    foreach (var token in node.DescendantNodes())
                    {
                        var symbol = semanticModel.GetDeclaredSymbol(token, cancellationToken);

                        if (symbol != null &&
                            symbol.Kind == kind &&
                            SymbolKey.Equals(compilation, symbol.Name, localName))
                        {
                            yield return ValueTuple.Create(symbol, ordinal++);
                        }
                    }
                }
            }
コード例 #14
0
		public DefaultTypeParameter(
			ICompilation compilation, SymbolKind ownerType,
			int index, string name = null,
			VarianceModifier variance = VarianceModifier.Invariant,
			IList<IAttribute> attributes = null,
			DomRegion region = default(DomRegion),
			bool hasValueTypeConstraint = false, bool hasReferenceTypeConstraint = false, bool hasDefaultConstructorConstraint = false,
			IList<IType> constraints = null)
			: base(compilation, ownerType, index, name, variance, attributes, region)
		{
			this.hasValueTypeConstraint = hasValueTypeConstraint;
			this.hasReferenceTypeConstraint = hasReferenceTypeConstraint;
			this.hasDefaultConstructorConstraint = hasDefaultConstructorConstraint;
			this.constraints = constraints ?? EmptyList<IType>.Instance;
		}
        static string GetMemberType(SymbolKind symbolKind)
        {
            switch (symbolKind)
            {
                case SymbolKind.Field:
                    return GettextCatalog.GetString("field");
                case SymbolKind.Method:
                    return GettextCatalog.GetString("method");
                case SymbolKind.Property:
                    return GettextCatalog.GetString("property");
                case SymbolKind.Event:
                    return GettextCatalog.GetString("event");
            }

            return GettextCatalog.GetString("member");
        }
コード例 #16
0
		private string GetVimKind(SymbolKind entityType)
        {
    //        v	variable
    //f	function or method
    //m	member of a struct or class
            switch(entityType)
            {
			case(SymbolKind.Method):
                    return "f";
			case(SymbolKind.Field):
                    return "v";
			case(SymbolKind.Property):
                    return "m";
            }
            return " ";
        }
コード例 #17
0
 private bool AreEquivalentWorker(ISymbol x, ISymbol y, SymbolKind k, Dictionary<INamedTypeSymbol, INamedTypeSymbol> equivalentTypesWithDifferingAssemblies)
 {
     Contract.Requires(x.Kind == y.Kind && x.Kind == k);
     switch (k)
     {
         case SymbolKind.ArrayType:
             return ArrayTypesAreEquivalent((IArrayTypeSymbol)x, (IArrayTypeSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Assembly:
             return AssembliesAreEquivalent((IAssemblySymbol)x, (IAssemblySymbol)y);
         case SymbolKind.DynamicType:
             return DynamicTypesAreEquivalent((IDynamicTypeSymbol)x, (IDynamicTypeSymbol)y);
         case SymbolKind.Event:
             return EventsAreEquivalent((IEventSymbol)x, (IEventSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Field:
             return FieldsAreEquivalent((IFieldSymbol)x, (IFieldSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Label:
             return LabelsAreEquivalent((ILabelSymbol)x, (ILabelSymbol)y);
         case SymbolKind.Local:
             return LocalsAreEquivalent((ILocalSymbol)x, (ILocalSymbol)y);
         case SymbolKind.Method:
             return MethodsAreEquivalent((IMethodSymbol)x, (IMethodSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.NetModule:
             return ModulesAreEquivalent((IModuleSymbol)x, (IModuleSymbol)y);
         case SymbolKind.NamedType:
         case SymbolKind.ErrorType: // ErrorType is handled in NamedTypesAreEquivalent
             return NamedTypesAreEquivalent((INamedTypeSymbol)x, (INamedTypeSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Namespace:
             return NamespacesAreEquivalent((INamespaceSymbol)x, (INamespaceSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Parameter:
             return ParametersAreEquivalent((IParameterSymbol)x, (IParameterSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.PointerType:
             return PointerTypesAreEquivalent((IPointerTypeSymbol)x, (IPointerTypeSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Property:
             return PropertiesAreEquivalent((IPropertySymbol)x, (IPropertySymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.RangeVariable:
             return RangeVariablesAreEquivalent((IRangeVariableSymbol)x, (IRangeVariableSymbol)y);
         case SymbolKind.TypeParameter:
             return TypeParametersAreEquivalent((ITypeParameterSymbol)x, (ITypeParameterSymbol)y, equivalentTypesWithDifferingAssemblies);
         case SymbolKind.Preprocessing:
             return PreprocessingSymbolsAreEquivalent((IPreprocessingSymbol)x, (IPreprocessingSymbol)y);
         default:
             return false;
     }
 }
コード例 #18
0
ファイル: Symbol.cs プロジェクト: hesam/SketchSharp
 internal static uint SymbolKindToFieldKind(SymbolKind kind) {
   uint ret = 0;
   if (kind == SymbolKind.All)
     ret = (uint ) FIELD_KIND.FIELD_KIND_ALL;
   else{
     if (0 != (kind & SymbolKind.Method))
       ret |= (uint ) (FIELD_KIND.FIELD_SYM_MEMBER|FIELD_KIND.FIELD_TYPE_METHOD);
     if (0 != (kind & SymbolKind.Property))
       ret |= (uint ) (FIELD_KIND.FIELD_SYM_MEMBER|FIELD_KIND.FIELD_TYPE_PROP);
     if (0 != (kind & SymbolKind.Field))
       ret |= (uint ) (FIELD_KIND.FIELD_KIND_ALL & ~(FIELD_KIND.FIELD_TYPE_METHOD|FIELD_KIND.FIELD_TYPE_PROP));
     if (0 != (kind & SymbolKind.This))
       ret |= (uint ) FIELD_KIND.FIELD_SYM_THIS;
     if (0 != (kind & SymbolKind.Local))
       ret |= (uint ) FIELD_KIND.FIELD_SYM_LOCAL;
     if (0 != (kind & SymbolKind.Parameter))
       ret |= (uint ) FIELD_KIND.FIELD_SYM_PARAM;
   }
   return ret;
 }
コード例 #19
0
		static ITypeParameter GetTypeParameter(ref ITypeParameter[] typeParameters, SymbolKind symbolKind, int index)
		{
			ITypeParameter[] tps = typeParameters;
			while (index >= tps.Length) {
				// We don't have a normal type parameter for this index, so we need to extend our array.
				// Because the array can be used concurrently from multiple threads, we have to use
				// Interlocked.CompareExchange.
				ITypeParameter[] newTps = new ITypeParameter[index + 1];
				tps.CopyTo(newTps, 0);
				for (int i = tps.Length; i < newTps.Length; i++) {
					newTps[i] = new DummyTypeParameter(symbolKind, i);
				}
				ITypeParameter[] oldTps = Interlocked.CompareExchange(ref typeParameters, newTps, tps);
				if (oldTps == tps) {
					// exchange successful
					tps = newTps;
				} else {
					// exchange not successful
					tps = oldTps;
				}
			}
			return tps[index];
		}
コード例 #20
0
 public override void RegisterSymbolStartAction(Action <SymbolStartAnalysisContext> action, SymbolKind symbolKind)
 {
 }
コード例 #21
0
        private IEnumerable <DocumentSymbol> CreateSymbolsOfEntryDocument(ILocalizableSymbol symbol, Boogie.IToken token, SymbolKind kind)
        {
            var children = symbol.Children.SelectMany(Visit);

            if (!IsPartOfEntryDocument(token))
            {
                return(children);
            }
            var documentSymbol = new DocumentSymbol {
                Name     = symbol.Name,
                Kind     = kind,
                Detail   = symbol.GetDetailText(_cancellationToken),
                Children = children.ToArray()
            };

            if (_symbolTable.TryGetLocationOf(symbol, out var location))
            {
                documentSymbol = documentSymbol with {
                    Range          = location.Declaration,
                    SelectionRange = location.Name
                };
            }
            return(new[] { documentSymbol });
        }
    }
コード例 #22
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindToken(root, context.Span.Start, out SyntaxToken token))
            {
                return;
            }

            SyntaxKind kind = token.Kind();

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case CompilerDiagnosticIdentifiers.OperatorCannotBeAppliedToOperand:
                {
                    if (kind == SyntaxKind.QuestionToken &&
                        token.Parent is ConditionalAccessExpressionSyntax conditionalAccess)
                    {
                        SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                        ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(conditionalAccess.Expression, context.CancellationToken);

                        if (typeSymbol?.IsErrorType() == false &&
                            !typeSymbol.IsNullableType())
                        {
                            if (typeSymbol.IsValueType)
                            {
                                if (Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.RemoveConditionalAccess))
                                {
                                    CodeAction codeAction = CodeAction.Create(
                                        "Remove '?' operator",
                                        cancellationToken =>
                                        {
                                            var textChange = new TextChange(token.Span, "");
                                            return(context.Document.WithTextChangeAsync(textChange, cancellationToken));
                                        },
                                        GetEquivalenceKey(diagnostic));

                                    context.RegisterCodeFix(codeAction, diagnostic);
                                }
                            }
                            else if (typeSymbol.IsReferenceType)
                            {
                                if (Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.AddArgumentList) &&
                                    conditionalAccess.WhenNotNull is MemberBindingExpressionSyntax memberBindingExpression)
                                {
                                    ConditionalAccessExpressionSyntax newNode = conditionalAccess.WithWhenNotNull(
                                        InvocationExpression(
                                            memberBindingExpression.WithoutTrailingTrivia(),
                                            ArgumentList().WithTrailingTrivia(memberBindingExpression.GetTrailingTrivia())));

                                    CodeAction codeAction = CodeAction.Create(
                                        "Add argument list",
                                        cancellationToken => context.Document.ReplaceNodeAsync(conditionalAccess, newNode, cancellationToken),
                                        GetEquivalenceKey(diagnostic));

                                    context.RegisterCodeFix(codeAction, diagnostic);
                                }
                            }
                        }
                    }

                    break;
                }

                case CompilerDiagnosticIdentifiers.PartialModifierCanOnlyAppearImmediatelyBeforeClassStructInterfaceOrVoid:
                {
                    if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.OrderModifiers))
                    {
                        break;
                    }

                    ModifiersCodeFixRegistrator.MoveModifier(context, diagnostic, token.Parent, token);
                    break;
                }

                case CompilerDiagnosticIdentifiers.ValueCannotBeUsedAsDefaultParameter:
                {
                    if (!(token.Parent is ParameterSyntax parameter))
                    {
                        break;
                    }

                    ExpressionSyntax value = parameter.Default?.Value;

                    if (value == null)
                    {
                        break;
                    }

                    if (value.IsKind(SyntaxKind.NullLiteralExpression))
                    {
                        if (Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.ReplaceNullLiteralExpressionWithDefaultValue))
                        {
                            SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                            CodeFixRegistrator.ReplaceNullWithDefaultValue(context, diagnostic, value, semanticModel);
                        }
                    }
                    else if (!value.IsKind(SyntaxKind.DefaultExpression, SyntaxKind.DefaultLiteralExpression))
                    {
                        if (Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.ChangeParameterType))
                        {
                            SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                            ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(value, context.CancellationToken);

                            if (!typeSymbol.IsKind(SymbolKind.ErrorType))
                            {
                                CodeFixRegistrator.ChangeType(context, diagnostic, parameter.Type, typeSymbol, semanticModel);
                            }
                        }
                    }

                    break;
                }

                case CompilerDiagnosticIdentifiers.ObjectOfTypeConvertibleToTypeIsRequired:
                {
                    if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.ReturnDefaultValue))
                    {
                        break;
                    }

                    if (token.Kind() != SyntaxKind.ReturnKeyword)
                    {
                        break;
                    }

                    if (!token.IsParentKind(SyntaxKind.ReturnStatement))
                    {
                        break;
                    }

                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    ISymbol symbol = semanticModel.GetEnclosingSymbol(token.SpanStart, context.CancellationToken);

                    if (symbol == null)
                    {
                        break;
                    }

                    SymbolKind symbolKind = symbol.Kind;

                    ITypeSymbol typeSymbol = null;

                    if (symbolKind == SymbolKind.Method)
                    {
                        var methodSymbol = (IMethodSymbol)symbol;

                        typeSymbol = methodSymbol.ReturnType;

                        if (methodSymbol.IsAsync &&
                            (typeSymbol is INamedTypeSymbol namedTypeSymbol))
                        {
                            ImmutableArray <ITypeSymbol> typeArguments = namedTypeSymbol.TypeArguments;

                            if (typeArguments.Any())
                            {
                                typeSymbol = typeArguments[0];
                            }
                        }
                    }
                    else if (symbolKind == SymbolKind.Property)
                    {
                        typeSymbol = ((IPropertySymbol)symbol).Type;
                    }
                    else
                    {
                        Debug.Fail(symbolKind.ToString());
                    }

                    if (typeSymbol == null)
                    {
                        break;
                    }

                    if (typeSymbol.Kind == SymbolKind.ErrorType)
                    {
                        break;
                    }

                    if (!typeSymbol.SupportsExplicitDeclaration())
                    {
                        break;
                    }

                    var returnStatement = (ReturnStatementSyntax)token.Parent;

                    CodeAction codeAction = CodeAction.Create(
                        "Return default value",
                        cancellationToken =>
                        {
                            ExpressionSyntax expression = typeSymbol.GetDefaultValueSyntax(context.Document.GetDefaultSyntaxOptions());

                            if (expression.IsKind(SyntaxKind.DefaultExpression) &&
                                context.Document.SupportsLanguageFeature(CSharpLanguageFeature.DefaultLiteral))
                            {
                                expression = CSharpFactory.DefaultLiteralExpression().WithTriviaFrom(expression);
                            }

                            ReturnStatementSyntax newNode = returnStatement.WithExpression(expression);

                            return(context.Document.ReplaceNodeAsync(returnStatement, newNode, cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case CompilerDiagnosticIdentifiers.TypeExpected:
                {
                    if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.AddMissingType))
                    {
                        break;
                    }

                    if (token.Kind() != SyntaxKind.CloseParenToken)
                    {
                        break;
                    }

                    if (!(token.Parent is DefaultExpressionSyntax defaultExpression))
                    {
                        break;
                    }

                    if (!(defaultExpression.Type is IdentifierNameSyntax identifierName))
                    {
                        break;
                    }

                    if (!identifierName.IsMissing)
                    {
                        break;
                    }

                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    TypeInfo typeInfo = semanticModel.GetTypeInfo(defaultExpression, context.CancellationToken);

                    ITypeSymbol convertedType = typeInfo.ConvertedType;

                    if (convertedType?.SupportsExplicitDeclaration() != true)
                    {
                        break;
                    }

                    CodeAction codeAction = CodeAction.Create(
                        $"Add type '{SymbolDisplay.ToMinimalDisplayString(convertedType, semanticModel, defaultExpression.SpanStart, SymbolDisplayFormats.Default)}'",
                        cancellationToken =>
                        {
                            TypeSyntax newNode = convertedType.ToMinimalTypeSyntax(semanticModel, defaultExpression.SpanStart);

                            newNode = newNode
                                      .WithTriviaFrom(identifierName)
                                      .WithFormatterAnnotation();

                            return(context.Document.ReplaceNodeAsync(identifierName, newNode, cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case CompilerDiagnosticIdentifiers.SemicolonAfterMethodOrAccessorBlockIsNotValid:
                {
                    if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.RemoveSemicolon))
                    {
                        break;
                    }

                    if (token.Kind() != SyntaxKind.SemicolonToken)
                    {
                        break;
                    }

                    switch (token.Parent)
                    {
                    case MethodDeclarationSyntax methodDeclaration:
                    {
                        BlockSyntax body = methodDeclaration.Body;

                        if (body == null)
                        {
                            break;
                        }

                        CodeAction codeAction = CodeAction.Create(
                            "Remove semicolon",
                            cancellationToken =>
                                {
                                    SyntaxTriviaList trivia = body
                                                              .GetTrailingTrivia()
                                                              .EmptyIfWhitespace()
                                                              .AddRange(token.LeadingTrivia.EmptyIfWhitespace())
                                                              .AddRange(token.TrailingTrivia);

                                    MethodDeclarationSyntax newNode = methodDeclaration
                                                                      .WithBody(body.WithTrailingTrivia(trivia))
                                                                      .WithSemicolonToken(default(SyntaxToken));

                                    return(context.Document.ReplaceNodeAsync(methodDeclaration, newNode, cancellationToken));
                                },
                            GetEquivalenceKey(diagnostic));

                        context.RegisterCodeFix(codeAction, diagnostic);
                        break;
                    }

                    case PropertyDeclarationSyntax propertyDeclaration:
                    {
                        AccessorListSyntax accessorList = propertyDeclaration.AccessorList;

                        if (accessorList == null)
                        {
                            break;
                        }

                        CodeAction codeAction = CodeAction.Create(
                            "Remove semicolon",
                            cancellationToken =>
                                {
                                    SyntaxTriviaList trivia = accessorList
                                                              .GetTrailingTrivia()
                                                              .EmptyIfWhitespace()
                                                              .AddRange(token.LeadingTrivia.EmptyIfWhitespace())
                                                              .AddRange(token.TrailingTrivia);

                                    PropertyDeclarationSyntax newNode = propertyDeclaration
                                                                        .WithAccessorList(accessorList.WithTrailingTrivia(trivia))
                                                                        .WithSemicolonToken(default(SyntaxToken));

                                    return(context.Document.ReplaceNodeAsync(propertyDeclaration, newNode, cancellationToken));
                                },
                            GetEquivalenceKey(diagnostic));

                        context.RegisterCodeFix(codeAction, diagnostic);
                        break;
                    }

                    case AccessorDeclarationSyntax accessorDeclaration:
                    {
                        BlockSyntax body = accessorDeclaration.Body;

                        if (body == null)
                        {
                            break;
                        }

                        CodeAction codeAction = CodeAction.Create(
                            "Remove semicolon",
                            cancellationToken =>
                                {
                                    SyntaxTriviaList trivia = body
                                                              .GetTrailingTrivia()
                                                              .EmptyIfWhitespace()
                                                              .AddRange(token.LeadingTrivia.EmptyIfWhitespace())
                                                              .AddRange(token.TrailingTrivia);

                                    AccessorDeclarationSyntax newNode = accessorDeclaration
                                                                        .WithBody(body.WithTrailingTrivia(trivia))
                                                                        .WithSemicolonToken(default(SyntaxToken));

                                    return(context.Document.ReplaceNodeAsync(accessorDeclaration, newNode, cancellationToken));
                                },
                            GetEquivalenceKey(diagnostic));

                        context.RegisterCodeFix(codeAction, diagnostic);
                        break;
                    }
                    }

                    break;
                }

                case CompilerDiagnosticIdentifiers.CannotConvertType:
                {
                    if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.ChangeForEachType))
                    {
                        break;
                    }

                    if (token.Kind() != SyntaxKind.ForEachKeyword)
                    {
                        break;
                    }

                    if (!(token.Parent is ForEachStatementSyntax forEachStatement))
                    {
                        break;
                    }

                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    ForEachStatementInfo info = semanticModel.GetForEachStatementInfo(forEachStatement);

                    ITypeSymbol typeSymbol = info.ElementType;

                    if (typeSymbol.SupportsExplicitDeclaration())
                    {
                        CodeFixRegistrator.ChangeType(context, diagnostic, forEachStatement.Type, typeSymbol, semanticModel, CodeFixIdentifiers.ChangeForEachType);
                    }

                    CodeFixRegistrator.ChangeTypeToVar(context, diagnostic, forEachStatement.Type, CodeFixIdentifiers.ChangeTypeToVar);
                    break;
                }

                case CompilerDiagnosticIdentifiers.OptionalParametersMustAppearAfterAllRequiredParameters:
                {
                    if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.AddDefaultValueToParameter))
                    {
                        break;
                    }

                    if (!(token.Parent is BaseParameterListSyntax parameterList))
                    {
                        break;
                    }

                    SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters;

                    ParameterSyntax parameter = null;

                    for (int i = 0; i < parameters.Count; i++)
                    {
                        ParameterSyntax p = parameters[i];

                        if (p.FullSpan.End <= token.SpanStart)
                        {
                            parameter = p;
                        }
                        else
                        {
                            break;
                        }
                    }

                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    IParameterSymbol parameterSymbol = semanticModel.GetDeclaredSymbol(parameter, context.CancellationToken);

                    ITypeSymbol typeSymbol = parameterSymbol.Type;

                    if (typeSymbol.Kind == SymbolKind.ErrorType)
                    {
                        break;
                    }

                    CodeAction codeAction = CodeAction.Create(
                        "Add default value",
                        cancellationToken =>
                        {
                            ExpressionSyntax defaultValue = typeSymbol.GetDefaultValueSyntax(context.Document.GetDefaultSyntaxOptions());

                            ParameterSyntax newParameter = parameter
                                                           .WithDefault(EqualsValueClause(defaultValue).WithTrailingTrivia(parameter.GetTrailingTrivia()))
                                                           .WithoutTrailingTrivia()
                                                           .WithFormatterAnnotation();

                            return(context.Document.ReplaceNodeAsync(parameter, newParameter, cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }
                }
            }
        }
コード例 #23
0
 public SymbolKindOrTypeKind(SymbolKind symbolKind) : this()
 {
     SymbolKind = symbolKind;
     TypeKind   = null;
 }
コード例 #24
0
 public static bool MatchesKind(this ISymbol symbol, SymbolKind kind)
 {
     return(symbol?.Kind == kind);
 }
コード例 #25
0
 internal IntrinsicTypeSymbol(SymbolKind kind, string name, string documentation)
     : base(kind, name, documentation, null)
 {
 }
コード例 #26
0
        public static bool IsKind(this ISymbol symbol, SymbolKind kind1, SymbolKind kind2, SymbolKind kind3)
        {
            if (symbol == null)
            {
                return(false);
            }

            SymbolKind kind = symbol.Kind;

            return(kind == kind1 ||
                   kind == kind2 ||
                   kind == kind3);
        }
コード例 #27
0
 public static IMember Resolve(ITypeResolveContext context,
                               SymbolKind symbolKind,
                               string name,
                               ITypeReference explicitInterfaceTypeReference  = null,
                               IList <string> typeParameterNames              = null,
                               IList <ITypeReference> parameterTypeReferences = null)
 {
     if (context.CurrentTypeDefinition == null)
     {
         return(null);
     }
     if (parameterTypeReferences == null)
     {
         parameterTypeReferences = EmptyList <ITypeReference> .Instance;
     }
     if (typeParameterNames == null || typeParameterNames.Count == 0)
     {
         // non-generic member
         // In this case, we can simply resolve the parameter types in the given context
         var parameterTypes = parameterTypeReferences.Resolve(context);
         if (explicitInterfaceTypeReference == null)
         {
             foreach (IMember member in context.CurrentTypeDefinition.Members)
             {
                 if (member.IsExplicitInterfaceImplementation)
                 {
                     continue;
                 }
                 if (IsNonGenericMatch(member, symbolKind, name, parameterTypes))
                 {
                     return(member);
                 }
             }
         }
         else
         {
             IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(context);
             foreach (IMember member in context.CurrentTypeDefinition.Members)
             {
                 if (!member.IsExplicitInterfaceImplementation)
                 {
                     continue;
                 }
                 if (member.ImplementedInterfaceMembers.Count != 1)
                 {
                     continue;
                 }
                 if (IsNonGenericMatch(member, symbolKind, name, parameterTypes))
                 {
                     if (explicitInterfaceType.Equals(member.ImplementedInterfaceMembers[0].DeclaringType))
                     {
                         return(member);
                     }
                 }
             }
         }
     }
     else
     {
         // generic member
         // In this case, we must specify the correct context for resolving the parameter types
         foreach (IMethod method in context.CurrentTypeDefinition.Methods)
         {
             if (method.SymbolKind != symbolKind)
             {
                 continue;
             }
             if (method.Name != name)
             {
                 continue;
             }
             if (method.Parameters.Count != parameterTypeReferences.Count)
             {
                 continue;
             }
             // Compare type parameter count and names:
             if (!typeParameterNames.SequenceEqual(method.TypeParameters.Select(tp => tp.Name)))
             {
                 continue;
             }
             // Once we know the type parameter names are fitting, we can resolve the
             // type references in the context of the method:
             var contextForMethod = context.WithCurrentMember(method);
             var parameterTypes   = parameterTypeReferences.Resolve(contextForMethod);
             if (!IsParameterTypeMatch(method, parameterTypes))
             {
                 continue;
             }
             if (explicitInterfaceTypeReference == null)
             {
                 if (!method.IsExplicitInterfaceImplementation)
                 {
                     return(method);
                 }
             }
             else if (method.IsExplicitInterfaceImplementation && method.ImplementedInterfaceMembers.Count == 1)
             {
                 IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(contextForMethod);
                 if (explicitInterfaceType.Equals(method.ImplementedInterfaceMembers[0].DeclaringType))
                 {
                     return(method);
                 }
             }
         }
     }
     return(null);
 }
コード例 #28
0
ファイル: ContainerSymbol.cs プロジェクト: Samana/HlslTools
 internal ContainerSymbol(SymbolKind kind, string name, string documentation, Symbol parent)
     : base(kind, name, documentation, parent)
 {
     _members = new List <Symbol>();
 }
コード例 #29
0
        private void IndexedPropertiesBindingChecks(string source, MetadataReference reference, SymbolKind symbolKind, string name)
        {
            var tree = Parse(source);
            var comp = CreateCompilation(tree, new[] { reference });

            var model = comp.GetSemanticModel(tree);
            var expr  = GetExprSyntaxForBinding(GetExprSyntaxList(tree));

            var sym = model.GetSymbolInfo(expr);

            Assert.Equal(symbolKind, sym.Symbol.Kind);
            Assert.Equal(name, sym.Symbol.Name);

            var typeInfo = model.GetTypeInfo(expr);
            // https://github.com/dotnet/roslyn/issues/38509
            // Assert.NotEqual(default, typeInfo);

            var methodGroup = model.GetMemberGroup(expr);

            Assert.NotEqual(default, methodGroup);
コード例 #30
0
 private string LowerCaseKind(SymbolKind kind)
 {
     return(kind.ToString().ToLowerInvariant());
 }
 private static DiagnosticResult GetExpectedDiagnostic(DiagnosticDescriptor rule, int line, int column, SymbolKind unsupportedSymbolKind)
 {
     return(new DiagnosticResult(rule)
            .WithLocation(line, column)
            .WithArguments(unsupportedSymbolKind));
 }
 private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, SymbolKind unsupportedSymbolKind)
 {
     return(GetExpectedDiagnostic(VisualBasic.Analyzers.MetaAnalyzers.BasicRegisterActionAnalyzer.UnsupportedSymbolKindArgumentRule,
                                  line, column, unsupportedSymbolKind));
 }
コード例 #33
0
        private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, SymbolKind unsupportedSymbolKind)
        {
            string fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";

            return(new DiagnosticResult
            {
                Id = DiagnosticIds.UnsupportedSymbolKindArgumentRuleId,
                Message = string.Format(CodeAnalysisDiagnosticsResources.UnsupportedSymbolKindArgumentToRegisterActionMessage, unsupportedSymbolKind.ToString()),
                Severity = DiagnosticSeverity.Warning,
                Locations = new[]
                {
                    new DiagnosticResultLocation(fileName, line, column)
                }
            });
        }
コード例 #34
0
		public static IMember Resolve(ITypeResolveContext context,
		                              SymbolKind symbolKind,
		                              string name,
		                              ITypeReference explicitInterfaceTypeReference = null,
		                              IList<string> typeParameterNames = null,
		                              IList<ITypeReference> parameterTypeReferences = null)
		{
			if (context.CurrentTypeDefinition == null)
				return null;
			if (parameterTypeReferences == null)
				parameterTypeReferences = EmptyList<ITypeReference>.Instance;
			if (typeParameterNames == null || typeParameterNames.Count == 0) {
				// non-generic member
				// In this case, we can simply resolve the parameter types in the given context
				var parameterTypes = parameterTypeReferences.Resolve(context);
				if (explicitInterfaceTypeReference == null) {
					foreach (IMember member in context.CurrentTypeDefinition.Members) {
						if (member.IsExplicitInterfaceImplementation)
							continue;
						if (IsNonGenericMatch(member, symbolKind, name, parameterTypes))
							return member;
					}
				} else {
					IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(context);
					foreach (IMember member in context.CurrentTypeDefinition.Members) {
						if (!member.IsExplicitInterfaceImplementation)
							continue;
						if (member.ImplementedInterfaceMembers.Count != 1)
							continue;
						if (IsNonGenericMatch(member, symbolKind, name, parameterTypes)) {
							if (explicitInterfaceType.Equals(member.ImplementedInterfaceMembers[0].DeclaringType))
								return member;
						}
					}
				}
			} else {
				// generic member
				// In this case, we must specify the correct context for resolving the parameter types
				foreach (IMethod method in context.CurrentTypeDefinition.Methods) {
					if (method.SymbolKind != symbolKind)
						continue;
					if (method.Name != name)
						continue;
					if (method.Parameters.Count != parameterTypeReferences.Count)
						continue;
					// Compare type parameter count and names:
					if (!typeParameterNames.SequenceEqual(method.TypeParameters.Select(tp => tp.Name)))
						continue;
					// Once we know the type parameter names are fitting, we can resolve the
					// type references in the context of the method:
					var contextForMethod = context.WithCurrentMember(method);
					var parameterTypes = parameterTypeReferences.Resolve(contextForMethod);
					if (!IsParameterTypeMatch(method, parameterTypes))
						continue;
					if (explicitInterfaceTypeReference == null) {
						if (!method.IsExplicitInterfaceImplementation)
							return method;
					} else if (method.IsExplicitInterfaceImplementation && method.ImplementedInterfaceMembers.Count == 1) {
						IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(contextForMethod);
						if (explicitInterfaceType.Equals(method.ImplementedInterfaceMembers[0].DeclaringType))
							return method;
					}
				}
			}
			return null;
		}
コード例 #35
0
        private static bool MemberNameExistsInHierarchy(string memberName, INamedTypeSymbol containingType, SymbolKind kind)
        {
            for (INamedTypeSymbol baseType = containingType; baseType != null; baseType = baseType.BaseType)
            {
                if (baseType.GetMembers(memberName).Any(member => member.Kind == kind))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #36
0
 public SymbolKindViewModel(SymbolKind symbolKind, string name, SymbolSpecification specification)
 {
     this._symbolKind = symbolKind;
     Name = name;
     IsChecked = specification.ApplicableSymbolKindList.Any(k => k.SymbolKind == symbolKind);
 }
コード例 #37
0
 public SymInfo(string name, SymbolKind kind, string description)
 {
     this.name        = name;
     this.kind        = kind;
     this.description = description;
 }
コード例 #38
0
        protected override Accessibility GetDefaultAccessibility(SymbolKind targetSymbolKind, CodeGenerationDestination destination)
        {
            switch (targetSymbolKind)
            {
                case SymbolKind.Field:
                case SymbolKind.Method:
                case SymbolKind.Property:
                case SymbolKind.Event:
                    return Accessibility.Private;

                case SymbolKind.NamedType:
                    switch (destination)
                    {
                        case CodeGenerationDestination.ClassType:
                        case CodeGenerationDestination.EnumType:
                        case CodeGenerationDestination.InterfaceType:
                        case CodeGenerationDestination.StructType:
                            return Accessibility.Private;
                        default:
                            return Accessibility.Internal;
                    }

                default:
                    Debug.Fail("Invalid symbol kind: " + targetSymbolKind);
                    throw Exceptions.ThrowEFail();
            }
        }
コード例 #39
0
 public static bool IsKind(this ISymbol symbol, SymbolKind kind)
 {
     return(symbol.MatchesKind(kind));
 }
コード例 #40
0
 private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, SymbolKind unsupportedSymbolKind)
 {
     return(GetExpectedDiagnostic(LanguageNames.CSharp, line, column, unsupportedSymbolKind));
 }
コード例 #41
0
 public static bool MatchesKind(this ISymbol symbol, SymbolKind kind1, SymbolKind kind2, SymbolKind kind3)
 {
     return(symbol != null &&
            (symbol.Kind == kind1 || symbol.Kind == kind2 || symbol.Kind == kind3));
 }
コード例 #42
0
        /// <summary>
        /// Some kinds of methods are not considered to be hideable by certain kinds of members.
        /// Specifically, methods, properties, and types cannot hide constructors, destructors,
        /// operators, conversions, or accessors.
        /// </summary>
        public static bool CanBeHiddenByMemberKind(this MethodSymbol hiddenMethod, SymbolKind hidingMemberKind)
        {
            Debug.Assert((object)hiddenMethod != null);

            // Nothing can hide a destructor (see SymbolPreparer::ReportHiding)
            if (hiddenMethod.MethodKind == MethodKind.Destructor)
            {
                return false;
            }

            switch (hidingMemberKind)
            {
                case SymbolKind.ErrorType:
                case SymbolKind.NamedType:
                case SymbolKind.Method:
                case SymbolKind.Property:
                    return CanBeHiddenByMethodPropertyOrType(hiddenMethod);
                case SymbolKind.Field:
                case SymbolKind.Event: // Events are not covered by CSemanticChecker::FindSymHiddenByMethPropAgg.
                    return true;
                default:
                    throw ExceptionUtilities.UnexpectedValue(hidingMemberKind);
            }
        }
コード例 #43
0
        private static ISymbol CreateSymbolMock(
            SymbolKind kind,
            Accessibility declaredAccessibility = Accessibility.NotApplicable,
            bool isExtensionMethod          = false,
            MethodKind methodKind           = MethodKind.Ordinary,
            INamedTypeSymbol containingType = null,
            bool isConst                  = false,
            ITypeSymbol elementType       = null,
            INamespaceOrTypeSymbol target = null,
            ITypeSymbol pointedAtType     = null,
            bool isWithEvents             = false,
            TypeKind typeKind             = TypeKind.Unknown)
        {
            var symbolMock = new Mock <ISymbol>();

            symbolMock.SetupGet(s => s.Kind).Returns(kind);
            symbolMock.SetupGet(s => s.DeclaredAccessibility).Returns(declaredAccessibility);
            symbolMock.SetupGet(s => s.ContainingType).Returns(containingType);

            if (kind == SymbolKind.ArrayType)
            {
                var arrayTypeMock = symbolMock.As <IArrayTypeSymbol>();
                arrayTypeMock.SetupGet(s => s.ElementType).Returns(elementType);
            }

            if (kind == SymbolKind.Alias)
            {
                var aliasMock = symbolMock.As <IAliasSymbol>();
                aliasMock.SetupGet(s => s.Target).Returns(target);
            }

            if (kind == SymbolKind.Method)
            {
                var methodTypeMock = symbolMock.As <IMethodSymbol>();
                methodTypeMock.SetupGet(s => s.MethodKind).Returns(methodKind);
                methodTypeMock.SetupGet(s => s.IsExtensionMethod).Returns(isExtensionMethod);
            }

            if (kind == SymbolKind.NamedType)
            {
                var namedTypeMock = symbolMock.As <INamedTypeSymbol>();
                namedTypeMock.SetupGet(s => s.TypeKind).Returns(typeKind);
            }

            if (kind == SymbolKind.Field)
            {
                var fieldMock = symbolMock.As <IFieldSymbol>();
                fieldMock.SetupGet(s => s.IsConst).Returns(isConst);
            }

            if (kind == SymbolKind.PointerType)
            {
                var pointerTypeMock = symbolMock.As <IPointerTypeSymbol>();
                pointerTypeMock.SetupGet(s => s.PointedAtType).Returns(pointedAtType);
            }

            if (kind == SymbolKind.Property)
            {
                var propertyMock = symbolMock.As <IPropertySymbol>();
                propertyMock.SetupGet(s => s.IsWithEvents).Returns(isWithEvents);
            }

            return(symbolMock.Object);
        }
コード例 #44
0
 private void TestGlyph(
     StandardGlyphGroup expectedGlyphGroup,
     SymbolKind kind = SymbolKind.Method,
     Accessibility declaredAccessibility = Accessibility.NotApplicable,
     bool isExtensionMethod = true,
     MethodKind methodKind = MethodKind.Ordinary,
     INamedTypeSymbol containingType = null,
     bool isConst = false,
     ITypeSymbol elementType = null,
     INamespaceOrTypeSymbol target = null,
     ITypeSymbol pointedAtType = null,
     bool isWithEvents = false,
     TypeKind typeKind = TypeKind.Unknown)
 {
     var symbol = CreateSymbolMock(kind, declaredAccessibility, isExtensionMethod, methodKind, containingType, isConst, elementType, target, pointedAtType, isWithEvents, typeKind);
     Assert.Equal(expectedGlyphGroup, symbol.GetGlyph().GetStandardGlyphGroup());
 }
コード例 #45
0
        static string GetSymbolTypeName(SymbolKind kind, string name)
        {
            var ns = GetSymbolNamespace(kind);

            return(typeof(SymbolProvider).GetAssembly().GetName().Name + "." + ns + "." + kind + name);
        }
コード例 #46
0
        private static void TestGetSpeculativeSemanticModelForTypeSyntax_Common(
            SemanticModel model,
            int position,
            TypeSyntax speculatedTypeSyntax,
            SpeculativeBindingOption bindingOption,
            SymbolKind expectedSymbolKind,
            string expectedTypeDislayString)
        {
            Assert.False(model.IsSpeculativeSemanticModel);
            Assert.Null(model.ParentModel);
            Assert.Equal(0, model.OriginalPositionForSpeculation);

            SemanticModel speculativeModel;
            var success = model.TryGetSpeculativeSemanticModel(position, speculatedTypeSyntax, out speculativeModel, bindingOption);
            Assert.True(success);
            Assert.NotNull(speculativeModel);

            Assert.True(speculativeModel.IsSpeculativeSemanticModel);
            Assert.Equal(model, speculativeModel.ParentModel);
            Assert.NotNull(speculativeModel);
            Assert.Equal(position, speculativeModel.OriginalPositionForSpeculation);

            var symbol = speculativeModel.GetSymbolInfo(speculatedTypeSyntax).Symbol;
            Assert.NotNull(symbol);
            Assert.Equal(expectedSymbolKind, symbol.Kind);
            Assert.Equal(expectedTypeDislayString, symbol.ToDisplayString());

            var typeSymbol = speculativeModel.GetTypeInfo(speculatedTypeSyntax).Type;
            Assert.NotNull(symbol);
            Assert.Equal(expectedSymbolKind, symbol.Kind);
            Assert.Equal(expectedTypeDislayString, symbol.ToDisplayString());

            if (speculatedTypeSyntax.Kind == SyntaxKind.QualifiedName)
            {
                var right = ((QualifiedNameSyntax)speculatedTypeSyntax).Right;

                symbol = speculativeModel.GetSymbolInfo(right).Symbol;
                Assert.NotNull(symbol);
                Assert.Equal(expectedSymbolKind, symbol.Kind);
                Assert.Equal(expectedTypeDislayString, symbol.ToDisplayString());

                typeSymbol = speculativeModel.GetTypeInfo(right).Type;
                Assert.NotNull(symbol);
                Assert.Equal(expectedSymbolKind, symbol.Kind);
                Assert.Equal(expectedTypeDislayString, symbol.ToDisplayString());
            }
        }
コード例 #47
0
        public static bool recordSymbolKind(int symbolId, SymbolKind symbolKind)
        {
            bool ret = sourcetraildbPINVOKE.recordSymbolKind(symbolId, (int)symbolKind);

            return(ret);
        }
コード例 #48
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="kind">Symbol kind</param>
 /// <param name="symbol">Symbol name</param>
 /// <param name="address">Address of symbol, usually the same as the address passed to <see cref="ISymbolResolver.Resolve(ulong[], SymbolResolverResult[])"/></param>
 public SymbolResolverResult(SymbolKind kind, string symbol, ulong address)
 {
     Kind    = kind;
     Symbol  = symbol ?? throw new ArgumentNullException(nameof(symbol));
     Address = address;
 }
コード例 #49
0
ファイル: ColorColorTests.cs プロジェクト: CAPCHIK/roslyn
        private void CheckExpressionAndParent(
            string text,
            SymbolKind exprSymbolKind,
            string exprDisplayString,
            SymbolKind parentSymbolKind,
            string parentDisplayString,
            params DiagnosticDescription[] expectedDiagnostics)
        {
            var tree = Parse(text);

            var comp = CreateCompilationWithMscorlib(tree, new[] { TestReferences.NetFx.v4_0_30319.System_Core });
            comp.VerifyDiagnostics(expectedDiagnostics);

            var model = comp.GetSemanticModel(tree);

            var expr = GetExprSyntaxForBinding(GetExprSyntaxList(tree));
            Assert.Equal(SyntaxKind.IdentifierName, expr.Kind());
            var info = model.GetSymbolInfo(expr);
            Assert.NotNull(info);
            Assert.Equal(exprSymbolKind, info.Symbol.Kind);
            Assert.Equal(exprDisplayString, info.Symbol.ToTestDisplayString());

            var parentExpr = (ExpressionSyntax)expr.Parent;
            Assert.Equal(SyntaxKind.SimpleMemberAccessExpression, parentExpr.Kind());
            var parentInfo = model.GetSymbolInfo(parentExpr);
            Assert.NotNull(parentInfo);
            Assert.Equal(parentSymbolKind, parentInfo.Symbol.Kind);
            Assert.Equal(parentDisplayString, parentInfo.Symbol.ToTestDisplayString());
        }
コード例 #50
0
 public MyCompletionsCategory(SymbolKind entityType)
 {
     DisplayText = GetVimKind(entityType);
 }
コード例 #51
0
        private static ISymbol CreateSymbolMock(
            SymbolKind kind,
            Accessibility declaredAccessibility = Accessibility.NotApplicable,
            bool isExtensionMethod = false,
            MethodKind methodKind = MethodKind.Ordinary,
            INamedTypeSymbol containingType = null,
            bool isConst = false,
            ITypeSymbol elementType = null,
            INamespaceOrTypeSymbol target = null,
            ITypeSymbol pointedAtType = null,
            bool isWithEvents = false,
            TypeKind typeKind = TypeKind.Unknown)
        {
            var symbolMock = new Mock<ISymbol>();

            symbolMock.SetupGet(s => s.Kind).Returns(kind);
            symbolMock.SetupGet(s => s.DeclaredAccessibility).Returns(declaredAccessibility);
            symbolMock.SetupGet(s => s.ContainingType).Returns(containingType);

            if (kind == SymbolKind.ArrayType)
            {
                var arrayTypeMock = symbolMock.As<IArrayTypeSymbol>();
                arrayTypeMock.SetupGet(s => s.ElementType).Returns(elementType);
            }

            if (kind == SymbolKind.Alias)
            {
                var aliasMock = symbolMock.As<IAliasSymbol>();
                aliasMock.SetupGet(s => s.Target).Returns(target);
            }

            if (kind == SymbolKind.Method)
            {
                var methodTypeMock = symbolMock.As<IMethodSymbol>();
                methodTypeMock.SetupGet(s => s.MethodKind).Returns(methodKind);
                methodTypeMock.SetupGet(s => s.IsExtensionMethod).Returns(isExtensionMethod);
            }

            if (kind == SymbolKind.NamedType)
            {
                var namedTypeMock = symbolMock.As<INamedTypeSymbol>();
                namedTypeMock.SetupGet(s => s.TypeKind).Returns(typeKind);
            }

            if (kind == SymbolKind.Field)
            {
                var fieldMock = symbolMock.As<IFieldSymbol>();
                fieldMock.SetupGet(s => s.IsConst).Returns(isConst);
            }

            if (kind == SymbolKind.PointerType)
            {
                var pointerTypeMock = symbolMock.As<IPointerTypeSymbol>();
                pointerTypeMock.SetupGet(s => s.PointedAtType).Returns(pointedAtType);
            }

            if (kind == SymbolKind.Property)
            {
                var propertyMock = symbolMock.As<IPropertySymbol>();
                propertyMock.SetupGet(s => s.IsWithEvents).Returns(isWithEvents);
            }

            return symbolMock.Object;
        }
コード例 #52
0
 public SymbolStartAnalyzerAction(Action <SymbolStartAnalysisContext> action, SymbolKind kind, DiagnosticAnalyzer analyzer)
     : base(analyzer)
 {
     Action = action;
     Kind   = kind;
 }
コード例 #53
0
        protected MemberContainer(TypeContainer parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, Modifiers def_mod, MemberName name, VSharpAttributes attrs, SymbolKind sym)
        {
            caching_flags   = Flags.Obsolete_Undetected;
            this.SymbolKind = sym;
            this.Parent     = parent;
            this.declaringTypeDefinition = parent;
            this.name = name.Name;
            if (parent != null)
            {
                this.UnresolvedFile = parent.UnresolvedFile;
            }
            this.type_expr = type;
            this.attribs   = attrs;
            member_name    = name;
            mod_flags      = mod;

            mod_flags = ModifiersExtensions.Check(allowed_mod, mod, def_mod, name.Location, Report);
            if (DeclaringTypeDefinition.Kind == TypeKind.Interface)
            {
                mod_flags |= Modifiers.PUBLIC | Modifiers.ABSTRACT;
            }


            if (attrs != null)
            {
                foreach (var a in attrs.Attrs)
                {
                    this.attributes.Add(a);
                }
            }

            this.returnType = type as ITypeReference;

            if (member_name.ExplicitInterface != null)
            {
                ApplyExplicit(null);
            }
        }
コード例 #54
0
 private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, SymbolKind unsupportedSymbolKind)
 {
     return(GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, unsupportedSymbolKind));
 }
コード例 #55
0
		static bool IsNonGenericMatch(IMember member, SymbolKind symbolKind, string name, IList<IType> parameterTypes)
		{
			if (member.SymbolKind != symbolKind)
				return false;
			if (member.Name != name)
				return false;
			IMethod method = member as IMethod;
			if (method != null && method.TypeParameters.Count > 0)
				return false;
			return IsParameterTypeMatch(member, parameterTypes);
		}
コード例 #56
0
        public static int ToSortOrder(this SymbolKind kind)
        {
            switch (kind)
            {
            case SymbolKind.Field:
                return(0);

            case SymbolKind.Method:
                return(1);

            case SymbolKind.Property:
                return(2);

            case SymbolKind.Event:
                return(3);

            case SymbolKind.NamedType:
                return(4);

            case SymbolKind.Namespace:
                return(5);

            case SymbolKind.Alias:
                return(6);

            case SymbolKind.ArrayType:
                return(7);

            case SymbolKind.Assembly:
                return(8);

#if false
            case SymbolKind.ErrorType:
                return(9);
#endif
            case SymbolKind.Label:
                return(10);

            case SymbolKind.Local:
                return(11);

            case SymbolKind.NetModule:
                return(12);

            case SymbolKind.Parameter:
                return(13);

            case SymbolKind.RangeVariable:
                return(14);

            case SymbolKind.TypeParameter:
                return(15);

            case SymbolKind.PointerType:
                return(16);

            case SymbolKind.DynamicType:
                return(17);

            case SymbolKind.Preprocessing:
                return(18);

            default:
                throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
コード例 #57
0
		public DefaultUnresolvedTypeParameter(SymbolKind ownerType, int index, string name = null)
		{
			this.ownerType = ownerType;
			this.index = index;
			this.name = name ?? ((ownerType == SymbolKind.Method ? "!!" : "!") + index.ToString(CultureInfo.InvariantCulture));
		}
コード例 #58
0
            private bool AreEquivalentWorker(ISymbol x, ISymbol y, SymbolKind k, Dictionary <INamedTypeSymbol, INamedTypeSymbol> equivalentTypesWithDifferingAssemblies)
            {
                Contract.Requires(x.Kind == y.Kind && x.Kind == k);
                switch (k)
                {
                case SymbolKind.ArrayType:
                    return(ArrayTypesAreEquivalent((IArrayTypeSymbol)x, (IArrayTypeSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Assembly:
                    return(AssembliesAreEquivalent((IAssemblySymbol)x, (IAssemblySymbol)y));

                case SymbolKind.DynamicType:
                    return(DynamicTypesAreEquivalent((IDynamicTypeSymbol)x, (IDynamicTypeSymbol)y));

                case SymbolKind.Event:
                    return(EventsAreEquivalent((IEventSymbol)x, (IEventSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Field:
                    return(FieldsAreEquivalent((IFieldSymbol)x, (IFieldSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Label:
                    return(LabelsAreEquivalent((ILabelSymbol)x, (ILabelSymbol)y));

                case SymbolKind.Local:
                    return(LocalsAreEquivalent((ILocalSymbol)x, (ILocalSymbol)y));

                case SymbolKind.Method:
                    return(MethodsAreEquivalent((IMethodSymbol)x, (IMethodSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.NetModule:
                    return(ModulesAreEquivalent((IModuleSymbol)x, (IModuleSymbol)y));

                case SymbolKind.NamedType:
                case SymbolKind.ErrorType:     // ErrorType is handled in NamedTypesAreEquivalent
                    return(NamedTypesAreEquivalent((INamedTypeSymbol)x, (INamedTypeSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Namespace:
                    return(NamespacesAreEquivalent((INamespaceSymbol)x, (INamespaceSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Parameter:
                    return(ParametersAreEquivalent((IParameterSymbol)x, (IParameterSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.PointerType:
                    return(PointerTypesAreEquivalent((IPointerTypeSymbol)x, (IPointerTypeSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Property:
                    return(PropertiesAreEquivalent((IPropertySymbol)x, (IPropertySymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.RangeVariable:
                    return(RangeVariablesAreEquivalent((IRangeVariableSymbol)x, (IRangeVariableSymbol)y));

                case SymbolKind.TypeParameter:
                    return(TypeParametersAreEquivalent((ITypeParameterSymbol)x, (ITypeParameterSymbol)y, equivalentTypesWithDifferingAssemblies));

                case SymbolKind.Preprocessing:
                    return(PreprocessingSymbolsAreEquivalent((IPreprocessingSymbol)x, (IPreprocessingSymbol)y));

                default:
                    return(false);
                }
            }
コード例 #59
0
        protected LocalVariableSymbol(SymbolKind kind, string name, string documentation, Symbol parent, TypeSymbol valueType)
            : base(kind, name, documentation, parent, valueType)
        {

        }
コード例 #60
0
 static string GetSymbolTypeName(SymbolKind kind, string name)
 {
     return("Mono.Cecil" + "." + GetSymbolNamespace(kind) + "." + kind + name);
 }