Skip to content

Commit

Permalink
Annotations are not limited to the predefined ones anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsushi Eno committed Oct 17, 2012
1 parent 8bc7d73 commit 360436f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 58 deletions.
26 changes: 25 additions & 1 deletion JavaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()) {
Expand All @@ -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");
Expand Down Expand Up @@ -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 ())
Expand Down Expand Up @@ -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];
Expand Down
57 changes: 0 additions & 57 deletions Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit 360436f

Please sign in to comment.