blob: 26cfd2976d39d9e122a0aa1a6ad2c92b46f2da60 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/**
* Copyright (c) 2011 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* hrr@protos.de (initial contribution)
*/
package org.eclipse.etrice.core.genmodel.fsm.tests;
import com.google.inject.Injector;
import java.util.HashMap;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.etrice.core.RoomStandaloneSetup;
import org.eclipse.etrice.core.TestBase;
import org.eclipse.etrice.core.genmodel.fsm.ExtendedFsmGenBuilder;
import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician;
import org.eclipse.etrice.core.genmodel.fsm.NullDiagnostician;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
import org.eclipse.etrice.core.genmodel.fsm.tests.FSMGenModelTestsActivator;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.osgi.framework.Bundle;
@SuppressWarnings("all")
public class FsmGenTestBase extends TestBase {
protected Resource res = null;
protected ActorClass actor;
protected IDiagnostician diagnostician = new NullDiagnostician();
@Extension
protected ExtendedFsmGenBuilder builder;
protected GraphContainer getGraphContainer(final String roomFile, final String actorName) {
GraphContainer _xblockexpression = null;
{
FSMGenModelTestsActivator _instance = FSMGenModelTestsActivator.getInstance();
Bundle _bundle = _instance.getBundle();
this.prepare(_bundle);
Resource _resource = this.getResource(roomFile);
this.res = _resource;
EList<EObject> _contents = this.res.getContents();
EObject _get = _contents.get(0);
EList<ActorClass> _actorClasses = ((RoomModel) _get).getActorClasses();
final Function1<ActorClass, Boolean> _function = new Function1<ActorClass, Boolean>() {
@Override
public Boolean apply(final ActorClass it) {
String _name = it.getName();
return Boolean.valueOf(_name.equals(actorName));
}
};
ActorClass _findFirst = IterableExtensions.<ActorClass>findFirst(_actorClasses, _function);
this.actor = _findFirst;
RoomStandaloneSetup _roomStandaloneSetup = new RoomStandaloneSetup();
final Injector injector = _roomStandaloneSetup.createInjectorAndDoEMFRegistration();
ExtendedFsmGenBuilder _extendedFsmGenBuilder = new ExtendedFsmGenBuilder(injector, this.diagnostician);
this.builder = _extendedFsmGenBuilder;
_xblockexpression = this.builder.createTransformedModel(this.actor);
}
return _xblockexpression;
}
protected void save(final GraphContainer gc, final String fileName) {
try {
final ResourceSetImpl rs = new ResourceSetImpl();
final URI uri = URI.createFileURI((("./output/" + fileName) + ".fsmgen"));
final Resource res = rs.createResource(uri);
EList<EObject> _contents = res.getContents();
_contents.add(gc);
HashMap<Object, Object> _newHashMap = CollectionLiterals.<Object, Object>newHashMap();
res.save(_newHashMap);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
}
|