[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Bad code smells in AspectJ?
|
Hi neil,
maybe I'm wrong, but if you are intercepting a constructor, can't you
simply call proceed() to obtain the correct instance ?
public aspect X<T> {
pointcut myPct() : call(public T.new());
T around() : myPct() {
T ret = (T)proceed();
if(someTest) {
// do something with ret
}
return ret;
}
}
I can't remember exactly, but I think I already used an around advice on
a costructor to intercept object creation, an I suppose this can work
also on generics as long as rest of the aspect is supported.
Hope this helps,
Simone
neil loughran wrote:
> Hi,
>
> I have an issue where I am seeing the same kind of code in several of my
> aspects. For example in the following SomeClass appears at several points
> which makes me think generics would be a solution.
>
>
> public aspect X {
> pointcut myPct() : call(public SomeClass.new());
>
> SomeClass around() : myPct() {
> if(someTest) {
> SomeClass s = new SomeClass();
> // do something with s
> return s;
> }
> else proceed();
> }
> }
>
>
> Generic version.
>
> abstract aspect X<T> {
> pointcut myPct() : call(public T.new());
>
> T around() : myPct() {
> if(someTest) {
> T s = new T(); // error
> // do something with s
> return s;
> }
> else proceed();
> }
> }
>
>
> Unfortunately, it is not possible to instantiate a generic type from within
> the aspect. Just wondering if there was a way around this?
>
> Regards
> Neil
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>