~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Core/src/NRefactory/NRefactoryASTGenerator/Attributes.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
 
5
//     <version>$Revision: 979 $</version>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.CodeDom;
 
10
 
 
11
namespace NRefactoryASTGenerator
 
12
{
 
13
        public enum NullableImplementation
 
14
        {
 
15
                /// <summary>
 
16
                /// Implement INullable with a virtual bool IsNull, create Null class and static instance
 
17
                /// of it.
 
18
                /// </summary>
 
19
                Default,
 
20
                /// <summary>
 
21
                /// Create Null class and a static instance using the "new" modifier.
 
22
                /// </summary>
 
23
                Shadow,
 
24
                /// <summary>
 
25
                /// Implement INullable with a virtual bool IsNull.
 
26
                /// </summary>
 
27
                Abstract,
 
28
                /// <summary>
 
29
                /// Complete an abstract nullable implementation by creating the Null class
 
30
                /// and the static instance.
 
31
                /// </summary>
 
32
                CompleteAbstract
 
33
        }
 
34
        
 
35
        public abstract class TypeImplementationModifierAttribute : Attribute
 
36
        {
 
37
                public abstract void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type);
 
38
        }
 
39
        
 
40
        [AttributeUsage(AttributeTargets.Class)]
 
41
        public class CustomImplementationAttribute : Attribute
 
42
        {
 
43
        }
 
44
        
 
45
        [AttributeUsage(AttributeTargets.Class)]
 
46
        public class HasChildrenAttribute : Attribute
 
47
        {
 
48
        }
 
49
        
 
50
        [AttributeUsage(AttributeTargets.Field)]
 
51
        public class QuestionMarkDefaultAttribute : Attribute
 
52
        {
 
53
        }
 
54
        
 
55
        [AttributeUsage(AttributeTargets.Class)]
 
56
        public class FixOperatorDeclarationAttribute : TypeImplementationModifierAttribute
 
57
        {
 
58
                public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type)
 
59
                {
 
60
                        foreach (object o in ctd.Members) {
 
61
                                CodeConstructor cc = o as CodeConstructor;
 
62
                                if (cc != null) {
 
63
                                        cc.BaseConstructorArgs[0] = new CodePrimitiveExpression(null);
 
64
                                }
 
65
                        }
 
66
                }
 
67
        }
 
68
        
 
69
        [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
 
70
        public class IncludeMemberAttribute : TypeImplementationModifierAttribute
 
71
        {
 
72
                string code;
 
73
                
 
74
                public IncludeMemberAttribute(string code)
 
75
                {
 
76
                        this.code = code;
 
77
                }
 
78
                
 
79
                public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type)
 
80
                {
 
81
                        ctd.Members.Add(new CodeSnippetTypeMember(code));
 
82
                }
 
83
        }
 
84
        
 
85
        [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
 
86
        public class IncludeBoolPropertyAttribute : TypeImplementationModifierAttribute
 
87
        {
 
88
                string name;
 
89
                string code;
 
90
                
 
91
                public IncludeBoolPropertyAttribute(string name, string code)
 
92
                {
 
93
                        this.name = name;
 
94
                        this.code = code;
 
95
                }
 
96
                
 
97
                public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type)
 
98
                {
 
99
                        CodeMemberProperty prop = new CodeMemberProperty();
 
100
                        prop.Name = name;
 
101
                        prop.Type = new CodeTypeReference(typeof(bool));
 
102
                        prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
 
103
                        prop.GetStatements.Add(new CodeSnippetStatement("\t\t\t\t" + code));
 
104
                        ctd.Members.Add(prop);
 
105
                }
 
106
        }
 
107
        
 
108
        [AttributeUsage(AttributeTargets.Class)]
 
109
        public class ImplementNullableAttribute : TypeImplementationModifierAttribute
 
110
        {
 
111
                NullableImplementation implementation;
 
112
                
 
113
                public ImplementNullableAttribute()
 
114
                {
 
115
                        this.implementation = NullableImplementation.Default;
 
116
                }
 
117
                
 
118
                public ImplementNullableAttribute(NullableImplementation implementation)
 
119
                {
 
120
                        this.implementation = implementation;
 
121
                }
 
122
                
 
123
                public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type)
 
124
                {
 
125
                        if (implementation == NullableImplementation.Default || implementation == NullableImplementation.Abstract) {
 
126
                                ctd.BaseTypes.Add(new CodeTypeReference("INullable"));
 
127
                                CodeMemberProperty prop = new CodeMemberProperty();
 
128
                                prop.Name = "IsNull";
 
129
                                prop.Type = new CodeTypeReference(typeof(bool));
 
130
                                prop.Attributes = MemberAttributes.Public;
 
131
                                prop.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(false)));
 
132
                                ctd.Members.Add(prop);
 
133
                        }
 
134
                        if (implementation != NullableImplementation.Abstract) {
 
135
                                CodeTypeDeclaration newType = new CodeTypeDeclaration("Null" + ctd.Name);
 
136
                                newType.BaseTypes.Add(new CodeTypeReference(ctd.Name));
 
137
                                cns.Types.Add(newType);
 
138
                                
 
139
                                System.Reflection.ConstructorInfo baseCtor = MainClass.GetBaseCtor(type);
 
140
                                CodeConstructor ctor = new CodeConstructor();
 
141
                                ctor.Attributes = MemberAttributes.Private;
 
142
                                if (baseCtor != null) {
 
143
                                        foreach (object o in baseCtor.GetParameters()) {
 
144
                                                ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(null));
 
145
                                        }
 
146
                                }
 
147
                                newType.Members.Add(ctor);
 
148
                                
 
149
                                CodeMemberField field = new CodeMemberField(newType.Name, "instance");
 
150
                                field.Attributes = MemberAttributes.Static;
 
151
                                field.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference(newType.Name));
 
152
                                newType.Members.Add(field);
 
153
                                
 
154
                                CodeMemberProperty prop = new CodeMemberProperty();
 
155
                                prop.Name = "Instance";
 
156
                                prop.Type = new CodeTypeReference(newType.Name);
 
157
                                prop.Attributes = MemberAttributes.Public | MemberAttributes.Static;
 
158
                                prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("instance")));
 
159
                                newType.Members.Add(prop);
 
160
                                
 
161
                                prop = new CodeMemberProperty();
 
162
                                prop.Name = "IsNull";
 
163
                                prop.Type = new CodeTypeReference(typeof(bool));
 
164
                                prop.Attributes = MemberAttributes.Public | MemberAttributes.Override;
 
165
                                prop.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(true)));
 
166
                                newType.Members.Add(prop);
 
167
                                
 
168
                                CodeMemberMethod method = new CodeMemberMethod();
 
169
                                method.Name = "AcceptVisitor";
 
170
                                method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
 
171
                                method.Parameters.Add(new CodeParameterDeclarationExpression("IAstVisitor", "visitor"));
 
172
                                method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "data"));
 
173
                                method.ReturnType = new CodeTypeReference(typeof(object));
 
174
                                method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
 
175
                                newType.Members.Add(method);
 
176
                                
 
177
                                method = new CodeMemberMethod();
 
178
                                method.Name = "ToString";
 
179
                                method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
 
180
                                method.ReturnType = new CodeTypeReference(typeof(string));
 
181
                                method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression("[" + newType.Name + "]")));
 
182
                                newType.Members.Add(method);
 
183
                                
 
184
                                prop = new CodeMemberProperty();
 
185
                                prop.Name = "Null";
 
186
                                prop.Type = new CodeTypeReference(ctd.Name);
 
187
                                prop.Attributes = MemberAttributes.Public | MemberAttributes.Static;
 
188
                                if (implementation == NullableImplementation.Shadow) {
 
189
                                        prop.Attributes |= MemberAttributes.New;
 
190
                                }
 
191
                                CodeExpression ex = new CodeTypeReferenceExpression(newType.Name);
 
192
                                ex = new CodePropertyReferenceExpression(ex, "Instance");
 
193
                                prop.GetStatements.Add(new CodeMethodReturnStatement(ex));
 
194
                                ctd.Members.Add(prop);
 
195
                        }
 
196
                }
 
197
        }
 
198
}