Exemple #1
0
 public static ObjectArrayEventType MakeTransientOAType(
     string enumMethod,
     IDictionary <string, object> boxedPropertyTypes,
     StatementRawInfo statementRawInfo,
     StatementCompileTimeServices services)
 {
     return(MakeTransientOATypeInternal(
                enumMethod,
                boxedPropertyTypes,
                CodeGenerationIDGenerator.GenerateClassNameUUID(),
                statementRawInfo,
                services));
 }
Exemple #2
0
        public static ClassProvidedPrecompileResult CompileClassProvided(
            IList<string> classTexts,
            StatementCompileTimeServices compileTimeServices,
            ClassProvidedPrecompileResult optionalPrior)
        {
            if (classTexts == null || classTexts.IsEmpty()) {
                return ClassProvidedPrecompileResult.EMPTY;
            }

            if (!compileTimeServices.Configuration.Compiler.ByteCode.IsAllowInlinedClass) {
                throw new ExprValidationException("Inlined-class compilation has been disabled by configuration");
            }

            var index = -1;
            var existingTypes = new List<Type>(optionalPrior?.Classes ?? EmptyList<Type>.Instance);
            var existingTypesSet = new HashSet<string>(existingTypes.Select(_ => _.FullName));

            // In .NET our classes must be part of an assembly.  This is different from Java, where each class 
            // can be compiled into its own .class file.  Technically, we can create netmodules, but even then
            // its a container for classes.

            var compilables = new List<CompilableClass>();

            foreach (var classText in classTexts.Where(_ => !string.IsNullOrWhiteSpace(_))) {
                index++;

                var classNameId = CodeGenerationIDGenerator.GenerateClassNameUUID();
                var className = $"provided_{index}_{classNameId}";
                compilables.Add(new CompilableClass(classText, className));
            }

            CompileResponse response;
            try {
                response = compileTimeServices.CompilerServices.Compile(
                    new CompileRequest(compilables, compileTimeServices.Services));
            } 
            catch(CompilerServicesCompileException ex) {
                throw HandleException(ex, "Failed to compile class");
            }

            foreach (var exportedType in response.Assembly.ExportedTypes) {
                if (existingTypesSet.Contains(exportedType.FullName)) {
                    throw new ExprValidationException("Duplicate class by name '" + exportedType.FullName + "'");
                }

                existingTypes.Add(exportedType);
            }

            return new ClassProvidedPrecompileResult(response.Assembly, existingTypes);
        }
Exemple #3
0
        /// <summary>
        /// Determines a classname for the json event representation.
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="raw"></param>
        /// <param name="optionalUnderlyingProvided"></param>
        /// <returns></returns>
        private static string DetermineJsonClassName(
            EventTypeMetadata metadata,
            StatementRawInfo raw,
            Type optionalUnderlyingProvided)
        {
            if (optionalUnderlyingProvided != null)
            {
                return(optionalUnderlyingProvided.Name);
            }

            var jsonClassNameSimple = metadata.Name;

            if (metadata.AccessModifier.IsPrivateOrTransient())
            {
                var uuid = CodeGenerationIDGenerator.GenerateClassNameUUID();
                jsonClassNameSimple = $"{jsonClassNameSimple}__{uuid}";
            }
            else if (raw.ModuleName != null)
            {
                jsonClassNameSimple = $"{jsonClassNameSimple}__module_{raw.ModuleName}";
            }

            return(jsonClassNameSimple);
        }
 public MultiKeyClassRefUUIDBased(Type[] mkTypes)
 {
     uuid = CodeGenerationIDGenerator.GenerateClassNameUUID();
     MKTypes = mkTypes;
 }