From b91938f24693c7ea2495d742b7ce692d0bb95eb7 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sun, 14 Jun 2015 11:43:35 +0200 Subject: [PATCH] outer enum --- src/Makefile | 1 + src/gen_java_Message.ysl2 | 33 +++++++++++++++++++++++++-------- src/pEp.yml2 | 22 ++++++++++++++++++++-- src/textutils.ysl2 | 2 +- src/types_java.ysl2 | 2 +- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Makefile b/src/Makefile index 4bfff6a..27691ba 100644 --- a/src/Makefile +++ b/src/Makefile @@ -47,5 +47,6 @@ clean: rm -f org/pEp/jniadapter/pEp*.java rm -f org/pEp/jniadapter/Engine.java rm -f org/pEp/jniadapter/MimeMessage.java + rm -f org/pEp/jniadapter/Color.java rm -f throw_pEp_exception.* diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index d87e8e5..7851e5f 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/gen_java_Message.ysl2 @@ -3,7 +3,7 @@ include yslt.yml2 tstylesheet { include ./types_java.ysl2 - template "/namespace[@name='pEp']" apply "struct|interface", 0; + template "/namespace[@name='pEp']" apply "struct|interface|enum", 0; template "interface" { const "cname" call "toJava" with "type", "@name"; @@ -34,23 +34,36 @@ tstylesheet { import java.util.HashMap; public class «$cname» { - `` apply "enum" + `` apply "enum", mode=inner `` apply "*[name(.)!='enum']", mode=entry } || } - template "enum" + template "enum" { + const "jname" call "toJava" with "type", "@name"; + document("org/pEp/jniadapter/{$jname}.java", "text") + || + package org.pEp.jniadapter; + + import java.util.HashMap; + + `` apply ".", 0, mode=inner + || + } + + template "enum", mode=inner { + const "jname" call "CamelCase" with "text", "@name"; || - public enum «@name» { + public enum «$jname» { `` apply "*", mode=value ; public final int value; - public static final HashMap tag = - new HashMap(); + public static final HashMap tag = + new HashMap(); - «@name»(int value) { + «$jname»(int value) { this.value = value; fill(value); } @@ -61,6 +74,7 @@ tstylesheet { } || + } template "method" || @@ -104,6 +118,9 @@ tstylesheet { } } - template "*", mode=value | «name(.)» («.»)`if "position()!=last()" > , ` + template "*", mode=value { + const "name" call "toJava" with "type", "name(.)"; + | «$name» («.»)`if "position()!=last()" > , ` + } } diff --git a/src/pEp.yml2 b/src/pEp.yml2 index 5a0ac78..f2b567a 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -50,12 +50,30 @@ namespace pEp { pEp_unknown_error > -1 }; + enum color { + pEp_rating_undefined > 0 + pEp_rating_cannot_decrypt > 1 + pEp_rating_have_no_key > 2 + pEp_rating_unencrypted > 3 + pEp_rating_unreliable > 4 + pEp_rating_reliable > 5 + pEp_rating_yellow > 5 + pEp_rating_trusted > 6 + pEp_rating_green > 6 + pEp_rating_trusted_and_anonymized > 7 + pEp_rating_fully_anonymous > 8 + + pEp_rating_under_attack > -1 + pEp_rating_red > -1 + pEp_rating_b0rken > -2 + }; + interface Engine { method encrypt_message( in message src, in stringlist extra, creates message dst, - in encformat enc_format + in EncFormat enc_format ); method decrypt_message( @@ -110,7 +128,7 @@ namespace pEp { stringlist keywords; string comments; stringpairlist opt_fields; - encformat enc_format; + EncFormat enc_format; }; }; diff --git a/src/textutils.ysl2 b/src/textutils.ysl2 index 08121af..a8b7798 100644 --- a/src/textutils.ysl2 +++ b/src/textutils.ysl2 @@ -19,7 +19,7 @@ function "CamelCase" { when ".='pEp'" > pEp otherwise { call "UCASE" with "text", "substring(., 1, 1)"; - call "lcase" with "text", "substring(., 2)"; + value "substring(., 2)"; } } } diff --git a/src/types_java.ysl2 b/src/types_java.ysl2 index e1b9ccd..7cd0656 100644 --- a/src/types_java.ysl2 +++ b/src/types_java.ysl2 @@ -10,7 +10,7 @@ function "toJava" { when "$type='identity'" > Identity when "$type='identitylist'" > ArrayList when "$type='timestamp'" > Date - when "$type='encformat'" > MimeMessage.EncFormat + when "$type='EncFormat'" > MimeMessage.EncFormat when "$type='bloblist'" > ArrayList when "$type='stringpairlist'" > Vector> when "$type='message'" > MimeMessage