-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
482 additions
and
226 deletions.
There are no files selected for viewing
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
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
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
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
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/net/love2hina/kotlin/sharon/data/EnumEntryInfo.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.love2hina.kotlin.sharon.data | ||
|
||
import net.love2hina.kotlin.sharon.setProperty | ||
|
||
internal data class EnumEntryInfo( | ||
|
||
/** 説明 */ | ||
override val description: StringBuilder = StringBuilder(), | ||
|
||
/** since */ | ||
var since: String? = null, | ||
|
||
/** deprecated */ | ||
var deprecated: String? = null, | ||
|
||
/** serial */ | ||
var serial: String? = null, | ||
|
||
/* | ||
* @see | ||
* @serialField | ||
*/ | ||
|
||
): JavadocInfo { | ||
|
||
override fun parseTag(name: String?, value: String): Boolean | ||
= when (name) { | ||
"since", "deprecated", "serial" -> { | ||
this.setProperty(name, value) | ||
true | ||
} | ||
else -> false | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/net/love2hina/kotlin/sharon/data/EnumInfo.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.love2hina.kotlin.sharon.data | ||
|
||
import net.love2hina.kotlin.sharon.setProperty | ||
|
||
internal data class EnumInfo( | ||
|
||
/** 説明 */ | ||
override val description: StringBuilder = StringBuilder(), | ||
|
||
/** since */ | ||
var since: String? = null, | ||
|
||
/** deprecated */ | ||
var deprecated: String? = null, | ||
|
||
/** serial */ | ||
var serial: String? = null, | ||
|
||
/** author */ | ||
val author: MutableList<String> = mutableListOf(), | ||
|
||
/** version */ | ||
var version: String? = null, | ||
|
||
/* | ||
* @see | ||
*/ | ||
|
||
): JavadocInfo { | ||
|
||
override fun parseTag(name: String?, value: String): Boolean | ||
= when (name) { | ||
"author" -> { | ||
author.addAll(value.split(", ")) | ||
true | ||
} | ||
"since", "deprecated", "serial", "version" -> { | ||
this.setProperty(name, value) | ||
true | ||
} | ||
else -> false | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/kotlin/net/love2hina/kotlin/sharon/data/JavadocInfo.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,69 @@ | ||
package net.love2hina.kotlin.sharon.data | ||
|
||
import com.github.javaparser.ast.comments.Comment | ||
import net.love2hina.kotlin.sharon.appendNewLine | ||
import java.util.Optional | ||
|
||
internal interface JavadocInfo { | ||
|
||
val description: StringBuilder | ||
|
||
fun parseTag(name: String?, value: String): Boolean | ||
|
||
} | ||
|
||
internal fun Optional<Comment>.parseJavadoc(info: JavadocInfo) { | ||
this.ifPresent { | ||
if (it.isJavadocComment) { | ||
val content = getCommentContents(it) | ||
var index = 0 | ||
var name: String? = null | ||
|
||
// Javadocをパースする | ||
for (match in REGEXP_ANNOTATION.findAll(content)) { | ||
index = pushJavadocComment(content, name, index, match.range, info) | ||
name = (match.groups as MatchNamedGroupCollection)["name"]!!.value | ||
} | ||
pushJavadocComment(content, name, index, IntRange(content.length, content.length), info) | ||
} | ||
else if (it.isBlockComment) { | ||
val content = getCommentContents(it) | ||
info.description.appendNewLine(content) | ||
} | ||
else { | ||
info.description.appendNewLine(it.content) | ||
} | ||
} | ||
} | ||
|
||
private fun getCommentContents(comment: Comment): String = | ||
comment.content.split(REGEXP_NEWLINE) | ||
.stream().map { l -> | ||
val m = REGEXP_BLOCK_COMMENT.find(l) | ||
if (m != null) | ||
(m.groups as MatchNamedGroupCollection)["content"]?.value ?: "" | ||
else l | ||
} | ||
.reduce(StringBuilder(), | ||
{ b, l -> b.appendNewLine(l) }, | ||
{ b1, b2 -> b1.appendNewLine(b2) }) | ||
.toString() | ||
|
||
private fun pushJavadocComment(content: String, name: String?, start: Int, range: IntRange, info: JavadocInfo ): Int { | ||
|
||
if (start < range.start) { | ||
val value = content.substring(start, range.start).trim() | ||
|
||
when { | ||
info.parseTag(name, value) -> {} | ||
name == null -> { | ||
info.description.appendNewLine(value) | ||
} | ||
else -> { | ||
info.description.appendNewLine("@$name $value") | ||
} | ||
} | ||
} | ||
|
||
return range.endInclusive + 1 | ||
} |
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
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
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
Oops, something went wrong.