org.eclipse.xtext.generator.LanguageConfig Java Examples

The following examples show how to use org.eclipse.xtext.generator.LanguageConfig. 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: 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 #2
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 #3
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateGuiceModuleUi(final LanguageConfig config1, final XpandExecutionContext ctx) {
  final IXtextGeneratorLanguage config2 = this.getLanguage();
  final Set<Binding> bindings = this.fragment.getGuiceBindingsUi(config1.getGrammar());
  if ((bindings != null)) {
    final Function1<Binding, GuiceModuleAccess.Binding> _function = (Binding it) -> {
      return this.translateBinding(it);
    };
    config2.getEclipsePluginGenModule().addAll(IterableExtensions.<Binding, GuiceModuleAccess.Binding>map(bindings, _function));
  }
  if ((this.fragment instanceof IGeneratorFragmentExtension4)) {
    final String superClass = ((IGeneratorFragmentExtension4)this.fragment).getDefaultUiModuleClassName(config1.getGrammar());
    if ((superClass != null)) {
      GuiceModuleAccess _eclipsePluginGenModule = config2.getEclipsePluginGenModule();
      TypeReference _typeReference = new TypeReference(superClass);
      _eclipsePluginGenModule.setSuperClass(_typeReference);
    }
  }
}
 
Example #4
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 #5
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generatePluginXmlUi(final LanguageConfig config1, final XpandExecutionContext ctx) {
  PluginXmlAccess _pluginXml = this.getProjectConfig().getEclipsePlugin().getPluginXml();
  boolean _tripleNotEquals = (_pluginXml != null);
  if (_tripleNotEquals) {
    ctx.getOutput().openFile(null, StringConcatOutputImpl.STRING_OUTLET);
    try {
      if ((this.fragment instanceof IGeneratorFragmentExtension2)) {
        ((IGeneratorFragmentExtension2)this.fragment).addToPluginXmlUi(config1, ctx);
      } else {
        this.fragment.addToPluginXmlUi(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().getEclipsePlugin().getPluginXml().getEntries();
        _entries.add(entry);
      }
    } 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 generateManifestRt(final LanguageConfig config1, final XpandExecutionContext ctx) {
  ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    final String[] exported = this.fragment.getExportedPackagesRt(config1.getGrammar());
    if ((exported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntime().getManifest().getExportedPackages(), exported);
    }
    final String[] required = this.fragment.getRequiredBundlesRt(config1.getGrammar());
    if ((required != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntime().getManifest().getRequiredBundles(), required);
    }
    final String[] imported = this.fragment.getImportedPackagesRt(config1.getGrammar());
    if ((imported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntime().getManifest().getImportedPackages(), imported);
    }
  }
}
 
Example #7
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateManifestUi(final LanguageConfig config1, final XpandExecutionContext ctx) {
  ManifestAccess _manifest = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    final String[] exported = this.fragment.getExportedPackagesUi(config1.getGrammar());
    if ((exported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getEclipsePlugin().getManifest().getExportedPackages(), exported);
    }
    final String[] required = this.fragment.getRequiredBundlesUi(config1.getGrammar());
    if ((required != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles(), required);
    }
    final String[] imported = this.fragment.getImportedPackagesUi(config1.getGrammar());
    if ((imported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getEclipsePlugin().getManifest().getImportedPackages(), imported);
    }
  }
}
 
Example #8
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 #9
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateManifestTests(final LanguageConfig config1, final XpandExecutionContext ctx) {
  if (((this.fragment instanceof IGeneratorFragmentExtension) && (this.getProjectConfig().getRuntimeTest().getManifest() != null))) {
    final IGeneratorFragmentExtension fr = ((IGeneratorFragmentExtension) this.fragment);
    final String[] exported = fr.getExportedPackagesTests(config1.getGrammar());
    if ((exported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntimeTest().getManifest().getExportedPackages(), exported);
    }
    final String[] required = fr.getRequiredBundlesTests(config1.getGrammar());
    if ((required != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntimeTest().getManifest().getRequiredBundles(), required);
    }
    final String[] imported = fr.getImportedPackagesTests(config1.getGrammar());
    if ((imported != null)) {
      CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntimeTest().getManifest().getImportedPackages(), imported);
    }
  }
}
 
