code-generation

Generate a Version.java file in Maven

我的未来我决定 提交于 2019-11-27 06:13:57
I have a Java project that I build using an Ant script. I am trying to convert the project to Maven. One of the tasks generates a Java source file called Version.java that contains a static String representation of the compilation timestamp, as follows: package com.foo.bar; public final class Version { public static String VERSION="100301.1046"; } The Ant task is very simple: <target name="version" depends="init" description="Create Version.java"> <echo file="src/${package.dir}/Version.java" message="package ${package.name};${line.separator}" /> <echo file="src/${package.dir}/Version.java"

Type-safe generic data structures in plain-old C?

感情迁移 提交于 2019-11-27 05:04:27
问题 I have done far more C++ programming than "plain old C" programming. One thing I sorely miss when programming in plain C is type-safe generic data structures, which are provided in C++ via templates. For sake of concreteness, consider a generic singly linked list. In C++, it is a simple matter to define your own template class, and then instantiate it for the types you need. In C, I can think of a few ways of implementing a generic singly linked list: Write the linked list type(s) and

R.raw.anything cannot be resolved [duplicate]

最后都变了- 提交于 2019-11-27 04:36:38
This question already has an answer here: R cannot be resolved - Android error 106 answers I'm developing an android apps with Eclipse. In my app, I try to read a file : data.xml. I put it in res/raw/, and to access it i'm supposed to use getRessources().openRawResource(R.raw.data); But Eclipse show me an error : "data" cannot be resolved or is not a field. But the field is in the gen/R.java !!! public final class R { public static final class raw { public static final int data=0x7f040000; } } Any ideas ? Thanks Solution : Import the right R.java files ! import my_package.R; Stop trusting ctrl

GetEntryAssembly for web applications

耗尽温柔 提交于 2019-11-27 04:27:59
Assembly.GetEntryAssembly() does not work for web applications. But... I really need something like that. I work with some deeply-nested code that is used in both web and non-web applications. My current solution is to browse the StackTrace to find the first called assembly. /// <summary> /// Version of 'GetEntryAssembly' that works with web applications /// </summary> /// <returns>The entry assembly, or the first called assembly in a web application</returns> public static Assembly GetEntyAssembly() { // get the entry assembly var result = Assembly.GetEntryAssembly(); // if none (ex: web

Java reflection: How do I override or generate methods at runtime?

…衆ロ難τιáo~ 提交于 2019-11-27 04:20:40
问题 It is possible in plain Java to override a method of a class programmatically at runtime (or even create a new method)? I want to be able to do this even if I don't know the classes at compile time. What I mean exactly by overriding at runtime: abstract class MyClass{ public void myMethod(); } class Overrider extends MyClass{ @Override public void myMethod(){} } class Injector{ public static void myMethod(){ // STATIC !!! // do actual stuff } } // some magic code goes here Overrider altered =

SBT generate code using project defined generator

孤人 提交于 2019-11-27 03:50:35
问题 I'd like to compile a project which contains a java source generator and then compile the generated code within a single project. I.e: compile Generator.scala, run Generator.generate(outputDir), compile outputDir, package into a jar. I'm trying this: sourceGenerators in Compile <+= sourceManaged in Compile map { out => Generator.generate(out / "generated") } but sbt complains [error] Build.scala:1: object example is not a member of package org [error] import org.example.Generator Basically,

How can I see the machine code generated by v8?

南楼画角 提交于 2019-11-27 03:35:44
Does anybody know how I can see the actual machine code that v8 generates from Javascript? I've gotten as far as Script::Compile() in src/api.cc but I can't figure out where to go from there. I don't know how to invoke the disassembler from C++ code, but there is a quick-and-dirty way to get a disassembly from the shell. First, compile v8 with disassembler support: scons [your v8 build options here] disassembler=on sample=shell Now you can invoke the shell with the "--print_code" option: ./shell --print_code hello.js Which should give you something like this: --- Raw source --- print("hello

Dynamically generate classes at runtime in php?

故事扮演 提交于 2019-11-27 03:04:45
问题 Here's what I want to do: $clsName = substr(md5(rand()),0,10); //generate a random name $cls = new $clsName(); //create a new instance function __autoload($class_name) { //define that instance dynamically } Obviously this isn't what I'm actually doing, but basically I have unknown names for a class and based on the name, I want to generate the class with certain properties etc. I've tried using eval() but it is giving me fits over private and $this-> references... //edit Ok, obviously my

XJC Generating Integer Instead of int

隐身守侯 提交于 2019-11-27 03:00:08
问题 The following schema should be generating two primitive int fields in a Value class, but instead generates a primitive int for the element and java.lang.Integer for the attribute . <?xml version="1.0" encoding="UTF-8"?> <xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/test" xmlns:test="http://www.example.com/test" elementFormDefault="qualified"> <xsd:element name="values"> <xsd:complexType> <xsd:sequence minOccurs="0" maxOccurs=

Rails migration for has_and_belongs_to_many join table

£可爱£侵袭症+ 提交于 2019-11-27 02:36:39
How do I do a script/generate migration to create a join table for a has_and_belongs_to_many relationship? The application runs on Rails 2.3.2, but I also have Rails 3.0.3 installed. Where: class Teacher < ActiveRecord::Base has_and_belongs_to_many :students end and class Student < ActiveRecord::Base has_and_belongs_to_many :teachers end for rails 4: rails generate migration CreateJoinTableStudentTeacher student teacher for rails 3: rails generate migration students_teachers student_id:integer teacher_id:integer for rails < 3 script/generate migration students_teachers student_id:integer