Hello,
I am implementing a static cross cutting concern that enforces coding
standards on a project that I am working on. These standards extend beyond
those available via FindBugs and fb-contrib, are really only good to have
and not bugs. I could write a FindBugs extension detector, but that just
seems too much effort for me.
One of the standards that I would like to enforce is the Null Object
pattern for return type, rather than returning null. In effect I would like
to do something as follows
declare warning : <pointcut definition to capture null return values> :
"Coding standards enforced on project require use of Null Object";
or being more specific
declare warning : on returning null : "Coding standards enforced on
project require use of Null Object";
or being more generic
declare warning : on returning typepattern : "Some message"
(typepattern allows null)
I can think of at least one other use case, where it would be a warning to
return a type rather than return the interface type.
declare warning : on returning ArrayList : "Use the List interface type";
Is there any way to accomplish this right now using the existing pointcut
definition language?
I realize that I could accomplish something similar using around/after
advice and return a Null Object when the return value is null, but that
seems too cumber some to me at this time. I would have to find out the
return type of the method and return a Null Object which would be assignable
to the type, i.e. an around/after advice definition for each return type
where I would like to enforce Null Object.
Extracting an interface and defining my advice against a pointcut capturing
the interface in return types is an option too, but new types could not be
checked for without a change in the aspect, I guess dynamic proxies are an
alternative here, but then I'd rather do the findbugs detector.
I very well might be "special" in this instance and trying to do something
extremely dumb or something never intended to be done using aspectj, in
which case I can write the findbugs detector
Thanks
Bhaskar
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users