Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Embedding Comments in Custom DSL Files
Embedding Comments in Custom DSL Files [message #1866792] Thu, 06 June 2024 16:40 Go to next message
Eclipse UserFriend
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 13:28 Go to previous messageGo to next message
Eclipse UserFriend
Maybe you can do this with the codemining feature or the new file wizard feature
Re: Embedding Comments in Custom DSL Files [message #1866849 is a reply to message #1866840] Sun, 09 June 2024 03:34 Go to previous messageGo to next message
Eclipse UserFriend
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 11:33 Go to previous messageGo to next message
Eclipse UserFriend
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] Sun, 16 June 2024 22:49 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Embedding Comments in Custom DSL Files [message #1867179 is a reply to message #1867134] Tue, 18 June 2024 11:16 Go to previous messageGo to next message
Eclipse UserFriend
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 00:23 Go to previous message
Eclipse UserFriend
can you double check if plugin.xml_gen needs merging into plugin.xml.
depending on your situation it cannot happen automatically
Previous Topic:Import Ecore model mapping
Next Topic:Xtend + tycho maven + JDK 17 ==> java.lang.IllegalArgumentException:
Goto Forum:
  


Current Time: Sat Aug 30 19:37:17 EDT 2025

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

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

Back to the top