code-generation

Generating a model with many to many in Ruby on Rails

泄露秘密 提交于 2019-12-03 10:50:45
Is there a way to generate a Rails model with a many to many relationship predefined? I know how to add it to the Active Record after the fact but it would be nice to have it defined in the DB migration and the Active Record model right off the bat. Hitham S. AlQadheeb Remember that you do not want an id for the join table, so make sure to add :id => false |t| create_table assemblies_parts, :id => false do |t| t.integer :assembly_id t.integer :part_id end If you use rails rails generate model Assemblies_parts assembly:references part:references you will have two indexes, but what you want is #

Is there Python Clang wrapper in the vein of pygccxml which wraps GCC-XML?

时光怂恿深爱的人放手 提交于 2019-12-03 10:34:35
For a long time now I've been using pygccxml to parse and introspect my C++ source code: it helps me to do some clever code-generation during our build process. Recently I've read a lot about the benefits of the LLVM stack, and especially the benefits that the LLVM Clang parser brings to C++ compilation. I am now wondering if there is any Python interface to Clang such that I could use it as the basis for some of my existing code generation tasks? After further digging I found that in the LLVM 2.7 release there could be the beginings of something useful: In the LLVM 2.7 time-frame, the Clang

suppress warning for generated c# code

有些话、适合烂在心里 提交于 2019-12-03 09:53:24
I have turned on "Treat warnings as errors" for my VS project which mean that I get errors for missing documentation (nice reminder for this particular project). However, part of the code is generated by a custom tool which does not insert xml documentation so I'm looking for away to ignore the missing xml documentation for the generated code only, not for the entire project. I have no influence on the actual file generated and cannot really insert anything in the file (as it is regenerated frequently by the tool) so I looking for something existing outside the generated file (the classes that

What are CPU registers and how are they used, particularly WRT multithreading?

非 Y 不嫁゛ 提交于 2019-12-03 08:51:20
问题 This question and my answer below are mainly in response to an area of confusion in another question. At the end of the answer, there are some issues WRT "volatile" and thread synchronisation that I'm not entirely confident about - I welcome comments and alternative answers. The point of the question primarily relates to CPU registers and how they are used, however. 回答1: CPU registers are small areas of data storage on the silicon of the CPU. For most architectures, they're the primary place

Using a DSL to generate C# Code

送分小仙女□ 提交于 2019-12-03 07:49:15
Currently the project I'm working with does not have completely fixed models (due to an external influence) and hence I'd like some flexibility in writing them. Currently they are replicated across three different layers of the application (db, web api and client) and each has similar logic in it (ie. validation). I was wondering if there is an approach that would allow me to write a model file (say in ruby), and then have it convert that model into the necessary c# files. Currently it seems I'm just writing a lot of boilerplate code that may change at any stage, whereas this generated

Do any Java libraries use annotations for code generation?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 07:35:48
Is anyone aware of a library that uses the the techniques (annotations and classworking) described in this article for automatically generating the standard Object methods toString(), equals() and hashcode() for standard java classes? Yes, project Lombok does this. See http://projectlombok.org . It not only supports javac, but also Eclipse. So the methods are not in the source code, but are displayed in the outline view. I certainly haven't seen this and I'm not really sure what value would be gained from it. I find that automatic toString generation is not usually what you want when scouring

Generating PHP code (from Parser Tokens)

二次信任 提交于 2019-12-03 07:26:59
Is there any available solution for (re-)generating PHP code from the Parser Tokens returned by token_get_all ? Other solutions for generating PHP code are welcome as well, preferably with the associated lexer/parser (if any). If I'm not mistaken http://pear.php.net/package/PHP_Beautifier uses token_get_all() and then rewrites the stream. It uses heaps of methods like t_else and t_close_brace to output each token. Maybe you can hijack this for simplicity. wen From my comment: Does anyone see a potential problem, if I simply write a large switch statement to convert tokens back to their string

Is there a programatic way to identify c# reserved words?

做~自己de王妃 提交于 2019-12-03 07:11:56
问题 I'm looking for a function like public bool IsAReservedWord(string TestWord) I know I could roll my own by grabbing a reserve word list from MSDN. However I was hoping there was something built into either the language or .NET reflection that could be relied upon so I wouldn't have to revisit the function when I move to newer versions of C#/.NET. The reason I'm looking for this is I'm looking for a safeguard in .tt file code generation. 回答1: CSharpCodeProvider cs = new CSharpCodeProvider();

Generate database schema from NHibernate mapping

守給你的承諾、 提交于 2019-12-03 06:55:45
Is it possible to generate the database schema from the Nhibernate mappings DLL? My requirements is for MySQL. If so, how do I do that? Are there tools/scripts for this? Open source/freeware tools? Additionally, can I use these tools to insert/update datasets to the database? AJ. Have you tried using NHibernate's built-in schema generation tool ? var cfg = new NHibernate.Cfg.Configuration(); cfg.Configure(); cfg.AddAssembly(typeof(AnEntityInYourMappingLib).Assembly); new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false); I use this code : public void

Create hash from string and int

佐手、 提交于 2019-12-03 06:54:17
I remember eclipse and idea have this template to automatically create an object's hashCode based on its attributes. One of the strategies if a number and a string is used is something like this. return stringValue.hashCode() + intValue * 32; Ooor something like that. I don't have nor eclipse or idea at hand and I would like to create such function. EDIT Based on the answers I create this mini-class class StringInt { private final String s; private final int i; static StringInt valueOf( String string , int value ) { return new StringInt( string, value ); } private StringInt( String string, int