Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7919
| From | Alex J <vstrength@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Annotations processing + type introspection + code generation |
| Date | 2011-09-12 15:06 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <c681c248-39e6-4a04-a2b1-57ff5158f121@l10g2000yqe.googlegroups.com> (permalink) |
| References | <b4cda2f5-442e-42f3-af75-5040215ba997@k15g2000yqd.googlegroups.com> <9d6rupF6dkU1@mid.individual.net> <64f52727-b962-4d6b-b445-f04321d863b7@l10g2000yqe.googlegroups.com> <9d70ubFj6fU1@mid.individual.net> |
On Sep 12, 10:21 pm, Robert Klemme <shortcut...@googlemail.com> wrote:
> On 12.09.2011 20:00, Alex J wrote:
>
> > On Sep 12, 8:56 pm, Robert Klemme<shortcut...@googlemail.com> wrote:
> >> [snip]
> >> Why do you want to generate code? I mean, you could process annotations
> >> at runtime. Create appropriate classes for the handling and configure
> >> appropriate graphs of objects which do the work (or even use reflection).
>
> > I need to generate *source* code, the boilerplate code is complex
> > enough, unfortunately bytecode is not an option.
>
> > One of the reason why I need generated code is that the boilerplate
> > code is quite sofisticated, learning generated docs and debugging the
> > generated code most likely will be required.
>
> > There are other reasons, but I think that this one would be
> > sufficient.
>
> Hm... If you need to generate a lot identical code there is something
> wrong: that identical code could be better implemented directly and
> used. So that leaves adapters and stuff Mark mentioned for generation.
> I am not convinced yet that it is a good idea to generate loads of
> complex code.
>
> Can you shed some more light on the nature of the application you are
> going to implement?
Yes, that's a prototype of tool that helps to implement a part of code
for you.
You (as a user) define interface, the tool tries to guess what you
want based on the name patterns, references to domain objects, etc.
Say you have the following:
@Specification // tells tool "this interface is a subject to be
processed"
interface PersonDao {
long savePerson(String name, int age);
Person getPerson(long id);
List<Long> getPersons();
}
interface Person {
String getName();
int getAge();
}
Then tool defines final class PersonDaoImpl and PersonImpl:
final class PersonDaoImpl implements PersonDao {
private static final class PersonImpl extends JdbcDaoSupport
implements Person {
private final String name;
private final int age;
PersonImpl(String name, int age) { this.name = name; this.age =
age; }
@Override public String getName() { return name; }
@Override public int getAge() { return age; }
}
@Override public long savePerson(String name, int age) {
getJdbcTemplate().update("INSERT INTO person (name, age) VALUES
(?, ?)", name, age);
return getJdbcTemplate.queryForInt("CALL identity()");
}
//.. etc.
}
This is not that simple as I gave above (as much more complex human-
friendly definitions might be involved), but this clearly describes
the idea.
I'm implementing this out of pure interest, as my hobby project :)
>
> Kind regards
>
> robert
>
> --
> remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Annotations processing + type introspection + code generation Alex J <vstrength@gmail.com> - 2011-09-12 06:21 -0700
Re: Annotations processing + type introspection + code generation Robert Klemme <shortcutter@googlemail.com> - 2011-09-12 18:56 +0200
Re: Annotations processing + type introspection + code generation markspace <-@.> - 2011-09-12 10:04 -0700
Re: Annotations processing + type introspection + code generation Robert Klemme <shortcutter@googlemail.com> - 2011-09-12 19:22 +0200
Re: Annotations processing + type introspection + code generation Alex J <vstrength@gmail.com> - 2011-09-12 11:08 -0700
Re: Annotations processing + type introspection + code generation Alex J <vstrength@gmail.com> - 2011-09-12 11:00 -0700
Re: Annotations processing + type introspection + code generation Robert Klemme <shortcutter@googlemail.com> - 2011-09-12 20:21 +0200
Re: Annotations processing + type introspection + code generation Alex J <vstrength@gmail.com> - 2011-09-12 15:06 -0700
csiph-web