Repository navigation
ADFA-1980 | JVM-Tools: run Java and Kotlin programs with a main-class picker - #124
Open
Daniel-ADFA wants to merge 1 commit into
Open
Daniel-ADFA wants to merge 1 commit into
Daniel-ADFA wants to merge 1 commit into
Conversation
… picker CoGo could not run a plain Java or Kotlin program: Quick Run builds and installs an Android app. JVM-Tools adds, for a folder of .java/.kt files with no Gradle build: - Run: compiles every source on the device (kotlin-compiler-embeddable from the IDE's local Maven repository for Kotlin, then the JDK's javac, so Java and Kotlin can use each other) and execs java on the chosen main class. Output streams to Build Output; Cancel Run stops the JVM. Unsaved Java/Kotlin buffers are written before compiling. - Run configuration: lists every class with a main (Java static main, Kotlin top-level main as its FileNameKt facade, @JvmStatic main in an object or companion) and takes program arguments with shell-style quoting. It is a Material dialog built on the IDE activity and shown through PluginWindows, so it matches the IDE's dialogs. Saved per project in the plugin directory. - A Java/Kotlin Program template. The Gradle actions and Quick Build are hidden in these projects, as in Python-Tools. Requires 26.37 for PluginWindows. Programs cannot read stdin: plugin commands have no input stream.
| private fun javaMainClasses(code: String): List<String> { | ||
| val pkg = JAVA_PACKAGE.find(code)?.groupValues?.get(1) | ||
| return JAVA_MAIN.findAll(code) | ||
| .mapNotNull { main -> JAVA_TYPE.findAll(code.substring(0, main.range.first)).lastOrNull()?.groupValues?.get(1) } |
Contributor
There was a problem hiding this comment.
main is attributed to the last class/interface/enum/record declared anywhere before it in the file, so a nested type declared above main takes the name.
Example:
public class Main {
record Point(int x, int y) {}
public static void main(String[] args) {}
}This yields Point, so the script runs java -cp … Point and fails with "Could not find or load main class Point". A main inside a static nested class is likewise run under its simple name rather than Outer$Inner.
The Kotlin @JvmStatic path (ownerOf, line 70) has the same issue with nested objects. No test in MainClassFinderTest covers nested types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADFA-1980
Adds JVM-Tools: run Java and Kotlin programs the way a desktop IDE does. In a folder of
.java/.ktfiles with no Gradle build:javac) and runs the chosen main class. Output goes to Build Output; Cancel Run stops it.PluginWindows.Gradle actions and Quick Build are hidden in these projects, as in Python-Tools. Requires CoGo 26.37. Programs can't read keyboard input; plugin commands have no stdin.
Verified on an emulator: Kotlin, Java and mixed projects, arguments, cancel, unsaved edits, tooltips and help page, 2x font, and Android projects left unchanged.