使用 Class 和 JInvocation.arg 的 Sun CodeModel
Sun CodeModel using Class with JInvocation.arg
我正在使用 sun 的代码模型 (2.4.1) 类 生成代码。如何将 Class 传递给 JInvocation.arg?我要生成的代码是:
JAXBContext jc;
jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
我是运行的代码是:
JClass importJAXBContext = codeModel.directClass(javax.xml.bind.JAXBContext.class.toString());
JType typeJAXBContext = codeModel._ref(javax.xml.bind.JAXBContext.class);
JVar varJc = block.decl(typeJAXBContext, "jc");
JInvocation invokeJAXBContext = block.staticInvoke(importJAXBContext, "newInstance");
invokeJAXBContext.arg(??); // how do I pass NaturalLanguageUsage.class
我想生产什么:
JAXBContext jc;
jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
甚至更好:
JAXBContext jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
JClass importJAXBContext = codeModel.ref(javax.xml.bind.JAXBContext.class);
JVar varJc = block.decl(importJAXBContext, "jc");
JClass naturalLangClassRef = codeModel.ref(NaturalLanguageUsage.class);
JInvocation invokeJAXBContext = importJAXBContext.staticInvoke("newInstance");
invokeJAXBContext.arg(naturalLangClassRef.dotclass());
block.assign(varJc, invokeJAXBContext);
在一行中生成声明和赋值:
JVar varJc = block.decl(importJAXBContext, "jc", invokeJAXBContext);
我正在使用 sun 的代码模型 (2.4.1) 类 生成代码。如何将 Class 传递给 JInvocation.arg?我要生成的代码是:
JAXBContext jc;
jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
我是运行的代码是:
JClass importJAXBContext = codeModel.directClass(javax.xml.bind.JAXBContext.class.toString());
JType typeJAXBContext = codeModel._ref(javax.xml.bind.JAXBContext.class);
JVar varJc = block.decl(typeJAXBContext, "jc");
JInvocation invokeJAXBContext = block.staticInvoke(importJAXBContext, "newInstance");
invokeJAXBContext.arg(??); // how do I pass NaturalLanguageUsage.class
我想生产什么:
JAXBContext jc;
jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
甚至更好:
JAXBContext jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
JClass importJAXBContext = codeModel.ref(javax.xml.bind.JAXBContext.class);
JVar varJc = block.decl(importJAXBContext, "jc");
JClass naturalLangClassRef = codeModel.ref(NaturalLanguageUsage.class);
JInvocation invokeJAXBContext = importJAXBContext.staticInvoke("newInstance");
invokeJAXBContext.arg(naturalLangClassRef.dotclass());
block.assign(varJc, invokeJAXBContext);
在一行中生成声明和赋值:
JVar varJc = block.decl(importJAXBContext, "jc", invokeJAXBContext);