Changing NetBeans auto-generated code - templates

NetBeans has some great features in it like auto-generating code. However there are some things missing which I would like to change. One of my practises is to add comments to the generated code telling me what it is. For example say that I am writing in php and auto generate a constructor for an object. The end result would be auto generated like this:
function __construct(){};
However what if I wanted NetBeans to generate comments alongside it like this:
//constructor
function __construct(){};
Is it possible to change something in NetBeans to make this happen? Templates maybe? And if so which template file and how should I change it to suit my needs?

You can go to Tools->Options->Editor->Code Templetes.
You choose language php.
There you can see the templates. You can change them or add yours.

Related

Automatically format Curly Braces on Same Line in C++ VSCode

I have a problem with the way intellisense autocompletes snippets in VSCode, currently, when I write an if statement, it autocompletes to:
if (condition)
{
// some code
}
However, I would like it to autocomplete to:
if (condition) {
// some code
}
If I use my formatter in VSCode, it formats it to the convention above, however I would like to avoid having to press a separate command for this to occur. Optimally the intellisense snippet would just format it like this by default.
Any help with this would be appreciated.
This is a bigger subject than you might think
So typically with C++, the preferred formatter is the CLang Formatter. CLang's tool is so good, ECMAScript's ESLint has been taking notes, and has implemented many of the same rules found in the CLang formatter, specifically the rules that have to do with brackets.
VSCode has a default formatter that can be used for C++. And this really comes down to what your using.
Problem:
What your asking for, essentially, is for your brackets to be inserted using a certain style, rather than to be auto formatted to a specific style.
Solution
The snippets you are using are obviously predefined, and VSCode supports writing your own snippets.
Like this:
// FILE: #(".../.config/code/user/snippets/cpp.json")
{
"Print to console": {
"prefix": "if(",
"body": ["if($1){\n$2\n}", "$2"],
"description": "If Condition"
}
}
The problem with snippets is: You would need to defined every snippet you use, styling each one.
VSCode Snippets Documentation (official)
Snippet files are extensible, meaning they can be turned into VSCode extensions. Because a snippet library is quick & easy to write in comparison to most other extensions, there are a lot of them available in the Visual Studio Marketplace, and are all 100% Free to download.
You could download a pack that contains the snippets you wont, and then just ad the '\n' line character where needed, throughout the document.
Preferred Solution
It may not be what you want. But the best way to do this, is to do what 90% of C/Cpp developers do who write c/cpp in VSCode; use CLang formatter, and configure VSCode to format your code when you save. I am always hitting CTRL + S because I don't like throwing work down the drain because I forgot to save. And my if statements are all auto formatted exactly as you displayed the example in your question.

How do you modify Eclipse IDE tooltip?

When I'm writing C in Eclipse, sometimes I see an explanation of what the function does. For instance, the tooltip for fopen explains that you can use r for read and w for write.
How do you make this kind of information show up for your own functions? I'd like to be able to make a library and for anyone using it, they could see what the different parameters are for.
If you add comments before your function the Eclipse-CDT will automatically pick them up and apply them in the tool tip.

How to implement an #if function into a infobox?

