public SetValueAtIndexAction(GeneratedMethod method, GeneratedArray array, GeneratedVariable variable, int index) { this.method = method; this.array = array; this.variable = variable; this.index = index; }
public CallAction(Func<MethodBuilderBundle> bundle, Func<MethodInfo> method, IList<ITypeGenerationAction> actions, GeneratedMethod generatedMethod) { this.bundle = bundle; this.method = method; this.actions = actions; this.generatedMethod = generatedMethod; }
public SetValueOnObjectAction(GeneratedMethod method, GeneratedVariable variable, object value, MethodInfo info) { this.method = method; this.variable = variable; this.value = value; this.info = info; }
public CallAction(Func<MethodBuilderBundle> bundle, Func<MethodInfo> method, IList<ITypeGenerationAction> actions, GeneratedMethod generatedMethod, Func<List<IGeneratedParameter>> parameters) { this.bundle = bundle; this.method = method; this.actions = actions; this.generatedMethod = generatedMethod; this.parameters = parameters; }
public CallAction(Func<MethodBuilderBundle> bundle, Func<DelegateMethod> targetMethod, IList<ITypeGenerationAction> actions, GeneratedMethod generatedMethod, Func<List<GeneratedField>> fields) { this.bundle = bundle; this.delegateMethod = targetMethod; this.actions = actions; this.generatedMethod = generatedMethod; this.fields = fields; }
/// <summary>Adds a Component to a conformance Message /// adds a line to the constructor to instantiate that member variable /// </summary> /// <param name="profileName">this is the profile name associated with this Class /// </param> /// <param name="componentNumber">the number associated with the component in the profile /// </param> /// <param name="childGetter">adds this line to the constructor to instantiate Conformance Component class /// </param> private void addChild(ProfileName profileName, int componentNumber, System.String childGetter) { // Add member variable to class for holding Conformance Component class this.addMemberVariable("private " + profileName.ClassName + " " + profileName.MemberName + ";"); // Add line to constructor to instantiate Conformance Component class this.Constructor.addToBody(childGetter); // Add method for retrieving Conformance Component Class GeneratedMethod getChildMethod = new GeneratedMethod(); getChildMethod.addToComments("Provides access to the " + profileName.OriginalName + " component child"); getChildMethod.addToComments("@return " + profileName.ClassName + " The " + profileName.OriginalName + " component child"); getChildMethod.Visibility = "public"; getChildMethod.ReturnType = profileName.ClassName; getChildMethod.Name = profileName.AccessorName; getChildMethod.addToBody("return " + profileName.MemberName + ";"); this.addMethod(getChildMethod); }
/// <summary>This method will build a primitive conformance class (ST, NM, etc) which is /// a Component or Subcomponent. /// </summary> public virtual void buildClass(Genetibase.NuGenHL7.conf.spec.message.AbstractComponent primitive, int profileType) { GeneratedPrimitive genClass = new GeneratedPrimitive(); ProfileName profileName = new ProfileName(primitive.Name, profileType); // Set up class genClass.ClassPackage = packageName; genClass.addClassImport("Genetibase.NuGenHL7.model.*"); genClass.addClassImport("Genetibase.NuGenHL7.conf.classes.abs.*"); genClass.Properties = "extends AbstractConformanceDataType"; genClass.Name = profileName.ClassName; docBuilder.decorateConstructor(genClass.Constructor, profileName.ClassName); if (primitive.ConstantValue != null && primitive.ConstantValue.Length > 0) { // Add constant value constraints if there are any genClass.addConstantValue(primitive.ConstantValue); } else { // if no constant value, then we add a setter method GeneratedMethod setter = new GeneratedMethod(); setter.addParam("java.lang.String value"); setter.addToThrows("ConfDataException"); setter.addToBody("super.setValue( value );"); setter.ReturnType = "void"; setter.Visibility = "public"; setter.Name = "setValue"; docBuilder.decorateSetValue(setter, primitive.Length); genClass.addMethod(setter); genClass.addClassImport("Genetibase.NuGenHL7.conf.classes.exceptions.*"); } genClass.addMaxLength(primitive.Length); // Decorate with comments docBuilder.decoratePrimitive(genClass, primitive); if (depManager.Verbose) System.Console.Out.WriteLine("Generating Primitive: " + packageName + "." + genClass.Name); depManager.generateFile(genClass, packageName, genClass.Name); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { // nothing }
public void RegisterCommandEndpoints(List <Type> handlers) { if (handlers == null) { return; } foreach (var handler in handlers.Where(h => h.GetCustomAttribute <ApiGenAttribute>() != null)) { var temp = handler.GetMethods() .Where(x => x.IsPublic && x.Name == HandlerMethodName).ToList(); if (temp.Count == 0) { continue; } var handlerAttr = handler.GetCustomAttribute <ApiGenAttribute>(); var controllerName = handlerAttr?.ControllerName ?? MapHandlerNameToControllerName(handler.Name); var generatedControllerIndex = AddControllerIfNotExist(controllerName, handlerAttr, handler); foreach (var methodInfo in temp) { if (methodInfo.GetCustomAttribute <ApiGenIgnoreAttribute>() != null) { continue; } var commandType = methodInfo.GetParameters()[0].ParameterType; var attr = methodInfo.GetCustomAttribute <ApiGenActionAttribute>() ?? new ApiGenActionAttribute(); var originalName = commandType.Name.EndsWith("Command") ? commandType.Name.Substring(0, commandType.Name.Length - 7) : commandType.Name; var actionName = attr.ActionName ?? originalName; var httpMethod = attr.Method == default ? ApiMethods.Post : attr.Method; var method = new GeneratedMethod { Attributes = new HashSet <string>() { $"[Http{httpMethod.ToString()}(\"{actionName}\")]" }, IsAsync = true, ReturnType = "Task<IActionResult>", Name = originalName, Parameters = new List <string>() { $"[FromBody] {commandType.FullName} command" }, BodyLines = new List <string>() { "await Mediator.SendAsync(command);" }, ReturnValue = "return Ok();" }; _controllerGenerated[generatedControllerIndex].Methods.Add(method); } } }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.Write("// fake frame here"); Next?.GenerateCode(method, writer); }
public void GenerateSelectorCodeSync(GeneratedMethod method, int index) { method.AssignMemberFromReaderAsync(null, index, typeof(StreamAction), _member.Name); }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { var versionPosition = index;//mapping.IsHierarchy() ? 3 : 2; async.Frames.CodeAsync($"var version = await reader.GetFieldValueAsync<System.Guid>({versionPosition}, token);"); sync.Frames.Code($"var version = reader.GetFieldValue<System.Guid>({versionPosition});"); if (storageStyle != StorageStyle.QueryOnly) { // Store it sync.Frames.Code("_versions[id] = version;"); async.Frames.Code("_versions[id] = version;"); } if (Member != null) { sync.Frames.SetMemberValue(Member, "version", mapping.DocumentType, generatedType); async.Frames.SetMemberValue(Member, "version", mapping.DocumentType, generatedType); } }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine("FrameThatBuildsVariable"); }
void IStreamTableColumn.GenerateAppendCode(GeneratedMethod method, int index) { method.SetParameterFromMember <StreamAction>(index, x => x.TenantId); }
public FieldLoadAction(GeneratedMethod method, Func<FieldInfo> field) { this.method = method; this.field = field; }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { var variableName = "tenantId"; var memberType = typeof(string); if (Member == null) { return; } sync.Frames.Code($"var {variableName} = reader.GetFieldValue<{memberType.FullNameInCode()}>({index});"); async.Frames.CodeAsync($"var {variableName} = await reader.GetFieldValueAsync<{memberType.FullNameInCode()}>({index}, token);"); sync.Frames.SetMemberValue(Member, variableName, mapping.DocumentType, generatedType); async.Frames.SetMemberValue(Member, variableName, mapping.DocumentType, generatedType); }
public void GenerateAppendCode(GeneratedMethod method, EventGraph graph, int index) { method.SetParameterFromMember <IEvent>(index, x => x.TenantId); }
protected abstract void generateCode(GeneratedMethod method, ISourceWriter writer, Frame inner);
public override void GenerateCodeToSetDbParameterValue(GeneratedMethod method, GeneratedType type, int i, Argument parameters, DocumentMapping mapping, StoreOptions options) { method.Frames.Code($"{{0}}[{{1}}].Value = tenantId;", parameters, i); method.Frames.Code("{0}[{1}].NpgsqlDbType = {2};", parameters, i, DbType); }
public VariableLoadAction(GeneratedMethod method, int localIndex) { this.method = method; this.localIndex = localIndex; }
/// <summary> /// Implements the actual generation of the code for this <see cref="Frame" />, writing to /// the given <see cref="ISourceWriter" />. /// </summary> /// <remarks> /// <para> /// The <see cref="GeneratedMethod" /> given is the same as <see cref="_method" />, but is provided as /// a convenience parameter to make it more obvious it's available. /// </para> /// <para> /// The <see cref="ISourceWriter" /> given is the same as <see cref="_writer" />, but is provided as /// a convenience parameter to make it more obvious it's available. /// </para> /// <para> /// Frames <em>should</em> typically call <paramref name="next" /> to insert code from the next frame. If they /// do not then no further code is executed and this <see cref="Frame" /> therefore becomes the last frame /// of the method. /// </para> /// </remarks> /// <param name="variables">A source of variables, used to grab from other frames / <see cref="IVariableSource"/>s the /// variables needed to generate the code.</param> /// <param name="method">The method to which this <see cref="Frame" /> belongs.</param> /// <param name="writer">The writer to write code to.</param> /// <param name="next">The action to call to write the next frame (equivalent to calling <see cref="Next"/> directly).</param> protected abstract void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next);
void IStreamTableColumn.GenerateSelectorCodeSync(GeneratedMethod method, int index) { throw new System.NotImplementedException(); }
public override void GenerateCodeToSetDbParameterValue(GeneratedMethod method, GeneratedType type, int i, Argument parameters, DocumentMapping mapping, StoreOptions options) { method.Frames.Code($"{parameters.Usage}[{i}].{nameof(NpgsqlParameter.NpgsqlDbType)} = {{0}};", DbType); method.Frames.Code($"{parameters.Usage}[{i}].{nameof(NpgsqlParameter.Value)} = docType;"); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { base.GenerateCode(method, writer); writer.WriteLine($"{_operations.Usage}.Store({ReturnVariable.Usage});"); }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { if (storageStyle == StorageStyle.QueryOnly) { return; } sync.Frames.Code($"var id = reader.GetFieldValue<{mapping.IdType.FullNameInCode()}>({index});"); async.Frames.CodeAsync($"var id = await reader.GetFieldValueAsync<{mapping.IdType.FullNameInCode()}>({index}, token);"); if (storageStyle != StorageStyle.Lightweight) { sync.Frames.Code(IdentityMapCode); async.Frames.Code(IdentityMapCode); } }
public void GenerateSelectorCodeAsync(GeneratedMethod method, EventGraph graph, int index) { throw new System.NotImplementedException(); }
internal static MethodFrameArranger ToArranger(this GeneratedMethod method) { return(new MethodFrameArranger(method, new GeneratedType(new GenerationRules("SomeNamespace"), "SomeClassName"))); }
public LoadThisAction(GeneratedMethod method) { this.method = method; }
public VariableLoadAction(GeneratedMethod method, int localIndex) { this.method = method; this.localIndex = localIndex; }
public FieldLoadAction(GeneratedMethod method, Func<FieldInfo> field, GeneratedField parent) { this.method = method; this.field = field; this.parent = parent; }
public void GenerateAppendCode(GeneratedMethod method, int index) { method.SetParameterFromMember(index, _memberExpression); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine( $"return new {typeof(ValueTask).FullNameInCode()}<{_variableType.FullNameInCode()}>({_returnValue.Usage});"); }
public DeepConstructorGuy(IWidget widget, GeneratedMethod method, IVariableSource source) { }
public override void GenerateCode(GeneratedMethod method, GeneratedType type, int i, Argument parameters) { method.Frames.Code($"{parameters.Usage}[{i}].NpgsqlDbType = {{0}};", NpgsqlDbType.Jsonb); method.Frames.Code($"{parameters.Usage}[{i}].Value = {{0}}.Serializer.ToJson(_document);", Use.Type <IMartenSession>()); }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { sync.Frames.DeserializeDocument(mapping, index); async.Frames.DeserializeDocumentAsync(mapping, index); }
public CallBaseAction(Func<MethodBuilderBundle> bundle, Func<MethodInfo> method, IList<ITypeGenerationAction> actions, Type baseType, GeneratedMethod generatedMethod) : base(bundle, method, actions, generatedMethod) { this.baseType = baseType; }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.Write( $"var {_message.Usage} = ({_message.VariableType.FullNameInCode()}){_envelope.Usage}.{nameof(Envelope.Message)};"); Next?.GenerateCode(method, writer); }
/// <summary>This method adds a new method to the class contained within the generated Java source file</summary> /// <param name="method">the generated method to add /// </param> public virtual void addMethod(GeneratedMethod method) { methods.Add(method); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"var {Variable.Usage} = {Variable.VariableType.FullName}.{nameof(DateTime.UtcNow)};"); Next?.GenerateCode(method, writer); }
/// <summary>Adds min and max reps to the genrated classes</summary> /// <param name="minReps">the Minimum Repetitions /// </param> /// <param name="maxReps">Maximum Repetitions /// </param> public virtual void setMinMaxReps(short minReps, short maxReps) { GeneratedMethod maxRepsMethod = new GeneratedMethod(); GeneratedMethod minRepsMethod = new GeneratedMethod(); this.addMemberVariable("private final short MAX_REPS = " + maxReps + ";"); this.addMemberVariable("private final short MIN_REPS = " + minReps + ";"); // Creates the methos to return the maximum number of repitions for the generated Class DocumentationBuilder.getDocumentationBuilder().decorateMaxReps(maxRepsMethod); maxRepsMethod.Visibility = "public"; maxRepsMethod.ReturnType = "short"; maxRepsMethod.Name = "getMaxReps"; maxRepsMethod.addToBody("return this.MAX_REPS;"); this.addMethod(maxRepsMethod); // Creates the method to return the maximum number of repitions for the generated Class DocumentationBuilder.getDocumentationBuilder().decorateMaxReps(minRepsMethod); minRepsMethod.Visibility = "public"; minRepsMethod.ReturnType = "short"; minRepsMethod.Name = "getMinReps"; minRepsMethod.addToBody("return this.MIN_REPS;"); this.addMethod(minRepsMethod); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.Write($"var {Variable.Usage} = ({Variable.VariableType.FullNameInCode()}) {_scope.Usage}.{nameof(Scope.Root)};"); Next?.GenerateCode(method, writer); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.Write($"var {Variable.Usage} = {nameof(RouteHandler.ToPathSegments)}({Segments.Usage}, {Position});"); Next?.GenerateCode(method, writer); }
/// <summary>This method will build a primitive conformance class (ST, NM, etc) which is /// a Field. /// </summary> public virtual void buildClass(Genetibase.NuGenHL7.conf.spec.message.Field primitive, System.String parentUnderlyingType, ProfileName profileName) { GeneratedPrimitive genClass = new GeneratedPrimitive(); // Check for possible snags in the Runtime Profile Component if (primitive.Name == null || primitive.Name.Length < 1) throw new ConformanceError("Error building ConformanceSegment: Runtime AbstractComponent does not contain a name."); GeneratedMethod theConstructor = new GeneratedMethod(); genClass.Constructor = theConstructor; genClass.addClassImport("Genetibase.NuGenHL7.model.*"); UnderlyingAccessor underlyingAccessor = new UnderlyingAccessor(parentUnderlyingType, profileName.AccessorName); theConstructor.addParam(parentUnderlyingType + " parentSeg", "The parent underlying data type"); theConstructor.addParam("int rep", "The desired repetition"); theConstructor.Name = profileName.ClassName; theConstructor.Visibility = "public "; theConstructor.addToThrows("Genetibase.NuGenHL7.HL7Exception"); theConstructor.addToBody("super( (Primitive)parentSeg." + underlyingAccessor + " );"); theConstructor.addToBody("if ( parentSeg." + underlyingAccessor + " == null )"); theConstructor.addToBody(" throw new Genetibase.NuGenHL7.HL7Exception( \"Error accussing underlying object. This is a bug.\", 0 );"); // Set up class genClass.ClassPackage = packageName; //genClass.addClassImport("Genetibase.NuGenHL7.model.*"); genClass.addClassImport("Genetibase.NuGenHL7.conf.classes.abs.*"); //genClass.addClassImport( "Genetibase.NuGenHL7.conf.classes.exceptions.*" ); genClass.Properties = "extends AbstractConformanceDataType implements Repeatable"; // Add min and max reps stuff genClass.setMinMaxReps(primitive.Min, primitive.Max); genClass.Name = profileName.ClassName; docBuilder.decorateConstructor(genClass.Constructor, profileName.ClassName); // Add constant value constraints if there are any, if not, add a setter method if (primitive.ConstantValue != null && primitive.ConstantValue.Length > 0) { genClass.addConstantValue(primitive.ConstantValue); } else { GeneratedMethod setter = new GeneratedMethod(); setter.addParam("java.lang.String value"); setter.addToThrows("ConfDataException"); setter.addToBody("super.setValue( value );"); setter.ReturnType = "void"; setter.Visibility = "public"; setter.Name = "setValue"; docBuilder.decorateSetValue(setter, primitive.Length); genClass.addMethod(setter); genClass.addClassImport("Genetibase.NuGenHL7.conf.classes.exceptions.*"); } genClass.addMaxLength(primitive.Length); // Decorate with comments docBuilder.decoratePrimitive(genClass, primitive); if (depManager.Verbose) System.Console.Out.WriteLine("Generating Primitive: " + packageName + "." + genClass.Name); depManager.generateFile(genClass, packageName, genClass.Name); }
public override void GenerateCode(GeneratedMethod method, GeneratedType type, int i, Argument parameters) { method.Frames.Code("setCurrentVersionParameter({0}[{1}]);", parameters, i); }
/// <summary>Creates a new instance of GeneratedClass, /// creates a new instance of the all the memberVariables /// </summary> public GeneratedClass() { classImports = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); memberVariables = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); methods = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); classComments = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); license = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); constructor = new GeneratedMethod(); constructor.Visibility = "public"; classPackage = ""; properties = ""; }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.Write($"var {Variable.Usage} = {_root.Usage}.{nameof(IMessagingRoot.NewContext)}();"); Next?.GenerateCode(method, writer); }
public LoadValueAtIndexAction(GeneratedMethod method, GeneratedArray array, int index) { this.method = method; this.array = array; this.index = index; }
/// <summary>This method builds a Conformance Field Class</summary> /// <param name="field">the Field to build /// </param> /// <param name="parentUnderlyingType">the data type of the parent Segment for this field /// example "Genetibase.NuGenHL7.model.v24.segment.MSH" /// </param> /// <param name="profileName"> ProfileName /// </param> public virtual void buildClass(Field field, System.String parentUnderlyingType, ProfileName profileName) { GeneratedConformanceContainer gcc = new GeneratedConformanceContainer(); GeneratedMethod gm = new GeneratedMethod(); // Check for possible snags in the Runtime Profile Segment if (field.Name == null || field.Name.Length < 1) throw new ConformanceError("Error building ConformanceField: Runtime Field does not contain a name."); // Set up class gcc.ClassPackage = packageName; gcc.addClassImport("Genetibase.NuGenHL7.conf.classes.abs.*"); gcc.addClassImport("Genetibase.NuGenHL7.conf.classes.exceptions.*"); gcc.addClassImport("Genetibase.NuGenHL7.model.*"); gcc.addClassImport("Genetibase.NuGenHL7.*"); if (field.Components > 0) gcc.addClassImport(packageName + "." + profileName.PackageName + ".*"); gcc.Name = profileName.ClassName; gcc.Properties = "extends AbstractConformanceContainer implements Repeatable"; gcc.setMinMaxReps(field.Min, field.Max); underlyingType = "Genetibase.NuGenHL7.model." + versionString + ".datatype." + field.Datatype; gcc.addMemberVariable(underlyingType + " hapiType;"); gcc.addMemberVariable("private final short MAX_LENGTH = " + field.Length + ";"); gm.ReturnType = "long"; gm.Visibility = "public"; gm.Name = "getMaxLength"; gm.addToBody("return this.MAX_LENGTH;"); docBuilder.decorateMaxLength(gm); gcc.addMethod(gm); // Set up underlying Field type gcc.Constructor.addParam(parentUnderlyingType + " hapiSegment", "The underlying HAPI field object"); gcc.Constructor.addParam("int rep", "The desired repetition"); gcc.Constructor.addToBody("try {"); UnderlyingAccessor underlyingAccessor = new UnderlyingAccessor(parentUnderlyingType, profileName.AccessorName); gcc.Constructor.addToBody(" this.hapiType = hapiSegment." + underlyingAccessor + ";"); docBuilder.decorateConstructor(gcc.Constructor, profileName.ClassName); // Create the getters and member variables associated with each child for (int i = 1; i <= field.Components; i++) { //don't build not supported, backward, or unknown types System.String usage = field.getComponent(i).Usage; if (usage != null && (usage.Equals("X") || usage.Equals("B") || usage.Equals("U"))) continue; bool hasChildren = (field.getComponent(i).SubComponents > 0)?true:false; ProfileName childProfileName = new ProfileName(field.getComponent(i).Name, ProfileName.PS_COMP); gcc.addComponent(childProfileName, (short) (i - 1), hasChildren); } gcc.Constructor.addToBody("} catch ( HL7Exception e ) {"); gcc.Constructor.addToBody(" throw new ConformanceError( \"Invalid Attempt to access a rep. This is a bug.\" );"); gcc.Constructor.addToBody("}"); // Decorate with comments docBuilder.decorateField(gcc, field); if (depManager.Verbose) System.Console.Out.WriteLine("Generating Field: " + packageName + "." + gcc.Name); // Create the components for (int i = 1; i <= field.Components; i++) { if (field.getComponent(i).SubComponents == 0) { ConformancePrimitiveBuilder childBuilder = new ConformancePrimitiveBuilder(packageName + "." + profileName.PackageName, depManager); childBuilder.buildClass(field.getComponent(i), ProfileName.PS_COMP); } else { ConformanceComponentBuilder childBuilder = new ConformanceComponentBuilder(packageName + "." + profileName.PackageName, depManager, versionString); childBuilder.buildClass(field.getComponent(i)); } } depManager.generateFile(gcc, packageName, gcc.Name); }