[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Constructor ITD question: introduce no-arg ctor instead of letting JDO/JPA enhancer do it?

I'm having some trouble getting around a problem I'm having with field
initialization and a persistence enhancer (OpenJPA's, but any JDO or
JPA enhancer will suffer this problem).  The build process is to first
compile with ajc, then enhance, which adds a no-arg constructor.
Problem is, since the enhancer adds the constructor **after** ajc
compilation, introduced fields are not initialized.

Is there a way to introduce a constructor to any class with a given
annotation that doesn't already have a no-arg constructor of any
visibility such that field initialization takes place?  This would
prevent the enhancer from adding a no-arg constructor after aspect

JPA Example where a UUID field is being introduced with its field
initialization inlined:

public class Foo {
    @Id protected Long id;
    // ...
public interface HasUuid { UUID getUuid(); }
public aspect HasUuidMixin {
    public static interface Intro extends HasUuid {}
    declare parents:  (@Entity *) implements Intro;
    private UUID Intro.uuid = UUID.randomUUID();
    public UUID Intro.getUuid() { return uuid; }
public aspect NoArgConstructorMixin {
    public ((@Entity *) && !hasmethod(* new())).new() { // can't
introduce constructors with this syntax
        // how do I ensure fields are initialized in here?  call super()?