One file extension for different plug-ins? [message #1745542] |
Wed, 12 October 2016 10:45 |
Martin Westerkamp Messages: 9 Registered: September 2016 |
Junior Member |
|
|
Hey,
I'm having the following situation: I have three languages A,B,C. B and C inherit from A, providing some functionalities.
Now what I want to do is using the same file extensions for languages B and C (A should not be used). Which language to use should either be decided by the content of the file or its URI. I have tried to implement the second solution by extending DefaultResourceServiceProvider in the following manner:
class BResourceServiceProvider extends DefaultResourceServiceProvider {
override public boolean canHandle(URI uri) {
val isWorkflow = Arrays.contains(uri.segments, "B")
return (super.canHandle(uri) && isWorkflow)
}
}
The thought behind is, that this language should only be use if "B" is part of the file's URI. When debugging, I observed that the value is negative when B isn't part of the URI, so that the method returns false as well. However, B is still hooked in Eclipse.
Does anyone have an idea how to solve this issue? Do I have to use an Eclipse specific class instead?
Many greetings,
Martin
|
|
|
|
|
Re: One file extension for different plug-ins? [message #1745760 is a reply to message #1745554] |
Mon, 17 October 2016 09:13 |
Martin Westerkamp Messages: 9 Registered: September 2016 |
Junior Member |
|
|
First of all, thank you guys very much for the hint!
I have been trying to get it working using content types, but wasn't successful so far.
I have implemented it the following way:
plugin.xml (UI):
<extension point="org.eclipse.ui.editors">
<editor class="com.b.ui.BExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
id="com.b.B"
name="B Editor">
<contentTypeBinding
contentTypeId="com.b.contentType">
</contentTypeBinding>
</editor>
</extension>
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.text"
file-extensions="common"
id="com.b.contentType"
name="B"
priority="normal">
</content-type>
</extension>
ContentHandler:
class BContentHandler extends PlatformContentHandlerImpl {
public static final String B_FILE_CONTENT_TYPE = "com.b";
override public boolean canHandle(URI uri) {
return Arrays.contains(uri.segments, "b")
}
override public Map<String, Object> contentDescription(URI uri, InputStream inputStream, Map<?, ?> options, Map<Object, Object> context) throws IOException {
val Map<String, Object> description = super.contentDescription(uri, inputStream, options, context);
if (canHandle(uri)) {
description.put(VALIDITY_PROPERTY, VALID);
description.put(CONTENT_TYPE_PROPERTY, B_FILE_CONTENT_TYPE);
}
return description;
}
}
I have then registered the content handler, a ResourceFactoryDescriptor and ResourceServiceProvider in the UIModule.
Generally, I pretty much followed Alex' description from here: https://dzone.com/articles/associating-xtext-editors-file
I have applied all the changes to both languages, B and C. However, only one is available in the eclipse instance. Any ideas?
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04892 seconds