0
나는 xText와 xPand로 DSL 코드 생성을 이해하려고 노력하고있다.생성 된 Xpand 코드 '편집기에 주 유형이 없습니다'. 그러나 나는 주된 방법을 가지고있다.
이클립스에서 statemachine xText 예제를 열고 새로운 Eclipse 애플리케이션으로 실행했습니다. 그런 다음 src에 test.statemachine 파일을 첨부하여 제공된 코드를 복사했습니다.
다음 된 .java 파일은 다음 SRC 세대 폴더에 생성됩니다 그러나
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class testing {
public static void main(String[] args) {
new testing().run();
}
protected void doUnlockPanel() {
System.out.println("Executing command unlockPanel (PNUL)");
}
protected void doLockPanel() {
System.out.println("Executing command lockPanel (PNLK)");
}
protected void doLockDoor() {
System.out.println("Executing command lockDoor (D1LK)");
}
protected void doUnlockDoor() {
System.out.println("Executing command unlockDoor (D1UL)");
}
protected void run() {
boolean executeActions = true;
String currentState = "idle";
String lastEvent = null;
while (true) {
if (currentState.equals("idle")) {
if (executeActions) {
doUnlockDoor();
doLockPanel();
executeActions = false;
}
System.out.println("Your are now in state 'idle'. Possible events are [doorClosed].");
lastEvent = receiveEvent();
if ("doorClosed".equals(lastEvent)) {
currentState = "active";
executeActions = true;
}
}
if (currentState.equals("active")) {
if (executeActions) {
executeActions = false;
}
System.out.println("Your are now in state 'active'. Possible events are [drawOpened, lightOn].");
lastEvent = receiveEvent();
if ("drawOpened".equals(lastEvent)) {
currentState = "waitingForLight";
executeActions = true;
}
if ("lightOn".equals(lastEvent)) {
currentState = "waitingForDraw";
executeActions = true;
}
}
if (currentState.equals("waitingForLight")) {
if (executeActions) {
executeActions = false;
}
System.out.println("Your are now in state 'waitingForLight'. Possible events are [lightOn].");
lastEvent = receiveEvent();
if ("lightOn".equals(lastEvent)) {
currentState = "unlockedPanel";
executeActions = true;
}
}
if (currentState.equals("waitingForDraw")) {
if (executeActions) {
executeActions = false;
}
System.out.println("Your are now in state 'waitingForDraw'. Possible events are [drawOpened].");
lastEvent = receiveEvent();
if ("drawOpened".equals(lastEvent)) {
currentState = "unlockedPanel";
executeActions = true;
}
}
if (currentState.equals("unlockedPanel")) {
if (executeActions) {
doUnlockPanel();
doLockDoor();
executeActions = false;
}
System.out.println("Your are now in state 'unlockedPanel'. Possible events are [panelClosed].");
lastEvent = receiveEvent();
if ("panelClosed".equals(lastEvent)) {
currentState = "idle";
executeActions = true;
}
}
if ("doorClosed".equals(lastEvent)) {
System.out.println("Resetting state machine.");
currentState = "idle";
executeActions = true;
}
}
}
private String receiveEvent() {
System.out.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
return br.readLine();
} catch (IOException ioe) {
System.out.println("Problem reading input");
return "";
}
}
}
이됩니다 오류 '에디터가 주요 유형을 포함하지 않는'하지만이 볼 수에서 어떤 재미를하지 존재
'testing'에는 main이 포함됩니다. 당신이 그것을 포함하지 않았기 때문에'editor'가 무엇인지 확실하지 않습니다 ... – John3136
Java 프로젝트의 Java 빌드 경로에 있습니까? 패키지를 선언 할 수 있습니까 (그렇지 않으면 현대 JRE에서 실행되지 않습니다)? – nitind