本文整理匯總了Java中com.sun.codemodel.JCodeModel._class方法的典型用法代碼示例。如果您正苦於以下問題:Java JCodeModel._class方法的具體用法?Java JCodeModel._class怎麽用?Java JCodeModel._class使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.codemodel.JCodeModel
的用法示例。
在下文中一共展示了JCodeModel._class方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createRetrieveClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private static void createRetrieveClass(Retrieve retrieve, String packageName, File destinationDir) throws JClassAlreadyExistsException, IOException {
JCodeModel codeModel = new JCodeModel();
JClass mapClass = codeModel.ref(String.format("%s.%sMap", packageName, retrieve.getId()));
JDefinedClass retrieveClass = codeModel._class(String.format("%s.%sRetrieve", packageName, retrieve.getId()));
retrieveClass.javadoc().append("Auto generated class. Do not modify!");
retrieveClass._extends(codeModel.ref(AbstractRetrieve.class).narrow(mapClass));
// Constructor
JMethod constructor = retrieveClass.constructor(JMod.PUBLIC);
constructor.param(String.class, "id");
constructor.body().invoke("super").arg(JExpr.ref("id"));
// Implemented method
JMethod getMapMethod = retrieveClass.method(JMod.PUBLIC, mapClass, "getMap");
getMapMethod.annotate(Override.class);
getMapMethod.param(codeModel.ref(Map.class).narrow(String.class, Object.class), "data");
getMapMethod.body()._return(JExpr._new(mapClass).arg(JExpr.ref("data")));
codeModel.build(destinationDir);
}
示例2: getNarrowedArrayClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
@Override
protected JClass getNarrowedArrayClass()
{
//TODO #series hack
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass;
try
{
definedClass = codeModel._class("java.lang.Object");
JClass genericArray = new JCodeModel().ref(Array.class);
JClass arrayOfSpecializedType = genericArray.narrow(definedClass);
return arrayOfSpecializedType;
}
catch (JClassAlreadyExistsException e)
{
throw new RuntimeException();
}
}
示例3: NodeGenerator
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public NodeGenerator(Symbols symbols, String pckg, JCodeModel model, Framework f,
SymbolsGenerator symbolsGen) throws JClassAlreadyExistsException{
this.symbols = symbols;
this.framework = f;
this.symbolsGen = symbolsGen;
this.model = model;
this.pckg = pckg;
String name = pckg == null ? VISITOR : pckg + "." + VISITOR;
this.visitorInterface = model._class(name, ClassType.INTERFACE);
CodeGenerator.appendJDocHeader(visitorInterface);
name = pckg == null ? SYMBOLS : pckg + "." + SYMBOLS;
this.eofTokenClass = this.defineEOFToken();
this.tokens = this.defineTokenNodes();
this.abstractNodes= this.defineAbstractNodes();
this.concreteNodes= this.defineConcreteNodes();
}
示例4: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName());
definedClass.javadoc().append(this.clazz.getJavaDoc());
JMethod constructor = definedClass.constructor(Visibility.PRIVATE.getMod());
constructor.body().directStatement(String.format("this.baseUri = \"%s\";", this.baseUri));
this.appendClassAttributes(codeModel, definedClass);
this.appendClassMethods(codeModel, definedClass);
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例5: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName());
definedClass.javadoc().append(this.clazz.getJavaDoc());
String narrowClass = this.getModelFetchType();
for (String interfaceName : this.clazz.getInterfaces()) {
definedClass._implements(codeModel.ref(interfaceName).narrow(codeModel.ref(narrowClass)));
}
JMethod constructor = definedClass.constructor(Visibility.PUBLIC.getMod());
constructor.param(String.class, "url");
constructor.body().directStatement("this.url = ((url == null || url.equals(\"\")) ? \"\" : url) + \"" + this.serviceMeta.getUri() + "\";");
this.appendClassAttributes(codeModel, definedClass);
this.appendClassMethods(codeModel, definedClass);
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例6: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName());
definedClass.javadoc().append(this.clazz.getJavaDoc());
for (String interfaceName : this.clazz.getInterfaces()) {
definedClass._implements(codeModel.ref(interfaceName));
}
this.appendClassAttributes(codeModel, definedClass);
this.appendClassMethods(codeModel, definedClass);
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例7: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName(), ClassType.INTERFACE);
definedClass.javadoc().append(this.clazz.getJavaDoc());
String genericType = this.clazz.getPackageName().replace(".service", ".model.ICollectionModel");
definedClass.generify("T extends " + genericType + "<?>");
this.appendClassMethods(codeModel, definedClass);
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例8: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName());
definedClass.javadoc().append(this.clazz.getJavaDoc());
JClass collectionType = codeModel.ref(ArrayList.class).narrow(codeModel.ref("E"));
definedClass._extends(collectionType).generify("E");
for (String interfaceName : this.clazz.getInterfaces()) {
definedClass._implements(codeModel.ref(interfaceName));
}
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
JClass param = codeModel.ref(this.clazz.getPackageName() + ".service." + ServiceFetchInterfaceGenerator.CLASS_NAME).narrow(codeModel.ref("?"));
constructor.param(param, "service");
constructor.body().directStatement(this.getConstructoryBody());
this.appendClassAttributes(codeModel, definedClass);
this.appendClassMethods(codeModel, definedClass);
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例9: createReportingValueClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void createReportingValueClass(JCodeModel codeModel, String name, JPrimitiveType type) throws JClassAlreadyExistsException {
JClass reportClazz = codeModel.ref("org.jpmml.evaluator.Report");
JDefinedClass clazz = codeModel._class(JMod.PUBLIC, "org.jpmml.evaluator.Reporting" + name, ClassType.CLASS);
clazz._extends(codeModel.ref("org.jpmml.evaluator." + name));
clazz._implements(codeModel.ref("org.jpmml.evaluator.HasReport"));
JFieldVar reportField = clazz.field(JMod.PRIVATE, reportClazz, "report", JExpr._null());
createCopyMethod(clazz);
createOperationMethods(clazz, name, type);
createReportMethod(clazz);
createExpressionMethods(clazz);
createAccessorMethods(clazz, reportField);
createFormatMethod(clazz, type);
}
示例10: AbstractBaseMetaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public AbstractBaseMetaClass(JCodeModel cm, String fqn, ClassType ct) {
try {
this.generatedClass = cm._class(fqn, ct);
} catch (JClassAlreadyExistsException e) {
throw new IllegalStateException("Class: " + fqn + " already exists.", e);
}
}
示例11: createMapClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private static void createMapClass(Retrieve retrieve, Map<String, Integer> columns, String packageName, File destinationDir) throws JClassAlreadyExistsException,
MapperEngineCodeGeneratorException,
IOException {
JCodeModel codeModel = new JCodeModel();
JDefinedClass mapClass = codeModel._class(String.format("%s.%sMap", packageName, retrieve.getId()));
mapClass.javadoc().append("Auto generated class. Do not modify!");
// Constructor
JMethod constructor = mapClass.constructor(JMod.PROTECTED);
constructor.param(codeModel.ref(Map.class).narrow(String.class, Object.class), "data");
for (String column : columns.keySet()) {
String varName = WordUtils.uncapitalize(column);
Class<?> type = null;
switch (columns.get(column)) {
case Types.INTEGER:
type = Integer.class;
break;
case Types.VARCHAR:
type = String.class;
break;
case Types.DECIMAL:
type = BigDecimal.class;
break;
default:
throw new MapperEngineCodeGeneratorException(String.format("Missing Type map for column %s: %d", column, columns.get(column)));
}
JFieldVar field = mapClass.field(JMod.PRIVATE | JMod.FINAL, type, varName);
// Getter
JMethod getter = mapClass.method(JMod.PUBLIC, type, String.format("get%s", column));
getter.body()._return(JExpr._this().ref(field));
constructor.body().assign(JExpr._this().ref(varName), JExpr.cast(codeModel.ref(type), JExpr.ref("data").invoke("get").arg(column)));
}
codeModel.build(destinationDir);
}
示例12: createRetrieveIdEnum
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private static void createRetrieveIdEnum(List<Retrieve> retrieves, String packageName, File destinationDir) throws JClassAlreadyExistsException, IOException {
JCodeModel codeModel = new JCodeModel();
JDefinedClass enumClass = codeModel._class(JMod.PUBLIC, String.format("%s.MapEngineRetrieveId", packageName), ClassType.ENUM);
for (Retrieve retrieve : retrieves) {
enumClass.enumConstant(retrieve.getId());
}
codeModel.build(destinationDir);
}
示例13: generatePrintVisitor
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
/**
* Generates a Visitor implementation that traverses the abstract syntax tree
* and prints its structure.
* @param pckg - package in which to create this class
* @param model - JCodeModel
* @param iVisitor - the JDefinedClass for the visitor interface
* @param terminals - a set containing the JDefinedClass objects for the
* terminal nodes
* @return - the generated visitor implementation
* @throws JClassAlreadyExistsException
*
* @author Tristan Bepler
*/
public static JDefinedClass generatePrintVisitor(String pckg, JCodeModel model,
JDefinedClass iVisitor, Set<JDefinedClass> terminals)
throws JClassAlreadyExistsException{
String name = pckg == null ? PRINT_VISITOR : pckg + "." + PRINT_VISITOR;
JDefinedClass printVisitor = model._class(name);
CodeGenerator.appendJDocHeader(printVisitor);
printVisitor._implements(iVisitor);
//add a field for the delimiter string
JVar delim = printVisitor.field(JMod.PRIVATE+JMod.STATIC+JMod.FINAL, String.class, "DELIM", JExpr.lit(" "));
//add a field for the current depth
JVar depth = printVisitor.field(JMod.PRIVATE, int.class, "depth", JExpr.lit(0));
//add a print method which prints an object with the proper indentation
JMethod print = definePrintMethod(model, printVisitor, delim, depth);
for(JMethod method : iVisitor.methods()){
JDefinedClass paramType = getParameterClass(method);
//declare this method in the print visitor
JMethod def = printVisitor.method(JMod.PUBLIC, void.class, method.name());
def.annotate(Override.class);
JVar param = def.param(paramType, "node");
//print this node
def.body().invoke(JExpr._this(), print).arg(param);
if(!terminals.contains(paramType)){
//the param is not a terminal, so traverse its children
defineChildNodeTraversal(param, depth, print, paramType, def);
}
}
return printVisitor;
}
示例14: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName(), ClassType.INTERFACE);
definedClass.javadoc().append(this.clazz.getJavaDoc());
definedClass.generify("T extends IModel");
this.appendClassMethods(codeModel, definedClass);
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例15: buildJavaClass
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void buildJavaClass() {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass definedClass = codeModel._class(this.clazz.getCanonicalClassName(), ClassType.INTERFACE);
definedClass.javadoc().append(this.clazz.getJavaDoc());
codeModel.build(new File("src/main/java"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}