Add command parameter name saving
This commit is contained in:
parent
ad3bd451ba
commit
fd63e995ff
4 changed files with 68 additions and 71 deletions
103
build.sbt
103
build.sbt
|
@ -51,50 +51,83 @@ saveConfigComments := {
|
||||||
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:(?:get(?:I)?Config)|(?:DPUtils.\\w+Data))") //Hack: DPUtils
|
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:(?:get(?:I)?Config)|(?:DPUtils.\\w+Data))") //Hack: DPUtils
|
||||||
val clRegex = Pattern.compile("class (\\w+) extends (\\w+)")
|
val clRegex = Pattern.compile("class (\\w+) extends (\\w+)")
|
||||||
val objRegex = Pattern.compile("object (\\w+)")
|
val objRegex = Pattern.compile("object (\\w+)")
|
||||||
|
val subRegex = Pattern.compile("def `?(\\w+)`?\\((?:((?:\\w|\\d)+): ((?:\\w|[\\[\\].]|\\d)+),?\\s*)+\\)")
|
||||||
val config = new YamlConfiguration()
|
val config = new YamlConfiguration()
|
||||||
|
|
||||||
|
def getConfigComments(line: String, clKey: String, comment: String, justCommented: Boolean): (String, String, Boolean) = {
|
||||||
|
val clMatcher = clRegex.matcher(line)
|
||||||
|
if (clKey == null && clMatcher.find()) { //First occurrence
|
||||||
|
(if (clMatcher.group(2).contains("Component"))
|
||||||
|
"components." + clMatcher.group(1)
|
||||||
|
else "global", comment, justCommented)
|
||||||
|
} else if (line.contains("/**")) {
|
||||||
|
(clKey, "", false)
|
||||||
|
} else if (line.contains("*/") && comment != null)
|
||||||
|
(clKey, comment, true)
|
||||||
|
else if (comment != null) {
|
||||||
|
if (justCommented) {
|
||||||
|
if (clKey != null) {
|
||||||
|
val matcher = cdataRegex.matcher(line)
|
||||||
|
if (matcher.find())
|
||||||
|
config.set(s"$clKey.${matcher.group(1)}", comment.trim)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val matcher = objRegex.matcher(line)
|
||||||
|
if (matcher.find()) {
|
||||||
|
val clName = matcher.group(1)
|
||||||
|
val compKey = if (clName.contains("Module")) s"component.$clName"
|
||||||
|
else if (clName.contains("Plugin")) "global"
|
||||||
|
else null
|
||||||
|
if (compKey != null)
|
||||||
|
config.set(s"${compKey}.generalDescriptionInsteadOfAConfig", comment.trim)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(clKey, null, false)
|
||||||
|
}
|
||||||
|
else (clKey, comment + line.replaceFirst("^\\s*\\*\\s+", "") + "\n", justCommented)
|
||||||
|
}
|
||||||
|
else (clKey, comment, justCommented)
|
||||||
|
}
|
||||||
|
|
||||||
for (file <- sv) {
|
for (file <- sv) {
|
||||||
Using(Source.fromFile(file)) { src =>
|
Using(Source.fromFile(file)) { src =>
|
||||||
var clKey: String = null
|
var clKey: String = null
|
||||||
var comment: String = null
|
var comment: String = null
|
||||||
var justCommented: Boolean = false
|
var justCommented: Boolean = false
|
||||||
|
|
||||||
|
var subCommand = false
|
||||||
|
var pkg: String = null
|
||||||
|
var clName: String = null
|
||||||
for (line <- src.getLines) {
|
for (line <- src.getLines) {
|
||||||
|
val (clk, c, jc) = getConfigComments(line, clKey, comment, justCommented)
|
||||||
|
clKey = clk; comment = c; justCommented = jc
|
||||||
|
|
||||||
|
val objMatcher = objRegex.matcher(line)
|
||||||
val clMatcher = clRegex.matcher(line)
|
val clMatcher = clRegex.matcher(line)
|
||||||
if (clKey == null && clMatcher.find()) { //First occurrence
|
if (pkg == null && line.startsWith("package "))
|
||||||
clKey = if (clMatcher.group(2).contains("Component"))
|
pkg = line.substring("package ".length)
|
||||||
"components." + clMatcher.group(1)
|
/*else if (clName == null && (line.contains("object") || line.contains("class"))
|
||||||
else
|
&& !line.contains("import")) {
|
||||||
"global"
|
val i = line.indexOf("class")
|
||||||
/*println("Class: "+clKey)
|
val j = if (i == -1) line.indexOf("object") + "object ".length else i + "class ".length
|
||||||
println("Comment: "+comment)
|
clName = line.substring(j)
|
||||||
println("Just commented: "+justCommented)
|
}*/
|
||||||
if (comment != null) { //Not checking justCommented because the object may have the comment and not extend anything
|
else if (clName == null && objMatcher.find())
|
||||||
config.set(s"$clKey.generalDescriptionInsteadOfAConfig", comment.trim)
|
clName = objMatcher.group(1)
|
||||||
justCommented = false
|
else if (clName == null && clMatcher.find())
|
||||||
comment = null
|
clName = clMatcher.group(1)
|
||||||
println("Found class comment for " + clKey)
|
val subMatcher = subRegex.matcher(line)
|
||||||
}*/
|
val sub = line.contains("@Subcommand") || line.contains("@Command2.Subcommand")
|
||||||
} else if (line.contains("/**")) {
|
if (subCommand || sub) //This line or the previous one had the annotation
|
||||||
comment = ""
|
if (subMatcher.find()) {
|
||||||
justCommented = false
|
val groups = (2 to subMatcher.groupCount()).map(subMatcher.group)
|
||||||
} else if (line.contains("*/") && comment != null)
|
val pairs = for (i <- groups.indices by 2) yield (groups(i), groups(i + 1))
|
||||||
justCommented = true
|
val mname = subMatcher.group(1)
|
||||||
else if (comment != null) {
|
print(s"$pkg.$clName.$mname(")
|
||||||
if (justCommented) {
|
for ((name, ty) <- pairs) print(s"$name: $ty, ")
|
||||||
if (clKey != null) {
|
println(")")
|
||||||
val matcher = cdataRegex.matcher(line)
|
|
||||||
if (matcher.find())
|
|
||||||
config.set(s"$clKey.${matcher.group(1)}", comment.trim)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
val matcher = objRegex.matcher(line)
|
|
||||||
if (matcher.find())
|
|
||||||
config.set(s"${matcher.group(1)}.generalDescriptionInsteadOfAConfig", comment.trim)
|
|
||||||
}
|
|
||||||
justCommented = false
|
|
||||||
comment = null
|
|
||||||
}
|
}
|
||||||
else comment += line.replaceFirst("^\\s*\\*\\s+", "") + "\n"
|
subCommand = sub
|
||||||
}
|
|
||||||
}
|
}
|
||||||
config.save("target/configHelp.yml")
|
config.save("target/configHelp.yml")
|
||||||
}.recover[Unit]({ case t => t.printStackTrace() })
|
}.recover[Unit]({ case t => t.printStackTrace() })
|
||||||
|
|
8
commenter/.idea/.gitignore
vendored
8
commenter/.idea/.gitignore
vendored
|
@ -1,8 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
|
@ -1,10 +0,0 @@
|
||||||
name := "Chroma-Commenter"
|
|
||||||
version := "1.0"
|
|
||||||
organization := "com.github.TBMCPlugins"
|
|
||||||
scalaVersion := "2.13.4"
|
|
||||||
|
|
||||||
resolvers += Resolver.mavenLocal
|
|
||||||
|
|
||||||
libraryDependencies += "org.reflections" % "reflections" % "0.9.12"
|
|
||||||
libraryDependencies += "com.github.TBMCPlugins.ChromaCore" % "ButtonProcessor" % "master-SNAPSHOT"
|
|
||||||
libraryDependencies += "com.github.TBMCPlugins.ChromaCore" % "Chroma-Core" % "v1.0.0"
|
|
|
@ -1,18 +0,0 @@
|
||||||
import buttondevteam.buttonproc.HasConfig
|
|
||||||
import buttondevteam.lib.architecture.ConfigData
|
|
||||||
import org.reflections.Reflections
|
|
||||||
|
|
||||||
import scala.jdk.javaapi.CollectionConverters.asScala
|
|
||||||
|
|
||||||
object Commenter extends App {
|
|
||||||
val ref = new Reflections("buttondevteam.discordplugin")
|
|
||||||
val types = asScala(ref.getTypesAnnotatedWith(classOf[HasConfig], true))
|
|
||||||
for (ty <- types) {
|
|
||||||
val path = if (ty.getAnnotation(classOf[HasConfig]).global()) "global"
|
|
||||||
else s"components.${ty.getSimpleName}"
|
|
||||||
val cdcl = classOf[ConfigData[_]]
|
|
||||||
ty.getDeclaredMethods.filter(m => cdcl.isAssignableFrom(m.getReturnType))
|
|
||||||
.concat(ty.getDeclaredFields.filter(f => cdcl.isAssignableFrom(f.getType)))
|
|
||||||
.map(path + "." + _.getName)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue