org.eclipse.xpand2.XpandExecutionContext Java Examples

The following examples show how to use org.eclipse.xpand2.XpandExecutionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generatePluginXmlUi(List<LanguageConfig> configs, XpandExecutionContext ctx) {
	if (isUi() && !isUiMergedIntoRt()) {
		String filePath = fileExists(ctx, "plugin.xml", PLUGIN_UI) ? "plugin.xml_gen" : "plugin.xml";
		deleteFile(ctx, filePath, PLUGIN_UI);
		ctx.getOutput().openFile(filePath, PLUGIN_UI);
		try {
			XpandFacade facade = XpandFacade.create(ctx);
			List<Grammar> grammars = getGrammars(configs);
			facade.evaluate("org::eclipse::xtext::generator::Plugin::pre", grammars);
			for (LanguageConfig conf : languageConfigs) {
				conf.addToPluginXmlUi(conf, ctx);
			}
			facade.evaluate("org::eclipse::xtext::generator::Plugin::post", grammars);
		} finally {
			ctx.getOutput().closeFile();
		}
	}
}
 
Example #2
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void generate() {
  if ((this.naming == null)) {
    this.naming = this.createNaming();
  }
  final XpandExecutionContext ctx = this.createExecutionContext();
  final LanguageConfig config1 = this.createLanguageConfig();
  if ((this.fragment instanceof IGeneratorFragmentExtension2)) {
    ((IGeneratorFragmentExtension2)this.fragment).generate(config1, ctx);
  } else {
    this.fragment.generate(config1.getGrammar(), ctx);
  }
  this.generateStandaloneSetup(config1, ctx);
  this.generateGuiceModuleRt(config1, ctx);
  this.generateGuiceModuleUi(config1, ctx);
  this.generatePluginXmlRt(config1, ctx);
  this.generateManifestRt(config1, ctx);
  this.generatePluginXmlUi(config1, ctx);
  this.generateManifestUi(config1, ctx);
  this.generateManifestIde(config1, ctx);
  this.generateManifestTests(config1, ctx);
}
 
Example #3
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generatePluginXmlRt(final LanguageConfig config1, final XpandExecutionContext ctx) {
  PluginXmlAccess _pluginXml = this.getProjectConfig().getRuntime().getPluginXml();
  boolean _tripleNotEquals = (_pluginXml != null);
  if (_tripleNotEquals) {
    ctx.getOutput().openFile(null, StringConcatOutputImpl.STRING_OUTLET);
    try {
      if ((this.fragment instanceof IGeneratorFragmentExtension2)) {
        ((IGeneratorFragmentExtension2)this.fragment).addToPluginXmlRt(config1, ctx);
      } else {
        this.fragment.addToPluginXmlRt(config1.getGrammar(), ctx);
      }
      Output _output = ctx.getOutput();
      final StringConcatenation result = ((StringConcatOutputImpl) _output).getStringOutlet();
      final StringBuilder entry = this.decreaseIndentation(result.toString(), 1);
      boolean _isEmpty = entry.toString().trim().isEmpty();
      boolean _not = (!_isEmpty);
      if (_not) {
        List<CharSequence> _entries = this.getProjectConfig().getRuntime().getPluginXml().getEntries();
        _entries.add(entry);
      }
    } finally {
      ctx.getOutput().closeFile();
    }
  }
}
 
Example #4
Source File: XtextAntlrUiGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	super.generate(grammar, ctx);
	String srcUiGenPath = ctx.getOutput().getOutlet(Generator.SRC_GEN_IDE).getPath();
	final String encoding = getEncoding(ctx, Generator.SRC_GEN_IDE);
	String absoluteGrammarFileName = srcUiGenPath + "/" + getGrammarFileName(grammar, getNaming()).replace('.', '/') + ".g";
	addAntlrParam("-fo");
	addAntlrParam(absoluteGrammarFileName.substring(0, absoluteGrammarFileName.lastIndexOf('/')));
	getAntlrTool().runWithEncodingAndParams(absoluteGrammarFileName, encoding, getAntlrParams());
	Charset charset = Charset.forName(getEncoding(ctx, Generator.SRC_GEN_IDE));
	simplifyUnorderedGroupPredicatesIfRequired(grammar, absoluteGrammarFileName, charset);
	splitParserAndLexerIfEnabled(absoluteGrammarFileName, charset);
	suppressWarnings(absoluteGrammarFileName, charset);
	removeBacktrackingGuardsIfEnabled(absoluteGrammarFileName, charset);
	normalizeLineDelimiters(absoluteGrammarFileName, charset);
	normalizeTokens(absoluteGrammarFileName, charset);
}
 
Example #5
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generatePluginXmlRt(List<LanguageConfig> configs, XpandExecutionContext ctx) {
	String filePath = fileExists(ctx, "plugin.xml", PLUGIN_RT) ? "plugin.xml_gen" : "plugin.xml";
	deleteFile(ctx, filePath, PLUGIN_RT);
	ctx.getOutput().openFile(filePath, PLUGIN_RT);
	ctx.getOutput().getOutlet(PLUGIN_RT).addVetoStrategy(new EmptyPluginXmlVeto());
	try {
		XpandFacade facade = XpandFacade.create(ctx);
		List<Grammar> grammars = getGrammars(configs);
		facade.evaluate("org::eclipse::xtext::generator::Plugin::pre", grammars);
		for (LanguageConfig conf : languageConfigs) {
			conf.addToPluginXmlRt(conf, ctx);
			if (isUiMergedIntoRt()) {
				conf.addToPluginXmlUi(conf, ctx);
			}
		}
		facade.evaluate("org::eclipse::xtext::generator::Plugin::post", grammars);
	} finally {
		ctx.getOutput().closeFile();
	}
}
 
Example #6
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateManifestIde(final LanguageConfig config1, final XpandExecutionContext ctx) {
  if (((this.fragment instanceof IGeneratorFragmentExtension3) && (this.getProjectConfig().getGenericIde().getManifest() != null))) {
    final IGeneratorFragmentExtension3 fr = ((IGeneratorFragmentExtension3) this.fragment);
    final String[] exported = fr.getExportedPackagesIde(config1.getGrammar());
    if ((exported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getGenericIde().getManifest().getExportedPackages(), exported);
    }
    final String[] required = fr.getRequiredBundlesIde(config1.getGrammar());
    if ((required != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getGenericIde().getManifest().getRequiredBundles(), required);
    }
    final String[] imported = fr.getImportedPackagesIde(config1.getGrammar());
    if ((imported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getGenericIde().getManifest().getImportedPackages(), imported);
    }
  }
}
 
Example #7
Source File: XtextAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	super.generate(grammar, ctx);
	String srcGenPath = ctx.getOutput().getOutlet(Generator.SRC_GEN).getPath();
	final String encoding = getEncoding(ctx, Generator.SRC_GEN);
	String absoluteGrammarFileName = srcGenPath+"/"+getGrammarFileName(grammar, getNaming()).replace('.', '/')+".g";
	addAntlrParam("-fo");
	addAntlrParam(absoluteGrammarFileName.substring(0, absoluteGrammarFileName.lastIndexOf('/')));
	getAntlrTool().runWithEncodingAndParams(absoluteGrammarFileName, encoding, getAntlrParams());
	Charset charset = Charset.forName(encoding);
	simplifyUnorderedGroupPredicatesIfRequired(grammar, absoluteGrammarFileName, charset);
	splitParserAndLexerIfEnabled(absoluteGrammarFileName, charset);
	suppressWarnings(absoluteGrammarFileName, charset);
	normalizeLineDelimiters(absoluteGrammarFileName, charset);
	normalizeTokens(absoluteGrammarFileName, charset);
}
 
