使用Bash(regex?)从AIDL文件中提取方法



我想提取所有方法,包括它们的参数和返回数据类型。(每行一个(

下面是一个示例文件:IPackageManager.aidl

我试过这样做:

wget -qO - "https://raw.githubusercontent.com/LineageOS/android_frameworks_base/7fc95f204527ee079c5891d56c969668f0b35a0b/core/java/android/content/pm/IPackageManager.aidl" | 
sed -e '1,/interface/d' 
-e '/^$/d' 
-e 's/^[[:space:]]*//' 
-e '/^[^a-zA-Z]/d' 
-e '/^[^;]*$/{$!N}' 
-e '$d' 
-e 's/(^|n)[[:space:]]*|([[:space:]]){2,}/2/g'

但不幸的是,它仍然不能处理所有的案件。例如,它无法将queryIntentActivityOptions放在一行中(与setPackagesSuspendedAsUser相同(。

以下是一些输出示例:

ParceledListSlice queryIntentActivities(in Intent intent,String resolvedType, int flags, int userId);
ParceledListSlice queryIntentActivityOptions(in ComponentName caller, in Intent[] specifics,
in String[] specificTypes, in Intent intent,String resolvedType, int flags, int userId);
ParceledListSlice queryIntentReceivers(in Intent intent,String resolvedType, int flags, int userId);

这应该是3行,而不是4行,因为只有3种方法。

有什么想法吗?

再次执行sed命令,删除以;结尾的行上的n

wget -qO - "https://raw.githubusercontent.com/LineageOS/android_frameworks_base/7fc95f204527ee079c5891d56c969668f0b35a0b/core/java/android/content/pm/IPackageManager.aidl" | 
sed -e '1,/interface/d' 
-e '/^$/d' 
-e 's/^[[:space:]]*//' 
-e '/^[^a-zA-Z]/d' 
-e '/^[^;]*$/{$!N}' 
-e '$d' 
-e 's/(^|n)[[:space:]]*|([[:space:]]){2,}/2/g' | 
sed -e ':x;N;s/([^;])n/1/;bx'

最新更新