Beispiel #1
0
 void _Visit(JsSwitchStatement node)
 {
     Keyword("switch");
     Control("(");
     Visit(node.Expression);
     Control(")");
     BeginBlock();
     VisitEach(node.Sections);
     EndBlock();
 }
Beispiel #2
0
 public static JsSwitchStatement Case(this JsSwitchStatement node, JsExpression value, List <JsStatement> statements)
 {
     if (node.Sections == null)
     {
         node.Sections = new List <JsSwitchSection>();
     }
     node.Sections.Add(new JsSwitchSection {
         Labels = new List <JsSwitchLabel> {
             new JsSwitchLabel {
                 Expression = value
             }
         }, Statements = statements
     });
     return(node);
 }
 protected virtual void _visit( JsSwitchStatement node )
 {
     throw new NotImplementedException( "JsSwitchStatement" );
 }
        // Builds out the injection point JSSwitchStatement for the items passed in for a particiular class
        JsSwitchStatement getInjectionSwitchStatement(string switchVariableStr, IList<IMethod> constructors, IList<IField> fields, IList<IMethod> methods, IList<IField> views, IList<IProperty> properties, string superClassPath = null)
        {
            // Constructors 0
            JsSwitchSection constructorSection = getConstructorSwitchSection(InjectionPointVariableConstants.SWITCH_CONSTRUCTOR_BLOCK, constructors);

            // in the case of fields, properties, methods and views, we will call super if a superClassPath is defined.
            JsInvocationExpression initializer = null;
            if (superClassPath != null)
            {
                JsMemberExpression param = AstUtils.getNewMemberExpression( InjectionPointVariableConstants.INJECTION_POINT_PARAMETER_NAME );
                List<JsExpression> args = new List<JsExpression>();
                args.Add(param);

                initializer = AstUtils.getStaticMethodCallInvocationExpression(OutputNameConstants.PROPERTY_INJECTION_POINTS, superClassPath, args);
            }

            // Fields 1
            JsSwitchSection fieldsSection = getFieldsSwitchSection( InjectionPointVariableConstants.SWITCH_FIELDS_BLOCK, fields, initializer );

            // Methods 2
            JsSwitchSection methodsSection = getMethodsSwitchSection( InjectionPointVariableConstants.SWITCH_METHODS_BLOCK, methods );

            // Views 3
            JsSwitchSection viewsSection = getFieldsSwitchSection( InjectionPointVariableConstants.SWITCH_VIEWS_BLOCK, views, initializer );

            // Properties 4
            JsSwitchSection propertiesSection = getPropertiesSwitchSection( InjectionPointVariableConstants.SWITCH_PROPERTIES_BLOCK, properties, initializer );

            // if everything is null, there is nothing left to do, return null
            if ( constructorSection == null && fieldsSection == null && methodsSection == null && viewsSection == null && propertiesSection == null )
            {
                return null;
            }

            // If we have data, let's build out the JSSwitchStatement
            JsSwitchStatement results = new JsSwitchStatement();
            results.Sections = new List<JsSwitchSection>();
            results.Expression = AstUtils.getNewMemberExpression(switchVariableStr);

            if (constructorSection != null)
            {
                results.Sections.Add(constructorSection);
            }

            if (fieldsSection != null)
            {
                results.Sections.Add(fieldsSection);
            }

            if (methodsSection != null)
            {
                results.Sections.Add(methodsSection);
            }

            if (viewsSection != null)
            {
                results.Sections.Add(viewsSection);
            }

            if (propertiesSection != null)
            {
                results.Sections.Add(propertiesSection);
            }

            if (results != null)
            {
                results.Sections.Add(getSwitchDefaultSection());
            }

            return results;
        }
 protected override void _visit( JsSwitchStatement node )
 {
     if (node != null)
     {
         visit( node.Expression );
         foreach ( JsSwitchSection section in node.Sections )
         {
             visit( section );
         }
     }
 }