Commit 609d8399 authored by qsr@chromium.org's avatar qsr@chromium.org

Add module annotation to specify the name of the java class for constants.

R=rmcilroy@chromium.org, viettrungluu@chromium.org

Review URL: https://codereview.chromium.org/300223008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274526 0039d316-1c4b-4281-b951-d872f2087c98
parent f3fd2f21
......@@ -8,6 +8,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.TestCase;
import org.chromium.mojo.bindings.test.sample.InterfaceConstants;
import org.chromium.mojo.bindings.test.sample.SampleServiceConstants;
import java.lang.reflect.Field;
......@@ -18,16 +19,23 @@ import java.lang.reflect.Modifier;
*/
public class BindingsTest extends TestCase {
private static void checkConstantField(Field field, Class<?> expectedClass)
{
assertEquals(expectedClass, field.getType());
assertEquals(Modifier.FINAL, field.getModifiers() & Modifier.FINAL);
assertEquals(Modifier.STATIC, field.getModifiers() & Modifier.STATIC);
}
/**
* Testing constants are correctly generated.
*/
@SmallTest
public void testConstants() throws NoSuchFieldException, SecurityException {
assertEquals(3, SampleServiceConstants.THREE);
Field threeField = SampleServiceConstants.class.getField("THREE");
assertEquals(byte.class, threeField.getType());
assertEquals(Modifier.FINAL, threeField.getModifiers() & Modifier.FINAL);
assertEquals(Modifier.STATIC, threeField.getModifiers() & Modifier.STATIC);
checkConstantField(SampleServiceConstants.class.getField("THREE"), byte.class);
assertEquals(4405, InterfaceConstants.LONG);
checkConstantField(InterfaceConstants.class.getField("LONG"), long.class);
}
}
......@@ -3,9 +3,12 @@
// found in the LICENSE file.
[JavaPackage="org.chromium.mojo.bindings.test.sample",
JavaConstantsClassName="InterfaceConstants",
Foo = "hello world"]
module sample {
const uint64 kLong = 4405;
enum Enum {
ENUM_VALUE
};
......
......@@ -78,14 +78,16 @@ def GetNameForElement(element):
return ConstantStyle(element.name)
raise Exception("Unexpected element: " % element)
def ParseStringAttribute(attribute):
if isinstance(attribute, basestring):
return attribute
assert attribute[0] == 'EXPRESSION'
assert len(attribute[1]) == 1
return attribute[1][0][1:-1].encode('string_escape')
def GetPackage(module):
if 'JavaPackage' in module.attributes:
package = module.attributes['JavaPackage']
if isinstance(package, basestring):
return package
assert package[0] == 'EXPRESSION'
assert len(package[1]) == 1
return package[1][0][1:-1].encode('string_escape')
return ParseStringAttribute(module.attributes['JavaPackage'])
# Default package.
return "org.chromium.mojom." + module.namespace
......@@ -135,6 +137,8 @@ def ExpressionToText(value, module):
lambda token: TranslateConstants(token, module)))
def GetConstantsMainEntityName(module):
if 'JavaConstantsClassName' in module.attributes:
return ParseStringAttribute(module.attributes['JavaConstantsClassName'])
# This constructs the name of the embedding classes for module level constants
# by extracting the mojom's filename and prepending it to Constants.
return (UpperCamelCase(module.path.split('/')[-1].rsplit('.', 1)[0]) +
......
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