コード例 #1
0
        CodeGenFile generateExtension(string contextName, ComponentData data)
        {
            var componentName = data.GetFullTypeName().ToComponentName();
            var index         = contextName + ComponentsLookupGenerator.COMPONENTS_LOOKUP + "." + componentName;
            var memberData    = data.GetMemberData();
            var template      = memberData.Length == 0
                                      ? FLAG_COMPONENT_TEMPLATE
                                      : STANDARD_COMPONENT_TEMPLATE;

            var fileContent = template
                              .Replace("${ContextName}", contextName)
                              .Replace("${ComponentType}", data.GetFullTypeName())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${componentName}", componentName.LowercaseFirst())
                              .Replace("${prefixedName}", data.GetUniqueComponentPrefix().LowercaseFirst() + componentName)
                              .Replace("${Index}", index)
                              .Replace("${memberArgs}", getMemberArgs(memberData))
                              .Replace("${memberAssignment}", getMemberAssignment(memberData));

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
コード例 #2
0
        CodeGenFile generateExtension(string contextName, ComponentData data)
        {
            var memberData    = data.GetMemberData();
            var componentName = data.GetFullTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var template      = memberData.Length == 0
                ? FLAG_COMPONENT_TEMPLATE
                : STANDARD_COMPONENT_TEMPLATE;

            var fileContent = template
                              .Replace("${ContextName}", contextName)
                              .Replace("${ComponentType}", data.GetFullTypeName())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${componentName}", componentName.LowercaseFirst())
                              .Replace("${prefixedComponentName}", data.GetCustomComponentPrefix().LowercaseFirst() + componentName)
                              .Replace("${memberArgs}", getMemberArgs(memberData))
                              .Replace("${methodArgs}", getMethodArgs(memberData));

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
コード例 #3
0
        CodeGenFile generateInterface(ComponentData data)
        {
            var componentName = data.GetFullTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var memberData    = data.GetMemberData();
            var interfaceName = "I" + componentName.RemoveComponentSuffix();

            var template = memberData.Length == 0
                                     ? FLAG_INTERFACE_TEMPLATE
                                     : STANDARD_INTERFACE_TEMPLATE;

            var fileContent = template
                              .Replace("${InterfaceName}", interfaceName)
                              .Replace("${ComponentType}", data.GetFullTypeName())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${componentName}", componentName.LowercaseFirst())
                              .Replace("${prefixedName}", data.GetCustomComponentPrefix().LowercaseFirst() + componentName)
                              .Replace("${memberArgs}", getMemberArgs(memberData));

            return(new CodeGenFile(
                       "Components" + Path.DirectorySeparatorChar +
                       "Interfaces" + Path.DirectorySeparatorChar +
                       interfaceName + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
コード例 #4
0
        CodeGenFile generateExtension(string contextName, ComponentData data)
        {
            var memberData = data.GetMemberData();
            var template   = memberData.Length == 0
                                      ? FLAG_COMPONENT_TEMPLATE
                                      : STANDARD_COMPONENT_TEMPLATE;

            var fileContent = template
                              .Replace("${Context}", contextName)
                              .Replace("${Name}", data.GetComponentName())
                              .Replace("${name}", data.GetComponentName().LowercaseFirst())
                              .Replace("${FullName}", data.GetFullComponentName())
                              .Replace("${prefixedName}", data.GetUniqueComponentPrefix().LowercaseFirst() + data.GetComponentName())
                              .Replace("${Type}", data.GetFullTypeName())
                              .Replace("${memberArgs}", getMemberArgs(memberData))
                              .Replace("${methodArgs}", getMethodArgs(memberData));

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + data.GetFullComponentName() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
コード例 #5
0
        CodeGenFile generateEntityInterfaceExtension(string contextName, ComponentData data)
        {
            var componentName = data.GetFullTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var interfaceName = "I" + componentName.RemoveComponentSuffix();

            var fileContent = ENTITY_INTERFACE_EXTENSION
                              .Replace("${InterfaceName}", "I" + componentName.RemoveComponentSuffix())
                              .Replace("${ContextName}", contextName);

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
コード例 #6
0
        CodeGenFile generateMatcher(string contextName, ComponentData data)
        {
            var componentName  = data.GetFullTypeName().ToComponentName();
            var index          = contextName + ComponentsLookupGenerator.COMPONENTS_LOOKUP + "." + componentName;
            var componentNames = contextName + ComponentsLookupGenerator.COMPONENTS_LOOKUP + ".componentNames";

            var fileContent = MATCHER_TEMPLATE
                              .Replace("${ContextName}", contextName)
                              .Replace("${ComponentName}", componentName)
                              .Replace("${Index}", index)
                              .Replace("${ComponentNames}", componentNames);

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
コード例 #7
0
        CodeGenFile generateComponentClass(ComponentData data)
        {
            var fullComponentName = data.GetFullTypeName().RemoveDots();
            var contexts          = string.Join(", ", data.GetContextNames());
            var unique            = data.IsUnique() ? "[QFramework.CodeGeneration.Attributes.UniqueAttribute]" : string.Empty;

            if (!string.IsNullOrEmpty(contexts))
            {
                contexts = "[" + contexts + "]";
            }

            return(new CodeGenFile(
                       "Components" + Path.DirectorySeparatorChar + fullComponentName + ".cs",
                       COMPONENT_TEMPLATE
                       .Replace("${FullComponentName}", fullComponentName)
                       .Replace("${Type}", data.GetObjectType())
                       .Replace("${Contexts}", contexts)
                       .Replace("${Unique}", unique),
                       GetType().FullName
                       ));
        }
コード例 #8
0
    void when_providing()
    {
        context["component"] = () => {
            Type          type = null;
            ComponentData data = null;

            before = () => {
                type = typeof(MyNamespaceComponent);
                data = getData <MyNamespaceComponent>();
            };

            it["get data"] = () => {
                data.should_not_be_null();
            };

            it["gets full type name"] = () => {
                data.GetFullTypeName().GetType().should_be(typeof(string));
                data.GetFullTypeName().should_be(type.ToCompilableString());
            };

            it["gets contexts"] = () => {
                var contextNames = data.GetContextNames();
                contextNames.GetType().should_be(typeof(string[]));
                contextNames.Length.should_be(2);
                contextNames[0].should_be("Test");
                contextNames[1].should_be("Test2");
            };

            it["sets first context as default when component has no context"] = () => {
                var contextNames = getData <NoContextComponent>().GetContextNames();
                contextNames.Length.should_be(1);
                contextNames[0].should_be("Game");
            };

            it["gets unique"] = () => {
                data.IsUnique().GetType().should_be(typeof(bool));
                data.IsUnique().should_be_false();

                getData <UniqueStandardComponent>().IsUnique().should_be_true();
            };

            it["gets member data"] = () => {
                data.GetMemberData().GetType().should_be(typeof(MemberData[]));
                data.GetMemberData().Length.should_be(1);
                data.GetMemberData()[0].type.should_be("string");
            };

            it["gets generate component"] = () => {
                data.ShouldGenerateComponent().GetType().should_be(typeof(bool));
                data.ShouldGenerateComponent().should_be_false();
                data.ContainsKey(ShouldGenerateComponentComponentDataExtension.COMPONENT_OBJECT_TYPE).should_be_false();
            };

            it["gets generate index"] = () => {
                data.ShouldGenerateIndex().GetType().should_be(typeof(bool));
                data.ShouldGenerateIndex().should_be_true();

                getData <DontGenerateIndexComponent>().ShouldGenerateIndex().should_be_false();
            };

            it["gets generate methods"] = () => {
                data.ShouldGenerateMethods().GetType().should_be(typeof(bool));
                data.ShouldGenerateMethods().should_be_true();

                getData <DontGenerateMethodsComponent>().ShouldGenerateMethods().should_be_false();
            };

            it["gets custom prefix"] = () => {
                data.GetCustomComponentPrefix().GetType().should_be(typeof(string));
                data.GetCustomComponentPrefix().should_be("is");

                getData <CustomPrefixFlagComponent>().GetCustomComponentPrefix().should_be("My");
            };
        };

        context["non component"] = () => {
            Type          type = null;
            ComponentData data = null;

            before = () => {
                type = typeof(ClassToGenerate);
                data = getData <ClassToGenerate>();
            };

            it["get data"] = () => {
                data.should_not_be_null();
            };

            it["gets full type name"] = () => {
                // Not the type, but the component that should be generated
                // See: no namespace
                data.GetFullTypeName().should_be("ClassToGenerateComponent");
            };

            it["gets contexts"] = () => {
                var contextNames = data.GetContextNames();
                contextNames.Length.should_be(2);
                contextNames[0].should_be("Test");
                contextNames[1].should_be("Test2");
            };

            it["gets unique"] = () => {
                data.IsUnique().should_be_false();
            };

            it["gets member data"] = () => {
                data.GetMemberData().Length.should_be(1);
                data.GetMemberData()[0].type.should_be(type.ToCompilableString());
            };

            it["gets generate component"] = () => {
                data.ShouldGenerateComponent().GetType().should_be(typeof(bool));
                data.ShouldGenerateComponent().should_be_true();
                data.GetObjectType().should_be(typeof(ClassToGenerate).ToCompilableString());
            };

            it["gets generate index"] = () => {
                data.ShouldGenerateIndex().should_be_true();
            };

            it["gets generate methods"] = () => {
                data.ShouldGenerateMethods().should_be_true();
            };

            it["gets custom prefix"] = () => {
                data.GetCustomComponentPrefix().should_be("is");
            };
        };

        context["multiple types"] = () => {
            it["creates data for each type"] = () => {
                var types    = new [] { typeof(NameAgeComponent), typeof(Test2ContextComponent) };
                var provider = new ComponentDataProvider(types);
                provider.Configure(new Properties(
                                       "Entitas.CodeGeneration.Plugins.Contexts = Game, GameState"
                                       ));
                var data = provider.GetData();
                data.Length.should_be(types.Length);
            };
        };

        context["multiple custom component names"] = () => {
            Type          type  = null;
            ComponentData data1 = null;
            ComponentData data2 = null;

            before = () => {
                type = typeof(CustomName);
                var data = getMultipleData <CustomName>();
                data1 = data[0];
                data2 = data[1];
            };

            it["creates data for each custom component name"] = () => {
                data1.GetObjectType().should_be(type.ToCompilableString());
                data2.GetObjectType().should_be(type.ToCompilableString());

                data1.GetFullTypeName().should_be("NewCustomNameComponent1Component");
                data2.GetFullTypeName().should_be("NewCustomNameComponent2Component");
            };
        };

        context["configure"] = () => {
            Type          type = null;
            ComponentData data = null;

            before = () => {
                var properties = new Properties(
                    "Entitas.CodeGeneration.Plugins.Contexts = ConfiguredContext" + "\n"
                    );

                type = typeof(NoContextComponent);
                data = getData <NoContextComponent>(properties);
            };

            it["gets default context"] = () => {
                var contextNames = data.GetContextNames();
                contextNames.Length.should_be(1);
                contextNames[0].should_be("ConfiguredContext");
            };
        };
    }
コード例 #9
0
    void when_providing()
    {
        context["component"] = () => {
            Type[]          types = null;
            ComponentData[] data  = null;
            ComponentData   d     = null;

            before = () => {
                types = new [] { typeof(MyNamespaceComponent) };
                var provider = new ComponentDataProvider(types);
                data = (ComponentData[])provider.GetData();
                d    = data[0];
            };

            it["get data"] = () => {
                data.Length.should_be(1);
            };

            it["gets component name"] = () => {
                d.GetComponentName().GetType().should_be(typeof(string));
                d.GetComponentName().should_be("MyNamespace");

                d.GetFullComponentName().GetType().should_be(typeof(string));
                d.GetFullComponentName().should_be("MyNamespaceComponent");
            };

            it["gets full type name"] = () => {
                d.GetFullTypeName().GetType().should_be(typeof(string));
                d.GetFullTypeName().should_be(types[0].ToCompilableString());
            };

            it["gets contexts"] = () => {
                d.GetContextNames().GetType().should_be(typeof(string[]));
                d.GetContextNames().Length.should_be(2);
                d.GetContextNames()[0].should_be("Test");
                d.GetContextNames()[1].should_be("Test2");
            };

            it["sets first context as default when component has no context"] = () => {
                var contextNames = getData <NoContextComponent>().GetContextNames();
                contextNames.Length.should_be(1);
                contextNames[0].should_be("Game");
            };

            it["gets unique"] = () => {
                d.IsUnique().GetType().should_be(typeof(bool));
                d.IsUnique().should_be_false();

                getData <UniqueStandardComponent>().IsUnique().should_be_true();
            };

            it["gets member data"] = () => {
                d.GetMemberData().GetType().should_be(typeof(MemberData[]));
                d.GetMemberData().Length.should_be(1);
            };

            it["gets generate component"] = () => {
                d.ShouldGenerateComponent().GetType().should_be(typeof(bool));
                d.ShouldGenerateComponent().should_be_false();
                d.ContainsKey(ShouldGenerateComponentComponentDataExtension.COMPONENT_OBJECT_TYPE).should_be_false();
            };

            it["gets generate index"] = () => {
                d.ShouldGenerateIndex().GetType().should_be(typeof(bool));
                d.ShouldGenerateIndex().should_be_true();

                getData <DontGenerateIndexComponent>().ShouldGenerateIndex().should_be_false();
            };

            it["gets generate methods"] = () => {
                d.ShouldGenerateMethods().GetType().should_be(typeof(bool));
                d.ShouldGenerateMethods().should_be_true();

                getData <DontGenerateMethodsComponent>().ShouldGenerateMethods().should_be_false();
            };

            it["gets unique prefix"] = () => {
                d.GetUniqueComponentPrefix().GetType().should_be(typeof(string));
                d.GetUniqueComponentPrefix().should_be("is");

                getData <CustomPrefixFlagComponent>().GetUniqueComponentPrefix().should_be("My");
            };
        };

        context["non component"] = () => {
            Type[]          types = null;
            ComponentData[] data  = null;
            ComponentData   d     = null;

            before = () => {
                types = new [] { typeof(ClassToGenerate) };
                var provider = new ComponentDataProvider(types);
                data = (ComponentData[])provider.GetData();
                d    = data[0];
            };

            it["get data"] = () => {
                data.Length.should_be(1);
            };

            it["gets component name"] = () => {
                d.GetComponentName().GetType().should_be(typeof(string));

                // Not the type, but the component that should be generated
                // See: no namespace
                d.GetComponentName().should_be("ClassToGenerate");

                d.GetFullComponentName().GetType().should_be(typeof(string));

                // Not the type, but the component that should be generated
                // See: no namespace
                d.GetFullComponentName().should_be("ClassToGenerateComponent");
            };

            it["gets full type name"] = () => {
                d.GetFullTypeName().GetType().should_be(typeof(string));

                // Not the type, but the component that should be generated
                // See: no namespace
                d.GetFullTypeName().should_be("ClassToGenerateComponent");
            };

            it["gets contexts"] = () => {
                d.GetContextNames().GetType().should_be(typeof(string[]));
                d.GetContextNames().Length.should_be(2);
                d.GetContextNames()[0].should_be("Test");
                d.GetContextNames()[1].should_be("Test2");
            };

            it["gets unique"] = () => {
                d.IsUnique().GetType().should_be(typeof(bool));
                d.IsUnique().should_be_false();
            };

            it["gets member data"] = () => {
                d.GetMemberData().Length.should_be(1);
                d.GetMemberData()[0].type.should_be(typeof(ClassToGenerate).ToCompilableString());
            };

            it["gets generate component"] = () => {
                d.ShouldGenerateComponent().GetType().should_be(typeof(bool));
                d.ShouldGenerateComponent().should_be_true();
                d.GetObjectType().should_be(typeof(ClassToGenerate).ToCompilableString());
            };

            it["gets generate index"] = () => {
                d.ShouldGenerateIndex().GetType().should_be(typeof(bool));
                d.ShouldGenerateIndex().should_be_true();
            };

            it["gets generate methods"] = () => {
                d.ShouldGenerateMethods().GetType().should_be(typeof(bool));
                d.ShouldGenerateMethods().should_be_true();
            };

            it["gets unique prefix"] = () => {
                d.GetUniqueComponentPrefix().GetType().should_be(typeof(string));
                d.GetUniqueComponentPrefix().should_be("is");
            };
        };

        context["multiple types"] = () => {
            it["creates data for each type"] = () => {
                var types    = new [] { typeof(NameAgeComponent), typeof(Test2ContextComponent) };
                var provider = new ComponentDataProvider(types);
                var data     = provider.GetData();
                data.Length.should_be(types.Length);
            };
        };

        context["multiple custom component names"] = () => {
            Type[]          types = null;
            ComponentData[] data  = null;
            ComponentData   d1    = null;
            ComponentData   d2    = null;

            before = () => {
                types = new [] { typeof(CustomName) };
                var provider = new ComponentDataProvider(types);
                data = (ComponentData[])provider.GetData();
                d1   = data[0];
                d2   = data[1];
            };

            it["get data"] = () => {
                data.Length.should_be(2);
            };

            it["creates data for each custom component name"] = () => {
                d1.GetComponentName().should_be("NewCustomNameComponent1");
                d2.GetComponentName().should_be("NewCustomNameComponent2");

                d1.GetObjectType().should_be(types[0].ToCompilableString());
                d2.GetObjectType().should_be(types[0].ToCompilableString());

                d1.GetFullTypeName().should_be("NewCustomNameComponent1Component");
                d2.GetFullTypeName().should_be("NewCustomNameComponent2Component");

                d1.GetComponentName().should_be("NewCustomNameComponent1");
                d2.GetComponentName().should_be("NewCustomNameComponent2");

                d1.GetFullComponentName().should_be("NewCustomNameComponent1Component");
                d2.GetFullComponentName().should_be("NewCustomNameComponent2Component");
            };
        };
    }