Java Hyperlink to file in text editor - java

I have a question related to hyperlinks in java.
How can I set hyperlink in java file to point to another java file loaded on the text editor in Eclipse, when I have the filename and code line:
ex. Test.java:102
How to show the given code line of that file on the text editor?
Thank you!

The Java language does not know hyperlinks.
JavaDoc does know hyperlinks, which you can easily access in the Eclipse editor by typing either the # sign and choose a local member or by typing the name of an external class and hitting controlspace, then choose the right link.
Fortunately, you cannot directly create links to lines. Lines change in time, the contract of the class (the description of the methods/fields) is what should remain relatively static. When configured correctly, Eclipse will even change your links if you refactor your code (e.g. rename your method or class).

You cannot create hyperlinks to lines -afaik, but you can create links to fields or functions in javadoc:
/**
* {#link package.ClassName#fieldOrFunction}
*/
doing it like that allows you to ctrl-click on the "fieldOrFunction" and jumps right there (at least in eclipse)

2 years later, I know...
If you are looking for hyperlinks from any file surround it with parenthesis like so
(AnotherClass.java:52)
ctrl click will take you there if it knows of that class.

Related

How to document runtime of a function with Javadoc

I'm want to document the asymptotic runtime of a function, as it will be used for algorithm-engineering for graph problems.
What's the most idiomatic way to do this? Is there a way to create new tags in Javadoc like #return or #author?
I provided an example below, which is the method to delete a vertex in the graph.
/**
* Runtime: O( degreeOf(v) ) because every neighbour of [v] also needs to be updated.
*/
fun deleteVertex(v: V): SimpleGraph<V> {
if (v in m.keys) {
for (nb in m[v]!!)
m[nb]!!.remove(v)
m.remove(v)
}
return this
}
To create custom tags for Javadocs, simply follow these instructions.
You can create other customizations for Javadoc. For example, in Eclipse, you can create "templates" so that when you create new classes or add new methods, the IDE automatically apply this template to add a (Javadoc) comment formatted in the prescribed style of the template you applied. You can save these templates in an XML file so that you could share it with other members of your team. I am sure that IntelliJ and other modern IDEs will have similar features. I am just more familiarized with Eclipse. Here is a video I created many years ago on how to create a Code Formatter in Eclipse. If you advance to the 1:48 mark, you will see "Code Template" right above the "Code Formatter" option I selected in the video. Creating a code template is much easier than a formatter.
To do this, simply click on Windows > Preferences menu to get the Preferences popup. There, select Java > Code Style > Code Templates. in the right pane, expand Comments and select the component you wish to create a comment template for, for example Methods. Click Edit button and format the Javadoc comment to your liking. Obviously, you will have to do a bit of research to get really creative with your comments. For example, you might need to figure out how to use system variables or create your own. For example, in the image below, I made use the year variable to apply the current year whenever I create a new class.
Once you finish with all your template customizations, simply click the Export button and use the File Chooser dialog to save the file wherever you would like.
One last tip, if you need to embed code snippets in your Javadocs, you can follow the recommendations in this article. I do this very often. Sometimes I find it useful to embed a few lines of code to illustrate different use cases for the method. That way, other developers can see how to use the method in the correct context.

Intellij: How can I wrap a piece of text in Javadoc?

