[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Problems with generic aspects
|
I am pretty sure it is a bug. My little program exhibits exactly the
same problem:
----8<-----
abstract aspect Replicate<T> {
protected pointcut broadcast(T servant);
void around(T servant): broadcast(servant) {
proceed(servant);
}
}
aspect ReplicateConcrete extends Replicate<Foo> {
protected pointcut broadcast(Foo servant) : call(* *.setScene(..))
&& target(servant);
}
public class Foo {
public static void main(String []argv) {
new Foo().setScene();
}
public void setScene() {}
}
----8<-----
You *could* change the around advice signature from:
void around(T servant): broadcast(servant) {
to
void around(Object servant): broadcast(servant) {
which causes code to be generated that doesn't need the cast. But I'm
not sure how much of a mess that will make in your advice body.
Andy.
On 16/02/07, Nuno Santos <developer@xxxxxxxxxxxxxx> wrote:
Hi,
Are you sure it's a bug?
Is there any possibility of being something something else in my code?
Best regards,
Nuno
Look below
Concrete:
package section3.raytracer;
public aspect ReplicateConcrete extends Replicate<JGFRayTracerBench> {
protected pointcut broadcast(JGFRayTracerBench servant) : call(*
*.setScene(..)) && target(servant) /*within*/;
}
Abstract:
package section3.raytracer;
import java.util.HashMap;
import java.util.Vector;
public abstract aspect Replicate<T> {
int numberOfWorkers=4;
HashMap <T,Vector<T>> aggregates = new HashMap<T,Vector<T>>();
HashMap <Integer,T> id = new HashMap<Integer,T>();
boolean debug = true;
protected pointcut broadcast(T servant); // broadcast funtion
protected pointcut scatter(T servant, Object arg); // scatter function
protected pointcut reduce(T servant); // reduction function
T around() : call( T.new() ) {
if (debug) System.out.println("Number of workers: " + numberOfWorkers);
System.out.println("Creating aggregate of " + numberOfWorkers + "
workers");
Vector <T>elements = new Vector<T>();
T target = proceed(); // create aggregate representative
setId(0,target);
elements.add(target);
for(int i=1; i<numberOfWorkers; i++) {
System.out.println("Creating aggregate worker number: " + i);
T targetn = proceed();
//T targetn = new T();
if (debug) System.out.println("Memory address for worker with id " + i + ":
" + targetn);
setId(i,targetn);
elements.add(targetn);
}
aggregates.put(target,elements);
return(target);
}
void around(T servant): broadcast(servant) {
if (debug) System.out.println("Broadcasting...");
for(int i=0; i<numberOfWorkers; i++) {
Vector<T> elements = aggregates.get(servant);
final T obj = elements.elementAt(i);
}
proceed(servant);
}
public Object getId(int i) {
return id.get(i);
}
public void setId(int i,T b) {
id.put(i,b);
}
}
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users