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

 

> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx 
> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of 
> gerhard@xxxxxxxxxxxxxxxxxxx
> Sent: Donnerstag, 14. August 2008 10:07
> To: CDT General developers list.
> Subject: RE: [cdt-dev] Programmatically generating c++ source file
> 
> Hi,
> 
> thanx Walter - obviously I can't see the details anymore :(

IIRC, you can set the symbol in the corresponding indexer property page
just as well (in case you do not want to compile what you generate;-).

> Is the below mentioned way the prefered one for generating a 
> c++ file with CDT?

That I don't know. I guess, a simple file IO would do as well - like
this:

File file = new File(project.getLocation().toFile, "file.c");
BufferedWriter os = new BufferedWriter(new FileWriter(file, true));
try {
	os.write(text);
	os.flush();
}
finally {
	os.close();
}

Cheers,

Walter

> BR
> Gerhard
> 
> > 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
> >>
> > _______________________________________________
> > cdt-dev mailing list
> > cdt-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >
> >
> 
> 
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> 


Back to the top