From b04d0fac4221ed5fc8ca8b659faf3dbbdefab661 Mon Sep 17 00:00:00 2001 From: Sebastian Zarnekow Date: Thu, 19 Nov 2015 19:56:10 +0100 Subject: [PATCH] [xtext][generator] Additional abstract base class Helps to implement generator fragments that write to other locations on the disk, e.g to generate plugins for other editors --- .../AbstractExternalFolderAwareFragment.xtend | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 plugins/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/AbstractExternalFolderAwareFragment.xtend diff --git a/plugins/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/AbstractExternalFolderAwareFragment.xtend b/plugins/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/AbstractExternalFolderAwareFragment.xtend new file mode 100644 index 000000000..ee661b8ce --- /dev/null +++ b/plugins/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/AbstractExternalFolderAwareFragment.xtend @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.xtext.xtext.generator + +import com.google.inject.Injector +import org.eclipse.xtend.lib.annotations.Accessors +import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess +import org.eclipse.xtext.xtext.generator.model.XtextGeneratorFileSystemAccess +import org.eclipse.emf.mwe2.runtime.Mandatory + +/** + * Generator fragment that allows to write files to arbitrary, user configurable + * locations. + * + * @author Sebastian Zarnekow - Initial contribution and API + */ +abstract class AbstractExternalFolderAwareFragment extends AbstractXtextGeneratorFragment { + + String absolutePath + + @Accessors(PROTECTED_GETTER, PUBLIC_SETTER) + boolean ^override = false + + IXtextGeneratorFileSystemAccess outputLocation + + 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 + } + +} \ No newline at end of file