Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get Project Name in new Project Wizard for Eclipse
Get Project Name in new Project Wizard for Eclipse [message #1745299] Fri, 07 October 2016 11:29 Go to next message
Martin Westerkamp is currently offline Martin WesterkampFriend
Messages: 9
Registered: September 2016
Junior Member
Hey everyone,

I have a short question concerning the new Project Wizard for eclipse feature which was added I think with version 2.9 of xtext.

While before the Project name was accessible through xpand using projectName of MD2ProjectInfo (as I understand), now I try to use it within MyDslNewProjectWizardInitialContents.

I have tried to inject MyDslProjectInfo, however, the projectName variable is null, when accessed.

Does anyone have an idea how to access the Project Name from MyDslNewProjectWizardInitialContents in order to generate the files from there?

Greets,
Martin

[Updated on: Thu, 08 December 2016 15:02]

Report message to a moderator

Re: Get Project Name in new Project Wizard for Eclipse [message #1745301 is a reply to message #1745299] Fri, 07 October 2016 11:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you elaborate what you are actually doing? share a small reproducing example?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get Project Name in new Project Wizard for Eclipse [message #1745305 is a reply to message #1745301] Fri, 07 October 2016 11:49 Go to previous messageGo to next message
Martin Westerkamp is currently offline Martin WesterkampFriend
Messages: 9
Registered: September 2016
Junior Member
Sure, I want to use the project's name within the path for the generated file as well as wihtin the generated file.

However, when using the wizard I receive a NullPointerException, since projectInfo.projectName is null at that point.

/*
 * generated by Xtext 2.10.0
 */
package com.mydsl.ui.wizard

import org.eclipse.xtext.generator.IFileSystemAccess2
import com.google.inject.Inject

class MyDslNewProjectWizardInitialContents  {
	@Inject
	MyDslProjectInfo projectInfo

	def generateInitialContents(IFileSystemAccess2 fsa) {
		
		val projectName = projectInfo.projectName

		fsa.generateFile(
			"src/" + projectName + "/model/default.mydsl",
			'''
			package «projectName» + ".model"
				
			/*
			 * Implement the model here
			 */
			'''
			)
	}
}
Re: Get Project Name in new Project Wizard for Eclipse [message #1745307 is a reply to message #1745305] Fri, 07 October 2016 12:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
well this is something the infrastructure is not really built for. i think you have to customize MyDslProjectCreator for that.
@lorenzo what do you think?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get Project Name in new Project Wizard for Eclipse [message #1745317 is a reply to message #1745307] Fri, 07 October 2016 12:44 Go to previous messageGo to next message
Martin Westerkamp is currently offline Martin WesterkampFriend
Messages: 9
Registered: September 2016
Junior Member
Actually your hint using MyDslProjectCreator already did the trick.

All that is necessary is injecting MyDslProjectCreator and using its method getProjectInfo which returns MyDslProjectInfo. From there projectName can be accessed.

Thanks Christian for the hint!

/*
 * generated by Xtext 2.10.0
 */
package com.mydsl.ui.wizard

import org.eclipse.xtext.generator.IFileSystemAccess2
import com.google.inject.Inject

class MyDslNewProjectWizardInitialContents {
	@Inject
	MyDslProjectCreator projectCreator

	def generateInitialContents(IFileSystemAccess2 fsa) {
		
		val projectName = projectCreator.projectInfo.projectName

		fsa.generateFile(
			"src/" + projectName + "/model/default.mydsl",
			'''
			package «projectName».model
				
			/*
			 * Implement the model here
			 */
			'''
			)
	}
}

[Updated on: Fri, 07 October 2016 12:45]

Report message to a moderator

Re: Get Project Name in new Project Wizard for Eclipse [message #1745323 is a reply to message #1745307] Fri, 07 October 2016 13:01 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Christian Dietrich wrote on Fri, 07 October 2016 12:01
well this is something the infrastructure is not really built for. i think you have to customize MyDslProjectCreator for that.
@lorenzo what do you think?


Indeed the project info is not meant to be injected: it is used by the wizard infrastructure to store information about the project. I see that the solution has already been found... though it's strange that it works by just injecting the project creator: I would assume that project info is null if you inject project creator...


Previous Topic:problem with using import quickfix
Next Topic:OCL into XTEXT
Goto Forum:
  


Current Time: Wed Apr 24 21:02:08 GMT 2024

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

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

Back to the top