Example #10
Source File: GeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addToPluginXmlUi(LanguageConfig config, XpandExecutionContext ctx) {
	Grammar grammar = config.getGrammar();
	List<Object> parameters = newArrayList();
	parameters.addAll(getParameters(grammar));
	parameters.add(config.getFileExtensions(grammar));
	XpandFacade.create(ctx).evaluate2(getTemplate() + "::addToPluginXmlUi", grammar, parameters);
}
 
Example #11
Source File: SerializerFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(LanguageConfig config, XpandExecutionContext ctx) {
	adapterSetup = new Generator2AdapterSetup(config, ctx, getNaming());
	com.google.inject.Module module = new com.google.inject.Module() {

		@Override
		public void configure(Binder binder) {
			binder.bind(org.eclipse.xtext.xtext.generator.util.SyntheticTerminalDetector.class)
					.toInstance(syntheticTerminalDetector);
		}

	};
	adapterSetup.setAdditionalLanguageBindings(module);
	super.generate(config, ctx);
}
 
Example #12
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void generateStandaloneSetup(final LanguageConfig config1, final XpandExecutionContext ctx) {
  ctx.getOutput().openFile(null, StringConcatOutputImpl.STRING_OUTLET);
  try {
    final IXtextGeneratorLanguage config2 = this.getLanguage();
    if ((this.fragment instanceof IGeneratorFragmentExtension2)) {
      ((IGeneratorFragmentExtension2)this.fragment).addToStandaloneSetup(config1, ctx);
    } else {
      this.fragment.addToStandaloneSetup(config1.getGrammar(), ctx);
    }
    Output _output = ctx.getOutput();
    final StringConcatenation result = ((StringConcatOutputImpl) _output).getStringOutlet();
    List<StringConcatenationClient> _registrations = config2.getRuntimeGenSetup().getRegistrations();
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        StringBuilder _decreaseIndentation = FragmentAdapter.this.decreaseIndentation(result.toString(), 2);
        _builder.append(_decreaseIndentation);
      }
    };
    _registrations.add(_client);
    Set<TypeReference> _imports = config2.getRuntimeGenSetup().getImports();
    TypeReference _typeReference = new TypeReference("org.eclipse.emf.ecore.EPackage");
    _imports.add(_typeReference);
    Set<TypeReference> _imports_1 = config2.getRuntimeGenSetup().getImports();
    TypeReference _typeReference_1 = new TypeReference("org.eclipse.emf.ecore.resource.Resource");
    _imports_1.add(_typeReference_1);
  } finally {
    ctx.getOutput().closeFile();
  }
}
 
Example #13
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected LanguageConfig createLanguageConfig() {
  IXtextGeneratorLanguage _language = this.getLanguage();
  final XtextGeneratorLanguage config2 = ((XtextGeneratorLanguage) _language);
  final LanguageConfig config = new LanguageConfig();
  config.setForcedResourceSet(config2.getResourceSet());
  config.setFileExtensions(IterableExtensions.join(config2.getFileExtensions(), ","));
  config.setUri(config2.getGrammarUri());
  config.registerNaming(this.naming);
  return config;
}
 
Example #14
Source File: Generator2AdapterSetup.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Generator2AdapterSetup(LanguageConfig languageConfig, XpandExecutionContext xpandContext, Naming naming) {
	this.languageConfig = languageConfig;
	this.xpandContext = xpandContext;
	this.naming = naming;
}
 
Example #15
Source File: LazyLanguageConfig.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate(LanguageConfig config, XpandExecutionContext ctx) throws CompositeGeneratorException {
    initializeReally();
    super.generate(config, ctx);
}
 
Example #16
Source File: LazyLanguageConfig.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate(LanguageConfig config, XpandExecutionContext ctx) throws CompositeGeneratorException {
    initializeReally();
    super.generate(config, ctx);
}