Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Embedding Comments in Custom DSL Files
Embedding Comments in Custom DSL Files [message #1866792] Thu, 06 June 2024 20:40 Go to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
Hi everyone,

I have a quick question: when creating a new dsl file (.mydsl, for example), would it be possible to have comments embedded in it?
An example would be:
1. Create *.mydsl file
2. When opening *.mydsl, the result would be:
/*
* This is a DSL tutorial
*/



I wanted to be able to give the user more insight into how to use and define dsl through these comments. Is something like this possible?

Thanks in advance
Re: Embedding Comments in Custom DSL Files [message #1866840 is a reply to message #1866792] Sat, 08 June 2024 17:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14698
Registered: July 2009
Senior Member
Maybe you can do this with the codemining feature or the new file wizard feature

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Embedding Comments in Custom DSL Files [message #1866849 is a reply to message #1866840] Sun, 09 June 2024 07:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
Yes.

When a wizard creates a new file it can have initial (textual) contents which can of course include comments.

See https://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.xtext.oclinecore.ui/src/org/eclipse/ocl/xtext/oclinecore/ui/wizards/AbstractOCLinEcoreFileNewWizard.java
Re: Embedding Comments in Custom DSL Files [message #1867116 is a reply to message #1866849] Sun, 16 June 2024 15:33 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
And where do I create the custom class that extends AbstractFileNewWizard in an Xtext project and bind or register that class so the Xtext editor knows that should call that wizard instead of the default?
Re: Embedding Comments in Custom DSL Files [message #1867134 is a reply to message #1867116] Mon, 17 June 2024 02:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14698
Registered: July 2009
Senior Member
I am not sure if I get your question and there is no misunderstanding

You still have to call the wizard in the menu and not new file

https://blogs.itemis.com/en/new-file-wizard-easy-to-generate-with-xtext-2.14


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Embedding Comments in Custom DSL Files [message #1867179 is a reply to message #1867134] Tue, 18 June 2024 15:16 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
So I followed the blog explanation and it generated the wizard package in the UI project of my language, but when i created a new file in runtime it didn't generate the content in .xtend class.

This is mwe2 file
language = StandardLanguage {
			name = "org.xtext.example.cicd.CICD"
			fileExtensions = "cicd"
			referencedResource = "platform:/resource/CICD_metamodel/model/cICD_metamodel.genmodel"
			
			fragment = ecore2xtext.Ecore2XtextValueConverterServiceFragment2 auto-inject {}

			formatter = {
				generateStub = true
				generateXtendStub = true
			}

			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
				// Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage
				generateDeprecationValidation = true
			}
			generator = {
				generateXtendStub = true
			}
			junitSupport = {
				junitVersion = "5"
			}
			fileWizard = {
        		generate = true
    		}
}


and this is the xtend class automatically generated when invoking Run As -> MWE2 Workflow
/*
 * generated by Xtext 2.34.0
 */
package org.xtext.example.cicd.ui.wizard


import org.eclipse.xtext.ui.wizard.template.FileTemplate
import org.eclipse.xtext.ui.wizard.template.IFileGenerator
import org.eclipse.xtext.ui.wizard.template.IFileTemplateProvider

/**
 * Create a list with all file templates to be shown in the template new file wizard.
 * 
 * Each template is able to generate one or more files.
 */
class CICDFileTemplateProvider implements IFileTemplateProvider {
	override getFileTemplates() {
		#[new HelloWorldFile]
	}
}

@FileTemplate(label="Hello World", icon="file_template.png", description="Create a hello world for CICD.")
final class HelloWorldFile {
	val helloName = combo("Hello Name:", #["Xtext", "World", "Foo", "Bar"], "The name to say 'Hello' to")

	override generateFiles(IFileGenerator generator) {
		generator.generate('''«folder»/«name».cicd''', '''
			/*
			 * This is an example model
			 */
			Hello «helloName»!
		''')
	}
}

Re: Embedding Comments in Custom DSL Files [message #1867185 is a reply to message #1867179] Wed, 19 June 2024 04:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14698
Registered: July 2009
Senior Member
can you double check if plugin.xml_gen needs merging into plugin.xml.
depending on your situation it cannot happen automatically


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Import Ecore model mapping
Next Topic:Xtend + tycho maven + JDK 17 ==> java.lang.IllegalArgumentException:
Goto Forum:
  


Current Time: Fri Jul 19 23:51:18 GMT 2024

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

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

Back to the top