Exemple #1
0
 public override void ExitMethod([NotNull] XSharpParser.MethodContext context)
 {
     // Reset
     initComponent = null;
     _locals.Clear();
 }
Exemple #2
0
        public override void EnterMethod([NotNull] XSharpParser.MethodContext context)
        {
            _locals.Clear();
            var newMethod = new XCodeMemberMethod();

            writeTrivia(newMethod, context);
            newMethod.Name       = context.Sig.Id.GetCleanText();
            newMethod.Attributes = MemberAttributes.Public;
            newMethod.Parameters.AddRange(GetParametersList(context.Sig.ParamList));
            FillCodeDomDesignerData(newMethod, context.Start.Line, context.Start.Column);
            var returnType = BuildDataType(context.Sig.Type);

            newMethod.ReturnType = returnType;
            //
            if (context.Modifiers != null)
            {
                // Get standard Visibilities
                newMethod.Attributes = ContextToMethodModifiers(context.Modifiers);
                // Is it a NEW method ?
                if (context.Modifiers.NEW().Length > 0)
                {
                    newMethod.Attributes |= MemberAttributes.New;
                }
                if (context.Modifiers.STATIC().Length > 0)
                {
                    newMethod.Attributes |= MemberAttributes.Static;
                }
                if (context.Modifiers.VIRTUAL().Length > 0)
                {
                    // According to MSDN, The absence of the Final flag makes a member virtual in C#, same for us
                    newMethod.Attributes &= ~MemberAttributes.Final;
                }
                else
                {
                    // Other cases = FINAL
                    newMethod.Attributes |= MemberAttributes.Final;
                }
            }
            // !!! WARNING !!!
            // If the method is InitializeComponent, we will have to find all CodeObjects, as the designer is using them
            // Else, we can just copy the whole code in USERDATA, that will be fine
            if (newMethod.Name == "InitializeComponent")
            {
                initComponent = newMethod;
                if (context.Attributes != null)
                {
                    newMethod.CustomAttributes = GenerateAttributes(context.Attributes);
                }
            }
            else
            {
                if (context.StmtBlk != null)
                {
                    // Copy all source code to User_Data
                    // --> See XSharpCodeGenerator.GenerateMethod for writing
                    FillCodeSource(newMethod, context, _tokens);

                    // The designer will need to locate the code in the file, so we must add the location
                    if (context.StmtBlk.ChildCount > 0)
                    {
                        FillCodeDomDesignerData(newMethod, context.StmtBlk.Start.Line, context.StmtBlk.Start.Column);
                    }
                    else
                    {
                        FillCodeDomDesignerData(newMethod, context.Start.Line + 1, context.Start.Column);
                    }
                }
            }
            //
            this.CurrentClass.Members.Add(newMethod);
            this.addClassMember(new XMemberType(newMethod.Name, MemberTypes.Method, false, returnType.BaseType));
        }