Example #8
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateGuiceModuleRt(final LanguageConfig config1, final XpandExecutionContext ctx) {
  final IXtextGeneratorLanguage config2 = this.getLanguage();
  final Set<Binding> bindings = this.fragment.getGuiceBindingsRt(config1.getGrammar());
  if ((bindings != null)) {
    final Function1<Binding, GuiceModuleAccess.Binding> _function = (Binding it) -> {
      return this.translateBinding(it);
    };
    config2.getRuntimeGenModule().addAll(IterableExtensions.<Binding, GuiceModuleAccess.Binding>map(bindings, _function));
  }
  if ((this.fragment instanceof IGeneratorFragmentExtension4)) {
    final String superClass = ((IGeneratorFragmentExtension4)this.fragment).getDefaultRuntimeModuleClassName(config1.getGrammar());
    if ((superClass != null)) {
      GuiceModuleAccess _runtimeGenModule = config2.getRuntimeGenModule();
      TypeReference _typeReference = new TypeReference(superClass);
      _runtimeGenModule.setSuperClass(_typeReference);
    }
  }
}
 
Example #9
Source File: LanguageConfig.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	if (LOG.isInfoEnabled()) {
		LOG.info("generating infrastructure for " + grammar.getName() + " with fragments : "
				+ Strings.toString(this.fragments, new ToStringFunction(", "), ", "));
	}
	super.generate(grammar, ctx);
}
 
Example #10
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
void updateBuildProperties(XpandExecutionContext ctx) throws Exception {
	if (!updateBuildProperties || modelPluginID != null)
		return;
	Outlet rootOutlet = ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT);
	Outlet modelOutlet = ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.MODEL);
	String buildPropertiesPath = rootOutlet.getPath() + "/build.properties";
	String modelPath = modelOutlet.getPath().substring(rootOutlet.getPath().length() + 1) + "/";
	Properties buildProperties = new Properties();
	Reader reader = new InputStreamReader(new FileInputStream(new File(buildPropertiesPath)), Charset.forName(rootOutlet.getFileEncoding()));
	try {
		String existingContent = CharStreams.toString(reader);
		// for encoding details, see Properties.load
		buildProperties.load(new StringInputStream(existingContent, "ISO-8859-1"));
		String binIncludes = buildProperties.getProperty("bin.includes");
		boolean changed = false;
		if (binIncludes == null) {
			existingContent += "bin.includes = " + modelPath + Strings.newLine()+ "               ";
			changed = true;
		} else if (!binIncludes.contains(modelPath)) {
			existingContent = existingContent.replace("bin.includes = ", "bin.includes = " + modelPath + ",\\" + Strings.newLine() +"               ");
			changed = true;
		}
		if (changed) {
			Writer writer = new OutputStreamWriter(new FileOutputStream(new File(buildPropertiesPath)), Charset.forName(rootOutlet.getFileEncoding()));
			writer.write(existingContent);
			writer.close();
		}
	} finally {
		reader.close();
	}
}
 
Example #11
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected URI getEcoreFileUri(Grammar grammar, XpandExecutionContext ctx) {
	String javaPath = getJavaModelDirectory(ctx);
	String xmiPath = getXmiModelDirectory(grammar, javaPath, ctx);
	try {
		String prefix = new File(xmiPath).getCanonicalPath() + File.separator + getModelName(grammar);
		URI ecoreFileUri = URI.createFileURI(prefix + ".ecore");
		return ecoreFileUri;
	} catch (IOException e) {
		throw new IllegalStateException("Couldn't compute canonical path for "
				+ new File(xmiPath).getAbsolutePath());
	}
}
 
Example #12
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getEditDirectory(XpandExecutionContext ctx) {
	if (this.editDirectory == null || "".equals(this.editDirectory)) {
		return ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT).getPath()
				+ ".edit/src";
	}
	return editDirectory;
}
 
Example #13
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getEditorDirectory(XpandExecutionContext ctx) {
	if (editorDirectory == null || "".equals(editorDirectory)) {
		return ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT).getPath()
				+ ".editor/src";
	}
	return editorDirectory;
}
 
