code-generation

How do I get Eclipse to resolve classes generated with Maven 2?

不羁岁月 提交于 2019-11-27 10:01:52
问题 I'm using Google Protocol Buffers to generate some Java classes for my project. Using Maven 2 and its "antrun" plugin, these classes are freshly generated before compile, output to target/generated-sources and put on the classpath during the build. So building the project from the POM is no problem. However, Eclipse doesn't know how to resolve the generated class, because the folder it's in doesn't seem to be on the IDE's classpath during development. I'm using m2eclipse and have it manage

How to make CMake reconfiguration depend on custom file?

风格不统一 提交于 2019-11-27 09:30:36
I have a project under CMake with some files generated with python generator from XML files. I cannot specify all files generated by this generator in CMakeLists.txt so I use file globbing for this. The problem is that when I update my XML files or generator sources (which are in the same repository) I would like to have my build system reconfigured so changed files are taken into account when rebuilding the code (via make for example). Is it possible to make CMake treat some files like it treats CMakeLists.txt files and to make it regenerate build system when those file are changed? Yes, you

Generating Delegate Types dynamically in C#

强颜欢笑 提交于 2019-11-27 09:08:55
We have a requirement where we need to generate delegate types on the fly. We need to generate delegates given the input parameters and the output. Both input and output would be simple types. eg, we need to generate int Del(int, int, int, string) and int Del2(int, int, string, int) Any pointers on how to get started on this would be very helpful. We need to parse formulate which are represented as xml. For example, we represent (a + b) as <ADD> <param type="decimal">A</parameter> <param type="decimal">B</parameter> </ADD> We now want this to be exposed as Func<decimal, decimal, decimal> . We

Can't access Parent's Members while dealing with Macro Annotations

天涯浪子 提交于 2019-11-27 08:57:55
I am kind of blocked with the following ( macro annotation ) situation. Suppose I have an annotation called @factory which aims to generate an apply method for the annotated trait in the corresponding companion object. For instance, given the trait A : @factory trait A { val a1: Int } the expected code to be generated is the following one: object A extends Factory[A] { def apply(_a1: Int) = new A { val a1 = _a1 } } Now suppose we have a trait B which inherits from A : @factory trait B extends A { val b1: String } which is supposed to generate: object B extends Factory[B] { def apply(_a1: Int,

Are there alternatives to cglib? [closed]

心不动则不痛 提交于 2019-11-27 08:56:53
问题 Just out of curiosity, are there any (stable) open source projects for runtime java code generation other than cglib? And why should I use them? 回答1: ASM java-asm CGLIB and almost all other libraries are built on top of ASM which itself acts on a very low level. This is a show-stopper for most people as you have to understand the byte code and a little bit of the JVMS to use it properly. But mastering ASM is most certainly very interesting. Note however that while there is a great ASM 4 guide

Formatting Literal parameters of a C# code snippet

血红的双手。 提交于 2019-11-27 08:49:43
Is there any way that I can change how a Literal of a code snippet renders when it is used in the code that the snippet generates? Specifically I'd like to know if I can have a literal called say, $PropertyName$ and then get the snippet engine to render "_$PropertyName$ where the first character is made lowercase. I can't afford R#. Please help :) Caerbanog Unfortunately there seems to be no way. Snippets offer amazingly limited support for transformation functions as you can see. You have to stick with the VS standard solution, which is to write two literals: one for the property name, and

How can I add my attributes to Code-Generated Linq2Sql classes properties?

梦想与她 提交于 2019-11-27 08:03:12
I would like to add attributes to Linq 2 Sql classes properties. Such as this Column is browsable in the UI or ReadOnly in the UI and so far. I've thought about using templates, anybody knows how to use it? or something different? Generally speaking, would do you do to address this issue with classes being code-generated? As requested, here's an approach using a CustomTypeDescriptor to edit the attributes at run-time; the example here is win-forms, but it should be pretty simple to swap it into WPF to see if it works... using System; using System.Collections.Generic; using System

Is it possible to programmatically compile java source code in memory only?

旧街凉风 提交于 2019-11-27 06:54:25
I have found many references explaining how to programmatically compile a Java class using the JavaCompiler class: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int result = compiler.run(null, null, null, "a_file_name"); However, I would like to know if there is an open source library that let me compile source code generated programmatically (therefore without a src file being involved) and generate some byte code in an output stream (without generating a class file in the file system). For example, I am looking for being able to write something like this: InputStream input =

How to emit and execute Java bytecode at runtime?

痴心易碎 提交于 2019-11-27 06:44:59
I am writing an interpreter in Java for a domain-specific language with some scripting capabilities. I have already implemented a parser and now need to do a back end. To this end I am considering either to write my own interpreter (either working with abstract syntax trees or with some custom bytecodes) or target JVM (emit and execute Java bytecode at runtime). Could someone with more experience in this area say how feasible is the approach of targeting JVM and what libraries would you recommend to use for emitting Java bytecode? Here is a working "hello world" made with ObjectWeb ASM (a

NHibernate Code Generation

☆樱花仙子☆ 提交于 2019-11-27 06:26:42
问题 I am working with NHibernate, and a few code generation tools. MyGeneration is one and SmartCode is the other. This question has been asked before, but I have looked at some other responses and found that the code generation tools in the nHibernate space to be pretty poor. I might be able to get away with MyGeneration and SmartCode, but are there any other possibilities out there that you have specifically used, and would recommend? I guess my criteria is that they must work with MSSQL 2008,