[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] within{static}initialization - was Re: [aspectj-users] withincode(clinit)

Very neat!
But one suggestion (you might consider this not so important): try to write down a few times those pointcut names.... to me they seem quite annoying :-).


[quote Wes Isberg::on 12/22/2004 2:07 PM]
Hi -

(proposal for new lexical pointcut below)

I am trying to figure out if there is a special syntax for using a withincode(<clinit>) other than:

within(TypeX) && !withincode(* TypeX.*(..)) && !withincode(TypeX.new(..))

This says, "anything in TypeX except stuff in methods and constructors," but would also pick out instance field initializers, adviceexecution, pre-initialization, etc. You could continue along this vein by excluding all these other join points. (minor point: code not upwards-compatible with enhanced join point model.)

Ganesh's cflow suggestion works

  cflow(staticinitialization(TypeX)) && {not too much else}

at the expense of a dynamic pointcut.

I'd agree w/Ramnivas that there is a bucket here that might be useful to scope the code that's involved in class or object initialization. Ironically, the code is scattered in source but a
Java compiler gathers all the initializers, etc. into one class or
instance initialization chunk of code that can be staticly scoped.

So perhaps two new "lexical" pointcuts:

  - withinstaticinitialization(TypePattern)
  Restricts the scope of the join points picked out to those join
  points associated with static (class) initialization
  within types matched by {TypePattern}.

- withininitialization(TypePattern)
Restricts the scope of the join points picked out to those join
points associated with object (instance) initialization
within types matched by {TypePattern}, including object initialization, preinitialization, and constructors.

Neither form will exclude methods that might be called during initialization or superclass initialization code.
[need to comment on aspect-defined initialization code]

Code that might be useful to write:

/** setting field outside setter or init */
set(* T.*) && !withincode(void set*(*)) && !withininitialization(T) && !withinclassinitializatin(T)

  /** accessing other statics during init */
  get(static * T.*) && withinclassinitialization(T)

  /** instance field-set in initialization but outside constructors */
  set(!static * T.*) && withininitialization(T) && !within(T.new(..))

  pointcut throwsUncheckedExceptions() : call(void blah()) || ...;
  /** find touchy calls in static initializers */
  throwsUncheckedExceptions() && withinclassinitialization(T)

Note these all could be used in declare-warning.

Are there any (other) compelling use-cases?


P.S. - "associated with" is clearly fudge language, to be explicated
by reference to JLS/VMS language about initialization blocks.

aspectj-users mailing list