[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Matching unwanted calls to toString()
|
I think the "args" pointcut expression is a binding device for the
arguments of an advised method, not a filtering device -- correct me
if I'm wrong, folks.
I don't think you can do what you mean with a compile-time check. The
closest that I think you can get is the following:
declare warning:
call(StringBuilder java.lang.StringBuilder.append(Object)):
"You're a bad person...";
Anything that's passed to a StringBuilder append method that isn't
known by StringBuilder will be passed to append(Object). That is,
StringBuilder's append only knows about things like Float/float,
Integer/int, String, StringBuilder, etc. If you call
new StringBuilder().append(new Foo())
it will get bound to the append(Object) method because there is no
append(Foo) method. You could add methods like append(Foo) to
java.lang.StringBuilder using introduction I suppose, but I don't
think that's really going to get you much.
If you want to know the actual type of the argument passed to
append(Object), you'd need to use a runtime pointcut and advice:
before(Object appended) : call(StringBuilder
java.lang.StringBuilder.append(Object)) && args(appended) {
System.out.println("Called StringBuilder.append(Object) with
instance of " + appended.getClass().getName());
}
HTH,
Matthew
On Mon, Mar 22, 2010 at 2:41 AM, Roland Illig <rillig@xxxxxxxxxxxx> wrote:
> Hi,
>
> in a current project, I want to find all calls to toString() methods which may generate unwanted text like "ClassName@1234567". For that, I have written the following AspectJ-like code:
>
> declare warning:
> call(* StringBuilder.append(Object))
> && !args(Exception)
> && !args(Integer)
> && !args(Double):
> "Hidden toString()";
>
> What I wanted to express is:
>
> * if the append(Object) method is called, give me a warning.
> * but don't do so if the compile-time type of the argument
> is an instanceof Exception, Integer or Double.
>
> Now the AspectJ compiler tells me I cannot use "args" in a declare statement. Why can't I?
>
> Roland
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
--
mailto:matthew@xxxxxxxxxxxxxxx
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:matthewadams12@xxxxxxxxx
msn:matthew@xxxxxxxxxxxxxxx
http://matthewadams.me
http://www.linkedin.com/in/matthewadams