Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Hover and Enums

> I am working to understand/fix the bug
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=285126

Cool, thanks for looking at this.

> Is it possible to retrieve from ASTTranslationUnit object the value
> associated to each element?

Yes.

   1. Find the IASTName corresponding to the enumerator whose
       value you want.

   2. Call resolveBinding() on this name. It will return an IBinding
       which is more specifically an IEnumerator. (The implementation
       will be CEnumerator or PDOMCEnumerator depending on
       whether the enumerator is defined in the currently open file
       and thus the binding is based on its AST, or in another file and
       thus the binding is read from the index).

   3. Call getValue() on the IEnumerator to get an IValue.

   4. Call numericalValue() on the IValue to get a Long. This may be
       null if the enumerator's value is dependent on a template
       parameter and thus a numerical value cannot be determined.
       If it's not null, it should be the number you want.

Hope that helps,
Nate

Back to the top