Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How can we judge if a method is overrides other method?
How can we judge if a method is overrides other method? [message #217707] Tue, 25 October 2005 05:42 Go to next message
Eclipse UserFriend
Hi, dear all

I get an MethodDeclaration instance through traversing from
CompilationUnit. MethodDeclaration can offer many info about method, but
I haven't found a method to tell if this method overrides other method.
Although I found some internal API such as "Bindings" is revelant, I
think there should be other ways rather to use internal API.

Could you please help me?

Thanks!
James
Re: How can we judge if a method is overrides other method? [message #217716 is a reply to message #217707] Tue, 25 October 2005 06:19 Go to previous messageGo to next message
Eclipse UserFriend
MethodDeclaration methodDeclaration = ...
IMethodBinding methodBinding = methodDeclaration.resolveBinding();
return methodBinding.overrides(otherMethodBinding);

Note you need to ask the ASTParser to resolve bindings before creating the AST.
See ASTParser#setResolveBindings(boolean).

Jerome

James Gan wrote:
> Hi, dear all
>
> I get an MethodDeclaration instance through traversing from
> CompilationUnit. MethodDeclaration can offer many info about method, but
> I haven't found a method to tell if this method overrides other method.
> Although I found some internal API such as "Bindings" is revelant, I
> think there should be other ways rather to use internal API.
>
> Could you please help me?
>
> Thanks!
> James
Re: How can we judge if a method is overrides other method? [message #217874 is a reply to message #217716] Wed, 26 October 2005 04:03 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Jerome

Thank you for telling me this API. This is really helpful. But my
problem is a little different. I haven't an otherMethodBinding in hand.
I want to know if a method overrides any other method.

Should I search the hierarchy and get every method then test it with
"overrides()"?

Jerome Lanneluc wrote:
> MethodDeclaration methodDeclaration = ...
> IMethodBinding methodBinding = methodDeclaration.resolveBinding();
> return methodBinding.overrides(otherMethodBinding);
>
> Note you need to ask the ASTParser to resolve bindings before creating
> the AST.
> See ASTParser#setResolveBindings(boolean).
>
> Jerome
>
> James Gan wrote:
>
>> Hi, dear all
>>
>> I get an MethodDeclaration instance through traversing from
>> CompilationUnit. MethodDeclaration can offer many info about method,
>> but I haven't found a method to tell if this method overrides other
>> method. Although I found some internal API such as "Bindings" is
>> revelant, I think there should be other ways rather to use internal API.
>>
>> Could you please help me?
>>
>> Thanks!
>> James
Re: How can we judge if a method is overrides other method? [message #217881 is a reply to message #217874] Wed, 26 October 2005 04:49 Go to previous messageGo to next message
Eclipse UserFriend
I'm afraid that what you're asking is not available yet (see the
feature request https://bugs.eclipse.org/bugs/show_bug.cgi?id=90660).

So in the meantime, the only solution is to search the hierarchy and
test every method.

Jerome

James Gan wrote:
> Hi, Jerome
>
> Thank you for telling me this API. This is really helpful. But my
> problem is a little different. I haven't an otherMethodBinding in hand.
> I want to know if a method overrides any other method.
>
> Should I search the hierarchy and get every method then test it with
> "overrides()"?
>
> Jerome Lanneluc wrote:
>
>> MethodDeclaration methodDeclaration = ...
>> IMethodBinding methodBinding = methodDeclaration.resolveBinding();
>> return methodBinding.overrides(otherMethodBinding);
>>
>> Note you need to ask the ASTParser to resolve bindings before creating
>> the AST.
>> See ASTParser#setResolveBindings(boolean).
>>
>> Jerome
>>
>> James Gan wrote:
>>
>>> Hi, dear all
>>>
>>> I get an MethodDeclaration instance through traversing from
>>> CompilationUnit. MethodDeclaration can offer many info about method,
>>> but I haven't found a method to tell if this method overrides other
>>> method. Although I found some internal API such as "Bindings" is
>>> revelant, I think there should be other ways rather to use internal API.
>>>
>>> Could you please help me?
>>>
>>> Thanks!
>>> James
Re: How can we judge if a method is overrides other method? [message #217901 is a reply to message #217881] Wed, 26 October 2005 05:57 Go to previous message
Eclipse UserFriend
You are right. Thanks for discussion!

Jerome Lanneluc wrote:
> I'm afraid that what you're asking is not available yet (see the
> feature request https://bugs.eclipse.org/bugs/show_bug.cgi?id=90660).
>
> So in the meantime, the only solution is to search the hierarchy and
> test every method.
>
> Jerome
>
> James Gan wrote:
>
>> Hi, Jerome
>>
>> Thank you for telling me this API. This is really helpful. But my
>> problem is a little different. I haven't an otherMethodBinding in
>> hand. I want to know if a method overrides any other method.
>>
>> Should I search the hierarchy and get every method then test it with
>> "overrides()"?
>>
>> Jerome Lanneluc wrote:
>>
>>> MethodDeclaration methodDeclaration = ...
>>> IMethodBinding methodBinding = methodDeclaration.resolveBinding();
>>> return methodBinding.overrides(otherMethodBinding);
>>>
>>> Note you need to ask the ASTParser to resolve bindings before
>>> creating the AST.
>>> See ASTParser#setResolveBindings(boolean).
>>>
>>> Jerome
>>>
>>> James Gan wrote:
>>>
>>>> Hi, dear all
>>>>
>>>> I get an MethodDeclaration instance through traversing from
>>>> CompilationUnit. MethodDeclaration can offer many info about method,
>>>> but I haven't found a method to tell if this method overrides other
>>>> method. Although I found some internal API such as "Bindings" is
>>>> revelant, I think there should be other ways rather to use internal
>>>> API.
>>>>
>>>> Could you please help me?
>>>>
>>>> Thanks!
>>>> James
Previous Topic:How to get IType from Class
Next Topic:how to change color of occurence marks?
Goto Forum:
  


Current Time: Fri Jul 18 07:32:47 EDT 2025

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

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

Back to the top