Skip to content

Commit

Permalink
Added ability to auto-wrap notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Schoenherr committed Jan 5, 2022
1 parent 9b81922 commit c2393ca
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,27 @@
*/
Position position() default Position.TOP;

/**
* Max line length of the note.
*
* @return the maximum number of characters in a line.
*/
int maxLineLength() default 30;

/**
* A flag indicating if long words shall be wrapped if they exceed
* maxLineLength.
*
* @return true if long words should be wrapped.
*/
boolean wrapLongwords() default true;

/**
* A regular expression used to specify characters where line breaks may be
* inserted.
*
* @return a regular expression.
*/
String wrapOn() default "";
}

6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<snakeyaml.version>1.27</snakeyaml.version>
<junit-platform.version>1.8.1</junit-platform.version>
<tools.version>0.16.0</tools.version>
<commons-text.version>1.9</commons-text.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -84,6 +85,11 @@
<artifactId>commons-configuration2</artifactId>
<version>${commons-configuration2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.comsysto.livingdoc.s0t.model

import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlNote
import com.comsysto.livingdoc.s0t.annotation.plantuml.PlantUmlNotes
import org.apache.commons.text.WordUtils
import javax.lang.model.element.TypeElement

/**
Expand All @@ -11,9 +12,12 @@ data class NoteModel(val text: String, val position: Position) {

companion object {
fun allOf(typeElement: TypeElement): List<NoteModel> = typeElement.getAnnotation(PlantUmlNotes::class.java)
?.let { notes -> notes.value.map { NoteModel(it.value, Position.valueOf(it.position.name)) } }
?.let { notes -> notes.value.map { toNoteModel(it) } }
?: typeElement.getAnnotation(PlantUmlNote::class.java)
?.let { listOf(NoteModel(it.value, Position.valueOf(it.position.name))) }
?.let { listOf(toNoteModel(it)) }
.orEmpty()

private fun toNoteModel(it: PlantUmlNote) =
NoteModel(WordUtils.wrap(it.value, it.maxLineLength, "\n", it.wrapLongwords, it.wrapOn), Position.valueOf(it.position.name))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@PlantUmlClass
@PlantUmlNote(
value = "This models an airplane, a //flying// \nvehicle that is **very** fast.",
value = "This models an airplane, a //flying// vehicle that is **very** fast.",
position = BOTTOM)
public class Airplane extends FlyingVehicle {

Expand All @@ -22,7 +22,7 @@ public class Airplane extends FlyingVehicle {

@Override
@PlantUmlExecutable
@PlantUmlNote(position = RIGHT, value = "Directly after launch, the\nplane needs to **retract** its wheels.")
@PlantUmlNote(position = RIGHT, value = "Directly after launch, the plane needs to **retract** its wheels.")
public void launch() {
super.launch();
retractWheels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@PlantUmlClass(diagramIds = { "package", "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)
@PlantUmlNote(value = "Multiple notes may be attached to a type", position = Position.RIGHT)
public abstract class GroundVehicle extends Vehicle {

@PlantUmlField
Expand Down
16 changes: 10 additions & 6 deletions processors/src/test/resources/expected/example-class.puml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ title Example class diagram
}

note bottom of Airplane
This models an airplane, a //flying//
vehicle that is **very** fast.
This models an airplane, a
//flying// vehicle that is
**very** fast.
end note

class Car
Expand All @@ -23,11 +24,12 @@ end note
}

note top of GroundVehicle
A vehicle that drives on the ground
A vehicle that drives on the
ground
end note
note right of GroundVehicle
Multiple notes may be
attached to a type
Multiple notes may be attached
to a type
end note

class Train {
Expand All @@ -42,7 +44,9 @@ end note
}

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

class Vehicle {
Expand Down

0 comments on commit c2393ca

Please sign in to comment.