blob: b8ad9fb1a9674ecc2b9fbc6f5ca7f244ef84f0f6 (
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
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* 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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.generator.java.gen
import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.HashMap
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.WiredActorClass
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers
import org.eclipse.etrice.generator.base.io.IGeneratorFileIO
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.core.room.util.RoomHelpers
@Singleton
class ActorClassDataGen {
@Inject IGeneratorFileIO fileIO
@Inject extension RoomHelpers
@Inject extension RoomExtensions
@Inject extension FileSystemHelpers
@Inject extension ProcedureHelpers
def doGenerate(Root root) {
val HashMap<ActorClass, WiredActorClass> ac2wired = new HashMap<ActorClass, WiredActorClass>
root.wiredInstances.filter(w|w instanceof WiredActorClass).forEach[w|ac2wired.put((w as WiredActorClass).actorClass, w as WiredActorClass)]
for (xpac: root.actorClasses.filter[isValidGenerationLocation].map[root.getExpandedActorClass(it)]) {
val wired = ac2wired.get(xpac.actorClass)
val path = xpac.actorClass.getPath
var file = xpac.actorClass.name+"_DataObject.java"
fileIO.generateFile("generating ActorClass implementation", path + file, root.generate(xpac, wired))
}
}
def generate(Root root, ExpandedActorClass xpac, WiredActorClass wired) {
val ac = xpac.actorClass
val clsname = ac.name+"_DataObject"
val models = root.getReferencedModels(ac)
val baseClass = if (ac.base!==null) "extends "+ac.actorBase.name+"_DataObject " else ""
'''
package «ac.getPackage»;
import org.eclipse.etrice.runtime.java.modelbase.IActorClassDataObject;
«FOR model : models»
import «model.name».*;
«ENDFOR»
public class «clsname» «baseClass»implements IActorClassDataObject {
«IF ac.hasNonEmptyStateMachine»
// state and history
private int state;
private int[] history;
«ENDIF»
«ac.attributes.attributes»
«IF ac.hasNonEmptyStateMachine»
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public int[] getHistory() {
return history;
}
public void setHistory(int[] history) {
this.history = history;
}
«ENDIF»
«attributeSettersGettersImplementation(ac.attributes, ac.name)»
};
'''
}
}
|