Add Include statement (IASTPreprocessorIncludeStatement) using cdt - eclipse-cdt

I want to add programmaticlly
1- Create header pragmatically maybe via CDTUITools or something relevant as there is class called NewHeaderFileCreationWizardPage, I tried it but with no luck
2- Add include statement IASTPreprocessorIncludeStatement node in ast tree, i.e "#include headerFileName" to certain AST, I can obtain the ast for a C code and Also I want to update the index of after insert this node in ast

Related

How to create Source that results in empty node sequence

Is there a way to create a javax.xml.transform.Source implementation that Saxon 10 will interpret as an empty node sequence. There are various ways of constructing a Source that is a document node that has no children, i.e. an empty document, but in this case the Source should return an empty node sequence.
Use case for this is an javax.xml.transform.URIResolver implementation that is able to return a Source for an empty document node sequence, when XSLT document() function is used. This allows the URIResolver to mimic a recoverable error behaviour when the target resource is not available.
No sorry, I think I led you up the garden path on this one. It can't be done; a Source must either resolve to a single Node, or fail.

Sublime text. A kinda macro for creating a pair of .h and .cpp for class

So I'm tired of creating two new files for every class I make. AFAIK, macros don't record actions such as creating new files. Snippets also can't create new files. I want to press a kinda hotkey to create a new .h and .cpp file with a specified name. Maybe with a class template.
You can use https://sublime.wbond.net/packages/AdvancedNewFile to create multiple files at the same time with the curly brace expansion. For example, inputting test.{cpp,h} will create test.cpp and test.h. You will need to set posix_input to true for the expansion to work. Templates with expansion do not work (right now anyways), but that may change in the future. There may be other plugins with much more specific functionality out there, but I do not know of them.

Is there anyway to rename the "Source" button to something like "HTML"?

Is there anyway to rename the "Source" button to something like "HTML", I ask this as users are confused at how to add html code using the editor?
Yes, inside of the "lang" folder you will see all of the various language files.
For my case, and probably yours, You will want to edit the file "en.js". The file is "compressed" to some degree so it may be difficult to read, but it's still not too difficult to change one string. If you do plan on changing multiple strings you will most likely want to use a service to format Javascript.
Search for the following segment of code. It was one of the very last lines in the file.
"sourcearea":{"toolbar":"Source"}
change it to
"sourcearea":{"toolbar":"HTML"}
Avoid This Method Unless Required
And as for a very unsuggested method, since you can't modify the language files for some reason, you can modify the ckeditor.js file and force a specific label.
Inside of "ckeditor.js" change the line below
a.ui.addButton("Source",{label:a.lang.sourcearea.toolbar,command:"source",toolbar:"mode,10"});
to the follow code
a.ui.addButton("Source",{label:"HTML",command:"source",toolbar:"mode,10"});
The only thing modified is the "label" value in the above line. We remove the reference to the a.language.sourcearea.toolbar and insert a string in it's place instead.

Find member variable using Locator in Qt Creator

Qt Creator has the Locator box, which allows you to easily find classes, methods, etc. Is there a way to use it to find class member variables, as well?
Using . <expr> will show member variables too, but that is only for searching inside the current file, not globally.
This the Locator:
By default, there is not such feature, but as said in the doc you can create a filter (I can't test it now, but I'll try this soon):
To create a locator filter:
In the locator, select Options > Configure to open the Locator options.
In the Filter Configuration dialog:
Name your filter.
Select at least one directory. The locator searches directories recursively.
Define the file pattern as a comma separated list. For example, to search all .h and .cpp files, enter *.h, *.cpp
Specify the prefix string.
To show only results matching this filter, select Limit to prefix.
Click OK.
QtCreator have no such feature - member variables are not good candidates for pivot points in search. If you want find usages of particular member, use "find symbol usages" (Ctrl+Shift+U when cursor is under symbol). If you want to find members of particular type, use usual search in regular expressions mode, something like:
\w+\s*\*\s*\w+\s*;
And limit scope to headers only (i.e use "*.h" file mask).
Have you tried using the 'Advanced...' option in the locator? You can change the scope of the search to the Current Project, All Projects, Files on the System, etc. I use this to even search for strings I use for debug output in my code.

Customizing include-guard for Eclipse CDT

I want an automatically generated include-guard by creating a new C++-class with Eclipse/CDT, but I don't find any way to change the ${include_guard_symbol} attribute.
My wish is an include-guard with a namespace prefix like following:
#ifndef NAMSPACE1_NAMESPACE2_HEADER_HPP
But if I use #ifndef ${namespace_name}_${include_guard_symbol} for this, it will produce:
namepace1::namespace2::_HEADER_HPP
How can I do this?
I had a dig around in the source for CDT, and found an undocumented preference setting you can use to change what is generated by ${include_guard_symbol}. There's no GUI for it either, but if you add the codetemplates.includeGuardGenerationScheme setting to <projectpath>/.settings/org.eclipse.cdt.ui.prefs, you can choose between file name (the default), file path or UUID.
Given the file <projectpath>/src/include/Class.h, the following values give these results:
0 gives an upper-case filename, i.e. CLASS_H_
1 gives a UUID, for example. HC9ABE718_D04E_411C_B5A2_F9FE1D9F9409
2 gives an upper-case file path, that is, SRC_INCLUDE_CLASS_H_
To avoid any doubt, here's the contents of our .settings/org.eclipse.cdt.ui.prefs:
codetemplates.includeGuardGenerationScheme=2
eclipse.preferences.version=1
formatter_settings_version=1
It's obviously not exactly what you're after, but we use 2 to give us an approximation of our namespaces since, generally speaking, our namespaces follow our folder structure.
The relevant code is in these files in the CDT source:
core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java for the constants for each option
core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java for the generateIncludeGuardSymbol() method that does the work.
It would be really nice to see an extra option added for using the namespace, and a GUI too.
I'm using Eclipse Oxygen (CDT 9.3) and as Eelke described in their comment, there has been a UI setting for this for a while now.
However it only lets you choose from the preset schemes, no namespace or richer customisation options available yet.
Search for 'guard' in the preferences dialog, or navigate to C/C++ > Code Style > Name Style and select Code > Include Guard and then choose from the available guard schemes.