SourceType代表源代码中的Class,Interface,Anonation,Enum等类型。
直接看代码
eg:
SourceType sType = (SourceType) type;
System.out.println("名称:" + sType.getElementName());
if(sType.isClass()){
sType.createMethod("public void v(){}", null, false,null);//创建方法
sType.createField("int i = 100;", null, false,null);//创建字段
sType.createInitializer("{System.out.println(\"初始化\");}",null,null);//创建初始化代码
}else if(sType.isInterface()){
sType.createMethod("public void v();", null, false,null);//在接口中创建方法
}