Exemple #1
0
        public SyntaxTokenCollection Format(IndexorSyntax syntax)
        {
            SyntaxTokenCollection tokens = new SyntaxTokenCollection();

            tokens.AddRange(FormatVisibility(syntax));
            tokens.Add(Constants.Space);
            tokens.Add(new SyntaxToken("Property", SyntaxTokens.Keyword));
            tokens.Add(Constants.Space);
            tokens.Add(FormatIdentifier(syntax));
            tokens.Add(Constants.Space);
            tokens.Add(Constants.KeywordAs);
            tokens.Add(Constants.Space);
            tokens.AddRange(FormatType(syntax));
            return(tokens);
        }
Exemple #2
0
        /// <summary>
        /// Formats the indexer based on the language specification as a
        /// collection of syntax tokens.
        /// </summary>
        /// <param name="syntax">The syntax class that describes the indexer.</param>
        /// <returns>The collection of tokens describing the indexer in the language</returns>
        public SyntaxTokenCollection Format(IndexorSyntax syntax)
        {
            SyntaxTokenCollection tokens = new SyntaxTokenCollection();

            tokens.AddRange(FormatVisibility(syntax));
            tokens.Add(Constants.Space);
            tokens.AddRange(FormatType(syntax));
            tokens.Add(Constants.Space);
            tokens.Add(FormatIdentifier(syntax));

            // Provide the properties to access the indexer, these are
            // obtained from the get method.
            MethodSyntax getMethod = new MethodSyntax(
                _syntax.GetMethod != null ? _syntax.GetMethod : _syntax.SetMethod
                );

            tokens.Add(new SyntaxToken("[", SyntaxTokens.Text));
            List <ParameterDetails> parameters = getMethod.GetParameters();

            // dont output the last parameter if we are not using the get method as it is the return value...
            for (int i = 0; i < parameters.Count; i++)
            {
                ParameterDetails current = parameters[i];

                tokens.AddRange(FormatTypeDetails(current.TypeDetails));
                tokens.Add(Constants.Space);
                tokens.Add(new SyntaxToken(current.Name, SyntaxTokens.Text));

                if (i < parameters.Count - 1)
                {
                    tokens.Add(new SyntaxToken(", ", SyntaxTokens.Text));
                }
            }
            tokens.Add(new SyntaxToken("]", SyntaxTokens.Text));

            tokens.Add(new SyntaxToken(" {", SyntaxTokens.Text));
            if (_syntax.GetMethod != null)
            {
                tokens.Add(new SyntaxToken("\n\t", SyntaxTokens.Text));
                if (syntax.GetVisibility() != syntax.GetGetterVisibility())
                {
                    tokens.AddRange(FormatGetVisibility(syntax));
                    tokens.Add(Constants.Space);
                }
                tokens.Add(Constants.KeywordGet);
                tokens.Add(new SyntaxToken(";", SyntaxTokens.Text));
            }
            if (this._syntax.SetMethod != null)
            {
                tokens.Add(new SyntaxToken("\n\t", SyntaxTokens.Text));
                if (syntax.GetVisibility() != syntax.GetSetterVisibility())
                {
                    tokens.AddRange(FormatSetVisibility(syntax));
                    tokens.Add(Constants.Space);
                }
                tokens.Add(Constants.KeywordSet);
                tokens.Add(new SyntaxToken(";", SyntaxTokens.Text));
            }
            tokens.Add(new SyntaxToken("\n\t}", SyntaxTokens.Text));
            return(tokens);
        }
Exemple #3
0
 public List <SyntaxToken> FormatSetVisibility(IndexorSyntax syntax)
 {
     return(FormatVisibility(syntax.GetSetterVisibility()));
 }
Exemple #4
0
 public SyntaxToken FormatInheritance(IndexorSyntax syntax)
 {
     return(FormatInheritance(syntax.GetInheritance()));
 }
Exemple #5
0
 public List <SyntaxToken> FormatType(IndexorSyntax syntax)
 {
     return(FormatTypeDetails(syntax.GetType()));
 }
Exemple #6
0
 public SyntaxToken FormatIdentifier(IndexorSyntax syntax)
 {
     return(Constants.KeywordThis);
 }
Exemple #7
0
 /// <summary>
 /// Initialises a new instance of the CSharpIndexorFormatter.
 /// </summary>
 /// <param name="syntax">The syntax containing the information about the member.</param>
 public CSharpIndexerFormatter(IndexorSyntax syntax)
 {
     _syntax = syntax;
 }
Exemple #8
0
 public SyntaxToken FormatIdentifier(IndexorSyntax syntax)
 {
     return(new SyntaxToken(syntax.GetIdentifier(), SyntaxTokens.Text));
 }
Exemple #9
0
 public VBIndexorFormatter(IndexorSyntax syntax)
 {
     _syntax = syntax;
 }