Search in sources :

Example 11 with GenPackage

use of org.eclipse.emf.codegen.ecore.genmodel.GenPackage in project xtext-core by eclipse.

the class EMFGeneratorFragment2 method addProjectContributions.

protected void addProjectContributions(final Grammar grammar, final List<EPackage> generatedPackages, final ResourceSet rs) {
    PluginXmlAccess _pluginXml = this.getProjectConfig().getRuntime().getPluginXml();
    boolean _tripleNotEquals = (_pluginXml != null);
    if (_tripleNotEquals) {
        List<CharSequence> _entries = this.getProjectConfig().getRuntime().getPluginXml().getEntries();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("<extension point=\"org.eclipse.emf.ecore.generated_package\">");
        _builder.newLine();
        {
            for (final EPackage pack : generatedPackages) {
                _builder.append("\t");
                _builder.append("<package ");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("uri = \"");
                String _nsURI = pack.getNsURI();
                _builder.append(_nsURI, "\t\t");
                _builder.append("\"");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("class = \"");
                String _qualifiedPackageInterfaceName = GenModelUtil2.getGenPackage(pack, rs).getQualifiedPackageInterfaceName();
                _builder.append(_qualifiedPackageInterfaceName, "\t\t");
                _builder.append("\"");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("genModel = \"");
                String _relativePath = this.getRelativePath(this.getGenModelPath(grammar));
                _builder.append(_relativePath, "\t\t");
                _builder.append("\" />");
                _builder.newLineIfNotEmpty();
            }
        }
        _builder.append("</extension>");
        _builder.newLine();
        _entries.add(_builder.toString());
    }
    ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals_1 = (_manifest != null);
    if (_tripleNotEquals_1) {
        CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntime().getManifest().getRequiredBundles(), "org.eclipse.emf.ecore", "org.eclipse.emf.common");
    }
    for (final EPackage pack_1 : generatedPackages) {
        {
            final GenPackage genPackage = GenModelUtil2.getGenPackage(pack_1, rs);
            if (((this.getProjectConfig().getRuntime().getManifest() != null) && (this.modelPluginID == null))) {
                CollectionExtensions.<String>addAll(this.getProjectConfig().getRuntime().getManifest().getExportedPackages(), genPackage.getInterfacePackageName(), genPackage.getClassPackageName(), genPackage.getUtilitiesPackageName());
            }
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("if (!");
                    _builder.append(EPackage.class);
                    _builder.append(".Registry.INSTANCE.containsKey(\"");
                    String _nsURI = pack_1.getNsURI();
                    _builder.append(_nsURI);
                    _builder.append("\")) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append(EPackage.class, "\t");
                    _builder.append(".Registry.INSTANCE.put(\"");
                    String _nsURI_1 = pack_1.getNsURI();
                    _builder.append(_nsURI_1, "\t");
                    _builder.append("\", ");
                    String _qualifiedPackageInterfaceName = genPackage.getQualifiedPackageInterfaceName();
                    TypeReference _typeReference = new TypeReference(_qualifiedPackageInterfaceName);
                    _builder.append(_typeReference, "\t");
                    _builder.append(".eINSTANCE);");
                    _builder.newLineIfNotEmpty();
                    _builder.append("}");
                    _builder.newLine();
                }
            };
            this.getLanguage().getRuntimeGenSetup().getRegistrations().add(_client);
        }
    }
}
Also used : PluginXmlAccess(org.eclipse.xtext.xtext.generator.model.PluginXmlAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) EPackage(org.eclipse.emf.ecore.EPackage) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)11 GenModel (org.eclipse.emf.codegen.ecore.genmodel.GenModel)7 EPackage (org.eclipse.emf.ecore.EPackage)7 EObject (org.eclipse.emf.ecore.EObject)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 URI (org.eclipse.emf.common.util.URI)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)4 Predicate (com.google.common.base.Predicate)2 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 EReference (org.eclipse.emf.ecore.EReference)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)2 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)2 ComparisonFailure (org.junit.ComparisonFailure)2 GenClassifier (org.eclipse.emf.codegen.ecore.genmodel.GenClassifier)1 GenModelImpl (org.eclipse.emf.codegen.ecore.genmodel.impl.GenModelImpl)1 GenPackageImpl (org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl)1