-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finishes implementation of Groovydoc formatter
- Loading branch information
1 parent
004697a
commit 91e0f32
Showing
19 changed files
with
728 additions
and
24 deletions.
There are no files selected for viewing
73 changes: 71 additions & 2 deletions
73
...roovydoc-formatter/src/main/kotlin/com/copperleaf/groovydoc/json/formatter/formatClass.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,11 +1,80 @@ | ||
package com.copperleaf.groovydoc.json.formatter | ||
|
||
import com.copperleaf.groovydoc.json.models.GroovydocClassDoc | ||
import com.copperleaf.groovydoc.json.models.SignatureComponent | ||
import org.codehaus.groovy.groovydoc.GroovyClassDoc | ||
|
||
fun GroovyClassDoc.toClassDoc(): GroovydocClassDoc { | ||
fun GroovyClassDoc.toClassDoc(deep: Boolean = true): GroovydocClassDoc { | ||
val modifiers = listOf(this.modifiers()).filterNotNull() | ||
|
||
return GroovydocClassDoc( | ||
this, | ||
this.name() | ||
this.containingPackage().nameWithDots(), | ||
modifiers, | ||
this.classKind, | ||
this.simpleTypeName(), | ||
this.qualifiedTypeName(), | ||
this.commentText().trim(), | ||
if(deep) this.constructors().map { it.toConstructor(this) } else emptyList(), | ||
if(deep) this.methods().map { it.toMethod(this) } else emptyList(), | ||
if(deep) this.fields().map { it.toField(this) } else emptyList(), | ||
this.classSignature( | ||
modifiers | ||
) | ||
) | ||
} | ||
|
||
val GroovyClassDoc.classKind: String | ||
get() { | ||
return when { | ||
isInterface -> "interface" | ||
isAnnotationType -> "@interface" | ||
isEnum -> "enum" | ||
isException -> "exception" | ||
else -> "class" | ||
} | ||
} | ||
|
||
fun GroovyClassDoc.classSignature( | ||
modifiers: List<String> | ||
): List<SignatureComponent> { | ||
val list = mutableListOf<SignatureComponent>() | ||
|
||
list.addAll(modifiers.toModifierListSignature()) | ||
list.add(SignatureComponent("name", "${this.classKind} ", "")) | ||
list.add(SignatureComponent("type", "" + this.simpleTypeName(), "" + this.qualifiedTypeName())) | ||
// list.addAll(this.typeParameters().toWildcardSignature()) | ||
|
||
if(this.isInterface) { | ||
val interfaces = this.interfaces() | ||
if(interfaces.isNotEmpty()) { | ||
list.add(SignatureComponent("name", " extends ", "")) | ||
interfaces.forEachIndexed { boundsIndex, type -> | ||
list.addAll(type.toTypeSignature()) | ||
if (boundsIndex < interfaces.size - 1) { | ||
list.add(SignatureComponent("punctuation", ", ", "")) | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
val superclass = this.superclass() | ||
if(superclass != null) { | ||
list.add(SignatureComponent("name", " extends ", "")) | ||
list.addAll(superclass.toTypeSignature()) | ||
} | ||
|
||
val interfaces = this.interfaces() | ||
if(interfaces.isNotEmpty()) { | ||
list.add(SignatureComponent("name", " implements ", "")) | ||
interfaces.forEachIndexed { boundsIndex, type -> | ||
list.addAll(type.toTypeSignature()) | ||
if (boundsIndex < interfaces.size - 1) { | ||
list.add(SignatureComponent("punctuation", ", ", "")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return list | ||
} |
40 changes: 40 additions & 0 deletions
40
...oc-formatter/src/main/kotlin/com/copperleaf/groovydoc/json/formatter/formatConstructor.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,40 @@ | ||
package com.copperleaf.groovydoc.json.formatter | ||
|
||
import com.copperleaf.groovydoc.json.models.GroovydocConstructor | ||
import com.copperleaf.groovydoc.json.models.GroovydocParameter | ||
import com.copperleaf.groovydoc.json.models.SignatureComponent | ||
import org.codehaus.groovy.groovydoc.GroovyClassDoc | ||
import org.codehaus.groovy.groovydoc.GroovyConstructorDoc | ||
|
||
fun GroovyConstructorDoc.toConstructor(parent: GroovyClassDoc): GroovydocConstructor { | ||
val modifiers = listOf(this.modifiers()).filterNotNull() | ||
val parameters = formatParameters(this.parameters()) | ||
return GroovydocConstructor( | ||
this, | ||
parent.simpleTypeName(), | ||
parent.qualifiedTypeName(), | ||
this.commentText().trim(), | ||
modifiers, | ||
parameters, | ||
this.constructorSignature( | ||
parent, | ||
modifiers, | ||
parameters | ||
) | ||
) | ||
} | ||
|
||
fun GroovyConstructorDoc.constructorSignature( | ||
parent: GroovyClassDoc, | ||
modifiers: List<String>, | ||
parameters: List<GroovydocParameter> | ||
): List<SignatureComponent> { | ||
val list = mutableListOf<SignatureComponent>() | ||
|
||
list.addAll(modifiers.toModifierListSignature()) | ||
// list.addAll(this.typeParameters().toWildcardSignature()) | ||
list.add(SignatureComponent("type", parent.simpleTypeName(), parent.qualifiedTypeName())) | ||
list.addAll(parameters.toParameterListSignature()) | ||
|
||
return list | ||
} |
37 changes: 37 additions & 0 deletions
37
...roovydoc-formatter/src/main/kotlin/com/copperleaf/groovydoc/json/formatter/formatField.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,37 @@ | ||
package com.copperleaf.groovydoc.json.formatter | ||
|
||
import com.copperleaf.groovydoc.json.models.GroovydocField | ||
import com.copperleaf.groovydoc.json.models.SignatureComponent | ||
import org.codehaus.groovy.groovydoc.GroovyClassDoc | ||
import org.codehaus.groovy.groovydoc.GroovyFieldDoc | ||
import org.codehaus.groovy.groovydoc.GroovyType | ||
|
||
fun GroovyFieldDoc.toField(parent: GroovyClassDoc): GroovydocField { | ||
val modifiers = listOf(this.modifiers()).filterNotNull() | ||
return GroovydocField( | ||
this, | ||
this.name(), | ||
this.name(), | ||
this.commentText().trim(), | ||
modifiers, | ||
this.type().real().simpleTypeName(), | ||
this.type().real().qualifiedTypeName(), | ||
this.fieldSignature( | ||
modifiers, | ||
this.type() | ||
) | ||
) | ||
} | ||
|
||
fun GroovyFieldDoc.fieldSignature( | ||
modifiers: List<String>, | ||
type: GroovyType | ||
): List<SignatureComponent> { | ||
val list = mutableListOf<SignatureComponent>() | ||
|
||
list.addAll(modifiers.toModifierListSignature()) | ||
list.addAll(type.toTypeSignature()) | ||
list.add(SignatureComponent("name", " ${this.name()}", "")) | ||
|
||
return list | ||
} |
41 changes: 41 additions & 0 deletions
41
...ovydoc-formatter/src/main/kotlin/com/copperleaf/groovydoc/json/formatter/formatHelpers.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,41 @@ | ||
package com.copperleaf.groovydoc.json.formatter | ||
|
||
import com.copperleaf.groovydoc.json.models.SignatureComponent | ||
import org.codehaus.groovy.groovydoc.GroovyParameter | ||
import org.codehaus.groovy.groovydoc.GroovyType | ||
import org.codehaus.groovy.tools.groovydoc.ExternalGroovyClassDoc | ||
|
||
fun List<String>.toModifierListSignature(): List<SignatureComponent> { | ||
return this.map { SignatureComponent("modifier", "$it ", "") } | ||
} | ||
|
||
fun GroovyType.real(): GroovyType { | ||
return if (this is ExternalGroovyClassDoc) { | ||
ExternalGroovyClassDocWrapper(this) | ||
} else { | ||
this | ||
} | ||
} | ||
|
||
class ExternalGroovyClassDocWrapper(val ext: ExternalGroovyClassDoc) : GroovyType { | ||
override fun qualifiedTypeName() = ext.externalClass().name | ||
override fun simpleTypeName() = ext.externalClass().simpleName | ||
override fun typeName() = ext.externalClass().simpleName | ||
override fun isPrimitive() = ext.isPrimitive | ||
} | ||
|
||
fun GroovyParameter.realType() : GroovyType { | ||
return if(this.type() == null) { | ||
PrimitiveFieldTypeWrapper(this) | ||
} | ||
else { | ||
this.type() | ||
} | ||
} | ||
|
||
class PrimitiveFieldTypeWrapper(val field: GroovyParameter) : GroovyType { | ||
override fun qualifiedTypeName() = field.typeName() | ||
override fun simpleTypeName() = field.typeName() | ||
override fun typeName() = field.typeName() | ||
override fun isPrimitive() = true | ||
} |
58 changes: 58 additions & 0 deletions
58
...oovydoc-formatter/src/main/kotlin/com/copperleaf/groovydoc/json/formatter/formatMethod.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,58 @@ | ||
package com.copperleaf.groovydoc.json.formatter | ||
|
||
import com.copperleaf.groovydoc.json.models.GroovydocMethod | ||
import com.copperleaf.groovydoc.json.models.GroovydocParameter | ||
import com.copperleaf.groovydoc.json.models.GroovydocReturnType | ||
import com.copperleaf.groovydoc.json.models.GroovydocType | ||
import com.copperleaf.groovydoc.json.models.SignatureComponent | ||
import org.codehaus.groovy.groovydoc.GroovyClassDoc | ||
import org.codehaus.groovy.groovydoc.GroovyMethodDoc | ||
import org.codehaus.groovy.groovydoc.GroovyType | ||
|
||
fun GroovyMethodDoc.toMethod(parent: GroovyClassDoc): GroovydocMethod { | ||
val modifiers = listOf(this.modifiers()).filterNotNull() | ||
val parameters = formatParameters(this.parameters()) | ||
val returnType = this.returnType().real().toReturnType() | ||
return GroovydocMethod( | ||
this, | ||
this.name(), | ||
this.name(), | ||
this.commentText().trim(), | ||
modifiers, | ||
parameters, | ||
returnType, | ||
this.methodSignature( | ||
modifiers, | ||
parameters, | ||
returnType | ||
) | ||
) | ||
} | ||
|
||
fun GroovyType.toReturnType(): GroovydocReturnType { | ||
return GroovydocReturnType( | ||
this, | ||
this.simpleTypeName(), | ||
this.qualifiedTypeName(), | ||
"", | ||
this.simpleTypeName(), | ||
this.qualifiedTypeName(), | ||
this.toTypeSignature() | ||
) | ||
} | ||
|
||
fun GroovyMethodDoc.methodSignature( | ||
modifiers: List<String>, | ||
parameters: List<GroovydocParameter>, | ||
returnType: GroovydocType | ||
): List<SignatureComponent> { | ||
val list = mutableListOf<SignatureComponent>() | ||
|
||
list.addAll(modifiers.toModifierListSignature()) | ||
// list.addAll(this.typeParameters().toWildcardSignature()) | ||
list.addAll(returnType.signature) | ||
list.add(SignatureComponent("name", " ${this.name()}", "")) | ||
list.addAll(parameters.toParameterListSignature()) | ||
|
||
return list | ||
} |
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.