Skip to content

Instantly share code, notes, and snippets.

@szarnekow
Last active November 19, 2015 17:42
Show Gist options
  • Save szarnekow/b54db10cf06fae53d3a7 to your computer and use it in GitHub Desktop.
Save szarnekow/b54db10cf06fae53d3a7 to your computer and use it in GitHub Desktop.
module org.eclipse.xtext.example.arithmetics.GenerateArithmetics
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
var rootPath = ".."
var sublimePath
/*
* Some more stuff in between
*/
language = StandardLanguage {
name = "org.eclipse.xtext.example.arithmetics.Arithmetics"
fileExtensions = "calc"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
fragment = WriteToExternalFolderFragment {
absolutePath = sublimePath
// override = true
}
}
import com.google.inject.Injector
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess
import org.eclipse.xtext.xtext.generator.model.XtextGeneratorFileSystemAccess
import org.eclipse.emf.mwe2.runtime.Mandatory
class WriteToExternalFolderFragment extends AbstractXtextGeneratorFragment {
String absolutePath
@Accessors(PROTECTED_GETTER, PUBLIC_SETTER)
boolean ^override = false
IXtextGeneratorFileSystemAccess outputLocation
override generate() {
// content is produced here
// Currently processed Grammar is obtained via getGrammar
outputLocation.generateFile('MyFileName.txt', 'SomeContent')
}
protected def getOutputLocation() {
return outputLocation
}
override initialize(Injector injector) {
super.initialize(injector)
this.outputLocation = new XtextGeneratorFileSystemAccess(absolutePath, override)
injector.injectMembers(outputLocation)
}
protected def getAbsolutePath() {
return absolutePath
}
@Mandatory
def void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment