Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » How to use the MethodSignature.getReturnType()
How to use the MethodSignature.getReturnType() [message #58267] Thu, 10 November 2005 22:46 Go to next message
Eclipse User
Originally posted by: aim.yahoo.com

Hi --

I am novice to Eclipse AJDT. I am trying to get the retrun type of a
signature in an advice.
I am using the following code to get that :

AdviceSignature adviceSig =
((AdviceSignature)thisJoinPoint.getSignature());

But when I execute my AspectJ project it's throwing a classcastexception
as follows:
java.lang.ClassCastException
at
com.sequence.Sequence.ajc$before$com_sequence_Sequence$1$b31 4f86e(Sequence.aj:34)
at com.sequence.Figure.main(Figure.java)
Exception in thread "main"

I also tried to use MethodSignature class to get the return type of the
signature but same result (Exception)

Thanks in Advance
Aim
Re: How to use the MethodSignature.getReturnType() [message #58293 is a reply to message #58267] Fri, 11 November 2005 02:12 Go to previous messageGo to next message
Didier Villevalois is currently offline Didier Villevalois
Messages: 86
Registered: July 2009
Member
Hi Aim,

The sub-interface of Signature in which you can cast the result of
thisJointPoint.getSignature() depends on what join-point your pointcut
matched.

Say you defined a pointcut foo()

pointcut foo() : call(* MyClass.myMethod(..));

Then your pointcut will match all MyClass.myMethod() method call
join-points.

Thus you can cast the Signature instance in a MethodSignature instance.
And so you may define an advice

before() : foo()
{
MethodSignature signature = (MethodSignature)
thisJoinPoint.getSignature();
Class returnType = signature.getReturnType();
System.out.println(returnType.getName());
}

If you are not sure of what join-points matches your pointcut, you can
test if the Signature object instanceof MethodSignature.

Now, AdviceSignature is the type of the signature object when your
pointcut matches an advice call join-point.

Hope i was understandable!
Didier.

Rakesh wrote:
>
> Hi --
>
> I am novice to Eclipse AJDT. I am trying to get the retrun type of a
> signature in an advice.
> I am using the following code to get that :
>
> AdviceSignature adviceSig =
> ((AdviceSignature)thisJoinPoint.getSignature());
>
> But when I execute my AspectJ project it's throwing a classcastexception
> as follows:
> java.lang.ClassCastException
> at
> com.sequence.Sequence.ajc$before$com_sequence_Sequence$1$b31 4f86e(Sequence.aj:34)
>
> at com.sequence.Figure.main(Figure.java)
> Exception in thread "main"
> I also tried to use MethodSignature class to get the return type of the
> signature but same result (Exception)
>
> Thanks in Advance
> Aim
>
Re: How to use the MethodSignature.getReturnType() [message #58315 is a reply to message #58293] Fri, 11 November 2005 15:39 Go to previous message
Eclipse User
Originally posted by: aim.yahoo.com

Thanks a lot Didier. The solution you gave me solved my problem. I need
to read about these different types Join-point we can have in a pointcut.

Thanks
Aim
Re: How to use the MethodSignature.getReturnType() [message #590824 is a reply to message #58267] Fri, 11 November 2005 02:12 Go to previous message
Didier Villevalois is currently offline Didier Villevalois
Messages: 86
Registered: July 2009
Member
Hi Aim,

The sub-interface of Signature in which you can cast the result of
thisJointPoint.getSignature() depends on what join-point your pointcut
matched.

Say you defined a pointcut foo()

pointcut foo() : call(* MyClass.myMethod(..));

Then your pointcut will match all MyClass.myMethod() method call
join-points.

Thus you can cast the Signature instance in a MethodSignature instance.
And so you may define an advice

before() : foo()
{
MethodSignature signature = (MethodSignature)
thisJoinPoint.getSignature();
Class returnType = signature.getReturnType();
System.out.println(returnType.getName());
}

If you are not sure of what join-points matches your pointcut, you can
test if the Signature object instanceof MethodSignature.

Now, AdviceSignature is the type of the signature object when your
pointcut matches an advice call join-point.

Hope i was understandable!
Didier.

Rakesh wrote:
>
> Hi --
>
> I am novice to Eclipse AJDT. I am trying to get the retrun type of a
> signature in an advice.
> I am using the following code to get that :
>
> AdviceSignature adviceSig =
> ((AdviceSignature)thisJoinPoint.getSignature());
>
> But when I execute my AspectJ project it's throwing a classcastexception
> as follows:
> java.lang.ClassCastException
> at
> com.sequence.Sequence.ajc$before$com_sequence_Sequence$1$b31 4f86e(Sequence.aj:34)
>
> at com.sequence.Figure.main(Figure.java)
> Exception in thread "main"
> I also tried to use MethodSignature class to get the return type of the
> signature but same result (Exception)
>
> Thanks in Advance
> Aim
>
Re: How to use the MethodSignature.getReturnType() [message #590839 is a reply to message #58293] Fri, 11 November 2005 15:39 Go to previous message
Eclipse User
Originally posted by: aim.yahoo.com

Thanks a lot Didier. The solution you gave me solved my problem. I need
to read about these different types Join-point we can have in a pointcut.

Thanks
Aim
Previous Topic:How to use the MethodSignature.getReturnType()
Next Topic:Refactoring support
Goto Forum:
  


Current Time: Fri Oct 31 22:21:55 GMT 2014

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

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