Example #14
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void generateManifestIde(List<LanguageConfig> configs, XpandExecutionContext ctx) {
	if (isIde() && !isIdeMergedIntoRt() ) {
		String manifestPath = "META-INF/MANIFEST.MF";
		Set<String> exported = new LinkedHashSet<String>();
		Set<String> imported = new LinkedHashSet<String>();
		Set<String> requiredBundles = new LinkedHashSet<String>();
		for (LanguageConfig config : languageConfigs) {
			exported.addAll(Arrays.asList(config.getExportedPackagesIde(config.getGrammar())));
			imported.addAll(Arrays.asList(config.getImportedPackagesIde(config.getGrammar())));
			requiredBundles.addAll(Arrays.asList(config.getRequiredBundlesIde(config.getGrammar())));
		}

		if (isMergeManifest()) {
			String path = ctx.getOutput().getOutlet(PLUGIN_IDE).getPath() + "/" + manifestPath;
			mergeManifest(getProjectNameIde(), path, exported, requiredBundles, imported, null);
		} else {
			manifestPath = manifestPath + "_gen";
			deleteFile(ctx, manifestPath, PLUGIN_IDE);
			ctx.getOutput().openFile(manifestPath, PLUGIN_IDE);
			try {
				XpandFacade facade = XpandFacade.create(ctx);
				generateManifest(facade, getProjectNameIde(), getProjectNameIde(), getBundleVersion(), exported,
						requiredBundles, imported, null);
			} finally {
				ctx.getOutput().closeFile();
			}
		}
	}
}
 
Example #15
Source File: EcoreGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	// register all explicitly referenced genmodels
	// since this may cause side effects on global singeltons, we don't guard it
	registerReferencedGenModels();
	super.generate(grammar, ctx);
}
 
Example #16
Source File: CompositeGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.6
 */
@Override
public void addToPluginXmlUi(LanguageConfig config, XpandExecutionContext ctx) {
	for (IGeneratorFragment fragment : fragments) {
		if (fragment instanceof IGeneratorFragmentExtension2) {
			((IGeneratorFragmentExtension2)fragment).addToPluginXmlUi(config, ctx);
		} else {
			fragment.addToPluginXmlUi(config.getGrammar(), ctx);
		}
	}
}
 
Example #17
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void generate(LanguageConfig config, XpandExecutionContext ctx, Issues issues) {
	try {
		config.generate(config, ctx);
	} catch(CompositeGeneratorException e) {
		if (!handleWarnings(issues, e)) {
			throw e;
		}
	}
}
 
Example #18
Source File: CompositeGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 * @deprecated 
 */
@Override
@Deprecated
public void addToPluginXmlTests(Grammar grammar, XpandExecutionContext ctx) {
	for (IGeneratorFragment fragment : fragments) {
		if (fragment instanceof IGeneratorFragmentExtension) {
			((IGeneratorFragmentExtension) fragment).addToPluginXmlTests(grammar, ctx);
		}
	}
}
 
Example #19
Source File: CompositeGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.6
 */
@Override
public void addToStandaloneSetup(LanguageConfig config, XpandExecutionContext ctx) {
	for (IGeneratorFragment fragment : fragments) {
		if (fragment instanceof IGeneratorFragmentExtension2) {
			((IGeneratorFragmentExtension2)fragment).addToStandaloneSetup(config, ctx);
		} else {
			fragment.addToStandaloneSetup(config.getGrammar(), ctx);
		}
	}
}
 
Example #20
Source File: DebugAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	DebugGrammarToken token = DebugGrammarToken.aquire();
	try {
		super.generate(grammar, ctx);
		String srcGenPath = ctx.getOutput().getOutlet(Generator.SRC_GEN).getPath();
		String absoluteGrammarFileName = srcGenPath+"/"+getGrammarFileName(grammar, getNaming()).replace('.', '/')+".g";
		prettyPrint(absoluteGrammarFileName, Charset.forName(getEncoding(ctx, Generator.SRC_GEN)));
	} finally {
		token.done();
	}
}
 
Example #21
Source File: JavaValidatorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	if (log.isInfoEnabled()) {
		log.info("generating Java-based EValidator API");
	}
	XpandFacade.create(ctx).evaluate2(getTemplate() + "::generate", grammar, getParameters(grammar));
}
 
Example #22
Source File: DelegatingGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addToPluginXmlRt(Grammar grammar, XpandExecutionContext ctx) {
	if (delegate != null)
		delegate.addToPluginXmlRt(grammar, ctx);
	else
		fallback.addToPluginXmlRt(grammar, ctx);
}
 
Example #23
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void generateGuiceModuleUi(LanguageConfig config, XpandExecutionContext ctx) {
	if (isUi()) {
		XpandFacade facade = XpandFacade.create(ctx);
		Set<Binding> bindings = config.getGuiceBindingsUi(config.getGrammar());
		String superClassName = config.getDefaultUiModuleClassName(config.getGrammar());
		if (superClassName == null) {
			superClassName = "org.eclipse.xtext.ui.DefaultUiModule";
		}
		facade.evaluate("org::eclipse::xtext::generator::GuiceModuleUi::generate", config.getGrammar(), superClassName, bindings);
	}
}
 
Example #24
Source File: DelegatingGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addToStandaloneSetup(Grammar grammar, XpandExecutionContext ctx) {
	if (delegate != null)
		delegate.addToStandaloneSetup(grammar, ctx);
	else
		fallback.addToStandaloneSetup(grammar, ctx);
}
 
Example #25
Source File: DelegatingGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	if (delegate != null)
		delegate.generate(grammar, ctx);
	else
		fallback.generate(grammar, ctx);
}
 
Example #26
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void generateManifestTests(List<LanguageConfig> configs, XpandExecutionContext ctx) {
	if (isTest()) {
		String manifestPath = "META-INF/MANIFEST.MF";
		Set<String> exported = new LinkedHashSet<String>();
		Set<String> imported = new LinkedHashSet<String>();
		Set<String> requiredBundles = new LinkedHashSet<String>();
		for (LanguageConfig config : languageConfigs) {
			exported.addAll(Arrays.asList(config.getExportedPackagesTests(config.getGrammar())));
			imported.addAll(Arrays.asList(config.getImportedPackagesTests(config.getGrammar())));
			requiredBundles.addAll(Arrays.asList(config.getRequiredBundlesTests(config.getGrammar())));
		}

		if (isMergeManifest()) {
			String path = ctx.getOutput().getOutlet(PLUGIN_TEST).getPath() + "/" + manifestPath;
			mergeManifest(getProjectNameTests(), path, exported, requiredBundles, imported, null);
		} else {
			manifestPath = manifestPath + "_gen";
			deleteFile(ctx, manifestPath, PLUGIN_TEST);
			ctx.getOutput().openFile(manifestPath, PLUGIN_TEST);
			try {
				XpandFacade facade = XpandFacade.create(ctx);
				generateManifest(facade, getProjectNameTests(), getProjectNameTests(), getBundleVersion(),
						exported, requiredBundles, imported, getActivator());
			} finally {
				ctx.getOutput().closeFile();
			}
		}
	}
}
 
Example #27
Source File: GrammarAccessFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	RuleNames.ensureAdapterInstalled(grammar);
	super.generate(grammar, ctx);

	final ResourceSaveIndicator isSaving = new ResourceSaveIndicator();
	// create a defensive clone
	Grammar copy = deepCopy(grammar, isSaving);
	ResourceSet set = copy.eResource().getResourceSet();

	// save grammar model
	String path;
	if (xmlVersion == null) {
		path = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
	} else {
		log.warn("'xmlVersion' has been specified for this "
				+ GrammarAccessFragment.class.getSimpleName()
				+ ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
		path = GrammarUtil.getClasspathRelativePathToXmi(copy);
	}
	URI uri = URI.createURI(ctx.getOutput().getOutlet(Generator.SRC_GEN).getPath() + "/" + path);
	Resource resource = set.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	addAllGrammarsToResource(resource, copy, new HashSet<Grammar>());
	isSaving.set(Boolean.TRUE);
	Map<String, Object> saveOptions = Maps.newHashMap();
	if (resource instanceof XMLResource) {
		((XMLResource) resource).setXMLVersion(getXmlVersion());
	} else if (resource instanceof BinaryResourceImpl){
		saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
		saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.TRUE);
	}
	try {
		resource.save(saveOptions);
	} catch (IOException e) {
		log.error(e.getMessage(), e);
	} finally {
		isSaving.set(Boolean.FALSE);
	}
}
 
