Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 生成的Xpand代码';编辑器不包含主类型';。但是我有一个主要的方法_Java_Eclipse_Dsl_Xtext_Xpand - Fatal编程技术网

Java 生成的Xpand代码';编辑器不包含主类型';。但是我有一个主要的方法

Java 生成的Xpand代码';编辑器不包含主类型';。但是我有一个主要的方法,java,eclipse,dsl,xtext,xpand,Java,Eclipse,Dsl,Xtext,Xpand,我试图理解使用xText和xPand生成dsl代码 我已经在eclipse中打开了statemachine xText示例,并作为一个新的eclipse应用程序运行。然后,我在src中创建了一个包含test.statemachine文件的java,并将提供的代码复制到其中 然后在src gen文件夹中生成以下.java文件: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamR

我试图理解使用xText和xPand生成dsl代码

我已经在eclipse中打开了statemachine xText示例,并作为一个新的eclipse应用程序运行。然后,我在src中创建了一个包含test.statemachine文件的java,并将提供的代码复制到其中

然后在src gen文件夹中生成以下.java文件:

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 "";
    }
}
}

但是,如果出现“编辑器不包含主类型”的错误,这将不会很有趣,但从我所看到的情况来看,存在包含生成的
测试的
src gen
文件夹。默认情况下,java
是一个普通文件夹,而不是“源文件夹”。因此,So必须打开该文件夹上的上下文菜单,并选择“构建路径”->“用作源文件夹”。之后,您可以执行Java程序。

测试
包含main。不确定编辑器是什么,因为您没有包括它……它也在Java项目的Java构建路径中吗?您能声明一个包吗(否则它不会在现代JRE上运行)?