[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Using AspectJ to error when an implementing class does not declare a constructor
|
Wes Isberg wrote:
public aspect RequiredConstructor {
declare error : execution((!Module && Module+).new(..))
&& !execution(new(Module.ModuleContext,..))
: "Module constructor should take a ModuleContext";
}
interface Module {
public interface ModuleContext {
String getSetting(String name);
}
}
class A implements Module {} // error here
class B implements Module {
B(Module.ModuleContext context, int i) {}
}
class C implements Module {
C(Module.ModuleContext context) {}
}
class D implements Module {
D(int i) {} // error here
}
Wes, thanks for that. When I tried it it gave me loads of errors in
really odd places (like a Module implementation that had an ArrayList
member initialisation). Then I realised that the classes it was
erroring on implemented both the Module interface and another interface
that extends Module:
interface FooModule extends Module {
}
class E implements Module, FooModule {
E(Module.Context context) {}
}
When I put this into your example classes it gives an error on the
constructor of E!
It's easy enough for me to throw out the 'extends' bit on my interfaces
to fix this but maybe this is a bug in the ajc?
I've only got one more really odd error in an Application class that
doesn't implement Module but does use it. I'll see if I can work that
one out too.
Matt