So, for example, if I were to insert a Javadoc comment for a field from some external source on web, I would copy paste the relevant part from the website and then move on to my Class to incorporate the copied content as a Javadoc comment for the field.
But the problem is, I can't find any support from Intellij regarding this. Currently, I have to type, /** + Enter to generate a stub then paste the content there, which doesn't get properly pasted - I mean, a paragraph of 5 lines comes as a single long line and the Javadoc * on the side disappears.
I was looking for something like, paste the content copied raw in the place then select it and if Intellij provides some shortcut to wrap it as a Javadoc comment, do it except I couldn't find any support from Intellij for this approach.
So my question is, does anyone know of any such tool/plugin/built-in Intellij support or any other workaround for doing this as this is time consuming?
You will have to start with the /** and Return to get the basic javadoc comment. Then you can paste your text with ctrl+V (⌘+V on OSX) as the cursor is positioned at the right place.
All that is left then is use the keyboard shortcut that is defined for reformatting. In the menu you will find that under _Code/Reformat Code, on my Mac it is ⌘+⌥+L.

How to extend Eclipse's Java editor to recognize my own elements

I want to add references to other elements inside javadoc. The javadoc should look similar to:
/**
* ...
* #my.tag SomeElement
*/
I want to reuse the existing Java editor inside Eclipse. Of course I can type above javadoc already, however I'd like to add some features:
Navigation: upon Ctrl-Click / F3 I want to navigate to the editor showing SomeElement
Auto-completion: Ctrl-Space should complete the text / show valid alternatives
Checking: I want to create a warning marker and underline the SomeElement if it cannot be found
I already figured out that I can do the auto-completion by using the extension point org.eclipse.jdt.ui.javaCompletionProposalComputer, though this seems to be little more complex than I had hoped, so I might be on the wrong track here?
For checking my elements I might be able to use org.eclipse.jdt.core.compilationParticipant, which can generate markers upon compilation which afaik happens with every save operation.
But how can I can manage the navigation feature? Any pointers are welcome!
For navigation you can provide a Hyperlink Detector. You'll want to look at how the Java Editor and its existing detectors are declared in the org.eclipse.jdt.ui plug-in to determine the correct target ID.

Eclipse IDE Scope Highlighting?

When I first learned Java, I was using an IDE called "BlueJ." It had this feature called "Scope Highlighting" which made it very easy to read blocks of code. Now I've moved on from BlueJ and began using Eclipse. I'm currently in the process of customizing Eclipse to my liking and would like this Scope Highlighting feature inside Eclipse.
I've searched everywhere for an answer on how to do it but I cannot find any information pointing to a solution for doing it in Eclipse.
Here's a picture to demonstrate what Scope Highlighting looks like:
I think the best option for you is EditBox, a scope highlighting plugin for Eclipse:
http://editbox.sourceforge.net/
I'm afriad that closest you can get is Shift + Alt + arrow_up
It is selecting wider block of code. pressing this few times will give you very similar result to what you are searching for. I use it often.. it is useful, also for refactoring.
EDIT: As #j2emanue said: you can just double click the delimiter (like a bracket) and it will highlight the entire scope.
you can use Shift + Alt + arrow_up but many people dont realize you can just double click the delimiter (like a bracket) and it will highlight the entire scope. Try double clicking your if statements bracket for example and watch eclipse highlight the entire scope. It works with any delimiter. so you can use parenthesis as well.
as a side note: if your using intelliji checkout this plugin works great: https://github.com/izhangzhihao/intellij-rainbow-brackets#screenshots
This isn't exactly what you're after but you can put your cursor in a method and then click the Show Source Of Selected Element only button on the toolbar. Your editor gets reduced to just that method. Click again and your back to your entire file.
I doubt eclipse does have the same function as blue j.The best advise I can give you, is to change your theme to your liking which would enable you to easily select and highlight the block of code...and to customise your theme , go to http://eclipsecolorthemes.org/. ....
If you still have a problem, go to http://codejava.co.uk/contact.html and send your email.you can create a dummy one if want, then I will send you XML files I use for my eclipse themes.
can Bracketeer do this ? its an eclipse plug in ..
http://marketplace.eclipse.org/content/bracketeer-java-jdt#.UK6sY4fAdLc
Maybe you will also like the VSCode extension "Blockman". It highlights nested code blocks based on curly/square/round brackets, html/xml tags and Python/Yaml indentation. (I am the author of Blockman).
.
https://i.ibb.co/31F0rm9/vscode-blockman-intro-leodevbro-extension3.png
.
.

JTextPane immutable text blocks

I've been creating something like text editor for a while and noticed one interesting feature in NetBeans: when creating Java Application from a template (for example, "Desktop Application"), it creates immutable blocks of code (they are present for viewing but they can not be modified directly).
This shot should make all that text above clear:
So, the question is: how to implement such a feature using JTextPane?
You must create a class implementing the javax.swing.text.DocumentFilter used by your editor pane for the unchanged text. For the highlighting I suppose you will have to use a javax.swing.text.Highlighter.

Categories