File tree Expand file tree Collapse file tree 6 files changed +21
-17
lines changed
typescript-generator-core/src/main/java/cz/habarta/typescript/generator
typescript-generator-gradle-plugin/src/main/java/cz/habarta/typescript/generator/gradle
typescript-generator-maven-plugin/src/main/java/cz/habarta/typescript/generator/maven Expand file tree Collapse file tree 6 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -19,5 +19,6 @@ public class Settings {
1919 public DateMapping mapDate = DateMapping .asDate ;
2020 public TypeProcessor customTypeProcessor = null ;
2121 public boolean sortDeclarations = false ;
22+ public boolean sortTypeDeclarations = false ;
2223 public boolean noFileComment = false ;
2324}
Original file line number Diff line number Diff line change @@ -40,9 +40,6 @@ private void emitFileComment() {
4040 }
4141
4242 private void emitModule (TsModel model ) {
43- if (settings .sortDeclarations ) {
44- model .sort ();
45- }
4643 if (settings .module != null ) {
4744 writeNewLine ();
4845 writeIndentedLine ("declare module '" + settings .module + "' {" );
@@ -78,12 +75,20 @@ private void emitObjects(TsModel model) {
7875
7976 private void emitInterfaces (TsModel model ) {
8077 String exportPrefix = forceExportKeyword ? "export " : "" ;
81- for (TsBeanModel bean : model .getBeans ()) {
78+ final List <TsBeanModel > beans = model .getBeans ();
79+ if (settings .sortDeclarations || settings .sortTypeDeclarations ) {
80+ Collections .sort (beans );
81+ }
82+ for (TsBeanModel bean : beans ) {
8283 writeNewLine ();
8384 final String parent = bean .getParent () != null ? " extends " + bean .getParent () : "" ;
8485 writeIndentedLine (exportPrefix + "interface " + bean .getName () + parent + " {" );
8586 indent ++;
86- for (TsPropertyModel property : bean .getProperties ()) {
87+ final List <TsPropertyModel > properties = bean .getProperties ();
88+ if (settings .sortDeclarations ) {
89+ Collections .sort (properties );
90+ }
91+ for (TsPropertyModel property : properties ) {
8792 emitProperty (property );
8893 }
8994 indent --;
Original file line number Diff line number Diff line change 22package cz .habarta .typescript .generator .emitter ;
33
44import cz .habarta .typescript .generator .*;
5- import java .util .ArrayList ;
6- import java .util .Collections ;
7- import java .util .List ;
5+ import java .util .*;
86
97
108public class TsBeanModel implements Comparable <TsBeanModel > {
@@ -40,7 +38,4 @@ public int compareTo(TsBeanModel o) {
4038 return name .toString ().compareTo (o .name .toString ());
4139 }
4240
43- public void sort () {
44- Collections .sort (properties );
45- }
4641}
Original file line number Diff line number Diff line change @@ -18,10 +18,4 @@ public LinkedHashSet<TsType.AliasType> getTypeAliases() {
1818 return typeAliases ;
1919 }
2020
21- public void sort () {
22- for (TsBeanModel bean : beans ) {
23- bean .sort ();
24- }
25- Collections .sort (beans );
26- }
2721}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ public class GenerateTask extends DefaultTask {
2727 public DateMapping mapDate ;
2828 public String customTypeProcessor ;
2929 public boolean sortDeclarations ;
30+ public boolean sortTypeDeclarations ;
3031 public boolean noFileComment ;
3132
3233
@@ -65,6 +66,7 @@ public void generate() throws Exception {
6566 settings .customTypeProcessor = (TypeProcessor ) classLoader .loadClass (customTypeProcessor ).newInstance ();
6667 }
6768 settings .sortDeclarations = sortDeclarations ;
69+ settings .sortTypeDeclarations = sortTypeDeclarations ;
6870 settings .noFileComment = noFileComment ;
6971
7072 // TypeScriptGenerator
Original file line number Diff line number Diff line change @@ -128,6 +128,12 @@ public class GenerateMojo extends AbstractMojo {
128128 @ Parameter
129129 private boolean sortDeclarations ;
130130
131+ /**
132+ * If true TypeScript type declarations (interfaces) will be sorted alphabetically.
133+ */
134+ @ Parameter
135+ private boolean sortTypeDeclarations ;
136+
131137 /**
132138 * If true generated file will not contain comment at the top.
133139 * By default there is a comment with timestamp and typescript-generator version.
@@ -167,6 +173,7 @@ public void execute() {
167173 settings .customTypeProcessor = (TypeProcessor ) classLoader .loadClass (customTypeProcessor ).newInstance ();
168174 }
169175 settings .sortDeclarations = sortDeclarations ;
176+ settings .sortTypeDeclarations = sortTypeDeclarations ;
170177 settings .noFileComment = noFileComment ;
171178
172179 // TypeScriptGenerator
You can’t perform that action at this time.
0 commit comments