コード例 #1
0
        public static void GetClassWithObsoleteSuppression() =>
        Assert.That(ClassTemplates.GetClassWithObsoleteSuppression("a"), Is.EqualTo(
                        @"#pragma warning disable CS0618
#pragma warning disable CS0672
a
#pragma warning restore CS0672
#pragma warning restore CS0618"));
コード例 #2
0
ファイル: Builder.cs プロジェクト: ironcev-forks/Rocks
        private string MakeCode()
        {
            var hasEvents    = this.BaseType.HasEvents();
            var methods      = this.GetGeneratedMethods(hasEvents);
            var constructors = this.GetGeneratedConstructors();
            var properties   = this.GetGeneratedProperties(hasEvents);
            var events       = this.GetGeneratedEvents();

            this.IsUnsafe |= constructors.IsUnsafe || events.IsUnsafe || methods.IsUnsafe || properties.IsUnsafe;
            this.RequiresObsoleteSuppression |= this.BaseType.GetCustomAttribute <ObsoleteAttribute>() != null ||
                                                constructors.RequiresObsoleteSuppression || events.RequiresObsoleteSuppression ||
                                                methods.RequiresObsoleteSuppression || properties.RequiresObsoleteSuppression;

            this.Namespaces.Remove(this.BaseType.Namespace);

            var(_, constraints) = this.BaseType.GetGenericArguments(this.Namespaces);

            var namespaces = string.Join(Environment.NewLine,
                                         (from @namespace in this.Namespaces
                                          select $"using {@namespace};"));

            var @class = ClassTemplates.GetClass(namespaces,
                                                 this.TypeName, this.BaseType.GetFullName(),
                                                 methods.Result, properties.Result, events.Result, constructors.Result,
                                                 this.BaseType.Namespace,
                                                 this.Options.Serialization == SerializationOption.Supported ?
                                                 "[Serializable]" : string.Empty,
                                                 this.Options.Serialization == SerializationOption.Supported ?
                                                 ConstructorTemplates.GetConstructorWithNoArguments(this.GetTypeNameWithNoGenerics()) : string.Empty,
                                                 this.GetAdditionNamespaceCode(),
                                                 this.IsUnsafe, constraints,
                                                 hasEvents ? "R.IMockWithEvents" : "R.IMock",
                                                 hasEvents ? ClassTemplates.GetRaiseImplementation() : string.Empty);

            if (this.RequiresObsoleteSuppression)
            {
                @class = ClassTemplates.GetClassWithObsoleteSuppression(@class);
            }

            return(@class);
        }
コード例 #3
0
        public static void GetClassTemplateWhenIsUnsafeIsFalse() =>
        Assert.That(ClassTemplates.GetClass("a", "b", "c", "d", "e", "f", "g", "h", "i", "k", "l", false, "m", "n", "o"), Is.EqualTo(
                        @"#pragma warning disable CS8019
using R = Rocks;
using RE = Rocks.Exceptions;
using S = System;
using SCG = System.Collections.Generic;
using SCO = System.Collections.ObjectModel;
using SR = System.Reflection;
using STT = System.Threading.Tasks;
a
#pragma warning restore CS8019

namespace h
{
	i
	public  sealed class b
		: c, n m
	{
		private SCO.ReadOnlyDictionary<int, SCO.ReadOnlyCollection<R.HandlerInformation>> handlers;

		k

		g

		d

		e

		f

		SCO.ReadOnlyDictionary<int, SCO.ReadOnlyCollection<R.HandlerInformation>> R.IMock.Handlers => this.handlers;

		o

		l
	}
}"));
コード例 #4
0
ファイル: NewJavaGenerator.cs プロジェクト: SmaSTra/SmaSTra
        /// <summary>
        /// Creates the Java Class and all it's dependencies at the destination
        /// </summary>
        /// <param name="destinationFolder">To create at.</param>
        /// <param name="name">To use for creation</param>
        public void CreateJavaSource(string destinationFolder, string name)
        {
            if (!name.EndsWith(".java"))
            {
                name += ".java";
            }

            //Little hack, since the visited list is populated!
            var rootNode = _tree.OutputNode;
            var nodes    = new List <Node>();

            if (!IsValidTree(rootNode, nodes))
            {
                throw new InvalidTreeExection();
            }


            //Set the root node:
            var root = _tree.OutputNode.InputNodes[0];

            if (root is CombinedNode)
            {
                root = (root as CombinedNode).outputNode;
            }

            _codeExtension.RootNode = root;
            _codeExtension.Package  = "Test";

            //Get our Output type.
            _codeExtension.OutputType = rootNode.InputNodes[0].Class.OutputType;
            _codeExtension.ClassName  = name.RemoveAll(".java");

            //Generate the Traverse Data:
            var stack        = new Stack <QueueStatus>();
            var executeStack = new Stack <Node>();

            stack.Push(new QueueStatus(_tree.OutputNode, 0));
            executeStack.Push(root);

            //Get the loader for generating.
            var loader = Singleton <NodeLoader> .Instance;

            //Pre-Process the Stack:
            while (!stack.Empty())
            {
                var current = stack.Pop();
                if (current == null)
                {
                    break;
                }                               //Should not happen! Safetynet!

                var index = current.Index;
                var node  = current.Node.InputNodes[index];

                //Check for combined nodes:
                if (node is CombinedNode)
                {
                    node = (node as CombinedNode).outputNode;
                    executeStack.Push(node);
                }

                //Add next all to Stack:
                node.InputNodes
                .ForEachNonNull((n, i) => {
                    //Prevent doubles:
                    var status = new QueueStatus(n, i);
                    if (stack.Contains(status))
                    {
                        return;
                    }

                    stack.Push(new QueueStatus(node, i));
                    executeStack.Push(node.InputNodes[i]);
                });
            }

            //Now lets execute!
            while (!executeStack.Empty())
            {
                var next = executeStack.Pop();
                if (next == null)
                {
                    continue;
                }

                //Now really process:
                loader.CreateCode(next, _codeExtension);
            }


            //Build the rest:
            var sensorVars        = _codeExtension.BuildSensorDataVars();
            var transVars         = _codeExtension.BuildTransformDataVars();
            var initCode          = _codeExtension.BuildInitCode();
            var startCode         = _codeExtension.BuildStartCode();
            var stopCode          = _codeExtension.BuildStopCode();
            var proxyPropertyCode = _codeExtension.BuildProxyPropertyCode();
            var transformations   = _codeExtension.BuildTransformations();

            var theCode = ClassTemplates.GenerateTotal(
                _codeExtension.BuildPackage(),
                _codeExtension.BuildImports(),
                _codeExtension.BuildClassName(),
                _codeExtension.BuildOutputType(),
                initCode,
                sensorVars,
                transVars,
                startCode,
                stopCode,
                proxyPropertyCode,
                transformations
                );

            var exporter = Singleton <CodeExporter> .Instance;

            exporter.save(destinationFolder, theCode, _codeExtension);
        }