diff options
author | Bjorn Bringert <bringert@android.com> | 2010-02-01 21:39:22 +0000 |
---|---|---|
committer | Bjorn Bringert <bringert@android.com> | 2010-02-02 10:40:06 +0000 |
commit | 76a72277c9347dd8963097501f49df0f367544f3 (patch) | |
tree | a75a1ce400e4cd868d12077ed87816181385e696 /tools/java-event-log-tags.py | |
parent | 259e5b7a942c58e88f0a312add009caac70a7863 (diff) | |
download | build-76a72277c9347dd8963097501f49df0f367544f3.zip build-76a72277c9347dd8963097501f49df0f367544f3.tar.gz build-76a72277c9347dd8963097501f49df0f367544f3.tar.bz2 |
Generate write<TAG> methods in logtags-generated Java code
Change-Id: Iebca77f2f710ee4c15bf7089647f8d79fe79f33a
Diffstat (limited to 'tools/java-event-log-tags.py')
-rwxr-xr-x | tools/java-event-log-tags.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/java-event-log-tags.py b/tools/java-event-log-tags.py index 20b8ca4..3713bd8 100755 --- a/tools/java-event-log-tags.py +++ b/tools/java-event-log-tags.py @@ -26,6 +26,7 @@ tags in the given input file. import cStringIO import getopt import os +import re import sys import event_log_tags @@ -93,6 +94,37 @@ for t in tagfile.tags: buffer.write(" public static final int %s = %d;\n" % (t.tagname.upper(), t.tagnum)) + +keywords = frozenset(["abstract", "continue", "for", "new", "switch", "assert", + "default", "goto", "package", "synchronized", "boolean", + "do", "if", "private", "this", "break", "double", + "implements", "protected", "throw", "byte", "else", + "import", "public", "throws", "case", "enum", + "instanceof", "return", "transient", "catch", "extends", + "int", "short", "try", "char", "final", "interface", + "static", "void", "class", "finally", "long", "strictfp", + "volatile", "const", "float", "native", "super", "while"]) + +def javaName(name): + out = name[0].lower() + re.sub(r"[^A-Za-z0-9]", "", name.title())[1:] + if out in keywords: + out += "_" + return out + +javaTypes = ["ERROR", "int", "long", "String", "Object[]"] +for t in tagfile.tags: + methodName = javaName("write_" + t.tagname) + if t.description: + args = [arg.strip("() ").split("|") for arg in t.description.split(",")] + else: + args = [] + argTypesNames = ", ".join([javaTypes[int(arg[1])] + " " + javaName(arg[0]) for arg in args]) + argNames = "".join([", " + javaName(arg[0]) for arg in args]) + buffer.write("\n public static void %s(%s) {" % (methodName, argTypesNames)) + buffer.write("\n android.util.EventLog.writeEvent(%s%s);" % (t.tagname.upper(), argNames)) + buffer.write("\n }\n") + + buffer.write("}\n"); event_log_tags.WriteOutput(output_file, buffer) |