Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » How to include/exclude basic types in pointcuts?
How to include/exclude basic types in pointcuts? [message #47485] Mon, 07 February 2005 21:09 Go to next message
Michael Moser is currently offline Michael MoserFriend
Messages: 914
Registered: July 2009
Senior Member
Hi all,
our application creates some datastructure that need to be
java.io.Serializable (we use that format to transfer the data to
another system and then deserialize it there).

To make sure we do not inadvertedly refer to any non-serializable,
non-transient fields I wrote the below aspect to yield a compile error
if we do:

----------------------
import java.io.Serializable;

public aspect SerializableCheck
{
pointcut nonSerializableAccesses():
set (!transient !Serializable+ foo.bar.*.*);

declare error:
nonSerializableAccesses()
&& !adviceexecution()
: "use of non-serializable field!";
}
----------------------

This aspect in principle seems to work, at least it already pointed me
out, that at some point we were using a Map - which indeed is not
serializable (only some implementations of the Map-interface are, but
not all!) - but now I am stuck, since I get many errors in statements
that refer to basic types (like boolean, int, float, ...). I thought
these were "java.io.Serializable" by definition, aren't they!?!

Probably these fields are treated special in the compiler anyway,
since there is no "Class" associated with them and hence the check
whether they implement the Serializable interface fails. But then one
would need some mechanism in the AspectJ language to exclude these
basic types from such pointcuts. Can one do that?

Any ideas or suggestion how to tackle this? Or should I file yet
another bug-/feature-request?

Cheers,
Michael
Re: How to include/exclude basic types in pointcuts? [message #47666 is a reply to message #47485] Wed, 09 February 2005 10:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adrian_colyer.uk.ibm.com

Michael Moser wrote:

> public aspect SerializableCheck
> {
> pointcut nonSerializableAccesses():
> set (!transient !Serializable+ foo.bar.*.*);


> This aspect in principle seems to work, at least it already pointed me
> out, that at some point we were using a Map - which indeed is not
> serializable (only some implementations of the Map-interface are, but
> not all!) - but now I am stuck, since I get many errors in statements
> that refer to basic types (like boolean, int, float, ...). I thought
> these were "java.io.Serializable" by definition, aren't they!?!

> Probably these fields are treated special in the compiler anyway,
> since there is no "Class" associated with them and hence the check
> whether they implement the Serializable interface fails. But then one
> would need some mechanism in the AspectJ language to exclude these
> basic types from such pointcuts. Can one do that?

The secret is that primitive types do not extend Object. So the pointcut
expression:

set(!transient (Object+ && !Serializable+) foo.bar.*.*);

should do what you need...
Re: How to include/exclude basic types in pointcuts? [message #47696 is a reply to message #47666] Wed, 09 February 2005 16:15 Go to previous message
Michael Moser is currently offline Michael MoserFriend
Messages: 914
Registered: July 2009
Senior Member
Bingo - that did the trick! Thanks to the *real* expert!

Michael

"Adrian Colyer" <adrian_colyer@uk.ibm.com> wrote in message
news:cucou2$kuc$1@www.eclipse.org...
> Michael Moser wrote:
>
>> public aspect SerializableCheck
>> {
>> pointcut nonSerializableAccesses():
>> set (!transient !Serializable+ foo.bar.*.*);
>
>
>> This aspect in principle seems to work, at least it already pointed
>> me out, that at some point we were using a Map - which indeed is
>> not serializable (only some implementations of the Map-interface
>> are, but not all!) - but now I am stuck, since I get many errors in
>> statements that refer to basic types (like boolean, int, float,
>> ...). I thought these were "java.io.Serializable" by definition,
>> aren't they!?!
>
>> Probably these fields are treated special in the compiler anyway,
>> since there is no "Class" associated with them and hence the check
>> whether they implement the Serializable interface fails. But then
>> one would need some mechanism in the AspectJ language to exclude
>> these basic types from such pointcuts. Can one do that?
>
> The secret is that primitive types do not extend Object. So the
> pointcut expression:
>
> set(!transient (Object+ && !Serializable+) foo.bar.*.*);
>
> should do what you need...
>
>
>
Re: How to include/exclude basic types in pointcuts? [message #586531 is a reply to message #47485] Wed, 09 February 2005 10:33 Go to previous message
Adrian Colyer is currently offline Adrian ColyerFriend
Messages: 61
Registered: July 2009
Member
Michael Moser wrote:

> public aspect SerializableCheck
> {
> pointcut nonSerializableAccesses():
> set (!transient !Serializable+ foo.bar.*.*);


> This aspect in principle seems to work, at least it already pointed me
> out, that at some point we were using a Map - which indeed is not
> serializable (only some implementations of the Map-interface are, but
> not all!) - but now I am stuck, since I get many errors in statements
> that refer to basic types (like boolean, int, float, ...). I thought
> these were "java.io.Serializable" by definition, aren't they!?!

> Probably these fields are treated special in the compiler anyway,
> since there is no "Class" associated with them and hence the check
> whether they implement the Serializable interface fails. But then one
> would need some mechanism in the AspectJ language to exclude these
> basic types from such pointcuts. Can one do that?

The secret is that primitive types do not extend Object. So the pointcut
expression:

set(!transient (Object+ && !Serializable+) foo.bar.*.*);

should do what you need...
Re: How to include/exclude basic types in pointcuts? [message #586538 is a reply to message #47666] Wed, 09 February 2005 16:15 Go to previous message
Michael Moser is currently offline Michael MoserFriend
Messages: 914
Registered: July 2009
Senior Member
Bingo - that did the trick! Thanks to the *real* expert!

Michael

"Adrian Colyer" <adrian_colyer@uk.ibm.com> wrote in message
news:cucou2$kuc$1@www.eclipse.org...
> Michael Moser wrote:
>
>> public aspect SerializableCheck
>> {
>> pointcut nonSerializableAccesses():
>> set (!transient !Serializable+ foo.bar.*.*);
>
>
>> This aspect in principle seems to work, at least it already pointed
>> me out, that at some point we were using a Map - which indeed is
>> not serializable (only some implementations of the Map-interface
>> are, but not all!) - but now I am stuck, since I get many errors in
>> statements that refer to basic types (like boolean, int, float,
>> ...). I thought these were "java.io.Serializable" by definition,
>> aren't they!?!
>
>> Probably these fields are treated special in the compiler anyway,
>> since there is no "Class" associated with them and hence the check
>> whether they implement the Serializable interface fails. But then
>> one would need some mechanism in the AspectJ language to exclude
>> these basic types from such pointcuts. Can one do that?
>
> The secret is that primitive types do not extend Object. So the
> pointcut expression:
>
> set(!transient (Object+ && !Serializable+) foo.bar.*.*);
>
> should do what you need...
>
>
>
Previous Topic:Cannot create part for *.aj file?
Next Topic:Cannot create part for *.aj file?
Goto Forum:
  


Current Time: Fri Nov 08 21:53:47 GMT 2024

Powered by FUDForum. Page generated in 0.03076 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top