How do I include files with no extension for my Xtext DSL? - eclipse

By default Xtext allows to specify a single extension for DSL files when creating a new project. However, it is possible to add more extensions for a single DSL as described in Xtext FAQ. But I couldn't get it working with files with no extension at all.
A typical example is a makefile for Make build system. One can use Makefile, GNUmakefile and *.mk names, and Eclipse will open the same editor for such files.
I want to get Xtext to recognize both *.mydsl files and a file named Mydsl.
I tried to add
filenames="Mydsl"
attribute to editor node of org.eclipse.ui.editors extension point in plugin.xml of my UI project. This enables Eclipse to open Mydsl files in the proper editor. But Xtext does not index these files and reports linking errors when I try to refer an element defined in Mydsl from any other file.
Is there a way to enable Xtext to process source files with fixed name but with no extension as well as regular files?
UPD. 1
Accordingly to Sebastian's answer I tried to specify a custom content type in plugin.xml of the main project:
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.text"
file-extensions="mydsl"
file-names="Mydsl"
id="org.xtext.example.mydsl.contentType"
name="My Language"
priority="normal">
</content-type>
</extension>
And binding it as follows:
<extension
point="org.eclipse.xtext.content_resourceServiceProvider">
<resourceServiceProvider
class="org.xtext.example.mydsl.MyDslResourceServiceProvider"
contentTypeIdentifier="org.xtext.example.mydsl.contentType">
</resourceServiceProvider>
</extension>
But I still get linking errors as described above. I also added breakpoints into all methods of MyDslResourceServiceProvider and it seems that it doesn't even get instantiated or somehow invoked.
I also tried to move these extensions to the UI project but with no effect too.
UPD. 2
Finally, I've done it.
Steps to get things work in a nutshell:
Define new content type using org.eclipse.core.contenttype.contentTypes extension point
Create a content handler by extending org.eclipse.emf.ecore.resource.impl.PlatformContentHandlerImpl class and override canHandle(URI) method to return true if and only if the argument is not null
Register it with org.eclipse.emf.ecore.content_handler
Create a new resource service provider with canHandle(URI) returning true always. One can extend org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider and override the corresponding method
In the UI project bind it to org.eclipse.xtext.content_resourceServiceProvider, do not forget to specify an extension factory before the class name
In the UI project register org.eclipse.xtext.resource.IResourceFactory as org.eclipse.emf.ecore.content_parser, again with the extension factory
Add content type bindings to org.eclipse.ui.editors, org.eclipse.compare.contentViewers and org.eclipse.compare.contentMergeViewers
Depending on whether you need an old extension binding or not, remove org.eclipse.emf.ecore.extension_parser and org.eclipse.xtext.extension_resourceServiceProvider extensions
A change set (applied to a fresh project) for my case can be found here.

You could try to exploit the extension point for resource service providers and resource factories. It allows to register services / factory either by file extension or by content type. I think the latter should work if you provide a suitable content type for your files.

Related

Does register my custom cluster selection strategy need to compile source code?

I see the doc2.1.x describe the custom cluster selection strategy as follows:
that Register the implementation as a service. You can do this by creating a new file under META-INF/service. Use the filename com.orientechnologies.orient.core.metadata.schema.clusterselection.OClusterSelectionStrategy. For its contents, code your class with the full package.
Does it mean I must modify source code project, compile and publish?
Yes, you must modify the source code project and compile.
I have followed the docs http://orientdb.com/docs/2.1/Cluster-Selection.html#custom-cluster-selection-strategies
and it works.

Eclipse manage file suffix list

I decided to move some of my jsp files into separate files with special filetype (named *.part). Now I imported that files to be handled like jsp's to color them and make the coding more convenient.
I can find the new extension in "preferences/web/jsp/Add this suffix". Some comparable, registered file types can be found under e.g. pref./web/html or pref./web/css.
But how can I delete these types again? How to manage these files?
I found the answer to my above-mentioned question:
In Eclipse: Preferences->General->Content-Types->Text->[Remove/Add file here]

In-place ("Quick-Assist" or something easier) source code modifier?

