-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#176 support seperate enum classes
- Loading branch information
Showing
4 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 6 additions & 32 deletions
38
light-rest-4j/src/main/resources/templates/rest/enumClass.rocker.raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,8 @@ | ||
@import com.jsoniter.any.Any | ||
@import java.util.Map | ||
@import java.util.List | ||
@args (Map<String, Any> prop) | ||
@with (v = prop.get("nameWithEnum") + ".values()", value = prop.get("value").asList()) { | ||
public enum @prop.get("nameWithEnum") { | ||
@for((i, item) : value) { | ||
@with(u = item.toString().toUpperCase().replaceAll("-", "_")) {@if (i.index() < value.size() - 1) {@u ("@item"),}@if(i.index() == value.size() - 1) {@u ("@item");}} | ||
} | ||
@args (String modelPackage, String className, String enums) | ||
package @modelPackage; | ||
import java.util.Enumeration; | ||
|
||
private final @prop.get("type") value; | ||
public enum @className { | ||
@enums; | ||
|
||
@prop.get("nameWithEnum")(@prop.get("type") value) { | ||
this.value = value; | ||
} | ||
|
||
@@Override | ||
public String toString() { | ||
return String.valueOf(value); | ||
} | ||
|
||
public static @prop.get("nameWithEnum") fromValue(String text) { | ||
for (@prop.get("nameWithEnum") b : @v) { | ||
if (String.valueOf(b.value).equals(text)) { | ||
return b; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
private @prop.get("nameWithEnum") @prop.get("name"); | ||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
light-rest-4j/src/main/resources/templates/rest/enumInline.rocker.raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@import com.jsoniter.any.Any | ||
@import java.util.Map | ||
@import java.util.List | ||
@args (Map<String, Any> prop) | ||
@with (v = prop.get("nameWithEnum") + ".values()", value = prop.get("value").asList()) { | ||
public enum @prop.get("nameWithEnum") { | ||
@for((i, item) : value) { | ||
@with(u = item.toString().toUpperCase().replaceAll("-", "_")) {@if (i.index() < value.size() - 1) {@u ("@item"),}@if(i.index() == value.size() - 1) {@u ("@item");}} | ||
} | ||
|
||
private final @prop.get("type") value; | ||
|
||
@prop.get("nameWithEnum")(@prop.get("type") value) { | ||
this.value = value; | ||
} | ||
|
||
@@Override | ||
public String toString() { | ||
return String.valueOf(value); | ||
} | ||
|
||
public static @prop.get("nameWithEnum") fromValue(String text) { | ||
for (@prop.get("nameWithEnum") b : @v) { | ||
if (String.valueOf(b.value).equals(text)) { | ||
return b; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
private @prop.get("nameWithEnum") @prop.get("name"); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters