Skip to content

Commit

Permalink
Merge pull request #10 from comsysto/livingdoc-9
Browse files Browse the repository at this point in the history
[livingdoc-9] Support for custom dependencies
  • Loading branch information
close2infinity authored May 6, 2022
2 parents 60c2ec3 + 862a7ee commit f48bf02
Show file tree
Hide file tree
Showing 29 changed files with 395 additions and 272 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.comsysto.livingdoc.s0t.annotation.plantuml;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@Repeatable(PlantUmlDependencies.class)
public @interface PlantUmlDependency {
String target();
Class<?> target();
String description() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.comsysto.livingdoc.s0t

import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlExecutable
import com.comsysto.livingdoc.s0t.apextensions.qName
import com.comsysto.livingdoc.s0t.model.ExecutableModel
import com.comsysto.livingdoc.s0t.model.S0tModel
import com.comsysto.livingdoc.s0t.model.TypeModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.comsysto.livingdoc.s0t.apextensions

import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass
import com.comsysto.livingdoc.s0t.model.TypeName
import javax.lang.model.element.TypeElement

/**
* Get the type element's qualified name as a string.
*/
fun TypeElement.qName() = this.qualifiedName.toString()

/**
* Get the type element's qualified name as a TypeName.
*/
fun TypeElement.typeName() = TypeName.parse(this.qualifiedName.toString())

/**
* Checks if the type element is annotated with ``@PlantUmlClass``.
*/
fun isPlantUmlClass(type: TypeElement) = type.getAnnotation(PlantUmlClass::class.java) != null



Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.comsysto.livingdoc.s0t
package com.comsysto.livingdoc.s0t.apextensions

import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass
import com.comsysto.livingdoc.s0t.model.TypeName
import javax.lang.model.element.Element
import javax.lang.model.element.ElementKind
import javax.lang.model.element.TypeElement
import javax.lang.model.type.DeclaredType
import javax.lang.model.type.TypeMirror

fun TypeElement.qName() = this.qualifiedName.toString()
fun TypeElement.typeName() = TypeName.parse(this.qualifiedName.toString())

/**
* Checks if the type element represents an enum type.
*/
fun TypeMirror.isEnum() = this.asTypeElement()?.kind != ElementKind.ENUM

/**
Expand All @@ -27,15 +25,20 @@ fun TypeMirror.asTypeElement(): TypeElement? = when (this) {
else -> null
}

/**
* Get the type mirror's type arguments.
*/
fun TypeMirror.typeArguments() = asDeclaredType()?.typeArguments ?: emptyList()

/**
* Converts the type mirror to a DeclaredType if possible.
*/
fun TypeMirror.asDeclaredType() = when (this) {
is DeclaredType -> this
else -> null
}

fun isPartOfDiagram(type: TypeMirror) = type.asTypeElement()?.getAnnotation(PlantUmlClass::class.java) != null
fun isPartOfDiagram(type: TypeElement) = type.getAnnotation(PlantUmlClass::class.java) != null



/**
* Checks if the type mirror is annotated with ``@PlantUmlClass``.
*/
fun isPlantUmlClass(type: TypeMirror) = type.asTypeElement()?.getAnnotation(PlantUmlClass::class.java) != null
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.comsysto.livingdoc.s0t.S0tProcessor.Companion.configuration
import com.comsysto.livingdoc.s0t.annotation.plantuml.AutoCreateType
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlField
import com.comsysto.livingdoc.s0t.asDeclaredType
import com.comsysto.livingdoc.s0t.apextensions.asDeclaredType
import com.comsysto.livingdoc.s0t.model.AccessModifier.*
import javax.lang.model.element.Modifier
import javax.lang.model.element.TypeElement
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class S0tModel {
executables[executable.name] = executable
}

fun typesForDiagram(diagramId: String?) = if (diagramId != null) {
types.entries
.filter { it.value.diagramIds.contains(diagramId) }
.associate { Pair(it.key, it.value) }
}
else types
fun typesForDiagram(diagramId: String?) = (
if (diagramId != null) types.entries.filter { it.value.diagramIds.contains(diagramId) }
else types.entries.filter { !it.value.diagramIds.contains("!default") })
.associate { Pair(it.key, it.value) }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.comsysto.livingdoc.s0t.model

import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass
import com.comsysto.livingdoc.s0t.model.Relation.*
import com.comsysto.livingdoc.s0t.typeName
import com.comsysto.livingdoc.s0t.apextensions.typeName
import com.comsysto.livingdoc.s0t.model.relations.Association
import com.comsysto.livingdoc.s0t.model.relations.Dependency
import com.comsysto.livingdoc.s0t.model.relations.Inheritance
import com.comsysto.livingdoc.s0t.model.relations.Realization
import javax.lang.model.element.ElementKind
import javax.lang.model.element.Modifier
import javax.lang.model.element.TypeElement
Expand All @@ -17,6 +20,7 @@ data class TypeModel(
val realizations: List<Realization> = listOf(),
val inheritance: Inheritance? = null,
val associations: List<Association> = listOf(),
val dependencies: List<Dependency> = listOf(),
val notes: List<NoteModel> = listOf(),
val diagramIds: Set<String> = setOf()
) {
Expand Down Expand Up @@ -48,7 +52,9 @@ data class TypeModel(
Realization.allOf(typeElement),
Inheritance.of(typeElement),
Association.allOf(typeElement),
Dependency.allOf(typeElement),
NoteModel.allOf(typeElement),
typeElement.getAnnotation(PlantUmlClass::class.java).let { it.diagramIds.toSet() })
typeElement.getAnnotation(PlantUmlClass::class.java).diagramIds.toSet()
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.comsysto.livingdoc.s0t.model

import com.comsysto.livingdoc.s0t.asTypeElement
import com.comsysto.livingdoc.s0t.typeName
import com.comsysto.livingdoc.s0t.apextensions.asTypeElement
import com.comsysto.livingdoc.s0t.apextensions.typeName
import javax.lang.model.element.TypeElement
import javax.lang.model.type.TypeKind.*
import javax.lang.model.type.TypeMirror
import kotlin.reflect.KClass

/**
* Models the _reference_ to a type that is possibly not yet known (e.g. because
Expand All @@ -19,6 +20,8 @@ data class TypeRef(val name: TypeName, val kind: Kind) {
else -> TypeRef(TypeName.SimpleTypeName(type.toString()), Kind.UNKNOWN)
}
fun of(typeElement: TypeElement): TypeRef = TypeRef(typeElement.typeName(), Kind.COMPLEX)

fun <T: Any> of(type: KClass<T>) = TypeRef(TypeName.parse(type.java.name), if (type.java.isPrimitive) Kind.PRIMITIVE else Kind.COMPLEX)
}

enum class Kind {
Expand Down
Loading

0 comments on commit f48bf02

Please sign in to comment.