Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to identify a class in a *.cpp file?

You should create a visitor that extends ASTVisitor and attach it to the
IASTTranslationUnit of each C++ file. Implement visit(IASTDeclaration)
method as below. It will find all the classes.

Regards,
mani


ClassFinder.java:


import org.eclipse.cdt.core.dom.ast.ASTVisitor;
...

class ClassFinder extends ASTVisitor

	public int visitDeclaration(IASTDeclaration decl) {
		
		try {
	
			if ((decl instanceof IASTSimpleDeclaration) &&
decl.isPartOfTranslationUnitFile()) {
				IASTSimpleDeclaration simpDecl = (IASTSimpleDeclaration) decl;
				IASTDeclSpecifier declSpecifier = simpDecl.getDeclSpecifier();
				if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
					IASTCompositeTypeSpecifier compTypeSpecifier 
						= (IASTCompositeTypeSpecifier)declSpecifier;
					int key = compTypeSpecifier.getKey();
				        if (key == ICPPASTCompositeTypeSpecifier.k_class) {
						IASTName astName = compTypeSpecifier.getName();
						IBinding binding = astName.resolveBinding();
						if (binding instanceof ICPPClassType) {
							ICPPClassType cppClass = (ICPPClassType)binding;
                                                        //... you found the
class!


-- 
View this message in context: http://www.nabble.com/How-to-identify-a-class-in-a-*.cpp-file--tp23946997p23955760.html
Sent from the Eclipse CDT - Development mailing list archive at Nabble.com.



Back to the top