English 中文(简体)
利用AspectJ
原标题:Get method parameter values using AspectJ

I am using AspectJ to capture method calls. Then I need to get the method name and the parameter values passed. Let s have the following example:

Line2D line = new Line2D.Double(lineStart, lineEnd);
and graphics.draw(line);

我需要抓住所有电话。 我有这样的一点:

pointcut captureCallParameters(Shape name) : call(* *(Shape)) && args(name);

问题在于我试图获得参数的价值(这种方法中的沙伯)。 我拿到这个参数:java.awt.geom.Line2D$Double@596e1fb1

在Instad,我想得到在此情况下的形状点。

On the other hand I have also a pointcut that matches the construction of the new line mentioned above and I am able to get the parameters of that line. BUT I don t know how to relate the Draw method with that line constructor. I can have several constructors for Lines and I don t know which one of those Lines is drawn using the Draw(line) method.

最佳回答

你们完全正确!

你确实抓住了你所期待的线2D。 但是,你似乎正在打印<代码>shape在<编码>System.out.println(shape)上的变量。 您的<代码>java.awt.geom.Line2D$Double@596e1fb是变量的识别标志。 现在,你可以通过使用任何可用方法(例如<代码>shape.getBounds()查阅变量的内容。

此外,你还可以做以下工作:

Line2D line = (Line2D) shape; // cast it to Line2D
line.getX1(); // will give you X1 of your line
line.getX2(); // will give you X2 of your line

最后一点是,对你使用案例的更好定义:

pointcut captureCallParameters(Shape shape) : call(* Graphics2D.draw(..)) && args(shape);

在你看来,你将拦截所有有沙伯论点的方法。 在我的版本中,你将只掌握选取法。

问题回答

暂无回答




相关问题
Python: Binding method

In following example I am trying to bind a method object via types.MethodType(...). It does not seem to work. Any suggestions? Thanks in advance. import types class Base: def payload(self, *args)...

Invoking an instance method without invoking constructor

Let s say I have the following class which I am not allowed to change: public class C { public C() { CreateSideEffects(); } public void M() { DoSomethingUseful(); } } and I have to call M ...

Behaviour of final static method

I have been playing around with modifiers with static method and came across a weird behaviour. As we know, static methods cannot be overridden, as they are associated with class rather than instance....

Setting the Page-Title in .Net using C# from a Class

Question, How do i set the title of a page from a class. Is it even possible? I can and have set the page title from a page itself and a usercontrol. Can I, How Do I do this via a class using C# ....

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签