コード例 #1
0
        /// <summary>
        /// Finds a token according to the following rules:
        /// 1) If position matches the End of the node/s FullSpan and the node is CompilationUnit,
        ///    then EoF is returned.
        ///
        ///  2) If node.FullSpan.Contains(position) then the token that contains given position is
        ///     returned.
        ///
        ///  3) Otherwise an ArgumentOutOfRangeException is thrown
        /// </summary>
        internal SyntaxToken FindTokenIncludingCrefAndNameAttributes(int position)
        {
            SyntaxToken nonTriviaToken = this.FindToken(position, findInsideTrivia: false);

            SyntaxTrivia trivia = GetTriviaFromSyntaxToken(position, nonTriviaToken);

            if (!SyntaxKindFacts.IsDocumentationCommentTrivia(trivia.CSharpKind()))
            {
                return(nonTriviaToken);
            }

            Debug.Assert(trivia.HasStructure);
            SyntaxToken triviaToken = ((CSharpSyntaxNode)trivia.GetStructure()).FindTokenInternal(position);

            // CONSIDER: We might want to use the trivia token anywhere within a doc comment.
            // Otherwise, we'll fall back on the enclosing scope outside of name and cref
            // _annotation values.
            CSharpSyntaxNode curr = (CSharpSyntaxNode)triviaToken.Parent;

            while (curr != null)
            {
                // Don't return a trivia token unless we're in the scope of a cref or name _annotation.
                if (curr.Kind == SyntaxKind.XmlCrefAttribute || curr.Kind == SyntaxKind.XmlNameAttribute)
                {
                    return(LookupPosition.IsInXmlAttributeValue(position, (XmlAttributeSyntax)curr)
                                                ? triviaToken
                                                : nonTriviaToken);
                }

                curr = curr.Parent;
            }

            return(nonTriviaToken);
        }
コード例 #2
0
        //private bool TryAddAlias(
        //	INamespaceOrTypeSymbol symbol,
        //	ArrayBuilder<SymbolDisplayPart> builder)
        //{
        //	var alias = GetAliasSymbol(symbol);
        //	if (alias != null)
        //	{
        //		// We must verify that the alias actually binds back to the thing it's aliasing.
        //		// It's possible there's another symbol with the same name as the alias that binds
        //		// first
        //		var aliasName = alias.Name;

        //		var boundSymbols = semanticModelOpt.LookupNamespacesAndTypes(positionOpt, name: aliasName);

        //		if (boundSymbols.Length == 1)
        //		{
        //			var boundAlias = boundSymbols[0] as AliasSymbol;
        //			if ((object)boundAlias != null && alias.Target.Equals(symbol))
        //			{
        //				builder.Add(CreatePart(SymbolDisplayPartKind.AliasName, alias, aliasName));
        //				return true;
        //			}
        //		}
        //	}

        //	return false;
        //}

        protected override bool ShouldRestrictMinimallyQualifyLookupToNamespacesAndTypes()
        {
            var token     = semanticModelOpt.SyntaxTree.GetRoot().FindToken(positionOpt);
            var startNode = token.Parent;

            return(SyntaxKindFacts.IsInNamespaceOrTypeContext(startNode as ExpressionSyntax));
        }
コード例 #3
0
        public CSharpParseOptions(
            LanguageVersion languageVersion     = LanguageVersion.CSharp6,
            DocumentationMode documentationMode = DocumentationMode.Parse,
            SourceCodeKind kind = SourceCodeKind.Regular,
            ImmutableArray <string> preprocessorSymbols = default(ImmutableArray <string>))
            : this(languageVersion, documentationMode, kind, preprocessorSymbols.NullToEmpty(), privateCtor : true)
        {
            if (!languageVersion.IsValid())
            {
                throw new ArgumentOutOfRangeException("languageVersion");
            }

            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException("kind");
            }

            if (!preprocessorSymbols.IsDefaultOrEmpty)
            {
                foreach (var preprocessorSymbol in preprocessorSymbols)
                {
                    if (!SyntaxKindFacts.IsValidIdentifier(preprocessorSymbol))
                    {
                        throw new ArgumentException("preprocessorSymbols");
                    }
                }
            }
        }
コード例 #4
0
        internal static bool IsTypeInContextWhichNeedsDynamicAttribute(this IdentifierNameSyntax typeNode)
        {
            Debug.Assert(typeNode != null);
            Debug.Assert(SyntaxKindFacts.IsInTypeOnlyContext(typeNode));

            return(IsInContextWhichNeedsDynamicAttribute(typeNode));
        }
コード例 #5
0
        private static string EscapeIdentifier(string identifier)
        {
            var kind = SyntaxKindFacts.GetKeywordKind(identifier);

            return(kind == SyntaxKind.None
                                ? identifier
                                : string.Format("@{0}", identifier));
        }
コード例 #6
0
        public static string GetText(Accessibility accessibility)
        {
            switch (accessibility)
            {
            case Accessibility.NotApplicable:
                return(string.Empty);

            case Accessibility.Private:
                return(SyntaxKindFacts.GetText(SyntaxKind.PrivateKeyword));

            case Accessibility.Protected:
                return(SyntaxKindFacts.GetText(SyntaxKind.ProtectedKeyword));

            case Accessibility.Public:
                return(SyntaxKindFacts.GetText(SyntaxKind.PublicKeyword));

            default:
                System.Diagnostics.Debug.Assert(false, string.Format("Unknown accessibility '{0}'", accessibility));
                return(null);
            }
        }
コード例 #7
0
 private void AddKeyword(SyntaxKind keywordKind)
 {
     builder.Add(CreatePart(SymbolDisplayPartKind.Keyword, null, SyntaxKindFacts.GetText(keywordKind)));
 }
コード例 #8
0
 private void AddPunctuation(SyntaxKind punctuationKind)
 {
     builder.Add(CreatePart(SymbolDisplayPartKind.Punctuation, null, SyntaxKindFacts.GetText(punctuationKind)));
 }
コード例 #9
0
        //public static bool IsContextualKeyword(this SyntaxToken token)
        //{
        //	return SyntaxKindFacts.IsContextualKeyword(token.CSharpKind());
        //}

        public static bool IsReservedKeyword(this SyntaxToken token)
        {
            return(SyntaxKindFacts.IsReservedKeyword(token.CSharpKind()));
        }