Skip to content

Commit

Permalink
feat: accept class doc comment as component description
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashsaitwal committed Dec 28, 2023
1 parent 8d5f7c7 commit 9e307e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ExtensionProcessor : AbstractProcessor() {
val elements = roundEnv.getElementsAnnotatedWith(Extension::class.java)
val extensions = elements.map { processExtensionElement(it) }

val generator = InfoFilesGenerator(extensions)
val generator = InfoFilesGenerator(extensions, elementUtils)
try {
generator.generateComponentsJson()
generator.generateBuildInfoJson()
Expand All @@ -63,7 +63,7 @@ class ExtensionProcessor : AbstractProcessor() {
return false
}

private fun processExtensionElement(element: Element): Ext {
private fun processExtensionElement(element: Element): ExtensionModel {
val events = element.enclosedElements
.filter { it.getAnnotation(SimpleEvent::class.java) != null }
.map { Event(it as ExecutableElement, messager, elementUtils) }
Expand All @@ -84,9 +84,8 @@ class ExtensionProcessor : AbstractProcessor() {
val packageName = elementUtils.getPackageOf(element).qualifiedName.toString()
val fqcn = "$packageName.${element.simpleName}"

return Ext(
element.simpleName.toString(),
element.getAnnotation(Extension::class.java),
return ExtensionModel(
element,
fqcn,
events,
functions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ import java.nio.file.Paths
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.regex.Pattern
import javax.lang.model.util.Elements
import javax.lang.model.element.Element as JavaElement
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.parsers.ParserConfigurationException
import kotlin.io.path.createDirectory
import kotlin.io.path.exists

data class Ext(
val name: String,
val annotation: Extension,
data class ExtensionModel(
val element: JavaElement,
val fqcn: String,
val events: List<Event>,
val functions: List<Function>,
val properties: List<Property>,
val designerProperties: List<DesignerProperty>,
)

class InfoFilesGenerator(private val extensions: List<Ext>) {
class InfoFilesGenerator(private val extensions: List<ExtensionModel>, private val elementUtils: Elements) {
private val projectRoot = System.getenv("RUSH_PROJECT_ROOT")
private val rawBuildDir = Paths.get(projectRoot, ".rush", "build", "raw").apply {
if (!this.exists()) this.createDirectory()
Expand All @@ -63,9 +64,15 @@ class InfoFilesGenerator(private val extensions: List<Ext>) {
.put("showOnPalette", "true")
.put("nonVisible", "true")

val extAnnotation = ext.element.getAnnotation(Extension::class.java)
val description = extAnnotation.description.let {
it.ifBlank {
elementUtils.getDocComment(ext.element) ?: ""
}
}
extJsonObj
.put("name", ext.name)
.put("helpString", parseMdString(ext.annotation.description))
.put("name", ext.element.simpleName.toString())
.put("helpString", parseMdString(description))
.put("type", ext.fqcn)
.put("helpUrl", yaml.homepage)
.put("licenseName", yaml.license)
Expand All @@ -77,7 +84,7 @@ class InfoFilesGenerator(private val extensions: List<Ext>) {
val urlPattern = Pattern.compile(
"""https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_+.~#?&//=]*)"""
)
val icon = ext.annotation.icon
val icon = extAnnotation.icon
if (urlPattern.matcher(icon).find()) {
extJsonObj.put("iconName", icon)
} else {
Expand Down

0 comments on commit 9e307e8

Please sign in to comment.