Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] Programmatically generating c++ source file

Hi,

just like any compiler would not compile anything inside that file, if
you do not specify TEST_TestClassName as preprocessor macro (with a -D),
the indexer is not able to parse anything it doesn't know:-)

HTH,

Walter

> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx 
> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of 
> gerhard@xxxxxxxxxxxxxxxxxxx
> Sent: Donnerstag, 14. August 2008 02:19
> To: cdt-dev@xxxxxxxxxxx
> Subject: [cdt-dev] Programmatically generating c++ source file
> 
> Hi!
> 
> I tried to programmatically generate a C++ source file by 
> using StringBuffer. The generated C++ file can be compiled 
> and executed by CDT but I get no content in outline view. I 
> only get the #define statement.
> When I open the generated C++ source file the CEditor 
> displays it and marks the whole source code with a gray 
> filled box. What does this mean? I assume that the indexer 
> can't parse the file. But why? When I manually type the same 
> file everything is alright.
> 
> Here is the code snippet I use for generating the source file...
> 
> StringBuffer buf = new StringBuffer();
> buf.append("#ifdef TEST_TestClassName\n"); 
> buf.append("#include \"cppunit/extensions/HelperMacros.h\"\n");
> buf.append("\nclass  TestClassName : public 
> CppUnit::TestFixture {\n"); buf.append("public:\n"); 
> buf.append("\tvoid setUp()\n\t{\n"); buf.append("\t}\n"); 
> buf.append("\tvoid tearDown()\n\t{\n"); buf.append("\t}\n"); 
> buf.append("\tCPPUNIT_TEST_SUITE(" + testClassName + ");\n"); 
> buf.append("\tCPPUNIT_TEST_SUITE_END();\n");
> buf.append("};\n");
> buf.append("CPPUNIT_TEST_SUITE_REGISTRATION(" + testClassName 
> + ");\n"); buf.append("#endif\n");
> 
> IFile newFile = project.getProject().getFile(newFilePath);
> InputStream source = new ByteArrayInputStream(new byte[0]); 
> newFile.create(source, true, monitor); ITranslationUnit tu = 
> (ITranslationUnit) CoreModel.getDefault().create(newFile);
> IWorkingCopy workingCopy = tu.getWorkingCopy(); 
> workingCopy.getBuffer().setContents(buf.toString());
> workingCopy.reconcile(true, new SubProgressMonitor(monitor, 
> 50)); workingCopy.commit(true, new 
> SubProgressMonitor(monitor, 25)); workingCopy.destroy();
> 
> What did I wrong?
> 
> Thanx for your help.
> 
> BR
> Gerhard Leonhartsberger
> 
> 
> 
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> 


Back to the top