async function runJavaFile()

in src/extension.ts [232:295]


async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {
    const progressReporter = progressProvider.createProgressReporter(noDebug ? "Run" : "Debug");
    try {
        // Wait for Java Language Support extension being on Standard mode.
        const isOnStandardMode = await utility.waitForStandardMode(progressReporter);
        if (!isOnStandardMode) {
            throw new utility.OperationCancelledError("");
        }

        const activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
        if (!uri && activeEditor && _.endsWith(path.basename(activeEditor.document.fileName), ".java")) {
            uri = activeEditor.document.uri;
        }

        if (!uri) {
            vscode.window.showErrorMessage(`${noDebug ? "Run" : "Debug"} failed. Please open a Java file with main method first.`);
            throw new utility.OperationCancelledError("");
        }

        const mainMethods: IMainMethod[] = await resolveMainMethod(uri);
        const hasMainMethods: boolean = mainMethods.length > 0;
        const canRunTests: boolean = await canDelegateToJavaTestRunner(uri);
        const defaultPlaceHolder: string = "Select the main class to run";

        if (!hasMainMethods && !canRunTests) {
            progressReporter.report("Resolving main class...");
            const mainClasses: IMainClassOption[] = await utility.searchMainMethods();
            if (progressReporter.isCancelled()) {
                throw new utility.OperationCancelledError("");
            }

            const placeHolder: string = `The file '${path.basename(uri.fsPath)}' is not executable, please select a main class you want to run.`;
            await launchMain(mainClasses, uri, noDebug, progressReporter, placeHolder, false /*autoPick*/);
        } else if (hasMainMethods && !canRunTests) {
            await launchMain(mainMethods, uri, noDebug, progressReporter, defaultPlaceHolder);
        } else if (!hasMainMethods && canRunTests) {
            launchTesting(uri, noDebug, progressReporter);
        } else {
            const launchMainChoice: string = "main() method";
            const launchTestChoice: string = "unit tests";
            const choice: string | undefined = await vscode.window.showQuickPick(
                [launchMainChoice, launchTestChoice],
                { placeHolder: "Please select which kind of task you would like to launch" },
            );
            if (choice === launchMainChoice) {
                await launchMain(mainMethods, uri, noDebug, progressReporter, defaultPlaceHolder);
            } else if (choice === launchTestChoice) {
                launchTesting(uri, noDebug, progressReporter);
            }
        }
    } catch (ex) {
        progressReporter.done();
        if (ex instanceof utility.OperationCancelledError) {
            return;
        }

        if (ex instanceof utility.JavaExtensionNotEnabledError) {
            utility.guideToInstallJavaExtension();
            return;
        }

        vscode.window.showErrorMessage(String((ex && ex.message) || ex));
    }
}