Пример #1
0
 void _Visit(JsUnit node)
 {
     if (node.Statements == null)
     {
         return;
     }
     VisitEach(node.Statements);
     NewLine();
 }
Пример #2
0
 JsFile CreateExternalJsFile(string filename)
 {
     var unit = new JsUnit { Statements = new List<JsStatement>() };
     var st = new JsCodeStatement
     {
         Code = File.ReadAllText(filename)
     };
     var file = new JsFile { Filename = filename, Units = new List<JsUnit> { unit } };
     unit.Statements.Add(st);
     return file;
 }
Пример #3
0
        public override JsNode _VisitEnum(ITypeDefinition ce)
        {
            var unit = new JsUnit { Statements = new List<JsStatement>() };
            ExportTypeNamespace(unit, ce);
            var json = VisitEnumToJson(ce);
            var typeName = GetJsTypeName(ce);
            var st = Js.Members(typeName).Assign(json).Statement();

            unit.Statements.Add(st);
            return unit;
        }
Пример #4
0
 public override JsNode _VisitClass(ITypeDefinition ce)
 {
     var unit = new JsUnit { Statements = new List<JsStatement>() };
     ExportTypeNamespace(unit, ce);
     var members = GetMembersToExport(ce);
     VisitToUnit(unit, members);
     var baseCe = ce.GetBaseTypeDefinition();
     if (baseCe != null && Sk.IsNativeType(baseCe) && !Sk.IsGlobalType(baseCe) && !Sk.OmitInheritance(ce))
     {
         unit.Statements.Add(Js.Member("$Inherit").Invoke(SkJs.EntityToMember(ce), SkJs.EntityToMember(baseCe)).Statement());
     }
     return unit;
 }
Пример #5
0
        protected override JsUnit OnAfterExportType(ITypeDefinition ce, JsClrType jsType)
        {
            var extJsType = new ExtJsType
            {
                extend = jsType.baseTypeName,
                statics = jsType.staticDefinition,
            };
            //if (extJsType.extend == "System.Object")
            //    extJsType.extend = null;
            var json = (JsJsonObjectExpression)Serialize(extJsType);
            //var ctor = json.NamesValues.Where(t => t.Name.Name == "ctor").FirstOrDefault();
            if (jsType.definition == null)
                jsType.definition = new JsObject();
            var ctor = jsType.definition.TryGetValue("ctor");
            if (ctor != null)
            {
                jsType.definition.Remove("ctor");
                jsType.definition.Add("constructor", ctor);
                //ctor.Name.Name = "constructor";
                //var func = ctor.Value as JsFunction;
                //if (func != null)
                //{
                //    func.Block.Statements.Insert(0, Js.This().Member("callSuper").Invoke(Js.Member("arguments")).Statement());
                //}
            }
            foreach (var me in jsType.definition)
            {
                var name = me.Key;
                var value = (JsExpression)me.Value;
                if (json.NamesValues == null)
                    json.NamesValues = new List<JsJsonNameValue>();
                json.NamesValues.Add(new JsJsonNameValue { Name = new JsJsonMember { Name = name }, Value = value });
            }

            var define = Js.Members("Ext.define").Invoke(Js.String(jsType.fullname), json).Statement();
            var unit = new JsUnit { Statements = new List<JsStatement> { define } };
            return unit;// base.OnAfterExportType(ce, jsType);
        }
 protected virtual void _visit( JsUnit node )
 {
     throw new NotImplementedException( "JsUnit" );
 }
Пример #7
0
 protected void VisitToUnit(JsUnit unit, List<IMember> list)
 {
     var nodes = list.Select(Visit).ToList();
     ImportToUnit(unit, nodes);
 }
Пример #8
0
 protected void ImportToUnit(JsUnit unit, List<JsNode> list)
 {
     foreach (var node in list)
     {
         if (node == null)
             continue;
         JsStatement st = null;
         if (node is JsFunction)
             st = ((JsFunction)node).Statement();
         else if (node is JsNodeList)
             ImportToUnit(unit, ((JsNodeList)node).Nodes);
         else if (node is JsUnit)
             unit.Statements.AddRange(((JsUnit)node).Statements);
         else
             st = (JsStatement)node;
         if (st != null)
             unit.Statements.Add(st);
     }
 }
 public InjectionPointsFunctionBuilder(DefaultResolvedTypeDefinition arg1, JsUnit arg2)
 {
     this.cSharpDef = arg1;
     this.jsEntity = arg2;
 }
Пример #10
0
 protected JsUnit VisitToUnit(List<IMember> list)
 {
     var unit = new JsUnit { Statements = new List<JsStatement>() };
     VisitToUnit(unit, list);
     return unit;
 }
        public JsFunction getClassDependencyFunction(JsUnit jsNode)
        {
            // function contents
            JsBlock resultsBlock = new JsBlock();
            resultsBlock.Statements = new List<JsStatement>();

            // Check to see if we need to call super.
            string superClassPath = null;

            // bschmidtke: 12/04/1012 - We do not want to call super at the moment, commenting out to value remains null.
            // Clean up later once this is confirmed after testing.
            // Leaving the code using superClassPath intact until we decide what route to go with this.

            //bool initArray = true;
            //foreach (IType type in cSharpDef.DirectBaseTypes)
            //{
            //    // careful, type.FullName could be all sorts of stuff, like interfaces
            //    if (type.Kind == TypeKind.Class)
            //    {
            //        initArray = GuiceUtils.shouldExcludeBasedOnNamespace(type.Namespace);
            //        if (!initArray)
            //        {
            //            superClassPath = type.FullName;
            //        }
            //    }
            //}

            JsBinaryExpression pExpression = null;
            JsInvocationExpression initializer = null;

            // If we have to call super...do it
            // in the case of properties methods and views, we will call super if a superClassPath is defined.
            if (superClassPath != null)
            {
                // define return variable and call super
                initializer = AstUtils.getStaticMethodCallInvocationExpression(OutputNameConstants.FUNCTION_GET_CLASS_DEPENDENCIES, superClassPath, null);

                // initalized the result array, by calling super
                pExpression = AstUtils.getJsBinaryExpression(
                                                                AstUtils.getNewMemberExpression(InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME),
                                                                "=",
                                                                initializer
                                                                );
            }
            else
            {
                // initalized empty result array
                pExpression = AstUtils.getJsBinaryExpression( AstUtils.getNewMemberExpression( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME ),
                                                                                "=",
                                                                                AstUtils.getEmptyArrayInvocationExpression());
            }

            JsExpressionStatement pStatement = AstUtils.getJsExpressionStatement(pExpression);

            // define return variable.
            resultsBlock.Statements.Add( AstUtils.getJsVariableDeclarationStatement( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME ) );

            ClassDependencyVisitor visitor = new ClassDependencyVisitor( cSharpDef, jsEntity );
            List<string> dependencyList = visitor.dependencyList;

            if (dependencyList.Count > 0)
            {
                resultsBlock.Statements.Add( pStatement );

                List<string> dups = new List<string>();
                foreach ( string dependency in dependencyList )
                {
                    if ( !dups.Contains( dependency ) && dependency.Length > 1 )
                    {
                        dups.Add( dependency );

                        string value = "\'" + dependency + "\'";

                        JsExpressionStatement insert = AstUtils.getArrayInsertStatement( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME, value );
                        resultsBlock.Statements.Add( insert );
                    }
                }

                resultsBlock.Statements.Add( AstUtils.getJsReturnStatement( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME ) );
            }
            else
            {
                if( initializer != null )
                {
                    // if the super class path was defined, we have to no matter what make sure we call super.
                    resultsBlock.Statements.Add(pStatement);
                    resultsBlock.Statements.Add( AstUtils.getJsReturnStatement( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME ) );
                }
                else
                {
                    JsInvocationExpression initer = AstUtils.getEmptyArrayInvocationExpression();
                    resultsBlock.Statements.Add(AstUtils.getJsReturnStatement(initer));
                }
            }

            // define function
            JsFunction result = new JsFunction();
            // add the function block
            result.Block = resultsBlock;
            return result;
        }
Пример #12
0
        protected virtual JsUnit OnAfterExportType(ITypeDefinition ce, JsClrType jsType)
        {
            //HACK: backward
            if (jsType.Kind == JsClrTypeKind.Interface && jsType.baseTypeName.IsNullOrEmpty())
                jsType.baseTypeName = "System.Object";
            var unit = new JsUnit { Statements = new List<JsStatement>() };
            unit.Statements.Add(VerifyJsTypesArrayStatement.Clone());

            var json = (JsJsonObjectExpression)Serialize(jsType);
            var moveToEnd = json.NamesValues.Where(t => t.Name.Name.Contains("definition")).ToList();
            moveToEnd.ForEach(t => json.NamesValues.Remove(t));
            json.NamesValues.AddRange(moveToEnd);

            var ceVarName = GetJsTypeName(ce).Replace(".", "$");
            unit.Statements.Add(Js.Var(ceVarName, json).Statement());
            unit.Statements.Add(Js.Member("JsTypes").Member("push").Invoke(Js.Member(ceVarName)).Statement());
            return unit;
        }
 // inserts a list of other dependencies this class needs in order to run. Guice will load
 protected void insertDependencyList( DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef )
 {
     if ( cSharpDef != null && jsDef != null )
     {
         ClassDependencyFunctionBuilder dependencyBuilder = new ClassDependencyFunctionBuilder( cSharpDef, jsDef );
         JsExpressionStatement classDependencyStatement = dependencyBuilder.getDependencyExpression();
         if (classDependencyStatement != null)
         {
             jsDef.Statements.Add(classDependencyStatement);
         }
     }
 }
 // processes [Bindable] tagged items
 protected void insertBindableMetadata(DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef)
 {
     if (cSharpDef != null && jsDef != null)
     {
         ObservablePropertiesBuilder bpb = new ObservablePropertiesBuilder(cSharpDef);
         List<JsExpressionStatement> propertyStatements = bpb.getEncapsulateBindableProperties();
         if (propertyStatements != null)
         {
             foreach (JsExpressionStatement propertyStatement in propertyStatements)
             {
                 jsDef.Statements.Add(propertyStatement);
             }
         }
     }
 }
 public static JsUnit getNewJsUnit()
 {
     JsUnit result = new JsUnit();
     result.Statements = new List<JsStatement>();
     return result;
 }
Пример #16
0
 void ExportTypeNamespace(JsUnit unit, ITypeDefinition ce)
 {
     var name = GetJsTypeName(ce);
     if (name.IsNotNullOrEmpty() && name.Contains("."))
     {
         var ns = name.Split('.');
         ns = ns.Take(ns.Length - 1).ToArray();
         ExportNamespace(unit, ns.StringConcat("."));
     }
 }
Пример #17
0
 void ExportNamespace(JsUnit unit, string ns)
 {
     var Writer = new StringWriter();
     if (ns.IsNotNullOrEmpty())
     {
         var tokens = ns.Split('.');
         for (var i = 0; i < tokens.Length; i++)
         {
             var ns2 = tokens.Take(i + 1).StringJoin(".");
             JsStatement st;
             if (i == 0)
                 st = Js.Var(ns2, Js.Json()).Statement();
             else
                 st = Js.Member(ns2).Assign(Js.Json()).Statement();
             var st2 = Js.If(Js.Typeof(Js.Member(ns2)).Equal(Js.String("undefined"))).Then(st);
             unit.Statements.Add(st2);
             st2.AddAnnotation(new NamespaceVerificationAnnotation { Namespace = ns2 });//.Ex(true).NamespaceVerification = ns2;
         }
     }
 }
 // inserts static className property in JSFile
 // ex: randori.attributes.HtmlMergedFile.className = "randori.attributes.HtmlMergedFile";
 protected void insertClassNameProperty( DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef )
 {
     if ( cSharpDef != null && jsDef != null )
     {
         JsExpressionStatement classNameStatement = AstUtils.getStaticPropertyStatement( OutputNameConstants.PROPERTY_CLASS_NAME, cSharpDef.FullName );
         if ( classNameStatement != null )
         {
             jsDef.Statements.Add( classNameStatement );
         }
     }
 }
 protected override void _visit( JsUnit node )
 {
     if (node != null)
     {
         foreach (JsStatement statement in node.Statements)
         {
             visit( statement );
         }
     }
 }
 // creates injectionPoints function
 // ex: randori.formatters.AbstractFormatter.injectionPoints = function(t) { ... }
 protected void insertInjectionPoints( DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef )
 {
     if (cSharpDef != null && jsDef != null)
     {
         InjectionPointsFunctionBuilder ipBuilder = new InjectionPointsFunctionBuilder(cSharpDef, jsDef);
         JsExpressionStatement injectionPoints = ipBuilder.getInjectionPointsExpression();
         if (injectionPoints != null)
         {
             jsDef.Statements.Add(injectionPoints);
         }
     }
 }
 public ClassDependencyFunctionBuilder(DefaultResolvedTypeDefinition arg1, JsUnit arg2)
 {
     this.cSharpDef = arg1;
     this.jsEntity = arg2;
 }