From 360436f9fc9d1e1cd790f2bd16579c71e650a1d4 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 18 Oct 2012 01:07:53 +0900 Subject: [PATCH] Annotations are not limited to the predefined ones anymore. --- JavaClass.java | 26 ++++++++++++++++++++++- Start.java | 57 -------------------------------------------------- 2 files changed, 25 insertions(+), 58 deletions(-) diff --git a/JavaClass.java b/JavaClass.java index 5134520..bf88453 100644 --- a/JavaClass.java +++ b/JavaClass.java @@ -464,6 +464,7 @@ public void appendToDocument (Document doc, Element parent) void doAppendToDocument (Document doc, Element parent) { int mods = jclass.getModifiers (); + boolean is_annotation = false; Element e = doc.createElement (jclass.isInterface () && !jclass.isAnnotation () ? "interface" : "class"); if (!jclass.isInterface () || jclass.isAnnotation ()) { @@ -475,7 +476,8 @@ void doAppendToDocument (Document doc, Element parent) e.setAttribute ("extends", getClassName (t2, true)); } - e.setAttribute ("name", getClassName (jclass, false)); + String className = getClassName (jclass, false); + e.setAttribute ("name", className); e.setAttribute ("final", Modifier.isFinal (mods) ? "true" : "false"); e.setAttribute ("static", Modifier.isStatic (mods) ? "true" : "false"); e.setAttribute ("abstract", Modifier.isAbstract (mods) ? "true" : "false"); @@ -506,6 +508,9 @@ else if (iface instanceof ParameterizedType) { iface_elem.setAttribute ("name-generic-aware", getGenericTypeName (iface)); iface_elem.appendChild (doc.createTextNode ("\n")); e.appendChild (iface_elem); + + if (iface_elem.getAttribute ("name").equals ("java.lang.annotation.Annotation")) + is_annotation = true; } for (Constructor ctor : jclass.getDeclaredConstructors ()) @@ -607,6 +612,25 @@ else if (hret != null && !mret.isAssignableFrom (hret)) { for (Field field : fields) appendField (field, asmFields.get (field.getName ()), doc, e); parent.appendChild (e); + + if (is_annotation) + parent.appendChild (createAnnotationMock (doc, className)); + } + + static Element createAnnotationMock (Document doc, String name) + { + Element e = doc.createElement ("class"); + e.setAttribute ("abstract", "true"); + e.setAttribute ("deprecated", "not deprecated"); + e.setAttribute ("extends", "java.lang.Object"); + e.setAttribute ("final", "false"); + e.setAttribute ("name", name); + e.setAttribute ("static", "false"); + e.setAttribute ("visibility", "public"); + Element i = doc.createElement ("implements"); + i.setAttribute ("name", "java.lang.annotation.Annotation"); + e.appendChild (i); + return e; } static final Field [] empty_array = new Field [0]; diff --git a/Start.java b/Start.java index e0ef6ee..ac6734f 100644 --- a/Start.java +++ b/Start.java @@ -43,49 +43,6 @@ public class Start { - // FIXME: for future compatibility, they had better be scraped - // from java/lang/annotated/Annotation.html (known *direct subclasses) - static final String [] annotations = { - "android.test.FlakyTest", - "android.test.UiThreadTest", - "android.test.suitebuilder.annotation.LargeTest", - "android.test.suitebuilder.annotation.MediumTest", - "android.test.suitebuilder.annotation.SmallTest", - "android.test.suitebuilder.annotation.Smoke", - "android.test.suitebuilder.annotation.Suppress", - "android.view.ViewDebug$CapturedViewProperty", - "android.view.ViewDebug$ExportedProperty", - "android.view.ViewDebug$FlagToString", - "android.view.ViewDebug$IntToString", - "android.widget.RemoteViews$RemoteView", - "dalvik.annotation.TestTarget", - "dalvik.annotation.TestTargetClass", - "java.lang.Deprecated", - "java.lang.Override", - "java.lang.SuppressWarnings", - "java.lang.annotation.Documented", - "java.lang.annotation.Inherited", - "java.lang.annotation.Retention", - "java.lang.annotation.Target", - "java.lang.annotation.Documented" - }; - - static Element createAnnotationMock (Document doc, String name) - { - Element e = doc.createElement ("class"); - e.setAttribute ("abstract", "true"); - e.setAttribute ("deprecated", "not deprecated"); - e.setAttribute ("extends", "java.lang.Object"); - e.setAttribute ("final", "false"); - e.setAttribute ("name", name); - e.setAttribute ("static", "false"); - e.setAttribute ("visibility", "public"); - Element i = doc.createElement ("implements"); - i.setAttribute ("name", "java.lang.annotation.Annotation"); - e.appendChild (i); - return e; - } - public static void main (String[] args) { String droiddocs = null; @@ -156,20 +113,6 @@ public static void main (String[] args) doc.appendChild (root); for (JavaPackage pkg : jar.getPackages ()) pkg.appendToDocument (doc, root); - for (String ann : annotations) { - String pkg = ann.substring (0, ann.lastIndexOf ('.')); - NodeList nl = root.getChildNodes (); - for (int ind = 0; ind < nl.getLength (); ind++) { - Node n = nl.item (ind); - if (!(n instanceof Element)) - continue; - Element el = (Element) n; - if (el.getAttribute ("name").equals (pkg)) { - String local = ann.substring (pkg.length () + 1); - el.appendChild (createAnnotationMock (doc, local.replace ("$", "."))); - } - } - } } catch (Exception e) { System.err.println (e); System.err.println ("error J2X0002: API analyzer failed with java exception. See verbose output for details.");