Esempio n. 1
0
            bool TryAddPrivateSetter(out SyntaxNode newRoot)
            {
                if (TypeDecl.IsKind(SyntaxKind.ClassDeclaration) &&
                    PropertySymbol.DeclaredAccessibility != Accessibility.Private &&
                    !PropertySymbol.IsOverride &&
                    PropertySymbol.GetMethod != null &&
                    PropertySymbol.SetMethod == null &&
                    PropertyDecl.Initializer == null &&
                    IsAuto(PropertyDecl, PropertySymbol)
                    )
                {
                    var accessor =
                        SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                        .WithModifiers(
                            SyntaxFactory.TokenList(
                                SyntaxFactory.Token(SyntaxKind.PrivateKeyword)
                                ))
                        .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
                    newRoot =
                        Root.ReplaceNode(
                            PropertyDecl,
                            PropertyDecl
                            .AddAccessorListAccessors(accessor)
                            );
                    return(true);
                }

                newRoot = default(SyntaxNode);
                return(false);
            }
        public PropertyMetadaDefinition(PropertyDecl propertyCodeDOM)
        {
            this.Name               = propertyCodeDOM.Name;
            this.ReferenceName      = string.Empty;
            this.DataBaseColumnName = (Name.Length > 30) ? Name.Substring(0, 30).ToUpper() : Name.ToUpper();
            this.IsReferenceType    = propertyCodeDOM.Name.ToUpper().StartsWith(START_FK_ID);
            this.Enable             = IsReferenceType ? Visibility.Visible : Visibility.Collapsed;
            this.IndexName          = (IsReferenceType) ? Name.ToUpper() : String.Empty;
            this.HasFk              = (IsReferenceType);

            this.Type = TypeFactory.Create(propertyCodeDOM.Type, IsReferenceType);
        }
Esempio n. 3
0
            bool TryExpandExpressionBody(out SyntaxNode newRoot)
            {
                var expression = PropertyDecl.ExpressionBody?.Expression;

                if (expression != null)
                {
                    var isMultiline = IsMultiline(expression);
                    var indent      =
                        expression
                        .GetLeadingTrivia()
                        .TakeLast1()
                        .Where(t => t.IsKind(SyntaxKind.WhitespaceTrivia))
                        .Select(t => t.ToString())
                        .Intercalate("")
                        .RemoveSuffix("    ");

                    var returnStatement =
                        SyntaxFactory.ReturnStatement(
                            SyntaxFactory.Token(SyntaxKind.ReturnKeyword)
                            .WithLeadingTrivia(
                                SyntaxFactory.TriviaList(
                                    SyntaxFactory.EndOfLine(Environment.NewLine),
                                    SyntaxFactory.Whitespace(indent)
                                    ))
                            .WithTrailingTrivia(
                                isMultiline ? EndOfLineTriviaList() : WhitespaceTriviaList()
                                ),
                            expression,
                            SyntaxFactory.Token(SyntaxKind.SemicolonToken)
                            );
                    var accessorList =
                        SyntaxFactory.AccessorList(
                            SyntaxFactory.List <AccessorDeclarationSyntax>().Add(
                                SyntaxFactory.AccessorDeclaration(
                                    SyntaxKind.GetAccessorDeclaration,
                                    SyntaxFactory.Block(returnStatement)
                                    )));
                    newRoot =
                        Root.ReplaceNode(
                            PropertyDecl,
                            PropertyDecl
                            .WithExpressionBody(null)
                            .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.None))
                            .WithAccessorList(accessorList)
                            .WithAdditionalAnnotations(Formatter.Annotation)
                            );
                    return(true);
                }

                newRoot = default(SyntaxNode);
                return(false);
            }
Esempio n. 4
0
File: AST.cs Progetto: chenzuo/blue
    // For non-interface types
    public ClassDecl(
        Identifier idName,         
        TypeSig [] arSuper, // super class & implemented interfaces
        MethodDecl [] alMethods,
        PropertyDecl[] alProperties,
        FieldDecl[] alFields,
        EventDecl [] alEvents,
        TypeDeclBase[] alNestedTypes,
        Modifiers mods,
        bool fIsClass // true for class, false for struct
    ) 
    {        
        Debug.Assert(idName != null);
        Debug.Assert(alMethods != null);
        Debug.Assert(alFields != null);
        Debug.Assert(alProperties != null);
        Debug.Assert(alEvents != null);


        m_strName = idName.Text;
        
        m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper;

        m_alNestedTypes     = (alNestedTypes == null) ?  m_sEmptyTypeList : alNestedTypes;
        m_alMethods         = alMethods;
        m_alProperties      = alProperties;
        m_alFields          = alFields;
        m_alEvents          = alEvents;
        
        // @todo - this is wrong
        m_filerange = idName.Location;

        if (!fIsClass) // structs are implicitly sealed.           
            mods.SetSealed();
            
        m_mods = mods;          
                    
        m_genre = fIsClass ? TypeEntry.Genre.cClass : TypeEntry.Genre.cStruct;
    }
Esempio n. 5
0
File: AST.cs Progetto: chenzuo/blue
    // For interface types
    public ClassDecl(
        Identifier idName,         
        TypeSig [] arSuper, // super class & implemented interfaces
        MethodDecl [] alMethods,
        PropertyDecl[] alProperties,
        Modifiers mods    
    ) 
    {        
        Debug.Assert(idName != null);
        Debug.Assert(alMethods != null);
        

        m_strName = idName.Text;
        
        m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper;

        m_alMethods = alMethods;
        m_alProperties = alProperties;
        m_alNestedTypes = m_sEmptyTypeList;
        
        // @todo - this is wrong
        m_filerange = idName.Location;

        //m_mods.FlagSetter = mods.Flags | Modifiers.EFlags.Abstract;
        m_mods = mods;
        m_mods.SetAbstract();
       
        m_genre = TypeEntry.Genre.cInterface;
    }
Esempio n. 6
0
//-----------------------------------------------------------------------------
// Partial parse a property decl.
// We've already parsed the modifiers, return type & member name, so
// pass those in as parameters. Start parsing at '{'
// Note that indexers are just properties that take parameters.
//
// ** rules **
// PropertyDecl -> mods type id '{' property_body '}'
//-----------------------------------------------------------------------------
    protected PropertyDecl PartialParsePropertyDecl(
        Modifiers mods, 
        TypeSig typeReturn, 
        Identifier stMemberName
    )
    {   
        // Note that properties can be abstract, in which case their bodyStmt is null.
        // Also note that both get & set have the same modifiers        
                
        FileRange f = this.BeginRange();
                        
        BlockStatement stmtGet;
        BlockStatement stmtSet;
                        
        bool fHasGet;
        bool fHasSet;
                        
        ParseAccessors(mods.IsAbstract, stMemberName,
            out stmtGet, out fHasGet,
            out stmtSet, out fHasSet);
                
        PropertyDecl p = new PropertyDecl(
            stMemberName, typeReturn, 
            stmtGet, fHasGet, 
            stmtSet, fHasSet, 
            mods); 
        
        p.SetLocation(this.EndRange(f));
        return p;
    }
Esempio n. 7
0
//-----------------------------------------------------------------------------
// Partial parse an Indexer decl
//
// ** rules **
// IndexerDecl  -> mods type 'this' '[' param_list ']' '{' property_body '}'
//-----------------------------------------------------------------------------
    protected PropertyDecl PartialParseIndexerDecl(
        Modifiers mods, 
        TypeSig typeReturn, 
        Identifier stMemberName
    )
    {
        Debug.Assert(stMemberName.Text == "this");
        
        // @todo - Change name to 'Item'
        
        FileRange f = this.BeginRange();
        ReadExpectedToken(Token.Type.cLSquare);
        // @todo  - For now, we only support one parameter
        NonRefTypeSig t = this.ParseTypeSig();
        Identifier idParam = this.ReadExpectedIdentifier();   
             
        ReadExpectedToken(Token.Type.cRSquare);
                
        BlockStatement stmtGet;
        BlockStatement stmtSet;
                        
        bool fHasGet;
        bool fHasSet;
                        
        ParseAccessors(mods.IsAbstract, stMemberName,
            out stmtGet, out fHasGet,
            out stmtSet, out fHasSet);
        
        PropertyDecl p = new PropertyDecl(
            stMemberName, typeReturn,
            new ParamVarDecl(idParam, t, EArgFlow.cIn), 
            stmtGet, fHasGet, 
            stmtSet, fHasSet, 
            mods);
          
        p.SetLocation(this.EndRange(f));            
        return p;            
    }
