Example #1
0
        /// <summary>
        /// Extracts a variable from the clause.
        /// </summary>
        /// <param name="firstToken">The first token of the variable.</param>
        /// <param name="allowTypelessVariable">Indicates whether to allow a variable with no type defined.</param>
        /// <param name="onlyTypelessVariable">Indicates whether to only get a typeless variable.</param>
        /// <returns>Returns the variable.</returns>
        protected static QueryClauseVariable ExtractQueryVariable(Token firstToken, bool allowTypelessVariable, bool onlyTypelessVariable)
        {
            Param.RequireNotNull(firstToken, "firstToken");
            Param.Ignore(allowTypelessVariable);
            Param.Ignore(onlyTypelessVariable);

            if (onlyTypelessVariable || !firstToken.Is(TokenType.Type))
            {
                // In this case there is no type, only an identifier.
                return(new QueryClauseVariable(null, firstToken.Text, firstToken.Location, firstToken.Generated));
            }
            else
            {
                TypeToken type = (TypeToken)firstToken;

                // Attempt to get the identifier token coming after the type token.
                Token identifier = firstToken.FindNextSiblingToken();
                if (identifier == null || identifier.TokenType != TokenType.Literal)
                {
                    CsLanguageService.Debug.Assert(allowTypelessVariable, "The clause does not allow typeless variables. The parser should have thrown syntax exception already.");
                    return(new QueryClauseVariable(null, type.Text, type.Location, type.Generated));
                }
                else
                {
                    // There is a type and an identifier.
                    return(new QueryClauseVariable(type, identifier.Text, CodeUnit.JoinLocations(type, identifier), type.Generated || identifier.Generated));
                }
            }
        }
Example #2
0
            /// <summary>
            /// Initializes a new instance of the QueryClauseVariable class.
            /// </summary>
            /// <param name="type">The type of the variable.</param>
            /// <param name="name">The name of the variable.</param>
            /// <param name="location">The location of the variable.</param>
            /// <param name="generated">Indicates whethre the variable is located within a block of generated code.</param>
            internal QueryClauseVariable(TypeToken type, string name, CodeLocation location, bool generated)
            {
                Param.Ignore(type);
                Param.RequireValidString(name, "name");
                Param.RequireNotNull(location, "location");
                Param.Ignore(generated);

                this.type      = type;
                this.name      = name;
                this.location  = location;
                this.generated = generated;
            }
Example #3
0
        /// <summary>
        /// Gets the name of the element.
        /// </summary>
        /// <returns>The name of the element.</returns>
        protected override string GetElementName()
        {
            // Get the return type.
            TypeToken r = this.FindFirstChild <TypeToken>();

            if (r != null)
            {
                // The next Token is the name.
                Token nameToken = r.FindNextSiblingToken();
                if (nameToken != null)
                {
                    return(nameToken.Text);
                }
            }

            throw new SyntaxException(this.Document, this.LineNumber);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the Indexer class.
        /// </summary>
        /// <param name="proxy">Proxy object for the indexer.</param>
        /// <param name="name">The name of the indexer.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="returnType">The return type of the indexer.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        internal Indexer(CodeUnitProxy proxy, string name, ICollection<Attribute> attributes, TypeToken returnType, bool unsafeCode)
            : base(proxy, ElementType.Indexer, name, attributes, unsafeCode)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertValidString(name, "name");
            Param.Ignore(attributes);
            Param.AssertNotNull(returnType, "returnType");
            Param.Ignore(unsafeCode);

            this.returnType.Value = returnType;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the Field class.
        /// </summary>
        /// <param name="proxy">Proxy object for the field.</param>
        /// <param name="name">The name of the field.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="fieldType">The type of the field.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        internal Field(CodeUnitProxy proxy, string name, ICollection <Attribute> attributes, TypeToken fieldType, bool unsafeCode)
            : base(proxy, ElementType.Field, name, attributes, unsafeCode)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertValidString(name, "name");
            Param.Ignore(attributes);
            Param.AssertNotNull(fieldType, "fieldType");
            Param.Ignore(unsafeCode);

            this.fieldType.Value = fieldType;
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the Event class.
        /// </summary>
        /// <param name="proxy">Proxy object for the event.</param>
        /// <param name="name">The name of the event.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="eventHandlerType">The type of the event handler.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        internal Event(CodeUnitProxy proxy, string name, ICollection <Attribute> attributes, TypeToken eventHandlerType, bool unsafeCode)
            : base(proxy, ElementType.Event, name, attributes, unsafeCode)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertValidString(name, "name");
            Param.Ignore(attributes);
            Param.AssertNotNull(eventHandlerType, "eventHandlerType");
            Param.Ignore(unsafeCode);

            this.eventHandlerType.Value = eventHandlerType;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the Delegate class.
        /// </summary>
        /// <param name="proxy">Proxy object for the delegate.</param>
        /// <param name="name">The name of the delegate.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="returnType">The return type.</param>
        /// <param name="typeConstraints">The list of type constraints on the element.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        internal Delegate(CodeUnitProxy proxy, string name, ICollection <Attribute> attributes, TypeToken returnType, ICollection <TypeParameterConstraintClause> typeConstraints, bool unsafeCode)
            : base(proxy, ElementType.Delegate, name, attributes, unsafeCode)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertValidString(name, "name");
            Param.Ignore(attributes);
            Param.AssertNotNull(returnType, "returnType");
            Param.Ignore(typeConstraints);
            Param.Ignore(unsafeCode);

            this.returnType.Value = returnType;

            this.typeConstraints.Value = typeConstraints ?? TypeParameterConstraintClause.EmptyTypeParameterConstraintClause;
            CsLanguageService.Debug.Assert(typeConstraints == null || typeConstraints.IsReadOnly, "Must be a read-only collection.");
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the Method class.
        /// </summary>
        /// <param name="proxy">Proxy object for the method.</param>
        /// <param name="name">The name of the method.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="returnType">The method's return type.</param>
        /// <param name="typeConstraints">The list of type constraints on the element.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        internal Method(CodeUnitProxy proxy, string name, ICollection <Attribute> attributes, TypeToken returnType, ICollection <TypeParameterConstraintClause> typeConstraints, bool unsafeCode)
            : base(proxy, ElementType.Method, name, attributes, unsafeCode)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertValidString(name, "name");
            Param.Ignore(attributes);
            Param.Ignore(returnType);
            Param.Ignore(typeConstraints);
            Param.Ignore(unsafeCode);

            CsLanguageService.Debug.Assert(
                returnType != null || this.ContainsModifier(TokenType.Explicit, TokenType.Implicit),
                "A method's return type can only be null in an explicit or implicit operator overload method.");

            this.returnType.Value = returnType;

            this.typeConstraints.Value = typeConstraints ?? TypeParameterConstraintClause.EmptyTypeParameterConstraintClause;
            CsLanguageService.Debug.Assert(typeConstraints == null || typeConstraints.IsReadOnly, "Must be a read-only collection.");
        }