Ejemplo n.º 1
0
        protected virtual void EmitMethodsGroup(List <MethodDeclaration> group)
        {
            if (group.Count == 1)
            {
                if ((!group[0].Body.IsNull || Emitter.GetScript(group[0]) != null) && (!StaticBlock || !Helpers.IsEntryPointMethod(Emitter, group[0])))
                {
                    Emitter.VisitMethodDeclaration(group[0]);
                }
            }
            else
            {
                var typeDef    = Emitter.GetTypeDefinition();
                var name       = group[0].Name;
                var methodsDef = typeDef.Methods.Where(m => m.Name == name);
                Emitter.MethodsGroup        = methodsDef;
                Emitter.MethodsGroupBuilder = new Dictionary <int, StringBuilder>();

                foreach (var method in group)
                {
                    if (!method.Body.IsNull && (!StaticBlock || !Helpers.IsEntryPointMethod(Emitter, group[0])))
                    {
                        Emitter.VisitMethodDeclaration(method);
                    }
                }

                Emitter.MethodsGroup        = null;
                Emitter.MethodsGroupBuilder = null;
            }
        }
Ejemplo n.º 2
0
        protected override void DoEmit()
        {
            XmlToJsDoc.EmitComment(this, Emitter.Translator.EmitNode);
            string globalTarget = H5Types.GetGlobalTarget(TypeInfo.Type.GetDefinition(), TypeInfo.TypeDeclaration);

            if (globalTarget != null)
            {
                CheckGlobalClass();
                Emitter.NamedFunctions = new Dictionary <string, string>();
                WriteTopInitMethods();

                Write(JS.Types.H5.APPLY);
                WriteOpenParentheses();
                Write(globalTarget);
                Write(", ");
                BeginBlock();

                new MethodBlock(Emitter, TypeInfo, true).Emit();
                EmitMetadata();

                WriteNewLine();
                EndBlock();
                WriteCloseParentheses();
                WriteSemiColon();

                EmitAnonymousTypes();
                EmitNamedFunctions();

                WriteAfterInitMethods();

                WriteNewLine();
            }
            else
            {
                EmitClassHeader();

                Emitter.NamedFunctions = new Dictionary <string, string>();

                if (TypeInfo.TypeDeclaration.ClassType != ClassType.Interface)
                {
                    MethodDeclaration entryPoint = null;
                    if (TypeInfo.StaticMethods.Any(group =>
                    {
                        return(group.Value.Any(method =>
                        {
                            var result = Helpers.IsEntryPointMethod(Emitter, method);
                            if (result)
                            {
                                entryPoint = method;
                            }
                            return result;
                        }));
                    }))
                    {
                        if (!entryPoint.Body.IsNull)
                        {
                            Emitter.VisitMethodDeclaration(entryPoint);
                        }
                    }

                    EmitStaticBlock();
                    EmitInstantiableBlock();
                }

                EmitClassEnd();
            }
        }