[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] How to declare an error when implementations of an interface doesn't supply a certain constructor
|
2006/1/12, Hidehiko Masuhara <masuhara@xxxxxxxxx>:
> My apologies to for my previous message, which is accidentally sent to
> the entire list. But I thought that the problem might be solved by
> our extended AspectJ compiler (called SCoPE), which allows you to
> write declarations by using if-pointcut like:
> declare error: staticinitialization(...) &&
> if(thisJoinPoint.getSignature()....)
>
> I'd like to send our solution again when we find the way to do it.
> More information on SCoPE can be found from the follwing address:
> http://www.graco.c.u-tokyo.ac.jp/ppp/projects/scope/
FYI, a solution with SCoPE looks like below. (Due to current compiler
restrictions, the actual code is slightly uglyer.) The method
hasConstructor checks if the given join point is declared in a class
that has a constructor with the given parameter types by using
reflection API.
public aspect OptionAspect {
static boolean hasConstructor(JoinPoint jp, Class[] parameterTypes) {
try { // test if the join point is declared in a class that
// has a constructor with specified parameter types.
jp.getSignature().getDeclaringType()
.getDeclaredConstructor(parameterTypes);
return true; // when there is a constructor
} catch (NoSuchMethodException e) {
return false; // when no such a constructor
}
}
declare error:
staticinitialization(IOption+) &&
if(!hasConstructor(thisJoinPoint, new Class[] { OptionType.class })) :
"IOption implementations must provide a constructor which accepts
an OptionType";
}
Although this is not a solution with current AspectJ compilers, I hope
someone might be interested in it.
Regards,
Hidehiko
>
> Best regards,
>
> Hidehiko
>
> 2006/1/12, Jeppe Cramon <jeppe@xxxxxxxxx>:
> > Hi
> >
> > I'm trying to declare an error when implementations of a certain
> > interface doesn't supply a certain constructor.
> > I'm both having difficulty limiting the scope to only implementations of
> > the interface (IOpen+) seems too large a granularity and specifying the
> > constructor.
> >
> > I've tried with this aspect:
> >
> > public aspect OptionAspect {
> > declare error: staticinitialization(IOption+) &&
> > !execution(IOption+.new(OptionType)) : "IOption implementations must
> > provide a constructor which accepts an OptionType";
> > }
> >
> > Could you give me a pointer to what I'm missing/doing wrong?
> >
> > Thanks in advance :)
> >
> > /Jeppe
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
>