How to insert visual elements inside the Java text editor of Eclipse? - eclipse

I'd like to add extra visual elements inside the Java text editor of Eclipse, more specifically on top of classes and methods declarations. Things like indicators and links.
The best example is what Microsoft has done in Visual Studio with what they call CodeLens:
The closest solution I can think of is using Annotations (displayed in the rulers) but it's far from the user experience I want to have.
Are there any Eclipse plugins that have done this before?
Any pointers to give me somewhere to start?

Annotations are typically shown in the vertical and overview rulers (left and right), but they're not limited to them. Take a closer look at the documentation you linked to, particularly the mentions of AnnotationPainter, and then how it uses drawing strategies. I expect you'd need a rather complicated one, and I haven't even thought through how you'd generate the information in the first place, never mind adding it directly to the Annotation Model if you're not just going to stash it in a Marker on disk.
Of course, some of this looks like information you can already find through Team->Show Annotations (although that does use the ruler to let you find them by line).

Disclaimer, I'm the author of CodeLens Eclipse.
Eclipse doesn't provide Codelens feature, but it exists CodeLens Eclipse.
This project provides a CodeLens extension point to implement your own CodeLens. Today TypeScript, Java JDT CodeLens and lsp4e CodeLens are available. Here a little demo with Java JDT Editor:

Related

How to setup a new language IDE

