Skip to content

Commit

Permalink
Merge pull request #8 from comsysto/bugfix/livingdoc-7
Browse files Browse the repository at this point in the history
[livingdoc-7] Diagram IDs are ignored (Limit elements to specific dia…
  • Loading branch information
close2infinity authored May 5, 2022
2 parents 9bf0535 + a31bbc3 commit a7920eb
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,31 @@ import javax.tools.StandardLocation
/**
* Models a sequence of executable members in a tree-like structure.
*/
data class ExecutableModel(val name: ExecutableName, val outgoingCalls: List<ExecutableModel>, val signature: String? = null) {
data class ExecutableModel(

/**
* The name of the executable.
*/
val name: ExecutableName,

/**
* The outgoing calls from this executable's body.
*/
val outgoingCalls: List<ExecutableModel>,

/**
* The executables signature including parameters.
*/
val signature: String? = null,
) {

companion object {
private val log = LoggerFactory.getLogger(ExecutableModel::class.java.name)

/**
* Creates an instance from an ExecutableElement. This is usually only
* used for the start of a sequence (annotated with @StartOfSequence),
* as all other models are created from _JavaParser_ output.
* as all other models are created from _JavaParser_ output.
*/
fun of(element: ExecutableElement): ExecutableModel? {
val enclosingType = TypeRef.of(element.enclosingElement.asType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ class S0tModel {
fun addExecutable(executable: ExecutableModel) {
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
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 javax.lang.model.element.ElementKind
Expand All @@ -16,7 +17,8 @@ data class TypeModel(
val realizations: List<Realization> = listOf(),
val inheritance: Inheritance? = null,
val associations: List<Association> = listOf(),
val notes: List<NoteModel> = listOf()
val notes: List<NoteModel> = listOf(),
val diagramIds: Set<String> = setOf()
) {
enum class Type {
INTERFACE, ABSTRACT, CLASS, ENUM;
Expand All @@ -40,12 +42,13 @@ data class TypeModel(
* @return the type model.
*/
fun of(typeElement: TypeElement) = TypeModel(
typeElement.typeName() as TypeName.ComplexTypeName,
Type.of(typeElement),
FieldModel.allOf(typeElement),
Realization.allOf(typeElement),
Inheritance.of(typeElement),
Association.allOf(typeElement),
NoteModel.allOf(typeElement))
typeElement.typeName() as TypeName.ComplexTypeName,
Type.of(typeElement),
FieldModel.allOf(typeElement),
Realization.allOf(typeElement),
Inheritance.of(typeElement),
Association.allOf(typeElement),
NoteModel.allOf(typeElement),
typeElement.getAnnotation(PlantUmlClass::class.java).let { it.diagramIds.toSet() })
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<#-- @ftlvariable name="diagramId" type="String" -->

<#macro renderRelations s0tModel>
<#-- @ftlvariable name="s0tModel" type="com.comsysto.livingdoc.s0t.model.S0tModel" -->
<#list s0tModel.types?values as type>
<#list s0tModel.typesForDiagram(diagramId)?values as type>

<#compress>
<#list type.realizations as realization>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<#import "s0t-members.ftl" as Members>
<#-- @ftlvariable name="diagramId" type="String" -->

<#macro renderTypes s0tModel>
<#-- @ftlvariable name="s0tModel" type="com.comsysto.livingdoc.s0t.model.S0tModel" -->
<#list s0tModel.types?values as type>
<#list s0tModel.typesForDiagram(diagramId)?values as type>
<@renderType type/>
</#list>
</#macro>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass;

@PlantUmlClass(diagramIds = { "package", "ground-vehicles" })
@PlantUmlClass(diagramIds = "ground-vehicles")
public class Car extends GroundVehicle {

public Car() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlNote;
import com.comsysto.livingdoc.s0t.annotation.plantuml.Position;

@PlantUmlClass(diagramIds = { "package", "ground-vehicles" })
@PlantUmlClass(diagramIds = "ground-vehicles")
@PlantUmlNote(value = "A vehicle that drives on the ground", position = Position.TOP)
@PlantUmlNote(value = "Multiple notes may be\nattached to a type", position = Position.RIGHT)
public abstract class GroundVehicle extends Vehicle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* superfluous JavaDoc comment serves as a test for the note auto-generation
* capability.
*/
@PlantUmlClass(diagramIds = { "package", "ground-vehicles" })
@PlantUmlClass(diagramIds = "ground-vehicles")
@PlantUmlNote
public class Train extends GroundVehicle {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlField;
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlNote;

@PlantUmlClass(autoCreateFields = AutoCreateType.NO)
@PlantUmlClass(diagramIds = "ground-vehicles", autoCreateFields = AutoCreateType.NO)
@PlantUmlNote(value = "Indicates whether a vehicle transports passengers or cargo.")
public enum TransportType {
@PlantUmlField PASSENGERS("Persons are passengers."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlClass;
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlField;

@PlantUmlClass(diagramIds = { "package", "ground-vehicles" })
@PlantUmlClass(diagramIds = "ground-vehicles")
public class Vehicle {

@PlantUmlField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.google.testing.compile.Compilation
import com.google.testing.compile.Compiler.javac
import com.google.testing.compile.JavaFileObjects
import io.kotlintest.matchers.collections.shouldContainExactly
import io.kotlintest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotlintest.matchers.file.exist
import io.kotlintest.should
import io.kotlintest.shouldBe
Expand Down Expand Up @@ -34,17 +33,27 @@ internal class S0TProcessorTest : BehaviorSpec({
.withOptions(options)
.compile(files.map { javaFileObject(it) })
val classDiagramFile = File(System.getProperty(KEY_OUT_DIR, DEF_OUT_DIR), "${packagePath}/example-class.puml")
val groundVehiclesClassDiagramFile = File(System.getProperty(KEY_OUT_DIR, DEF_OUT_DIR), "${packagePath}/ground-vehicles-class.puml")
val sequenceDiagramFile = File(System.getProperty(KEY_OUT_DIR, DEF_OUT_DIR), "${packagePath}/example-sequence.puml")

Then("the processing status should be SUCCESS") { result.status() shouldBe Compilation.Status.SUCCESS }

And("the class diagram file exists") { classDiagramFile should exist() }
And("the class diagram contains the expected content") {
nonEmptyLinesTrimmed(classDiagramFile) shouldContainExactlyInAnyOrder nonEmptyLinesTrimmed(File(testClassLoaderRoot(), "/expected/expected-class.puml"))
// Check the general class diagram:
And("the general class diagram file exists") { classDiagramFile should exist() }
And("the general class diagram contains the expected content") {
nonEmptyLinesTrimmed(classDiagramFile) shouldContainExactly nonEmptyLinesTrimmed(File(testClassLoaderRoot(), "/expected/expected-example-class.puml"))
}

// Check the ground vehicles class diagram:
And("the ground vehicles class diagram file exists") { classDiagramFile should exist() }
And("the ground vehicles class diagram contains the expected content") {
nonEmptyLinesTrimmed(groundVehiclesClassDiagramFile) shouldContainExactly nonEmptyLinesTrimmed(File(testClassLoaderRoot(), "/expected/expected-ground-vehicles-class.puml"))
}

// Check the generated sequence diagram:
And("the sequence diagram file exists") { sequenceDiagramFile should exist() }
And("the sequence diagram contains the expected content") {
nonEmptyLinesTrimmed(sequenceDiagramFile) shouldContainExactlyInAnyOrder nonEmptyLinesTrimmed(File(testClassLoaderRoot(), "/expected/expected-sequence.puml"))
nonEmptyLinesTrimmed(sequenceDiagramFile) shouldContainExactly nonEmptyLinesTrimmed(File(testClassLoaderRoot(), "/expected/expected-example-sequence.puml"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<#ftl attributes={"s0t:is-template":true}/>
<#global diagramId="ground-vehicles"/>
<#-- @ftlvariable name="s0tModel" type="com.comsysto.livingdoc.s0t.model.S0tModel" -->
@startuml
!include ./format.iuml
hide empty members
title Ground Vehicles class diagram

<@S0tTypes.renderTypes s0tModel/>

<@S0tRelations.renderRelations s0tModel/>

@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@startuml
!include ./format.iuml
hide empty members
title Ground Vehicles class diagram

class Car
abstract class GroundVehicle {
-int numberOfWheels
}

note top of GroundVehicle
A vehicle that drives on the
ground
end note

note right of GroundVehicle
Multiple notes may be
attached
to a type
end note

class Train {
+List<Car> loadedCars
}

note top of Train
Models a train. A train may
carry a cargo of cars.
end note

enum TransportType {
PASSENGERS
CARGO
}

note top of TransportType
Indicates whether a vehicle
transports passengers or
cargo.
end note

class Vehicle {
+TransportType transportType
}

GroundVehicle <|-- Car

Vehicle <|-- GroundVehicle

GroundVehicle <|-- Train
Train --> "0..*" Car

Vehicle --> TransportType

@enduml

0 comments on commit a7920eb

Please sign in to comment.