Example #28
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void generateGuiceModuleRt(LanguageConfig config, XpandExecutionContext ctx) {
	XpandFacade facade = XpandFacade.create(ctx);
	Set<Binding> bindings = config.getGuiceBindingsRt(config.getGrammar());
	String superClassName = config.getDefaultRuntimeModuleClassName(config.getGrammar());
	if (superClassName == null) {
		superClassName = "org.eclipse.xtext.service.DefaultRuntimeModule";
	}
	facade.evaluate("org::eclipse::xtext::generator::GuiceModuleRt::generate", config.getGrammar(), superClassName, bindings,
			config.getFileExtensions(config.getGrammar()));
}
 
Example #29
Source File: ValidValidatorFragment.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void generate(final Grammar grammar, final XpandExecutionContext ctx) {
  if (LOGGER.isInfoEnabled()) {
    LOGGER.info(NLS.bind(Messages.EXECUTING_GENERATE, getClass().getName()));
  }

  ValidStandaloneSetup.doSetup();

  final ValidModel validModel = getValidModel(grammar);
  grammar.eResource().getResourceSet().getResources().add(validModel.eResource());
  grammar.eResource().getResourceSet().getResources().add(validModel.getImports().get(0).eResource());

  // profile for generator is:
  // <<DEFINE generate(List[String] packageQNames, List[String] composedChecks, ValidModel validModel) FOR Grammar>>
  XpandFacade.create(ctx).evaluate(getTemplate() + "::generate", // template //$NON-NLS-1$
      grammar, // this (the grammar)
      getParameters(grammar).get(0), // package Qualified Names (first parameter of the argument list is the 'list of
                                     // packages')
      this.composedChecks, // composed checks
      validModel); // validModel

  if (generateTests) {
    XpandFacade.create(ctx).evaluate("com::avaloq::tools::ddk::xtext::valid::generator::ValidatorTests::generate", // template //$NON-NLS-1$
        grammar, // this (the grammar)
        validModel); // validModel
    XpandFacade.create(ctx).evaluate("com::avaloq::tools::ddk::xtext::valid::generator::QuickfixTests::generate", // template //$NON-NLS-1$
        grammar, // this (the grammar)
        validModel); // validModel
  }
}
 
Example #30
Source File: FormatFragmentUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Retrieve the format model associated with a given grammar.
 * <p>
 * <em>Note</em>: Expected to either be in same folder with the same name (except for the extension) or in the SRC outlet.
 * </p>
 *
 * @param grammar
 *          the grammar, must not be {@code null}
 * @param context
 *          xpand execution context, must not be {@code null}
 * @return the format model, or {@code null} if the resource could not be loaded
 * @throws FileNotFoundException
 *           thrown if the format file could not be found
 */
@SuppressWarnings("PMD.NPathComplexity")
public static FormatConfiguration getFormatModel(final Grammar grammar, final XpandExecutionContext context) throws FileNotFoundException {
  Variable resourceUriVariable = context.getVariable("resourceUri");
  if (resourceUriVariable == null) {
    return null;
  }
  URI uri = (URI) resourceUriVariable.getValue();
  final Resource grammarResource = grammar.eResource();
  final ResourceSet resourceSet = grammarResource.getResourceSet();
  Resource formatResource = null;
  try {
    formatResource = resourceSet.getResource(uri, true);
  } catch (final ClasspathUriResolutionException e) {
    // make another attempt
    uri = getDefaultFormatLocation(grammar, context);
    try {
      formatResource = resourceSet.getResource(uri, true);
    } catch (WrappedException e1) {
      formatResource = resourceSet.getResource(uri, false);
      if (formatResource != null) {
        resourceSet.getResources().remove(formatResource);
      }
      throw new FileNotFoundException(uri.toString()); // NOPMD
    }
  }
  if (formatResource == null) {
    throw new FileNotFoundException(uri.toString());
  }

  final List<Issue> issues = getModelValidator().validate(formatResource, LOG);

  for (final Issue issue : issues) {
    if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
      throw new WorkflowInterruptedException("Errors found in " + uri.toString() + ": " + issue.getMessage());
    }
  }

  return formatResource.getContents().size() == 0 ? null : (FormatConfiguration) formatResource.getContents().get(0);
}