Esempio n. 8
0
 protected PropertyDecl [] PropertyDeclFromArray(ArrayList alProperties)
 {
     PropertyDecl [] v = new PropertyDecl[alProperties.Count];
     for(int i = 0; i < alProperties.Count; i++)
         v[i] = (PropertyDecl) alProperties[i];
         
     return v;
 }
Esempio n. 9
0
            bool TryAddBackingField(out SyntaxNode newRoot)
            {
                if (IsAuto(PropertyDecl, PropertySymbol))
                {
                    var typeDecl = PropertyDecl.Parent as TypeDeclarationSyntax;
                    if (typeDecl != null)
                    {
                        var propertyDeclIndex = typeDecl.Members.IndexOf(PropertyDecl);
                        if (propertyDeclIndex >= 0)
                        {
                            var fieldIdentifier = FieldIdentifierFromPropertyName(PropertySymbol.Name);

                            var varDecl = SyntaxFactory.VariableDeclarator(fieldIdentifier);
                            if (PropertyDecl.Initializer != null)
                            {
                                varDecl = varDecl.WithInitializer(PropertyDecl.Initializer);
                            }

                            var fieldDecl =
                                SyntaxFactory.FieldDeclaration(
                                    SyntaxFactory.VariableDeclaration(
                                        PropertyDecl.Type,
                                        SyntaxFactory.SingletonSeparatedList(varDecl)
                                        ));
                            if (PropertySymbol.SetMethod == null)
                            {
                                fieldDecl =
                                    fieldDecl.WithModifiers(
                                        SyntaxFactory.TokenList(
                                            SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)
                                            ));
                            }

                            var getter =
                                SyntaxFactory.AccessorDeclaration(
                                    SyntaxKind.GetAccessorDeclaration,
                                    SyntaxFactory.Block(
                                        SyntaxFactory.ReturnStatement(
                                            SyntaxFactory.Token(SyntaxKind.ReturnKeyword),
                                            SyntaxFactory.IdentifierName(fieldIdentifier),
                                            SyntaxFactory.Token(SyntaxKind.SemicolonToken)
                                            )));
                            var accessors = new List <AccessorDeclarationSyntax>()
                            {
                                getter
                            };

                            if (PropertySymbol.SetMethod != null)
                            {
                                var setter =
                                    SyntaxFactory.AccessorDeclaration(
                                        SyntaxKind.SetAccessorDeclaration,
                                        SyntaxFactory.Block(
                                            SyntaxFactory.ExpressionStatement(
                                                SyntaxFactory.AssignmentExpression(
                                                    SyntaxKind.SimpleAssignmentExpression,
                                                    SyntaxFactory.IdentifierName(fieldIdentifier),
                                                    SyntaxFactory.IdentifierName("value")
                                                    ),
                                                SyntaxFactory.Token(SyntaxKind.SemicolonToken)
                                                )));
                                accessors.Add(setter);
                            }
                            var accessorList =
                                SyntaxFactory.AccessorList(SyntaxFactory.List(accessors));

                            var members =
                                typeDecl.Members
                                .Replace(
                                    PropertyDecl,
                                    PropertyDecl
                                    .WithInitializer(null)
                                    .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.None))
                                    .WithAccessorList(accessorList)
                                    .WithAdditionalAnnotations(Formatter.Annotation)
                                    )
                                .Insert(
                                    propertyDeclIndex,
                                    fieldDecl
                                    .WithAdditionalAnnotations(Formatter.Annotation)
                                    );

                            newRoot =
                                Root.ReplaceNode(
                                    typeDecl,
                                    typeDecl.WithMembers(members)
                                    );
                            return(true);
                        }
                    }
                }

                newRoot = default(SyntaxNode);
                return(false);
            }