So I've been trying to implement an #if parser into an infobox, but I seem to be out of luck. The previous code I used seems to be outdated, and I can't find the a way to code it in again, differentely. :/
Basically, in this infobox, if a field is not typed in(or if typed in is left empty) it should become 'invisible' or not even render.
This code worked fine in a previous version of MediaWiki(not sure which one though), but no longer: http://pastebin.com/uQ49mPbQ. I've been trying to use it as a tutorial, and even outright copy and pasted it, but it simply doesn't work. All of the fields would become invisible, regardless of what I would have done to them...
This is the new code that I am using, and would like to be #if'ed: http://pastebin.com/3j0AbN5v
Any help would be welcome.
You need to enable the ParserFunctions extension to be able to use the {{#if}} parser function. Do this in your LocalSettings.php:
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
If you want to use the string functions (like {{#replace}}, {{#explode}}, etc), also add:
$wgPFEnableStringFunctions = true;
In recent versions of MediaWiki, ParserFunctions is included (but not enabled) so you don't need to download anything.
Basic troubleshooting: Whenever you see code like {{#zyx:...}} in a wiki page, it (probably) means, that someone tried to use a parser function that is not installed. Unless there is a parser function called “zyx” installed, the code {{#zyx:...}} has no special meaning to the wiki, and the text will be printed just like it is. The most common parser functions are collected in an extension called ParserFunctions, that is used on WikiMedia wikis. You will need the parser functions from ParserFunctions whenever copying templates from e.g. English Wikipedia.
To see what parser functions you have enabled, navigate to Special:Version on your wiki. Below the list of installed extensions is a list of tags (such as <gallery />) and parser functions available. As you can see, “if” is among the parser functions on your old wiki, but not on your new.

Implementing a custom wizard for Visual Studio for custom C++ classes

in order to make new C++ classes conform to some rather picky coding conventions (upfront: I am not in the position to discuss these...), I was thinking about a way of generating stubs for new C++ classes. Currently, everyone is doing copy-paste, regularly missing some detail. The IDE in use is MS Visual Studio 2005, but I think there has not been much of a change in 2008 and 2010 regarding these topics.
My first idea was to implement a command line script to do this, which would be fairly straight forward to do. Alternatively, I thought about using a default VS extension mechanism for better IDE integration. So, this would be hooking in some custom stuff when selecting Add->New Item... on a filter (Solution Explorer).
After some investigation, I found out there is an easy-to-use templating mechanism, which unfortunately does not work for C++ (http://msdn.microsoft.com/en-us/library/6db0hwky%28v=vs.80%29.aspx). For C++, it seems like you have to implement a custom wizard instead, incorporating html for the layout and javascript for the logic.
Regarding the custom wizard approach, I've come to the conclusion that this would require some effort (at least for me) to get this done. MSDN is not very detailed on this topic. I've found some walkthroughs in the web, which are dealing with custom wizards for projects only (Add->New Project... instead of Add->New Item...).
So, here's the qn: Anyone having done this or something similar? Is it (better IDE integration) worth the effort (coping with the details of custom wizard implementation), or would you suggest the go for the command line tool instead? More than two days of work would not pay off in the current project, I guess.
If you think custom wizards are great, maybe you can give some hints to get started. Also, maybe there are alternatives I did not come up with. VS Add-Ins seemed to be over the top for this, and adapting e.g. VC\vcprojectitems\newc++file.cpp will not do the job.
Thanks in advance and best regards...
Jerb
I have done something similar using a custom wizard.
For my purposes I just wanted to inject some simple macros into each class to insert it into a static factory object.
I didn't need to modify the actual wizard, just copied the default generic class wizard and modified the code generation javascript.
The documentation is rubbish on the topic, but here is a good place to start for the javascript (that is where you are going to get the most power):
http://msdn.microsoft.com/en-us/library/t41260xs(v=VS.71).aspx
The default class wizard javascript is located here:
C:\Program Files\Microsoft Visual Studio
10.0\VC\VCWizards\CodeWiz\Generic\Class\Scripts\1033\default.js
Duping the Project
Duplicating this is trickier than I thought, you need to copy and paste the
Microsoft Visual Studio 10.0\VC\VCWizards\CodeWiz\Generic\
folder, then head to:
C:\Program Files\Microsoft Visual Studio 10.0\VC\VCAddClass\Generic
Dupe this folder and modify the Generic.vsdir inside it to point to a dupe of ..\Simple.vsz (a file in the VCAddClass folder).
The Simple.vsz file points back to the location of the "Generic" folder in VCWizards you duped at the start, so point your new simple.vsz at that.
Code Generation
As for the actual code generation, its not all that difficult to pick up. To get things started faster, here is the General way the default.js works:
Once the wizard is finished, the code gen method kicks off from:
function OnFinish(selProj, selObj)
selProj is (as far as I can tell) an instance of EnvDTE.Project
http://msdn.microsoft.com/en-us/library/envdte.project.aspx
Getting information from the wizard seems to be based around:
wizard.FindSymbol("CLASS_NAME")
The real magic starts to happen on the selProj.CodeModel object
oCM.AddClass(strClassName, strHeader, vsCMAddPositionEnd, "", "", vsCMAccessDefault);
It seems the convention for these methods to add anything to a file simply modifies the file as a single action, as it requires the file path as its paramter.
This returns a CodeClass instance and can be added to by its methods like:
AddAttribute
AddFunction
...
This is quite restricting if you are looking for very strict code formatting (or in my case inserting macros that don't fit normal code syntax.
The simple way around this is to just build a string on your own for the parts that you need full control over using the EditPoint interface.
An EditPoint is a location inside a code file to which you can call methods like:
EditPoint.Insert(string)
Editpoint.InsertFromFile(path)
To get an EditPoint in a location where you would want to insert code, simply use the location of one of the existing items in the code gen file (like class or constructor) and get a TextPoint using .StartPointOf or .EndPointOf and manipulating the parameters.
Once you have a TextPoint you can create an EditPoint like so:
newclass.EndPointOf(vsCMPartBody).CreateEditPoint().Insert("\nprivate:\n REGISTER_TYPE_MEMBER("+strClassName+");\n");
To get a TextPoint inside the .cpp file instead:
oConstructor.StartPointOf(vsCMPartWhole,vsCMWhereDefinition).CreateEditPoint().Insert("REGISTER_TYPE_BODY_ID("+strClassName+",REPLACE_ID);\n\n\n");
This gives you the power to do anything you want via JScript string manipulation as long as you can find the input data you need via the wizard (which I have not yet delved into)

C++ Transformer scripting

Im looking to see if there are any pre-existing projects that do this.
Generally, I need something that will load in a c++ file and parse it and then based on a set of rules in script, transform it, say to add headers, reformat, or remove coding quirks for example, turning const int parameters in functions to int parameters, etc Or perhaps something that would generate a dom of some sorts based on the c++ file fed in that could be manipulated and written out again.
Are there any such projects/products out there free or commercial?
Taras Glek of Mozilla has been working on the dehydra tool, based on Elkhound and scripted using JavaScript to transform the Mozilla codebase to fit with XPCOM and garbage collector changes.
The Parser from Eclipse CDT seems to be pretty complete by now, as some refactoring methods have been alredy contributed to CDT.