Skip to main content

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

Hi Matthew,


Matthew Adams wrote:
=====================
// DOES NOT COMPILE
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()?
    }
}
=====================

you cannot use type patterns when declaring an ITD. The syntax of ITD expects a simple type, not a pattern.

So you can write :

public String SomeClass.toString() { ... }

But you cannot write :

public String ((@Entity *)).toString() { ... }

Instead you have to do as you have already done with the Intro interface : declare an empty marker interface, then tell AspectJ to inject methods to that interface, then use declare parents to place the interface using a type pattern.

You should be able to declare also constructors this way.

I'm also using ApsectJ + OpenJPA enhancer, and I'm not facing the problem this problem, but probably I don't have fields initialized calling a static method. Since OpenJPA enhances the class AFTER ajc (for me too), it should see all the fields and methods that ajc has added to the entity classes correctly (it surely does for property).

If the OpenJPA introduced constructor does not take into account the fields added by AspectJ then maybe you're hitting a bug in the OpenJPA enhancer.

Hope this helps,
Simone

--
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/



Back to the top