Commit 20cff19f authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improvements on enums and exceptions

parent ec8327d1
......@@ -104,7 +104,8 @@ class JavaTranslator(object):
if name in ENUMS_LIST:
className = ENUMS_LIST[name]
if name.startswith(className):
name = className + '.' + name[len(className):]
name = name[len(className):]
name = className + '.' + name
return name
elif type(_type) is AbsApi.BaseType:
if _type.name == 'string':
......@@ -115,6 +116,10 @@ class JavaTranslator(object):
return 'float'
elif _type.name == 'size':
return 'int'
elif _type.name == 'status':
if native:
return 'int'
return 'void'
return _type.name
def translate_argument(self, _arg, native=False):
......@@ -144,6 +149,7 @@ class JavaTranslator(object):
methodDict['name'] = _method.name.to_camel_case(lower=True)
methodDict['exception'] = self.throws_exception(_method.returnType)
methodDict['enumCast'] = type(_method.returnType) is AbsApi.EnumType
methodDict['params'] = ''
methodDict['native_params'] = 'long nativePtr'
methodDict['static_native_params'] = ''
......@@ -167,6 +173,8 @@ class JavaTranslator(object):
methodDict['native_params_impl'] += 'longArray'
else:
methodDict['native_params_impl'] += self.translate_argument_name(arg.name)
elif type(arg.type) is AbsApi.EnumType:
methodDict['native_params_impl'] += self.translate_argument_name(arg.name) + '.toInt()'
else:
methodDict['native_params_impl'] += self.translate_argument_name(arg.name)
......
......@@ -53,7 +53,7 @@ public interface {{className}} {
mValue = value;
}
static protected {{className}} fromInt(int value) throws CoreException {
static public {{className}} fromInt(int value) throws CoreException {
switch(value) {
{{#values}}
case {{value}}: return {{name}};
......@@ -62,6 +62,10 @@ public interface {{className}} {
throw new CoreException("Unhandled enum value " + value + " for {{className}}");
}
}
public int toInt() {
return mValue;
}
};
{{/enums}}
......@@ -142,7 +146,8 @@ class {{classImplName}} implements {{className}} {
return classArray;
{{/convertOutputClassArrayToLongArray}}
{{#classicMethod}}
{{return_keyword}}{{name}}(nativePtr{{native_params_impl}});
{{#exception}}int exceptionResult = {{/exception}}{{return_keyword}}{{#enumCast}}{{return}}.fromInt({{/enumCast}}{{name}}(nativePtr{{native_params_impl}}){{#enumCast}}){{/enumCast}};
{{#exception}}if (exceptionResult != 0) throw new CoreException("{{name}} returned value " + exceptionResult){{/exception}}
{{/classicMethod}}
}
......
......@@ -48,7 +48,7 @@ public enum {{className}} {
mValue = value;
}
static protected {{className}} fromInt(int value) throws CoreException {
static public {{className}} fromInt(int value) throws CoreException {
switch(value) {
{{#values}}
case {{value}}: return {{name}};
......@@ -57,4 +57,8 @@ public enum {{className}} {
throw new CoreException("Unhandled enum value " + value + " for {{className}}");
}
}
public int toInt() {
return mValue;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment