Created
April 13, 2017 01:43
-
-
Save Jire/2d9858576d585c49000176a63bbb95b3 to your computer and use it in GitHub Desktop.
This file contains 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
import java.io.File | |
import java.nio.file.Files | |
const val PLUGIN_FOLDER_PATH = "src/main/java/plugin/" | |
const val ANNOTATION = "@InitializablePlugin" | |
const val IMPORT = "import ps.eden.server.plugin.InitializablePlugin;" | |
fun main(args: Array<String>) { | |
val pluginFolder = File(PLUGIN_FOLDER_PATH) | |
pluginFolder.walkTopDown().forEach { | |
if (!it.name.endsWith(".java")) return@forEach | |
val lines = it.readLines().toMutableList() | |
var completed = false | |
forwards@ for (i in lines.indices) { | |
val line = lines[i] | |
if ((line.contains("extends") || line.contains("implements")) | |
&& line.contains("class") && line.contains("{")) { | |
lines.add(i, ANNOTATION) | |
for (j in i downTo 1) { | |
val im = lines[j] | |
if (im.contains("import")) { | |
lines.add(j, IMPORT) | |
completed = true | |
break@forwards | |
} | |
} | |
} | |
} | |
if (completed) Files.write(it.toPath(), lines) | |
else println("Failed to convert $it") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment