I was wondering if anyone knows of existing C++ parsers/code models that can be used programmatically in Java. I'm looking for something similar to the Eclipse CDT that can be used as a library from Java (and that does not rely upon Eclipse). Thanks in advance.
There are some incomplete LALR grammars for parser generators like Lex, Yacc, Antlr, Jack, etc.
C++ has an undecidable syntax grammar, so LALR and BNR grammars will always be incomplete, but as long as you're not trying to write a C++ compiler, they should be good enough.
You don't want to build your own C++ parser. It'll kill you.
You already know about the Eclipse CDT project: www.ibm.com/developerworks/library/os-ecl-cdt3/index.html AFAIK, that parser is, well, a bit fuzzy around the edges. YMMV. Advantage: in Java (and in Eclipse if you care). If you want to process C++, and do it in Java, this might be your only practical choice.
There is also our DMS Software Reengineering Toolkit C++ front end: http://www.semdesigns.com/Products/FrontEnds/CppFrontEnd.html Works with a wide variety of C++ dialects (ANSI, GNU, MSVC 2005/2008), tested by fire on millions of lines of code. Disadvantage from your point of view: Not in Java. But if you really want to analyze C++, making a rule that you are only willing to do it in Java might not serve you the best.