Giter Site home page Giter Site logo

kotlin-dsl-plantuml's Introduction

The library allows you to create plantuml via Kotlin DSL.

License Maven Central Maven Central

Library support:

  • Sequence diagram
  • Usecase diagram
  • Class diagram
  • Object diagram
  • Activity diagram
  • Component diagram
  • Deployment diagram
  • State diagram
  • Timing diagram

Setup

Gradle

// Only DSL
implementation "io.github.pavelannin:kotlin-plantuml-dsl:1.0.0"

// DSL with generator
implementation "io.github.pavelannin:kotlin-plantuml-generator:1.0.1"

Quickstart

1. Create dsl

val diagram = classDiagram {
  val abstractClass = abstractClass(name = "AbstractType") {
    property(name = "abstractProperty", type = "Int")  { isAbstract = true }
    property(name = "staticProperty", type = "Int")  { isStatic = true }
    property(name = "publicProperty", type = "Int")  { accessControl = AccessControlUml.Type.Public }
    property(name = "privateProperty", type = "Int")  { accessControl = AccessControlUml.Type.Private }
    property(name = "protectedProperty", type = "Int")  { accessControl = AccessControlUml.Type.Protected }
    property(name = "privatePackageProperty", type = "Int")  { accessControl = AccessControlUml.Type.PrivatePackage }

    method(name = "abstractMethod", returnType = "Int")  {
      isAbstract = true
    }
    method(name = "staticMethod", returnType = "Int")  {
      isStatic = true
      argument(name = "param1",  type = "String")
      argument(name = "param2",  type = "String")
    }
    method(name = "publicMethod", returnType = "Int")  {
      accessControl = AccessControlUml.Type.Public
      argument(name = "param1",  type = "String")
    }
    method(name = "privateMethod", returnType = "Int")  {
      accessControl = AccessControlUml.Type.Private
    }
    method(name = "protectedMethod", returnType = "Int")  {
      accessControl = AccessControlUml.Type.Protected
    }
    method(name = "privatePackageMethod", returnType = "Int")  {
      accessControl = AccessControlUml.Type.PrivatePackage
    }
  }
  val annotation = annotation(name = "AnnotationType")
  val circle = circle(name = "CircleType")
  val `class` = `class`(name = "ClassType") {
    property(name = "property1", type = "Int")  {
      notes { left(text = "Left note") }
      notes { right(text = "Right note") }
    }
    property(name = "property2", type = "Int")  {
      notes { left(text = "Left note") }
      notes { right(text = "Right note") }
    }
    method(name = "method1")  {
      notes { left(text = "Left note") }
      notes { right(text = "Right note") }
    }
    method(name = "method2")  {
      notes { left(text = "Left note") }
      notes { right(text = "Right note") }
    }
    notes {
      left(text = "Left note")
      right(text = "Right note")
      top(text = "Top note")
      bottom(text = "Bottom note")
    }
  }
  val diamond = diamond(name = "DiamondType")
  val entity = entity(name = "EntityType")
  val enum = enum(name = "EnumType") {
    case(name = "case1")
    case(name = "case2") {
      argument(name = "param1",  type = "String")
      argument(name = "param2",  type = "String")
    }
  }
  val exception = exception(name = "ExceptionType")
  val `interface` = `interface`(name = "InterfaceType")
  val metaClass = metaClass(name = "MetaclassType")
  val protocol = protocol(name = "ProtocolType")
  val stereotype = stereotype(name = "StereotypeType")
  val struct = struct(name = "StructType")

  `class` extension abstractClass
  `class` aggregation enum
  abstractClass composition `interface`
  circle solidLine diamond
  diamond dashedLine circle
  protocol directedSolidLine struct
  protocol directedDashedLine struct
}

2. Creating PlantUml

val plantUmlString = diagram.plantUml()
Result generated plantuml
@startuml

abstract class AbstractType {
{abstract} {field} abstractProperty: Int
{static} {field} staticProperty: Int
+ {field} publicProperty: Int
- {field} privateProperty: Int
# {field} protectedProperty: Int
~ {field} privatePackageProperty: Int
{abstract} {method} abstractMethod(): Int
{static} {method} staticMethod(param1: String, param2: String): Int
+ {method} publicMethod(param1: String): Int
- {method} privateMethod(): Int
# {method} protectedMethod(): Int
~ {method} privatePackageMethod(): Int
}

annotation AnnotationType

circle CircleType

class ClassType {
{field} property1: Int
{field} property2: Int
{method} method1()
{method} method2()
}

note left of ClassType
Left note
end note

note right of ClassType
Right note
end note

note top of ClassType
Top note
end note

note bottom of ClassType
Bottom note
end note

note left of ClassType::property1
Left note
end note

note right of ClassType::property1
Right note
end note

note left of ClassType::property2
Left note
end note

note right of ClassType::property2
Right note
end note

note left of ClassType::method1
Left note
end note

note right of ClassType::method1
Right note
end note

note left of ClassType::method2
Left note
end note

note right of ClassType::method2
Right note
end note

diamond DiamondType

entity EntityType

enum EnumType {
{field} case1
{field} case2(param1: String, param2: String)
}

exception ExceptionType

interface InterfaceType

metaclass MetaclassType

protocol ProtocolType

stereotype StereotypeType

struct StructType

ClassType <|-- AbstractType
ClassType o-- EnumType
AbstractType *-- InterfaceType
CircleType -- DiamondType
DiamondType .. CircleType
ProtocolType --> StructType
ProtocolType ..> StructType

@enduml
Result plantuml image

alt text

kotlin-dsl-plantuml's People

Contributors

pavelannin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.