Obtain config comments from sources
This commit is contained in:
parent
470212411d
commit
d80703ac68
2 changed files with 44 additions and 6 deletions
46
build.sbt
46
build.sbt
|
@ -1,3 +1,4 @@
|
||||||
|
import java.util.regex.Pattern
|
||||||
import scala.io.Source
|
import scala.io.Source
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
|
@ -42,14 +43,51 @@ assemblyMergeStrategy in assembly := {
|
||||||
case x => (assemblyMergeStrategy in assembly).value(x)
|
case x => (assemblyMergeStrategy in assembly).value(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
val teszt = TaskKey[Unit]("teszt")
|
val getConfigComments = TaskKey[Unit]("getConfigComments")
|
||||||
teszt := {
|
getConfigComments := {
|
||||||
val sv = (Compile / sources).value
|
val sv = (Compile / sources).value
|
||||||
|
//val cdataRegex = Pattern.compile("(?:def|val|var) \\w*ConfigData\\w*(?:\\[\\w+])? (\\w+)")
|
||||||
|
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = get(?:I)?Config")
|
||||||
|
val clRegex = Pattern.compile("class (\\w+) extends (\\w+)")
|
||||||
for (file <- sv) {
|
for (file <- sv) {
|
||||||
Using(Source.fromFile(file)) { src =>
|
Using(Source.fromFile(file)) { src =>
|
||||||
|
var pkg: String = null
|
||||||
|
var cl: String = null
|
||||||
|
var comment: String = null
|
||||||
|
var justCommented: Boolean = false
|
||||||
|
var isComponent: Boolean = false
|
||||||
for (line <- src.getLines) {
|
for (line <- src.getLines) {
|
||||||
if (line.contains("class"))
|
val clMatcher = clRegex.matcher(line)
|
||||||
println(line + "")
|
if (line.startsWith("package")) {
|
||||||
|
pkg = line.substring("package ".length)
|
||||||
|
//println("Found package: " + pkg)
|
||||||
|
} else if (line.contains("class") && pkg != null && cl == null && clMatcher.find()) { //First occurrence
|
||||||
|
//cl = line.substring(line.indexOf("class") + "class ".length)
|
||||||
|
cl = clMatcher.group(1)
|
||||||
|
isComponent = clMatcher.group(2).contains("Component")
|
||||||
|
//println("Found class: " + cl)
|
||||||
|
} else if (line.contains("/**") && cl != null) {
|
||||||
|
comment = ""
|
||||||
|
justCommented = false
|
||||||
|
//println("Found comment start")
|
||||||
|
} else if (line.contains("*/") && comment != null) {
|
||||||
|
justCommented = true
|
||||||
|
//println("Found comment end")
|
||||||
|
} else if (comment != null) {
|
||||||
|
if (justCommented) {
|
||||||
|
//println("Just commented")
|
||||||
|
//println(s"line: $line")
|
||||||
|
val matcher = cdataRegex.matcher(line)
|
||||||
|
if (matcher.find())
|
||||||
|
println(s"$pkg.$cl.${matcher.group(1)} comment:\n" + comment)
|
||||||
|
justCommented = false
|
||||||
|
comment = null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
comment += line.replaceFirst("^\\s*\\*\\s+", "")
|
||||||
|
//println("Adding to comment")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.recover[Unit]({ case t => t.printStackTrace() })
|
}.recover[Unit]({ case t => t.printStackTrace() })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
lazy val commenter = RootProject(file("../commenter"))
|
//lazy val commenter = RootProject(file("../commenter"))
|
||||||
lazy val root = (project in file(".")).dependsOn(commenter)
|
//lazy val root = (project in file(".")).dependsOn(commenter)
|
||||||
|
|
Loading…
Reference in a new issue