Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: AW: [cdt-dev] Methode Visibility in AST

Hi Leo,
Just a quick note about your getDeclarationName.  The IASTName you want is on the inner-most nested declarator, if the declaration in question is something like a pointer to function "void (*pf) ();" then your code will return the wrong IASTName.
There is a method CPPVisitor#getMostNestedDeclarator that you can use:
        return CPPVisitor.getMostNestedDeclarator( declarators[0] ).getName();


Sent by: cdt-dev-bounces@xxxxxxxxxxx

05/21/2006 06:12 AM

Please respond to
"CDT General developers list." <cdt-dev@xxxxxxxxxxx>

"CDT General developers list." <cdt-dev@xxxxxxxxxxx>
AW: [cdt-dev] Methode Visibility in AST

Thank you Doug and Andrew,
I've found the solution with your help. Following code snippet will perhaps help somebody how search for something similar.


public IASTName getDeclarationName(IASTSimpleDeclaration astNode) {
                IASTDeclarator[] declarators = astNode.getDeclarators();
                if(declarators != null && declarators.length > 0){
                                 return declarators[0].getName();
                } else {
                                 return null;
* Get the vibibility of the method.
* @return visibility defined in ICPPASTVisiblityLabel
public int getVisibility(){
                IASTName name = getDeclarationName();
                if(name == null){
                                 return 0;
                } else {
                                 try {
                                                  ICPPMember member = ((ICPPMember)getDeclarationName().resolveBinding());
                                                  return member.getVisibility();                                                  
                                 } catch (DOMException e) {
                                                  return 0;
                                 } catch (RuntimeException e){
                                                  return 0;

-----Urspr├╝ngliche Nachricht-----
Von: cdt-dev-bounces@xxxxxxxxxxx im Auftrag von Doug Schaefer
Gesendet: Fr 12.05.2006 16:12
An: CDT General developers list.
Betreff: RE: [cdt-dev] Methode Visibility in AST

If you have the IASTName for the method, you can resolveBinding() on it to
get at the ICPPMethod binding object. From there you can get the visibility.

Doug Schaefer, QNX Software Systems
Eclipse CDT Project Lead, Tools PMC member

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On
Behalf Of Leo B├╝ttiker
Sent: Friday, May 12, 2006 5:22 AM
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] Methode Visibility in AST

Hi all,
We currently working hard to implement refactoring with the DOM-AST. Is
currently a possibility to get the visibility of a method? If not, we try to

implement this.
cdt-dev mailing list
cdt-dev mailing list

cdt-dev mailing list

Back to the top