At work we are using a proprietary language and to program we are using Notepad++ with a simple code highlight. That is really annoying so, what I want to do is to invest some time to setup a text editor or an existing IDE to support my language.
I've googled a lot and there are so many options and before starting to work I wanna ask to you what is the best choice.
What I want to do is to have, like an IDE, a syntax highlight, a window with the function list tree, with the local function variables inside the same subtree, maybe text autocomplete (if I type "pro" I would like to see the suggestion "procedure" and if I press enter it will write for me something like
procedure "name" {
--code--
}
with the cursor on "name" ready to change it.
etc etc...
Can you suggest me the right path to follow?
Is it to keep using Notepad++? With sourcecookifier? functionlist?
Or I have to change to another text editor?
Or there is some famous IDE like Eclipse, NetBeans etc that allow to easily add my own language?
PS. my language is pretty simple, I don't have complex structures, is Pascal-like. Something like that:
variable int xyz
PROCEDURE asd
BEGIN
END PROCEDURE asd
I would recommend you to stay with Notepad++ and extend it with some plugins and configuration. This would be fairly quick and easy to set up and still give a big win, even though you might not be able to get all the nice features of something like Eclipse. But since you already know the Notepad++ it wouldn't require learning an entirely new tool.
Some plugins that I have found useful
Function List
Light Explorer
XBrackets Lite
There are probably a lot more that can be useful to you.
Notepad++ also got some built in auto-completion functionality that can be enabled in the settings.
Have you evaluated Eclipse XTEXT ?
What is Xtext?
Xtext is a framework for development of programming languages and domain specific languages.
The only IDE I have used for the last few years is Eclipse. There are lots of other IDEs available, also notable and popular is Netbeans. There are many others. It's important to note that all IDEs have their fans, but I can only speak to Eclipse.
Eclipse is a platform, which means it is an application on which you can build other applications. Eclipse provides a framework which you can customize and extend to produce a working application. It takes care of the user interface, preferences storage, modularisation using OSGi, and lots of other things.
Eclipse has facilities to support what you're looking for:
Syntax highlighting in the editor.
The Outline View provides function and variable listing in a tree
Autocompletion and Suggestions (activated by hitting ctrl-space)
Code Templates to fill out files and procedures etc.
The disadvantage is that customising and extending Eclipse to do what you want isn't trivial. Having written a language debugger for Eclipse, I can tell you that leveraging Eclipse's platform helped enormously, but there's a learning curve. You'd essentially have to be coming up with a new set of plugins to provide your highlighting, outlining, autocomplete suggestions and templates (I'm not sure if template support is built into the platform or not).
So I would say, unless you can find some sort of extensible editor for Eclipse - I know Aptana is extensible for tag-based markup - you are probably as well staying with your existing tooling.
Do explore the other IDEs though - I've heard good things about IDEA as well as Netbeans. :)
Good luck!
I can recommend SynWrite editor. Good support for external languages, fully customizable. (Editor of new lexers is there)

Creating JSPs with Eclipse

I'm trying to create several JSPs, and I was told that what most people do, is open notepad and hardcode the whole thing in. I come from the origins of C#, so that option is somewhat foreign to me :)
I did try to do several complex components by hand in Java. It took quite a bit of time (mostly with arrangements) but I was able to do it.
My question is, will I be able to create JSPs inside of Eclipse and will all the UI components that I will implement be there as I positioned them?
I'm asking because I found an Eclipse plugin (http://code.google.com/javadevtools/download-wbpro.html) that allows me to drag and drop components (C# style :D) and I needed to know if it is worth downloading, because if I still have to hardcode the JSP's UI in, the download time will be a waste (slow speed here).
Create a jsp page and right click on the editor and go to open with.
Select Web Page Editor and you will have the design view opened.
On the top right corner you will have an arrow. Click on the arrow and you will have elements to drag and drop on the editor.
I think almost nobody uses notepad to create JSP's. The editing is done in text mode in IDE's or comparable tools.
I agree with #BalusC, JSP's don't have good support for drag and drop development (like Visual Studio), although there tools like Dreamweaver which had some support to create the HTML structure in a WYSYWYG environment. I would not recommend these kind of tools for JSP but it's your choice.
The plugin you mention is not for JSP's and any of the alternatives it does support won't be quick to learn.
As #BalusCmentions, JSF's is an alternative for which there are some visual editors. You might want to look into that but you'd need to do some research as JSF is an standard and there are several implementations and related tools around. There are plugins for JSF support in Eclipse.
All in all I think you need to read further on Java web development and the alternatives that exist.

Customizing UI elements in Eclipse default Java Editor via plugin

I'm trying to develop a plugin for Eclipse that will allow me to modify various elements within the default java text editor. I've found lots of tutorials for creating my own text editor for a different language, but nothing for editing the default java editor. Specifically, I want to be able to run a command and highlight certain areas of the code based on a different program. How do I develop this?
Thanks
You will need to implement your own type of markers and maybe associate annotations with them. Then you can associate the java editor with the annotations to show them. Your application will generate the markers.
Specifically you might want to start to read about org.eclipse.core.resources.marker extension point and IResource.createMarker() to create the markers.
Its doable. You need to find the right extension point that allows you to add functionality to the java editor.
See IBM tutorial. The example with the heading "How do you analyze Java code to apply modifications" seems to be what you want to do.

Add functionality to all Eclipse TextEditors

I need to add some functionality to eclipse text editors. The goal is to get a Graphics Context or add a SWT Canvas to any and all Eclipse AbstractTextEditors and package these modifications within a plug-in (so by installing the plugin I provide, the editor modification will work for the Java Editor, XML Editor, plain text editor, etc.). Are there any extension points that would suffice for this purpose, or is my best bet with a fragment? Any help is appreciated.
I would recommend looking at the source code for AbstractTextEditor to see if an extension point exists for this purpose. If an extension point exists, it will be evident in that class source.
I would wager that such extension point does not exist. You are left with opening an enhancement request and in the meantime patching the plugin containing AbstractTextEditor plugin to alter the source of that file. A fragment isn't going to do the trick. Another alternative to consider is to learn and apply a bytecode weaving framework such as AspectJ (http://eclipse.org/ajdt/).

Why does one need the Eclipse Snippets View when editor templates already exist?

What are the tradeoffs of the Eclipse Snippets View vs. editor templates? Why were Snippets introduced in the first place?
Snippets appear to be a custom version of templates, with a view in the perspective and GUI dialogs to prompt for variable values in the template.
The only "new" functionality they have is to offer up their functionality through toolbar items in the editors.
Snippets view is sort of an extension proposed by WTP (Web Tool Platform) for template, more oriented to (web) code formatting, whereas templates help the user enter reoccurring patterns into a text editor.
So at the beginning, Eclipse Templates was a standard eclipse feature which could only be applied for java and javadocs.
Snippets are basically the same, but for other kind of files and were introduced by WTP to fill the same need, but for their own type of files (xml, jps, html, ...)
(and this is, right there, "why snippets were introduced in the first place")
Template does not have their own view, but rather an obscure Preference page (Preferences -> Java -> Editor -> Templates)
You could at the time however write a small eclipse extension in order to make a Template View.
This has been resolved since eclipse3.4M6 (Templates have their own view)
You can also build some custom advanced snippets view
Additionally, the Snippets view was first conceived during the development time frame between Eclipse 1.0 and 2.0, before the content assist templates were anywhere close to being as capable as they now are. That's why it was created, and it simply came into WTP as part of IBM's initial contribution to the project.