package com.minres.rdl.generator; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; import com.minres.rdl.RDLStandaloneSetup; import com.minres.rdl.generator.Options; import java.lang.reflect.MalformedParametersException; import java.text.ParseException; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.mwe.utils.ProjectMapping; import org.eclipse.emf.mwe.utils.StandaloneSetup; import org.eclipse.xtext.generator.GeneratorContext; import org.eclipse.xtext.generator.GeneratorDelegate; import org.eclipse.xtext.generator.JavaIoFileSystemAccess; import org.eclipse.xtext.generator.OutputConfiguration; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.util.CancelIndicator; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.eclipse.xtext.validation.Issue; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class Main { private final String USAGE_STR = "RDL2code [-h] [-v] [-I ] [-s ] [-g ] "; public static void main(final String[] args) { boolean _isEmpty = ((List)Conversions.doWrapArray(args)).isEmpty(); if (_isEmpty) { System.err.println("Aborting: no path to RDL file provided!"); return; } final Injector injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration(); final Main main = injector.
getInstance(Main.class); try { main.run(args); } catch (final Throwable _t) { if (_t instanceof MalformedParametersException) { final MalformedParametersException e = (MalformedParametersException)_t; String _message = e.getMessage(); String _plus = ("Command line error " + _message); InputOutput.print(_plus); System.exit(1); } else if (_t instanceof IllegalArgumentException) { final IllegalArgumentException e_1 = (IllegalArgumentException)_t; String _message_1 = e_1.getMessage(); String _plus_1 = ("generation error " + _message_1); InputOutput.print(_plus_1); e_1.printStackTrace(); System.exit(2); } else if (_t instanceof ParseException) { final ParseException e_2 = (ParseException)_t; String _message_2 = e_2.getMessage(); String _plus_2 = ("parse problem " + _message_2); String _plus_3 = (_plus_2 + " ("); int _errorOffset = e_2.getErrorOffset(); String _plus_4 = (_plus_3 + Integer.valueOf(_errorOffset)); String _plus_5 = (_plus_4 + ")"); InputOutput.print(_plus_5); System.exit(3); } else { throw Exceptions.sneakyThrow(_t); } } } @Inject private Provider resourceSetProvider; @Inject private IResourceValidator validator; @Inject private GeneratorDelegate generator; @Inject private JavaIoFileSystemAccess fileAccess; public void run(final String[] args) { final Options opt = new Options(args, 0, Integer.MAX_VALUE); opt.getSet().addOption("h", Options.Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("v", Options.Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("i", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("s", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("g", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("I", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE); boolean _check = opt.check(false, false); boolean _not = (!_check); if (_not) { System.err.println(("Usage is: " + this.USAGE_STR)); String _checkErrors = opt.getCheckErrors(); throw new MalformedParametersException(_checkErrors); } boolean _isSet = opt.getSet().isSet("h"); if (_isSet) { InputOutput.println(("Usage: " + this.USAGE_STR)); return; } boolean _xifexpression = false; boolean _isSet_1 = opt.getSet().isSet("v"); if (_isSet_1) { _xifexpression = true; } else { _xifexpression = false; } final boolean verbose = _xifexpression; boolean _isSet_2 = opt.getSet().isSet("I"); if (_isSet_2) { final ProjectMapping projectMapping = new ProjectMapping(); projectMapping.setProjectName("RDL Repository"); projectMapping.setPath(opt.getSet().getOption("I").getResultValue(0)); new StandaloneSetup().addProjectMapping(projectMapping); } this.fileAccess.setOutputPath("src-gen/"); Pair _mappedTo = Pair.of("incl-out", Boolean.valueOf(false)); Pair _mappedTo_1 = Pair.of("src-out", Boolean.valueOf(false)); Pair _mappedTo_2 = Pair.of("gen-out", Boolean.valueOf(true)); final BiConsumer _function = (String p1, Boolean p2) -> { boolean _isSet_3 = opt.getSet().isSet(p1.substring(0, 1)); if (_isSet_3) { String _resultValue = opt.getSet().getOption(p1.substring(0, 1)).getResultValue(0); String _plus = (_resultValue + "/"); this.fileAccess.setOutputPath(p1, _plus); } else { this.fileAccess.setOutputPath(p1, "src-gen/"); } OutputConfiguration _get = this.fileAccess.getOutputConfigurations().get(p1); if (_get!=null) { _get.setOverrideExistingResources((p2).booleanValue()); } }; Collections.unmodifiableMap(CollectionLiterals.newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2)).forEach(_function); final Consumer _function_1 = (String string) -> { try { if (verbose) { InputOutput.println(("Reading " + string)); } ResourceSet _get = this.resourceSetProvider.get(); final XtextResourceSet resourceSet = ((XtextResourceSet) _get); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); final Resource resource = resourceSet.getResource(URI.createFileURI(string), true); final List issues = this.validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); boolean _isEmpty = issues.isEmpty(); boolean _not_1 = (!_isEmpty); if (_not_1) { URI _uRI = resource.getURI(); String _plus = ("Error validating " + _uRI); System.err.println(_plus); final Consumer _function_2 = (Issue it) -> { System.err.println(it); }; issues.forEach(_function_2); URI _uRI_1 = resource.getURI(); String _plus_1 = ("error validating " + _uRI_1); int _size = issues.size(); throw new ParseException(_plus_1, _size); } GeneratorContext _generatorContext = new GeneratorContext(); final Procedure1 _function_3 = (GeneratorContext it) -> { it.setCancelIndicator(CancelIndicator.NullImpl); }; final GeneratorContext context = ObjectExtensions.operator_doubleArrow(_generatorContext, _function_3); this.generator.generate(resource, this.fileAccess, context); if (verbose) { InputOutput.print((("Code generation for " + string) + " finished, ")); } try { if (verbose) { URI _uRI_2 = this.fileAccess.getURI("", "incl-out"); String _plus_2 = ("includes are in " + _uRI_2); String _plus_3 = (_plus_2 + ", "); InputOutput.print(_plus_3); } } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception e = (Exception)_t; URI _uRI_3 = this.fileAccess.getURI(""); String _plus_4 = ("includes are in " + _uRI_3); String _plus_5 = (_plus_4 + ", "); InputOutput.print(_plus_5); } else { throw Exceptions.sneakyThrow(_t); } } try { if (verbose) { URI _uRI_4 = this.fileAccess.getURI("", "src-out"); String _plus_6 = ("sources are in " + _uRI_4); String _plus_7 = (_plus_6 + ", "); InputOutput.println(_plus_7); } } catch (final Throwable _t_1) { if (_t_1 instanceof Exception) { final Exception e_1 = (Exception)_t_1; URI _uRI_5 = this.fileAccess.getURI(""); String _plus_8 = ("sources are in " + _uRI_5); String _plus_9 = (_plus_8 + ", "); InputOutput.println(_plus_9); } else { throw Exceptions.sneakyThrow(_t_1); } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; opt.getSet().getData().forEach(_function_1); } }