Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » One file extension for different plug-ins?
One file extension for different plug-ins? [message #1745542] Wed, 12 October 2016 10:45 Go to next message
Martin Westerkamp is currently offline Martin WesterkampFriend
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 #1745552 is a reply to message #1745542] Wed, 12 October 2016 12:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
I just can you give a hint: content types. The stuff in plugin xml like the editor and he others that take a file extension support somehow content types as well

Unfortunately I have never used this nor have I seen any example impl


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: One file extension for different plug-ins? [message #1745554 is a reply to message #1745552] Wed, 12 October 2016 12:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
Hi

You can find some examples whereby XML can be used for UML. In particular see configuration in UMLResourcesUtil.init().

However using contentTypes is hard unless your extension is exclusive, as may be your case. You just need to use the overlooked content type argument to ResourceSet.createResource.

If you try to share the extension too wide you may have conflicts since IMHO an incorrect priority between content type and extensions usage was required in order to avoid a legacy incompatibility. You may therefore find that a global "*" occludes global content types. make sure they are all refined in a local ResourceSet.

Regards

Ed Willink
Re: One file extension for different plug-ins? [message #1745760 is a reply to message #1745554] Mon, 17 October 2016 09:13 Go to previous messageGo to next message
Martin Westerkamp is currently offline Martin WesterkampFriend
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?
Re: One file extension for different plug-ins? [message #1745777 is a reply to message #1745760] Mon, 17 October 2016 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
are your ids unique?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: One file extension for different plug-ins? [message #1745778 is a reply to message #1745777] Mon, 17 October 2016 13:21 Go to previous messageGo to next message
Martin Westerkamp is currently offline Martin WesterkampFriend
Messages: 9
Registered: September 2016
Junior Member
Do you mean the content type IDs? If so, yes they are unique.
Re: One file extension for different plug-ins? [message #1745780 is a reply to message #1745778] Mon, 17 October 2016 13:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
hmmm then i have no idea

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: One file extension for different plug-ins? [message #1745790 is a reply to message #1745780] Mon, 17 October 2016 14:38 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
Where is com.b.B defined?

It is hard to write XML manually without any content assist or validity checking; the smallest typo and it all goes hopelessly silent.

I know that debugging similar declarations took me a long time with a lot of single step debugging. Alternatively you might try migrating some declarations that work.

Regards

Ed Willink
Previous Topic:try-with-resource in Xbase
Next Topic:Xtext web content proposal
Goto Forum:
  


Current Time: Thu Dec 26 23:25:06 GMT 2024

Powered by FUDForum. Page generated in 0.04337 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top