~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConstructorInfo.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using ICSharpCode.NRefactory.Ast;
 
7
 
 
8
namespace ICSharpCode.PythonBinding
 
9
{
 
10
        public class PythonConstructorInfo
 
11
        {
 
12
                ConstructorDeclaration constructor;
 
13
                List<FieldDeclaration> fields = new List<FieldDeclaration>();
 
14
                
 
15
                PythonConstructorInfo(ConstructorDeclaration constructor, List<FieldDeclaration> fields)
 
16
                {
 
17
                        this.constructor = constructor;
 
18
                        this.fields = fields;
 
19
                }
 
20
                
 
21
                /// <summary>
 
22
                /// Gets the constructor information from a type declaration. Returns null if there is no 
 
23
                /// constructor defined or if there are no fields defined.
 
24
                /// </summary>
 
25
                public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type)
 
26
                {
 
27
                        List<FieldDeclaration> fields = new List<FieldDeclaration>();
 
28
                        ConstructorDeclaration constructor = null;
 
29
                        foreach (INode node in type.Children) {
 
30
                                ConstructorDeclaration currentConstructor = node as ConstructorDeclaration;
 
31
                                FieldDeclaration field = node as FieldDeclaration;
 
32
                                if (currentConstructor != null) {
 
33
                                        constructor = currentConstructor;
 
34
                                } else if (field != null) {
 
35
                                        fields.Add(field);
 
36
                                }
 
37
                        }
 
38
                        
 
39
                        if ((fields.Count > 0) || (constructor != null)) {
 
40
                                return new PythonConstructorInfo(constructor, fields);
 
41
                        }
 
42
                        return null;
 
43
                }
 
44
                
 
45
                public ConstructorDeclaration Constructor {
 
46
                        get { return constructor; }
 
47
                }
 
48
                
 
49
                public List<FieldDeclaration> Fields {
 
50
                        get { return fields; }
 
51
                }
 
52
        }
 
53
}