Search in sources :

Example 91 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class DeclarativeScopeProviderTest method testPolymorphic.

@SuppressWarnings("unused")
@Test
public void testPolymorphic() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(b, provider.getScope(details, details));
    assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 92 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class DeclarativeScopeProviderTest method testScopeByType2.

@SuppressWarnings("unused")
@Test
public void testScopeByType2() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(b, provider.getScope(details, details));
    assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 93 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class Formatter2Fragment2 method doGenerateStubFile.

protected void doGenerateStubFile() {
    boolean _isGenerateStub = this.isGenerateStub();
    boolean _not = (!_isGenerateStub);
    if (_not) {
        return;
    }
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
        final XtendFileAccess xtendFile = this.fileAccessFactory.createXtendFile(this.getFormatter2Stub(this.getGrammar()));
        xtendFile.setResourceSet(this.getLanguage().getResourceSet());
        final LinkedHashMultimap<EClass, EReference> type2ref = LinkedHashMultimap.<EClass, EReference>create();
        this.getLocallyAssignedContainmentReferences(this.getLanguage().getGrammar(), type2ref);
        final LinkedHashMultimap<EClass, EReference> inheritedTypes = LinkedHashMultimap.<EClass, EReference>create();
        this.getInheritedContainmentReferences(this.getLanguage().getGrammar(), inheritedTypes, CollectionLiterals.<Grammar>newHashSet());
        final Set<EClass> types = type2ref.keySet();
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("class ");
                String _simpleName = Formatter2Fragment2.this.getFormatter2Stub(Formatter2Fragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _stubSuperClass = Formatter2Fragment2.this.getStubSuperClass();
                _builder.append(_stubSuperClass);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@");
                _builder.append(Inject.class, "\t");
                _builder.append(" extension ");
                TypeReference _grammarAccess = Formatter2Fragment2.this._grammarAccessExtensions.getGrammarAccess(Formatter2Fragment2.this.getGrammar());
                _builder.append(_grammarAccess, "\t");
                _builder.newLineIfNotEmpty();
                {
                    Iterable<EClass> _take = IterableExtensions.<EClass>take(types, 2);
                    for (final EClass type : _take) {
                        _builder.newLine();
                        _builder.append("\t");
                        StringConcatenationClient _generateFormatMethod = Formatter2Fragment2.this.generateFormatMethod(type, type2ref.get(type), inheritedTypes.containsKey(type));
                        _builder.append(_generateFormatMethod, "\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("// TODO: implement for ");
                final Function1<EClass, String> _function = (EClass it) -> {
                    return it.getName();
                };
                String _join = IterableExtensions.join(IterableExtensions.<EClass, String>map(IterableExtensions.<EClass>drop(types, 2), _function), ", ");
                _builder.append(_join, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        xtendFile.setContent(_client);
        xtendFile.writeTo(this.getProjectConfig().getRuntime().getSrc());
    } else {
        String _name = this.getClass().getName();
        String _plus = (_name + " has been configured to generate a Java stub, but that\'s not yet supported. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=481563");
        Formatter2Fragment2.LOG.error(_plus);
    }
}
Also used : XtendFileAccess(org.eclipse.xtext.xtext.generator.model.XtendFileAccess) EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) EReference(org.eclipse.emf.ecore.EReference)

Example 94 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class Ecore2XtextExtensions method allDispatcherRuleClasses.

public static Collection<EClass> allDispatcherRuleClasses(final Ecore2XtextConfiguration it) {
    Set<EClass> _xifexpression = null;
    EClass _rootElementClass = it.getRootElementClass();
    boolean _tripleEquals = (_rootElementClass == null);
    if (_tripleEquals) {
        final Function1<EPackageInfo, Set<EClassifier>> _function = (EPackageInfo it_1) -> {
            return Ecore2XtextExtensions.allReferencedClassifiers(it_1.getEPackage(), false);
        };
        final Function1<EClassifier, Boolean> _function_1 = (EClassifier c) -> {
            return Boolean.valueOf(Ecore2XtextExtensions.needsDispatcherRule(c));
        };
        _xifexpression = IterableExtensions.<EClass>toSet(Iterables.<EClass>filter(IterableExtensions.<EClassifier>filter(IterableExtensions.<EClassifier>toSet(Iterables.<EClassifier>concat(IterableExtensions.<EPackageInfo, Set<EClassifier>>map(it.getEPackageInfos(), _function))), _function_1), EClass.class));
    } else {
        final Function1<EClass, Iterable<EClassifier>> _function_2 = (EClass c) -> {
            final Function1<EReference, Boolean> _function_3 = (EReference r) -> {
                return Boolean.valueOf(Ecore2XtextExtensions.needsAssignment(r));
            };
            final Function1<EReference, EClassifier> _function_4 = (EReference it_1) -> {
                return it_1.getEType();
            };
            return IterableExtensions.<EReference, EClassifier>map(IterableExtensions.<EReference>filter(c.getEAllReferences(), _function_3), _function_4);
        };
        _xifexpression = IterableExtensions.<EClass>toSet(Iterables.<EClass>filter(Iterables.<EClassifier>concat(IterableExtensions.<EClass, Iterable<EClassifier>>map(Iterables.<EClass>filter(Ecore2XtextExtensions.allConcreteRuleClassifiers(it), EClass.class), _function_2)), EClass.class));
    }
    return _xifexpression;
}
Also used : Set(java.util.Set) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) EClassifier(org.eclipse.emf.ecore.EClassifier) EClass(org.eclipse.emf.ecore.EClass) EPackageInfo(org.eclipse.xtext.xtext.wizard.EPackageInfo) EReference(org.eclipse.emf.ecore.EReference)

Example 95 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class PortableURIs method resolve.

/**
 * Resolves a given portable URI fragment against the given resource.
 *
 * @param resource the resource from which global scope to look up the EObject
 * @param portableFragment the portable fragment pointing to the to be resolved EObject
 *
 * @return the EObject for the given portableURIFragment
 */
public EObject resolve(final StorageAwareResource resource, final String portableFragment) {
    final PortableURIs.PortableFragmentDescription desc = this.fromFragmentString(portableFragment);
    final EReference mock = EcoreFactory.eINSTANCE.createEReference();
    mock.setEType(desc.descriptionEClass);
    final IScope scope = this.globalScopeProvider.getScope(resource, mock, Predicates.<IEObjectDescription>alwaysTrue());
    final IEObjectDescription description = IterableExtensions.<IEObjectDescription>head(scope.getElements(desc.descriptionQualifiedName));
    if ((description == null)) {
        return null;
    }
    final EObject container = EcoreUtil.resolve(description.getEObjectOrProxy(), resource);
    return this.getEObject(container, desc.descriptionRelativeFragment);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IScope(org.eclipse.xtext.scoping.IScope) EReference(org.eclipse.emf.ecore.EReference) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

EReference (org.eclipse.emf.ecore.EReference)229 EObject (org.eclipse.emf.ecore.EObject)118 EClass (org.eclipse.emf.ecore.EClass)58 List (java.util.List)52 ArrayList (java.util.ArrayList)48 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)37 Test (org.junit.Test)31 EAttribute (org.eclipse.emf.ecore.EAttribute)29 PalladioSelectEObjectDialog (org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog)28 EClassifier (org.eclipse.emf.ecore.EClassifier)21 Resource (org.eclipse.emf.ecore.resource.Resource)21 IdEObject (org.bimserver.emf.IdEObject)18 EList (org.eclipse.emf.common.util.EList)17 IScope (org.eclipse.xtext.scoping.IScope)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 InternalEObject (org.eclipse.emf.ecore.InternalEObject)14 URI (org.eclipse.emf.common.util.URI)13 EPackage (org.eclipse.emf.ecore.EPackage)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)10 CrossReference (org.eclipse.xtext.CrossReference)10