Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Getting methods/fields from CPPClassTemplate


The first thing to note is that your are mixing 2 different models here.  The cdt.core.model classes are unrelated to the cdt.core.dom.ast classes.  It is incorrect to be mixing the two models.

CPPClassTemplate actually extends CPPTemplateDefinition, not CPPClassType, the get* methods that return null do so simply because I never had time to implement them.
Assuming I'm not forgetting something, you can probably use the same kind of the implementation as CPPClassType.

There is still work to be done here.  Note that these methods are also unimplemented for the instantiations and specializations of class templates (CPPClassInstance, CPPClassSpecialization).  However, you can't just use the CPPClassType implementations here since the members need to be instantiated or specialized as appropriate.  CPPClassInstance should likely implement ICPPInternalClassType, proper implementations of getConstructors and getConversionOperators would improve the resolution of template bindings in arbitrary code.

-Andrew

cdt-dev-bounces@xxxxxxxxxxx wrote on 01/27/2006 10:17:05 AM:

>
> I need to get the field and methods objects in the AST from a
> template. However, org.eclipse.cdt.internal.core.dom.parser.cpp.
> CPPClassTemplate that extends CPPClassType explicitly returns null
> from the following methods: getDeclaredFields, getMethods,
> getAllDeclaredMethods & getDeclaredMethods. I was able to find a
> workaround for getting the fields by doing something like the code
> below. However, I still have not figured out how to get the methods.
> Can anybody point out the reasons why the methods were overridden to
> return null and what would be the best way to get the fields & methods?
>
>                         org.eclipse.cdt.core.dom.ast.IField[]
> astFields = null;
>                         ICppClassType type = getTemplateType();
>                         ICElement elem = getICElement(type);
>                         if (elem instanceof IStructureTemplate)  {
>                                 IStructureTemplate template =
> (IStructureTemplate) elem;
>                                 org.eclipse.cdt.core.model.IField[]
> fields = template.getFields();
>                                 astFields = new IField[fields.length];
>                                 for (int i = 0; i < fields.length; i++)  {
>                                         astFields[i] = type.
> findField(fields[i].getElementName());
>                                 }
>                         }
>
> --
> neeraj_______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top