How to prevent duplicate IDs / code in eclipse RCP plugins - eclipse

When writting RCP Plug-ins it often happens that i need to declare and reference IDs in the extension specification (i.e. in the plugin.xml) and also in my java code. When I change one of those, I also have to change the duplicate.
I'm not sure if the problem is already that the same IDs must be used in the code and the plug-in declaration, but thats how the eclipse plug-in templates do it. If that's the root of the problem: how to prevent it?
If it's the correct way, to declare and reference IDs in the plugin.xml and in the java code: how to prevent that code dulication?
Also inside the plugin.xml there is something that may be regarded as duplication: ID definitions and the references pointing at them. If I change the definition, all references have to be updated. One could do that by simply replacing all text-occurence. But I normally edit the plugin.xml in the Plug-in Manifest Editor (i.e. in the forms, not in the plain text XML). Is there a way to refactor the IDs from inside the forms, without touching the plain text xml and without the fault prone approach of simple text replacement?

If you are referring to properties such as Bundle-SymbolicName then you should think of it as a package name, i.e something that shouldn't change at all.
Several of the other fields can very easily be externalized to strings, this is to simplify translations. See this help page. A wizard is available on the overview tab in the manifest editor.

Related

"private" comments in Eclipse

I would like to write "private" comments in Eclipse while working on Java projects. In other words, I would like to write comments associated with areas in the Java classes that only I can see but other developers working on the project cannot. The comments therefore cannot be regular comments in the source code. Ideally I would select an area on a Java source file and have a view in the perspective allowing me to write and read my comments associated with the selected area. Those comments should be persisted in a file(s) outside of the Java source files of the project.
I understand that as other developers modify the Java code my comments might become stale and I will have to eventually have to work to alleviate this problem. I am not worried about the persistence right now, either.
How do I handle the Eclipse part of the challenge, i.e. create my own view in/to which I can write/read comments and have it associated with locations in the source files? Or, can I display comments lines in the source files that are not saved along with the source so that they are "private"?
This sounds like what you can already do with the Bookmarks View, aside from the text presentation in the view itself being rather limited.

Eclipse plugin for better JSP support

I'm looking for an eclipse plugin which can at least search where the current JSP is included (or the path mentioned for example in custom "include like" tags or comment or anything). Similar like doing copy qualified name and do a file search with the correct path.In IDEA it's called Analyze Backward Dependencies and it works for JSPs too (at least for the standard includes).
A better one would be to show all the JSPs where the current one is included and show all the included JSPs recursively as a tree maybe so I can navigate in it easily. I'm not sure if this can be done to be usable (I think it would be slow).
Another feature I would like if I click on a variable's name it jumps to where it's declared with even if it's declared in a different JSP.IDEA can do this too.
I have a simple solution for the first one but I can't add more functionality to it as I'm not familiar with the eclipse plugin system and RCP and I don't really have time to learn it.
And please don't tell me to use IDEA because unfortunately that's not an option at work.

Eclipse plug-in: Create a new file extension for a language not supported by Eclipse

