我有一堆充满枚举的 IDL 文件。我想要一种方法来解析 IDL 文件,提取枚举并基于这些创建本机 Java 枚举(也忽略 IDL 中的任何其他声明,如 const、联合或结构)。
我什至不知道从哪里开始。有没有为此目的而设计的好的 Linux 工具?我假设需要正则表达式?
为了解释我的意思,这里是 common.idl 中的一个例子:
#ifndef __common_idl__
#define __common_idl__
module common_idl {
const short MAX_UNITS = 99;
const short MAX_SIZE = 15;
enum Bearing_Type {
North_Bearing,
South_Bearing,
No_Bearing
};
enum Bounds_Type {
Empty,
Full,
Above,
Between,
Below
};
enum Identity_Type {
Pending,
Unknown,
Assumed_Friend,
Friend
};
enum Status_Type {
No_Status,
To_Status,
To_Established,
From_Established
};
enum Emergency_Type {
Reported,
Confirmed,
None
};
struct Console_Marker {
boolean Marked;
};
typedef unsigned short Index_Type;
typedef long TQ_Type;
typedef unsigned short Count_Type;
typedef unsigned long Number_Of_Type;
typedef unsigned short Special_Index_Type;
typedef string<2> Code_Type;
};
#endif
我想运行一个命令......例如:
converter common.idl -package com.myproject -outputDir src
并且 out 会用枚举吐出这些源 java 文件:
src/com/myproject/Bearing_Type.java
package com.myproject;
public enum Bearing_Type {
North_Bearing,
South_Bearing,
No_Bearing
}
src/com/myproject/Bounds_Type.java
package com.myproject;
public enum Bounds_Type {
Empty,
Full,
Above,
Between,
Below
}
src/com/myproject/Emergency_Type.java
package com.myproject;
public enum Emergency_Type {
Reported,
Confirmed,
None
}
src/com/myproject/Identity_Type.java
package com.myproject;
public enum Identity_Type {
Pending,
Unknown,
Assumed_Friend,
Friend
}
src/com/myproject/Status_Type.java
package com.myproject;
public enum Status_Type {
No_Status,
To_Status,
To_Established,
From_Established
}
这可行吗?