Annotation extractor which looks for annotations in parsed compilation units and writes the annotations into a format suitable for use by IntelliJ and Android Studio etc; it's basically an XML file, organized by package, which lists the signatures for fields and methods in classes in the given package, and identifiers method parameters by index, and lists the annotations annotated on that element.
This is primarily intended for use in Android libraries such as the support library,
where you want to use the resource int (StringRes
, DrawableRes
, and so on)
annotations to indicate what types of id's are expected, or the IntDef
or
StringDef
annotations to record which specific constants are allowed in int and
String parameters.
However, the code is also used to extract SDK annotations from the platform, where the package names of the annotations differ slightly (and where the nullness annotations do not have class retention for example). Therefore, this code contains some extra support not needed when extracting annotations in an Android library, such as code to skip annotations for any method/field not mentioned in the API database, and code to rewrite the android.jar file to insert annotations in the generated bytecode.
TODO:
- Warn if the @IntDef
annotation is used on a non-int, and similarly if
@StringDef
is used on a non-string
- Ignore annotations defined on
Modifiers | Name | Description |
---|---|---|
static String |
ANDROID_ANNOTATIONS_PREFIX |
|
static String |
ANDROID_INT_DEF |
|
static String |
ANDROID_NOTNULL |
|
static String |
ANDROID_NULLABLE |
|
static String |
ANDROID_STRING_DEF |
|
static String |
IDEA_CONTRACT |
|
static String |
IDEA_MAGIC |
|
static String |
IDEA_NON_NLS |
|
static String |
IDEA_NOTNULL |
|
static String |
IDEA_NULLABLE |
|
static String |
RESOURCE_TYPE_ANNOTATIONS_SUFFIX |
|
static String |
SUPPORT_NOTNULL |
|
static String |
SUPPORT_NULLABLE |
Constructor and description |
---|
Extractor
(ApiDatabase apiFilter, File classDir, boolean displayInfo) |
Type | Name and description |
---|---|
void |
export(File output) |
void |
extractFromProjectSource(Collection<org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration> units) |
boolean |
isListIgnored() |
void |
mergeExisting(File file) |
void |
removeTypedefClasses() |
void |
setListIgnored(boolean listIgnored) |
void |
writeStats() |