Search in sources :

Example 26 with EClass

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

the class InheritanceTest method testMetamodel.

@Test
public void testMetamodel() throws Exception {
    AbstractRule rule = GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "OverridableParserRule2");
    assertNotNull("rule", rule);
    TypeRef ref = rule.getType();
    assertNotNull("ref", ref);
    final EClass clazz = (EClass) ref.getClassifier();
    assertNotNull("class", clazz);
    assertEquals("AType2", clazz.getName());
    assertEquals(2, clazz.getESuperTypes().size());
    Set<String> expectedNames = new HashSet<String>(Arrays.asList(new String[] { "AType", "RootRule" }));
    Iterator<String> iter = Iterables.transform(clazz.getESuperTypes(), new Function<EClass, String>() {

        @Override
        public String apply(EClass param) {
            return param.getName();
        }
    }).iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        assertTrue("name = '" + name + "'", expectedNames.remove(name));
    }
    assertTrue(expectedNames.toString(), expectedNames.isEmpty());
}
Also used : Function(com.google.common.base.Function) EClass(org.eclipse.emf.ecore.EClass) TypeRef(org.eclipse.xtext.TypeRef) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with EClass

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

the class SyntacticSequencerPDAProviderNavigatorTest method getParserRule.

protected ISynAbsorberState getParserRule(String body, String name, String typeName) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    // SyntacticSequencerPDA2SimpleDot.drawGrammar("pdf/" + getName(),
    // grammar);
    // SyntacticSequencerPDA2ExtendedDot.drawGrammar(createSequenceParserPDAProvider(),
    // "pdf/" + getName(), grammar);
    ISyntacticSequencerPDAProvider pdaProvider = get(ISyntacticSequencerPDAProvider.class);
    SerializationContextMap<ISynAbsorberState> pdas = pdaProvider.getSyntacticSequencerPDAs(grammar);
    for (SerializationContextMap.Entry<ISynAbsorberState> e : pdas.sortedCopy().values()) {
        for (ISerializationContext context : e.getContexts()) {
            if (context.getAssignedAction() != null)
                continue;
            ISynAbsorberState pda = e.getValue();
            ParserRule rule = context.getParserRule();
            EClass type = context.getType();
            boolean nameMatches = rule == null || name == null || rule.getName().equals(name);
            boolean typeMatches = type == null || typeName == null || typeName.equals(type.getName());
            if (nameMatches && typeMatches)
                return pda;
        }
    }
    throw new IllegalStateException();
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) Grammar(org.eclipse.xtext.Grammar)

Example 28 with EClass

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

the class MetamodelTransformationTest method testMultiValueAssignments.

@Test
public void testMultiValueAssignments() throws Exception {
    EClass clazz = getModel("a+='keyword' & a+='keyword'");
    EStructuralFeature feature = clazz.getEStructuralFeature("a");
    assertSame(EcorePackage.Literals.ESTRING, feature.getEType());
    assertTrue(feature.isMany());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Test(org.junit.Test)

Example 29 with EClass

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

the class SlotEntry method findEClasses.

protected Set<EClass> findEClasses(ResourceSet resourceSet, String nsURI2, String typeName2) {
    if (typeName2 == null)
        return Collections.emptySet();
    Set<EClass> result = Sets.newHashSet();
    Set<String> keySet = getNsUris();
    for (String string : keySet) {
        try {
            EPackage ePackage = resourceSet.getPackageRegistry().getEPackage(string);
            if (ePackage != null) {
                EClassifier classifier = ePackage.getEClassifier(typeName2);
                if (classifier instanceof EClass)
                    result.add((EClass) classifier);
            }
        } catch (NoClassDefFoundError e) {
            throw new NoClassDefFoundError("NoClassDefFoundError while loading ePackage: " + string + " - " + e.getMessage());
        }
    }
    if (result.isEmpty()) {
        throw new WorkflowInterruptedException("Couldn't find EClass for name '" + typeName2 + "'.");
    }
    return result;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 30 with EClass

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

the class ResourceSetGlobalScopeProvider method createScopeWithQualifiedNames.

protected IScope createScopeWithQualifiedNames(final IScope parent, final Resource resource, final Predicate<IEObjectDescription> filter, ResourceSet resourceSet, EClass type, boolean ignoreCase) {
    final Iterable<ISelectable> resourceDescriptions = Iterables.transform(resourceSet.getResources(), new Function<Resource, ISelectable>() {

        @Override
        public ISelectable apply(Resource from) {
            return resourceDecriptionProvider.getResourceDescription(from);
        }
    });
    ISelectable compound = new ISelectable() {

        @Override
        public boolean isEmpty() {
            for (ISelectable description : resourceDescriptions) {
                if (!description.isEmpty())
                    return false;
            }
            return true;
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjectsByType(final EClass type) {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjectsByType(type);
                }
            }));
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjectsByObject(object);
                }
            }));
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName name, final boolean ignoreCase) {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjects(type, name, ignoreCase);
                }
            }));
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjects() {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjects();
                }
            }));
        }
    };
    return SelectableBasedScope.createScope(parent, compound, filter, type, ignoreCase);
}
Also used : Function(com.google.common.base.Function) EClass(org.eclipse.emf.ecore.EClass) ISelectable(org.eclipse.xtext.resource.ISelectable) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)205 Test (org.junit.Test)99 EPackage (org.eclipse.emf.ecore.EPackage)70 EClassifier (org.eclipse.emf.ecore.EClassifier)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)43 EObject (org.eclipse.emf.ecore.EObject)35 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)27 Resource (org.eclipse.emf.ecore.resource.Resource)23 EReference (org.eclipse.emf.ecore.EReference)22 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)16 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)13 ParserRule (org.eclipse.xtext.ParserRule)12 QualifiedName (org.eclipse.xtext.naming.QualifiedName)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)11 IScope (org.eclipse.xtext.scoping.IScope)11 ArrayList (java.util.ArrayList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 List (java.util.List)9 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9