Search in sources :

Example 1 with GProgram

use of org.eclipse.gemoc.gexpressions.GProgram 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 2 with GProgram

use of org.eclipse.gemoc.gexpressions.GProgram in project gemoc-studio by eclipse.

the class TestXtextSerializer2 method loadGexpressionTestFile.

public static void loadGexpressionTestFile() {
    // Getting the serializer
    GExpressionsStandaloneSetup setup = new GExpressionsStandaloneSetup();
    Injector injector = setup.createInjectorAndDoEMFRegistration();
    GexpressionsPackage.eINSTANCE.eClass();
    Serializer serializer = injector.getInstance(Serializer.class);
    // Load the model
    URI modelURI = URI.createFileURI("/home/flatombe/thesis/gemoc/git/gemoc-dev/org/eclipse/gemoc/GEL/org.eclipse.gemoc.gel.gexpressions.test/model/test.gexpressions");
    XtextResourceSet resSet = injector.getInstance(XtextResourceSet.class);
    resSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    Resource resource = resSet.getResource(modelURI, true);
    GProgram program = (GProgram) resource.getContents().get(0);
    List<GExpression> exps = program.getExpressions();
    for (GExpression exp : exps) {
        // Serializing
        String s = serializer.serialize(exp);
        System.out.println(s);
    }
}
Also used : GExpression(org.eclipse.gemoc.gexpressions.GExpression) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) GProgram(org.eclipse.gemoc.gexpressions.GProgram) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) GExpressionsStandaloneSetup(org.eclipse.gemoc.gexpressions.xtext.GExpressionsStandaloneSetup) Serializer(org.eclipse.xtext.serializer.impl.Serializer)

Example 3 with GProgram

use of org.eclipse.gemoc.gexpressions.GProgram in project gemoc-studio by eclipse.

the class GexpressionsExample method main.

/**
 * <!-- begin-user-doc -->
 * Load all the argument file paths or URIs as instances of the model.
 * <!-- end-user-doc -->
 * @param args the file paths or URIs.
 * @generated
 */
public static void main(String[] args) {
    // Create a resource set to hold the resources.
    // 
    ResourceSet resourceSet = new ResourceSetImpl();
    // Register the appropriate resource factory to handle all file extensions.
    // 
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Register the package to ensure it is available during loading.
    // 
    resourceSet.getPackageRegistry().put(GexpressionsPackage.eNS_URI, GexpressionsPackage.eINSTANCE);
    // 
    if (args.length == 0) {
        System.out.println("Enter a list of file paths or URIs that have content like this:");
        try {
            Resource resource = resourceSet.createResource(URI.createURI("http:///My.gexpressions"));
            GProgram root = GexpressionsFactory.eINSTANCE.createGProgram();
            resource.getContents().add(root);
            resource.save(System.out, null);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    } else {
        // 
        for (int i = 0; i < args.length; ++i) {
            // Construct the URI for the instance file.
            // The argument is treated as a file path only if it denotes an existing file.
            // Otherwise, it's directly treated as a URL.
            // 
            File file = new File(args[i]);
            URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
            try {
                // Demand load resource for this file.
                // 
                Resource resource = resourceSet.getResource(uri, true);
                System.out.println("Loaded " + uri);
                // 
                for (EObject eObject : resource.getContents()) {
                    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
                    if (diagnostic.getSeverity() != Diagnostic.OK) {
                        printDiagnostic(diagnostic, "");
                    }
                }
            } catch (RuntimeException exception) {
                System.out.println("Problem loading " + uri);
                exception.printStackTrace();
            }
        }
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) GProgram(org.eclipse.gemoc.gexpressions.GProgram) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) File(java.io.File) URI(org.eclipse.emf.common.util.URI)

Aggregations

GProgram (org.eclipse.gemoc.gexpressions.GProgram)3 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Injector (com.google.inject.Injector)1 File (java.io.File)1 IOException (java.io.IOException)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)1 GAdditionExpression (org.eclipse.gemoc.gexpressions.GAdditionExpression)1 GAndExpression (org.eclipse.gemoc.gexpressions.GAndExpression)1 GBooleanExpression (org.eclipse.gemoc.gexpressions.GBooleanExpression)1 GBraceExpression (org.eclipse.gemoc.gexpressions.GBraceExpression)1 GDoubleExpression (org.eclipse.gemoc.gexpressions.GDoubleExpression)1 GEnumLiteralExpression (org.eclipse.gemoc.gexpressions.GEnumLiteralExpression)1 GEqualityExpression (org.eclipse.gemoc.gexpressions.GEqualityExpression)1 GExpression (org.eclipse.gemoc.gexpressions.GExpression)1