is there any demo for eclipse cdt api use? - eclipse

I want to use the eclipse cdt api to resolve c++ code AST tree for code analysis.
base on the blow question answer, I try to create a default Workspace and project by java code. The Workspace init method require many IDE source support, when i fix one resouce issue, another comes. is there any demo for this?
Using CDT without Eclipse

If you want to parser a single source file, it is enough to use cdt.core only. If you want to use the higher level(semantic) you need to replace a lot dependences about those IDE packages. I did a project using Eclipse-JDT and use JavaCore and Workspace to generate IJavaProject. It is similar with CDT. I also do some research about static-code-analysis using JDT/CDT.

Related

Create Eclipse project using `make`?

Is it possible to create Eclipse project using make?
I have a bunch of Eclipse CDT c++ projects, but I can't keep the .project and .cproject files in the source reposotory - instead, one option is to create a makefile to be able to re-create Eclipse projects by running make. Would that be possible?
CMake can generate Eclipse project files, you could use that. I haven't come across a way to do it using plain make.
That said, please keep in mind the caveats I mention in this answer about Eclipse project file formats being undocumented and without guarantees of stability.

Define a Java 9 multi-moduled project in Eclipse

I'm trying out Java 9 Jigsaw module system (no module experience yet) and would like to use it for capsuling the classes within my project, but it's confusing.
According to this article it should be possible to have multiple modules within ONE project. I made a new project in Eclipse Oxygen (Java 9 is supported) with the same structure as shown in the article. But Eclipse keeps telling me that I must not have more than one module-info.java in a project.
I really don't know how to tell Eclipse that it should use the "multi-module-mode". And I really would appreciate not having to create a new project for every single module.
This works:
This not:
But according to this article something like that should work:
And how about deployment of a modularized project with Eclipse? There is nothing to see about the new jmod extension. Do I still export it as a runnable JAR file like before?
Notice that my questions refer to working with the IDE (no command line, I mean with an IDE that should be possible, right?) Thank you for enlightening me.
Currently, Eclipse requires you to create a separate project for each module (e. g. because each module has its own Java Build Path).
To understand this design decision, consider that Java modules correspond to OSGi bundles / Eclipse plug-ins and it has always been to have a separate project for each bundle/plug-in. If you come from the Maven world, you would probably expect a deeper folder structure instead. But modules are self-contained and combining several modules into one project would only add an additional folder level without meaning. However, Eclipse supports nested projects and so-called working sets if you need an additional folder level.
Exporting modules as images is planned for Eclipse 2019-03 (4.11), on March 20, 2019 (see Eclipse bug 518445). Exporting modules as JARs that can be used on the modulepath (-m) already works (see my video).
I don't know if this question is still open for an answer, but you can solve this problem by simply removing all source folders on the build path. At least this works for Eclipse 2021-12 version.
As you can see this is a demo project from the Official Gradle Guide Book and it has multiple modules. Each module has its own module-info.java.
project structure in IntelliJ IDEA
If I open this project in Eclipse it will give me the 'duplicated entries on module-info.java' error.
Eclipse shows the error
But if I delete all the source folders on the build path, the error is gone and the project can be built and run without problem.
project properties: Java build path
The only problem is that you have to build the project with Gradle so that it will produce the .jar of each module and you have to include them in the libraries later.
include all the .jar in libraries
I think this is probably the same solution mentioned by howlger above.

Using CDT without Eclipse

I want to use CDT parser in a project. The project would be a command-line, stand-alone project, i.e., not an Eclipse plugin.
All solutions that I've seen requires using a IWorkspace. But, I want to use the CDT parser on single files outside eclipse. Is there any way to do that?
It depends what you mean by "without Eclipse".
CDT's code is built on top of the Eclipse Platform, so you're going to need to be running an application that includes the Eclipse Platform. However, there's no reason that application can't be a command-line application. These are called "headless" applications in the Eclipse community, and you can find many tutorials for making one (here's one).
Requiring an IWorkspace shouldn't be a problem. You can e.g. create a workspace and a project in a temporary folder, and copy the code to be analyzed there.
If, for some reason, you really want to use just CDT's parser in an application that doesn't include the Eclipse Platform, you can probably copy the parser code from CDT, and replace any dependencies it has on the Eclipse Platform with your own implementations. However, this is likely to be a more labour-intensive approach, and I wouldn't recommend it.

Eclipse Plugin Development: Code Review

I'm trying to write a plugin for Eclipse which should analyse all java files in the open project.
Is it possible to add my code to the code parser of Eclipse itself?
Currently, I'm able to load the workspace and iterating over all java files but any changes after the first iteration are missed.
You can use the org.eclipse.jdt.core.compilationParticipant extension point to define a class extending org.eclipse.jdt.core.compiler.CompilationParticipant which will be called at various points during the compilation of a project.
You can also use an IResourceChangeListener to listen for changes to individual resources:
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);

Eclipse Find Code Coverage

I would need to use Eclipse to find code coverage of a test file generated by an automated tool with respect to a certain project.
I am thinking of using the "Emma" plugin but, as the project was not originally an Eclipse one, am having some difficulties importing it. I can open individual files, but that is not of much use as I can't run the plugin then.
Any ideas? :)
Thanks!