Eclipse already has very impressive and useful what I call "source code modifiers" (please suggest a better name).
For example, it has "Quick Fix", "Word Completion", "Externalize Strings" and other functions that modify source code via menu (or key-combination).
Now, I am looking to add my own "source code modifier" function: I would like to:
Highlight (select) an arbitrary string.
Right-click on it
Invoke a menu item that would "translate" that string to a different string, using a function that I wrote (preferably in Java). Similar to "Quick Fix" or "Replace With" currently on the default context menu.
Is this possible in Eclipse?
If so, what do I need to do to accomplish this?
The short answer:
The quick assist will have to modify the AST of the Java code. Essentially you will have to replace a org.eclipse.jdt.core.dom.SimpleName node with one that you want.
The long answer:
The org.eclipse.jdt.ui.quickAssistProcessors extension point enables you to contribute your own Java code quick assists.
To create a new extension for the extension point you need to first provide the required extension in the plugin.xml. For example, JDT defines the following processor
<extension
point="org.eclipse.jdt.ui.quickAssistProcessors">
<quickAssistProcessor
name="%defaultQuickAssistProcessor"
class="org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor"
id="org.eclipse.jdt.ui.text.correction.QuickAssistProcessor">
</quickAssistProcessor>
</extension>
(For a description of the individual attributes, please refer to the extension point documentation)
Then you need to create the class that implements the org.eclipse.jdt.ui.text.java.IQuickAssistProcessor interface, and modify the AST in this class. (This class is the same as the one you specified while declaring the extension)
Supplying the right IJavaCompletionProposal
JDT provides the following default implementations for correction proposals that can be used to contribute quick fixes and quick assists.
ChangeCorrectionProposal
CUCorrectionProposal
ASTRewriteCorrectionProposal
If you use an ASTRewrite, you should create an ASTRewriteCorrectionProposal.
ASTView Plugin
This is something that will help you visualize the AST of a Java source file http://www.eclipse.org/jdt/ui/astview/index.php
The right name is 'Quick Assist'. You have to write some code to create your Quick Assists.

Error with Groovy AST transformations when cleaning project in Eclipse

I'm trying to work through groovy's Implementing Local AST Transformations tutorial, but whenever I clean my project I get this error in each file that has the #WithLogging annotation in it:
Groovy:Could not find class for Transformation Processor AC.LoggingASTTransformation declared by AC.WithLogging
So you have a package named "AC" that contains both "WithLogging.groovy" and "LoggingASTTransformation.groovy" classes? Does it also contain any classes that implement the "WithLogging" interface?
If so, I'd suggest you move the class(es) that use your annotation to a location outside of the annotation defining package (the default will suffice, for diagnostic purposes) - Order of compilation matters with transformations. See this post on the groovy users mailing list for more on that.
Also try changing the annotation from #WithLogging to #AC.WithLogging.
As far as cleaning with Eclipse is concerned, I had a similar issue and found that I had to make a trivial modification after a clean to any file that contained my annotation. IE, add a space somewhere. Then save the file. This should rebuild everything properly.

IBM Eclipse WSDL Editor: How do I include an external wsdl/schema?

I am trying to create Web Services from the Top-Down approach. I downloaded Eclipse and am using the WSDL gui editor in it to build my WSDL files.
I am splitting up my Services based on "modules". The Types I am adding to the WSDLs all need to reference common stuff, such as PersonEntity, AddressEntity, States enumeration (simple type), Countries enumeration (simple type), and AbstractEntity. Since those items are all common I created a seperate WSDL file (named Commons.wsdl) that contains the type information for those types.
I want to "import" that WSDL into my other WSDL files to use:
For example, I have an entity named RegistrationEntity which inherits from AbstractEntity and contains a PersonEntity as well as an AddressEntity. I'm not sure how to do this... I saw that the WSDL spec has "import" and "include" and am not sure which one to use. Also, how do I actually import (or include) the Commons.wsdl file so that I can use the Types defined within it?
Thanks!
Oh, and I'm not sure if I'm supposed to stick this stuff in a seperate WSDL but another type of file such as an xsd or something. I really wanna follow best practices so if that's the proper way to do it then I'd rather do that.
I found out that the problem I had was I was creating a WSDL file for my commons and using an inline scheme for that, rather than creating an XSD file to be imported by my other WSDLs.
So instead I just created an Commons.XSD as my "Common Schema".