Search in sources :

Example 31 with EPackage

use of org.eclipse.emf.ecore.EPackage in project gemoc-studio by eclipse.

the class DslSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == DslPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case DslPackage.DSL:
                sequence_Dsl(context, (Dsl) semanticObject);
                return;
            case DslPackage.ENTRY:
                sequence_Entry(context, (Entry) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Entry(org.eclipse.gemoc.dsl.Entry) Parameter(org.eclipse.xtext.Parameter) Dsl(org.eclipse.gemoc.dsl.Dsl) EPackage(org.eclipse.emf.ecore.EPackage)

Example 32 with EPackage

use of org.eclipse.emf.ecore.EPackage in project gemoc-studio by eclipse.

the class AbstractGExpressionsSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == GexpressionsPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case GexpressionsPackage.GADDITION_EXPRESSION:
                sequence_GAdditionExpression(context, (GAdditionExpression) semanticObject);
                return;
            case GexpressionsPackage.GAND_EXPRESSION:
                sequence_GAndExpression(context, (GAndExpression) semanticObject);
                return;
            case GexpressionsPackage.GBOOLEAN_EXPRESSION:
                sequence_GBooleanExpression(context, (GBooleanExpression) semanticObject);
                return;
            case GexpressionsPackage.GBRACE_EXPRESSION:
                sequence_GBraceExpression(context, (GBraceExpression) semanticObject);
                return;
            case GexpressionsPackage.GDOUBLE_EXPRESSION:
                sequence_GDoubleExpression(context, (GDoubleExpression) semanticObject);
                return;
            case GexpressionsPackage.GENUM_LITERAL_EXPRESSION:
                sequence_GEnumLiteralExpression(context, (GEnumLiteralExpression) semanticObject);
                return;
            case GexpressionsPackage.GEQUALITY_EXPRESSION:
                sequence_GEqualityExpression(context, (GEqualityExpression) semanticObject);
                return;
            case GexpressionsPackage.GIF_EXPRESSION:
                sequence_GIfExpression(context, (GIfExpression) semanticObject);
                return;
            case GexpressionsPackage.GIMPORT_STATEMENT:
                sequence_GImportStatement(context, (GImportStatement) semanticObject);
                return;
            case GexpressionsPackage.GINTEGER_EXPRESSION:
                sequence_GIntegerExpression(context, (GIntegerExpression) semanticObject);
                return;
            case GexpressionsPackage.GMULTIPLICATION_EXPRESSION:
                sequence_GMultiplicationExpression(context, (GMultiplicationExpression) semanticObject);
                return;
            case GexpressionsPackage.GNAVIGATION_EXPRESSION:
                sequence_GNavigationExpression(context, (GNavigationExpression) semanticObject);
                return;
            case GexpressionsPackage.GNEGATION_EXPRESSION:
                sequence_GNegationExpression(context, (GNegationExpression) semanticObject);
                return;
            case GexpressionsPackage.GOR_EXPRESSION:
                sequence_GOrExpression(context, (GOrExpression) semanticObject);
                return;
            case GexpressionsPackage.GPROGRAM:
                sequence_GProgram(context, (GProgram) semanticObject);
                return;
            case GexpressionsPackage.GREFERENCE_EXPRESSION:
                sequence_GReferenceExpression(context, (GReferenceExpression) semanticObject);
                return;
            case GexpressionsPackage.GRELATION_EXPRESSION:
                sequence_GRelationExpression(context, (GRelationExpression) semanticObject);
                return;
            case GexpressionsPackage.GSTRING_EXPRESSION:
                sequence_GStringExpression(context, (GStringExpression) semanticObject);
                return;
            case GexpressionsPackage.GXOR_EXPRESSION:
                sequence_GXorExpression(context, (GXorExpression) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : GReferenceExpression(org.eclipse.gemoc.gexpressions.GReferenceExpression) ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) GMultiplicationExpression(org.eclipse.gemoc.gexpressions.GMultiplicationExpression) GNegationExpression(org.eclipse.gemoc.gexpressions.GNegationExpression) GProgram(org.eclipse.gemoc.gexpressions.GProgram) GEnumLiteralExpression(org.eclipse.gemoc.gexpressions.GEnumLiteralExpression) GStringExpression(org.eclipse.gemoc.gexpressions.GStringExpression) GDoubleExpression(org.eclipse.gemoc.gexpressions.GDoubleExpression) GNavigationExpression(org.eclipse.gemoc.gexpressions.GNavigationExpression) GAdditionExpression(org.eclipse.gemoc.gexpressions.GAdditionExpression) GBraceExpression(org.eclipse.gemoc.gexpressions.GBraceExpression) EPackage(org.eclipse.emf.ecore.EPackage) GOrExpression(org.eclipse.gemoc.gexpressions.GOrExpression) GXorExpression(org.eclipse.gemoc.gexpressions.GXorExpression) GImportStatement(org.eclipse.gemoc.gexpressions.GImportStatement) GEqualityExpression(org.eclipse.gemoc.gexpressions.GEqualityExpression) GAndExpression(org.eclipse.gemoc.gexpressions.GAndExpression) GIfExpression(org.eclipse.gemoc.gexpressions.GIfExpression) Parameter(org.eclipse.xtext.Parameter) GRelationExpression(org.eclipse.gemoc.gexpressions.GRelationExpression) GIntegerExpression(org.eclipse.gemoc.gexpressions.GIntegerExpression) GBooleanExpression(org.eclipse.gemoc.gexpressions.GBooleanExpression)

Example 33 with EPackage

use of org.eclipse.emf.ecore.EPackage in project dsl-devkit by dsldevkit.

the class CheckCompiler method findEPackageInterfaceType.

/**
 * {@inheritDoc}
 */
// CHECKSTYLE:OFF
@SuppressWarnings("restriction")
protected JvmType findEPackageInterfaceType(final ENamedElement element, final EObject context) {
    // CHECKSTYLE:ON
    EPackage ePackage = EcoreUtil2.getContainerOfType(element, EPackage.class);
    String qualifiedPackageInterfaceName = CheckGenModelUtil.getQualifiedPackageInterfaceName(ePackage);
    return getTypeComputationServices().getTypeReferences().findDeclaredType(qualifiedPackageInterfaceName, context);
}
Also used : EPackage(org.eclipse.emf.ecore.EPackage)

Example 34 with EPackage

use of org.eclipse.emf.ecore.EPackage in project dsl-devkit by dsldevkit.

the class ExtendedLanguageConfig method getReferencedEPackages.

/**
 * Returns the set of all EPackage resource URIs referenced by the given GenModel.
 *
 * @param genModel
 *          genModel
 * @return set of URIs
 */
private Set<URI> getReferencedEPackages(final GenModel genModel) {
    Set<URI> result = Sets.newHashSet();
    for (GenPackage genPackage : genModel.getGenPackages()) {
        EPackage ePackage = genPackage.getEcorePackage();
        result.add(ePackage.eResource().getURI());
    }
    for (GenPackage genPackage : genModel.getUsedGenPackages()) {
        result.addAll(getReferencedEPackages(genPackage.getGenModel()));
    }
    return result;
}
Also used : GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage)

Example 35 with EPackage

use of org.eclipse.emf.ecore.EPackage in project xtext-xtend by eclipse.

the class URIsInEcoreFilesXtendTest method doTestResource.

protected void doTestResource(String platformPath, String... packageNames) {
    Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
    assertNotNull(resource);
    assertEquals(1, resource.getContents().size());
    EObject obj = resource.getContents().get(0);
    if (obj instanceof EPackage) {
        assertEquals(packageNames[0], ((EPackage) obj).getName());
    } else if (obj instanceof GenModel) {
        GenModel model = (GenModel) obj;
        List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
        assertEquals(packageNames.length, packages.size());
        ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {

            @Override
            public String apply(GenPackage p) {
                return p.getEcorePackage().getName();
            }
        });
        List<String> packageNamesList = Arrays.asList(packageNames);
        Collections.sort(packageNamesList);
        for (int i = 0; i < packageNamesList.size(); i++) {
            assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
        }
        IStatus status = model.validate();
        assertTrue(printLeafs(status), status.isOK());
        EObject orig = EcoreUtil.copy(obj);
        ((GenModel) obj).reconcile();
        if (!EcoreUtil.equals(orig, obj)) {
            Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {

                @Override
                public boolean apply(EStructuralFeature f) {
                    if (f instanceof EReference) {
                        EReference casted = (EReference) f;
                        return !casted.isContainment();
                    }
                    return false;
                }
            };
            String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
            String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
            throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
        }
    } else {
        fail("Unexpected root element type: " + obj.eClass().getName());
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) EPackage(org.eclipse.emf.ecore.EPackage) Predicate(com.google.common.base.Predicate) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) GenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

EPackage (org.eclipse.emf.ecore.EPackage)424 ParserRule (org.eclipse.xtext.ParserRule)201 Action (org.eclipse.xtext.Action)196 Parameter (org.eclipse.xtext.Parameter)196 Test (org.junit.Test)101 EClass (org.eclipse.emf.ecore.EClass)85 Resource (org.eclipse.emf.ecore.resource.Resource)50 EObject (org.eclipse.emf.ecore.EObject)39 EClassifier (org.eclipse.emf.ecore.EClassifier)32 URI (org.eclipse.emf.common.util.URI)30 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)23 Grammar (org.eclipse.xtext.Grammar)22 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)16 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)15 GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)14 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)14 XtextResource (org.eclipse.xtext.resource.XtextResource)14 EEnum (org.eclipse.emf.ecore.EEnum)13 EReference (org.eclipse.emf.ecore.EReference)12 IOException (java.io.IOException)11