samples/gen_java.ysl2
author Volker Birk <vb@pep-project.org>
Mon, 04 Nov 2019 11:38:34 +0100
changeset 40 432ab62b2537
parent 0 76005e62091d
permissions -rw-r--r--
date
0
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     1
include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     3
define operator "†(\S+)" as call "printType" with "name", "%1";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     4
define operator "“(.*?)”" as call "ucase" with "text", "%1";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     5
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     6
decl umlstylesheet is tstylesheet (
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     7
    xmlns:uml="http://schema.omg.org/spec/UML/2.1",
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     8
    xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     9
);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    10
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    11
umlstylesheet {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    12
    template "/xmi:XMI/uml:Model"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    13
        apply "packagedElement", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    14
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    15
    template "packagedElement[@xmi:type='uml:Package']" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    16
        | package «@name»;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    17
        |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    18
        apply "packagedElement", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    19
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    20
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    21
    template "packagedElement[@xmi:type='uml:Class']" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    22
        | class «@name» {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    23
        apply "ownedAttribute";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    24
        | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    25
        if "position() != last()" |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    26
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    27
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    28
    template "ownedAttribute[@xmi:type='uml:Property' and count(@association)=0]" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    29
        | // attribute «@name»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    30
        |      
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    31
        | public †type get“@name”() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    32
        |     return «@name»;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    33
        | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    34
        |      
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    35
        | public void set“@name”(†type value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    36
        |     «@name» = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    37
        | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    38
        |      
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    39
        | private †type «@name»;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    40
        if "position() != last()" |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    41
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    42
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    43
    function "ucase" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    44
        param "text";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    45
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    46
        > «translate(substring($text, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    47
        > «substring($text, 2)»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    48
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    49
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    50
    function "printType" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    51
        param "name";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    52
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    53
        choose {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    54
            when '$name/@href = "http://schema.omg.org/spec/UML/2.1/uml.xml#UnlimitedNatural"'
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    55
                > int
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    56
            when '$name/@href = "http://schema.omg.org/spec/UML/2.1/uml.xml#String"'
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    57
                > String
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    58
        }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    59
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    60
}