1#!/usr/bin/env python3 2 3# Copyright (C) 2020 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16"""Generates stubs for annotations that aren't in the Android source tree.""" 17 18import pathlib 19import string 20import sys 21 22_ANNOTATIONS_CLASSES = ['org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement'] 23 24_CLASS_TEMPLATE = string.Template(""" 25package ${package_name}; 26 27import java.lang.annotation.ElementType; 28import java.lang.annotation.Retention; 29import java.lang.annotation.RetentionPolicy; 30import java.lang.annotation.Target; 31 32@Target({ 33 ElementType.ANNOTATION_TYPE, 34 ElementType.CONSTRUCTOR, 35 ElementType.FIELD, 36 ElementType.LOCAL_VARIABLE, 37 ElementType.METHOD, 38 ElementType.PACKAGE, 39 ElementType.PARAMETER, 40 ElementType.TYPE, 41 ElementType.TYPE_PARAMETER, 42 ElementType.TYPE_USE}) 43@Retention(RetentionPolicy.SOURCE) 44public @interface ${class_name} {} 45""") 46 47if __name__ == '__main__': 48 out_dir = pathlib.Path(sys.argv[1]) 49 50 for c in _ANNOTATIONS_CLASSES: 51 parts = c.split('.') 52 src_path = out_dir.joinpath(*parts).with_suffix('.java') 53 src_path.parent.mkdir(parents=True) 54 src_path.write_text( 55 _CLASS_TEMPLATE.substitute( 56 package_name='.'.join(parts[:-1]), class_name=parts[-1])) 57