I am creating an Eclipse plug-in for it to support a new language. The problem I have is with the content type/file association and its respective editor.
The language has no base in Java or XML and let's say its extension is '.xyz'
From what I understood of research online, I would need to create a new Content Type with file extension '.xyz'. But all the information I have found online has related to either associating a new extension with java (for java syntax highlighting) or creating a new type of file which can be a variant of XML, hence having a lot of details about the describer.
Basically, I am confused about the content describer, am I also to create a new describer for a new language? And what base-type would I give for a language not related to XML or JAVA at all?
Also, since I will be adding my own syntax highlighting, would I need to create my own editor or can I just open such a file in the pre-set editorArea (editors).
The package I am looking at for content types is org.eclipse.core.contenttype.contentTypes.
I realised that I never really picked an answer for this question and eventually I found some useful information on it, so I thought I would share it.
This is the information I understood and used; I apologize if there are any errors or I have misunderstood, and I am open to any corrections.
It was actually a lot simpler than I expected.
To create a new file extension, you just need to extend
org.eclipse.core.contenttype.contentTypes
If you are using the PDE, then you can just right click on the extension (once it is added in the extensions tab) and choose New... -> content-type
Here is the xml code for it,
<extension
id="com.newLanguage.XYZ.contentType"
point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="xyz,xyzz"
id="com.newLanguage.XYZ.contenttypeMod"
name="XYZ File"
priority="normal">
</content-type>
</extension>
Here you can set the properties of this content-type by defining a unique id, a human-readable name and the extension. You can also give multiple extensions for this content type. For example, my XYZ language can have 2 types of extension '.xyz, and '.xyzz'.
The content describer comes in when I have one generic file-extension: '.xy' but the content or format of the file may differentiate and so I need a describer for the editor to be able to go through the content of the file and recognize the difference. This is handy for syntax highlighting where I need to know the differences.
Since I am not very good at explaining this, this link was extremely useful to me.
But all in all, this tutorial is what set me on my pace and has actually taken me far in understanding how to implement an IDE plug-in for Eclipse. I think it is a very ideal place to start, especially for someone new.
Another place that kept my work going is the Eclipse FAQs but I would specifically like to point out to section 3.5 Implementing Support for Your Own Language which has many tutorial links.
Note: this (new language support, custom syntax highlighting, ...) is the kind of feature provided with XText.
Xtext - Language Development Framework
With Xtext you can easily create your own programming languages and domain-specific languages (DSLs).
The framework supports the development of language infrastructures including compilers and interpreters as well as full blown Eclipse-based IDE integration.
Since the sources are available, you might have a lots of clues to illustrate the usage of the packages you are currently looking.

Multiple languages used in one eclipse project

I was wondering whether it was possible for projects in Eclipse to have multiple languages associated with them, specifically PHP and Java. The purpose of this is that I'd like a common 'properties' file for the two projects.
If instead there's a way to hold a relative reference to a file so that both projects can reference the properties file, that will work too.
Part one of the question
whether it was possible for projects
in Eclipse to have multiple languages
associated with them, specifically PHP
and Java
No, a project in eclipse is language dependent. You could technically write some source in another language and then use another build method to compile from the secondary language - Not recommended !!!
For the second part of the question ...
Common Property files
Create another project and in that project put a java properties file.
Have both projects (Java and PHP) read the property file from here (In Java just add where you put the file as part of the classpath)
In PHP use this Java properties reader
If you are careful on how you write the Java properties file you could also use parse_ini_file
You could just place the properties you want the two languages to share into a plain text file. Then code a PHP file to read the plain text file, and code a Java file to read the plain text file. Be careful if you plan on having your two projects edit said-file though. If there's any chance that both of them could be editing the file at the same time, you're in trouble.

Eclipse - Is it possible to link to a file from within a Java comment?

I am looking for a way to link from a comment inside a .java file to another file somewhere in the project folder (like CMD-clicking a Java Type links to the Type declaration). In my case I am working on a (Spring Roo backed) web application, so I have controllers and view files.
What I have in mind may look like this (Javadoc-oriented but of course not parsed but used directly as a link):
public String orderlist(ModelMap modelMap){
modelMap.addAttribute("orders", Order.findAllOrders());
// #link("/WEB-INF/views/order/list.jspx")
return "order/list";
}
I want to CMD-click on the comment link to open the file.
I am heavily using Working Sets, filters and of course CMD+SHIFT+R ("Open Resource"), which are all great, but this might come in handy working on a controller and the corresponding view (especially in a team). Is this possible somehow, a basic feature that I missed completely so far or even total nonsense for some reason? I realize that those links should be considered when, for example, refactor|move the view file.
The feature you're describing is Eclipse's hyperlink detectors: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_workbench_texteditor_hyperlinkDetectors.html. Unfortunately I'm not sure an implementation as you're describing is likely available.
There's an URLHyperlinkDetector that can pick up URLs, so you could potentially put a file:// URL in a comment and link to that, but I think that Eclipse is hard-wired to assume it's something that can be opened in it's browser. It's worth a shot, but of course the absolute paths would break sharing across teams/machines.
You could try your hand at contributing your own via a plugin that your team could install. Here's an implementation we created in Aptana Studio for picking up relative URIs in files and opening them in editors if possible: https://github.com/aptana/studio3/blob/development/plugins/com.aptana.editor.common/src/com/aptana/editor/common/text/hyperlink/HyperlinkDetector.java