views:

205

answers:

2

Hi

We are developing an eclipse plugin and we have an extension like say, ".xyz" but it actually contains java code. JavaCore.createCompilationUnitFrom() accepts only files with extension ".java". JavaCore has JAVA_SOURCE_CONTENT_TYPE which returns the extensions that it treats as Java source files.

My questions is How do I add ".xyz" to this list ? I want JavaCore to treat files of ".xyz" extension as java source files.

Any pointers would be very helpful.

A: 

I wrote a extension to handle files with different endings ".xyz"

You have to define an editor which can open this file and you have to define a builder which can build this file.

The editor implementation for files which includes java source code can be, that you extend from the eclipse java editor and implement the extension point "org.eclipse.ui.editors".Add the file extension to the editor extension preference entry "extensions".

When you than open the specific file, the editor is used you have added. I dont now if you can add a additional extension to an editor which is defined in an eclipse plugin. I think you have to do it by your own.

When you want to build the specific file as it usual is in eclipse, you have to implement a new builder, using "org.eclipse.core.resource.builders". I do not have an example but the key word is "nature" (org.eclipse.core.resources.natures). As far as i now you can add this builders to project you defined. I am not sure if you can add these builders to existing projects like a "Java plugin project".


When you just want to add a editor to a file extension you can do this in the preference page

"General" - "Editors" - "File Associations"

Markus Lausberg
+2  A: 

The bug 71460 has introduced support for different extension for java-like sources in eclipse3.1.
The bug 121715 mentions for eclipse3.2, (for supporting .aj files as containing Java source):

<content-type id="ajSource" name="AspectJ Source File" 
              base-type="org.eclipse.jdt.core.javaSource"
              file-extensions="aj"/>
VonC
+1 for avoiding any nasty hacks
Rich Seller
@Rich: thank you Sir. You should see the other really nasty hack I do propose in http://stackoverflow.com/questions/1311720/where-to-tweak-an-eclipse-to-change-the-default-settings-used-when-creating-a-new/1311770#1311770 ;)
VonC
yeah I saw that, that is a nasty hack, no +1 for you
Rich Seller