Browse Source

generating switch

JNI-44
Volker Birk 7 years ago
parent
commit
032c365a5b
3 changed files with 11 additions and 70 deletions
  1. +8
    -2
      src/Makefile
  2. +1
    -31
      src/gen_java_exceptions.ysl2
  3. +2
    -37
      src/org_pEp_jniadapter_Engine.cc

+ 8
- 2
src/Makefile View File

@ -12,9 +12,9 @@ $(JAR): $(JAVASOURCE)
org_pEp_jniadapter_Engine.h: org/pEp/jniadapter/Engine.java
javah org.pEp.jniadapter.Engine
org_pEp_jniadapter_Engine.o: org_pEp_jniadapter_Engine.h org_pEp_jniadapter_Engine.cc
org_pEp_jniadapter_Engine.o: org_pEp_jniadapter_Engine.h org_pEp_jniadapter_Engine.cc throw_pEp_exception.hh
$(LIBRARY): org_pEp_jniadapter_Engine.o
$(LIBRARY): org_pEp_jniadapter_Engine.o throw_pEp_exception.o
ar -r $@ $<
.PHONY: clean generate distclean
@ -26,7 +26,13 @@ clean:
rm -f *.class
rm -f org/pEp/jniadapter/*.class
rm -f org/pEp/jniadapter/pEp*.java
rm -f throw_pEp_exception.*
org/pEp/jniadapter/pEpException.java: pEp.yml2 gen_java_exceptions.ysl2
yml2proc -y gen_java_exceptions.ysl2 $< -o $@
throw_pEp_exception.cc throw_pEp_exception.hh: pEp.yml2 gen_throw_pEp_exception.ysl2
yml2proc -y gen_throw_pEp_exception.ysl2 $< -o throw_pEp_exception.cc
throw_pEp_exception.o: throw_pEp_exception.cc throw_pEp_exception.hh

+ 1
- 31
src/gen_java_exceptions.ysl2 View File

@ -1,37 +1,7 @@
include yslt.yml2
tstylesheet {
function "UCASE" {
param "text";
value "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
}
function "lcase" {
param "text";
value "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')";
}
function "CamelCase" {
param "text";
choose {
when "contains($text, '-')" {
const "tokens", "str:tokenize($text, '-')";
for "$tokens" {
choose {
when ".='pEp'" > pEp
otherwise {
call "UCASE" with "text", "substring(., 1, 1)";
call "lcase" with "text", "substring(., 2)";
}
}
}
}
otherwise | unsupported
}
}
include ./textutils.ysl2
template "/" {
| package org.pEp.jniadapter;


+ 2
- 37
src/org_pEp_jniadapter_Engine.cc View File

@ -5,45 +5,10 @@
#include <assert.h>
#include <pEp/pEpEngine.h>
#include "throw_pEp_exception.hh"
namespace pEp {
namespace JNIAdapter {
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status)
{
jclass ex;
const char *ex_name;
switch (status) {
case PEP_INIT_CANNOT_LOAD_GPGME:
ex_name = "org/pEp/jniadapter/InitCannotLoadGPGME";
break;
case PEP_INIT_GPGME_INIT_FAILED:
ex_name = "org/pEp/jniadapter/GPGMEInitFailed";
break;
case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
ex_name = "org/pEp/jniadapter/SQLite3WithoutMutex";
break;
case PEP_INIT_CANNOT_OPEN_DB:
ex_name = "org/pEp/jniadapter/InitCannotOpenDB";
break;
case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
ex_name = "org/pEp/jniadapter/InitCannotOpenSystemDB";
break;
default:
assert(0);
ex_name = "Exception";
}
ex = env->FindClass(ex_name);
assert(ex);
if (ex == NULL) {
ex = env->FindClass("java/lang/NoClassDefFoundError");
assert(ex);
}
return env->ThrowNew(ex, ex_name);
}
jfieldID getFieldID(
JNIEnv *env,
const char *classname,


Loading…
Cancel
Save