Is there a way to modify the template IntelliJ uses for a method's Javadoc?
In particular, I want my javadoc comments to look like this:
/********************
*
* Comment here
*
*********************/
However, when I reformat the code, the javadoc ends up looking like this:
/**
* ******************
*
* Comment here
*
********************
*/
It doesn't seem like you want JavaDoc comments then, as they are defined to look like how IntelliJ is making them.
Format of a Doc Comment
Structure of a JavaDoc comment
You can disable JavaDoc formatting:
Settings > Project Settings > Code Style > JavaDoc
Uncheck Enable JavaDoc formatting
This way, you can have your multi-line comments not get reformatted as JavaDoc comments.
IntelliJ is identifying them (correctly) as JavaDoc comments since they have two asterisks.
You can also change them to regular multi-line comments (not JavaDoc comments) by adding a space before the second asterisk (e.g. /* ****************), which should also have IntelliJ not reformat them.
Related
I faced with the problem of writing my vcs current branch name each time I have written 'todo' comment.
Recently I learned about Intellij's 'Live Templates' which is quite comfortable to use. I tried to apply it to my problem but there's no templates to take out a branch name.
So the question is could I actually take out the name of my branch to code comments somehow?
It is possible to use the groovyScript predefined function and a script to extract the branch name. For example create the following live template:
$COMMENT$ todo [$BRANCH$]: $END$
with abbreviation "todo" and description "Inserts todo comment with branch name". Click Edit variables and give the variables the following definitions:
COMMENT:
lineCommentStart()
BRANCH (updated for 2020.2 and newer)
groovyScript("com.intellij.dvcs.repo.VcsRepositoryManager.getInstance(_editor.project).getRepositoryForFileQuick(com.intellij.openapi.fileEditor.FileDocumentManager.getInstance().getFile(_editor.document)).getCurrentBranchName()")
Skip if defined checked for both variables. The Groovy script is (unfortunately) all one line. Set applicable contexts to Everywhere.
With this live template it is now possible to type todoTab somewhere in a source file and a line comment with the branch name will be inserted. This will insert the proper line comment depending on the language of the file, or nothing in case of languages without a line comment like HTML. And should extract the branch name no matter the type of version control used (I tested with Git).
For live templates you can use predefined functions. Unfortunately there is no function to detect the current VCS branch.
But you can create a template to make work a little easier:
// TODO [$branch_name$]: $comment$
With this template, you still have to fill branch name, but you should not type symbols like [ and caret will be placed automatically.
You can also create a feature request for a new predefined function.
Given something like:
org.jboss:jboss-remote-naming
...it would be useful to be able to transform it to:
exclude group: "org.jboss", module: "jboss-remote-naming"
Use case is exclusions for Gradle dependencies. Have no idea how to do this though. Could use some tips. I've been to the documentation often enough to know this probably isn't in there, but I will double check.
"exclude group: \""+ "org.jboss.logging:jboss-logging".replaceAll(':','\", module: \"') +"\""
...OK I've figured that you can do the above in the Groovy shell which results in the below:
groovy:000> "exclude group: \""+ "org.jboss.logging:jboss-logging".replaceAll(':','\", module: \"') +"\""
===> exclude group: "org.jboss.logging", module: "jboss-logging"
Now, how to get IDEA to use it?
Well, nobody has responded and I've found the answer anyway.
So the problem is that I've got strings like this on my clip board:
org.jboss.logging:jboss-logging
I'm using Gradle and IntelliJ IDEA. What I'm doing is fixing a big bunch of dependencies and I want to be able to paste exclusions in in the right form which is:
exclude group: "org.jboss.logging", module: "jboss-logging"
What I did was:
CTRL+ALT+S | Edit | Live Templates. Note that I've previously created a "User" group herein to put my personal Live Templates. I click "+" to add a new one to the User group.
Set Template Text to: $VAR$$END$
Select the Edit Variables button and set the Expression field to:
groovyScript("'exclude group: \"'+ _1.replaceAll(':','\", module: \"') +'\"'",clipboard())
Set the Abbreviation field to 'xld'.
Note the following regarding the text above:
A. groovyScript executes a short one line Groovy script (or Groovy file for a bigger script). See the docs here: Predefined Functions
B. Everything is wrapped in "" and then inside those double quotes, every time you want to use a double quote like so: ", you have to escape it with a \. The output has double quotes but aside from that I tried to stick to single quotes.
C. _1 is a string that represents the result returned by the clipboard() method.
How to use it: Copy any dependency of the form "org.jboss:jboss-remote-naming" then at the appropriate location in IntelliJ IDEA type xld and then [TAB]. It should expand using the proper syntax for a Gradle exclusion.
I'm having a strange issue with the #todo command when I have other formatted data below it in a list in the latest version of doxygen (1.8). Consider the following example:
/**
#page build_instructions Build Instructions
- Library1
- #todo Detail build process
- get source
- build release/debug version for x64
- build release/debug version for x86
*/
If you run it, you will notice that the #todo tag adds extra indentation to the last two list items (after "get source"). If you remove the #todo tag, then the indentation looks OK. Also, if I remove the - in front of #todo, it encloses the items below it in a box.
Is this a bug? How can I make the #todo tag affect only one line?
I can confirm this: your code works in 1.5 but not 1.8, so it seems like a bug. Two possible workarounds follow:
try putting the todo item as the last element in the list,
if you want the todo item at the top (or anywhere other than the last element) in the list, then try putting a blank line in between each of the list items which follow the todo item.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I documented all of my classes and now I want to integrate an example of how to use these classes. How do I do that?
You can put example source code in a special path defined in the doxygen config under EXAMPLE_PATH, and then insert examples with the #example tag.
Doxygen will then generate an extra page containing the source of the example. It will also set a link to it from the class documentation containing the example tag.
Alternatively if you want to use small code snippets you can insert them with #code ... #endcode
The documentation for this is here:
doxygen documentation?
Another way of doing it is to use the \snippet command.
In your header file write something like:
\section ex1 Example
\snippet path_to_test_class/TestClass.cpp TestClass example
\section ex2 Expected output
\snippet path_to_test_class/TestClass.cpp TestClass expected output
In the TestClass.cpp file, have something like:
//! [OptimizeSpeedOnTrackTest example]
Class c;
const double res = c.do_something();
//! [OptimizeSpeedOnTrackTest example]
//! [OptimizeSpeedOnTrackTest expected output]
ASSERT_DOUBLE_EQ(5,res);
//! [OptimizeSpeedOnTrackTest expected output]
path_to_test_class must be in your EXAMPLE_PATH.
This gives you the following:
Your examples aren't just there for documentation: they provide test coverage as well
Your test runner (& your compiler) give you the insurance that your examples actually compile & run
It fits in pretty nicely in a TDD workflow
I had some errors using #example to include the example file in the documentation. This is the workaround I used.
Place examplefile.cs in a folder/project specifically for example code.
Place that folder in the Doxygen EXCLUDE list (Expert->Input->EXCLUDEin Doxygen GUI frontend) and in the EXAMPLE_PATH (Expert->Input->EXAMPLE_PATH in Doxygen GUI frontend)
Place this code block somewhere in a documented file (I put it in the file the example is for.)
/** #example examplefile.cs
* A description of the example file, causes the example file to show up in
* Examples */
This causes the file to show up under Examples in the Doxygen menu, but not show up as a class/file in your project.
Then document your class/function:
/** #brief MyClass does something
* #details I have something more long winded to say about it. See example
* in examplefile.cs: #include examplefile.cs */
This causes the example file to print out in it's entirety in the documentation of MyClass.
add a way to doxyfile
EXAMPLE_PATH = dir_example \
can connect all of the examples in the same file such example_list.h
and include it in doxyfile
INPUT = example_list.h \
(language - Russian)
http://www.scale-tech.ru/SimBookmaker/doc/html/examples__list_8h_source.html
and
http://www.scale-tech.ru/SimBookmaker/doc/html/examples.html
I have a simple question, but I couldn't solve it by myself.
I made a Eclipse Plugin, It's just an editor which has a CompletionProcessor (intelisense assitant). This assistant retrieve a set of phrases take into account a dictionary.
The thing is if i write "word example" in the editor and the assistant proposes "Word as an Example" I would like to replace my actual value for the value that get from my assistant.
To summarize actually when I pick that option , in my editor I get something like the following:
"word example Word as an Example"
And I would like to get just:
"Word as an Example"
Any idea?
The classes I have been using are the following:
org.eclipse.jface.text.contentassist.CompletionProposal;
org.eclipse.jface.text.contentassist.ICompletionProposal;
org.eclipse.jface.text.contentassist.IContentAssistProcessor;
org.eclipse.jface.text.contentassist.IContextInformation;
org.eclipse.jface.text.contentassist.IContextInformationValidator;
I'm gonna answer my own question :).
To solve this you have to use the following constructor of Completion Proposal:
http://help.eclipse.org/helios/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/text/contentassist/CompletionProposal.html#CompletionProposal(java.lang.String,%20int,%20int,%20int,%20org.eclipse.swt.graphics.Image,%20java.lang.String,%20org.eclipse.jface.text.contentassist.IContextInformation,%20java.lang.String)
As you can see two of its arguments are replacementOffset and replacementLength, these are the index to start replacement and the length itself.