使用Bashregex?从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,int userId);
ParceledListSlice queryIntentReceivers(in Intent intent,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'

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...