• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClassType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.sun.codemodel.ClassType的典型用法代码示例。如果您正苦于以下问题:Java ClassType类的具体用法?Java ClassType怎么用?Java ClassType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClassType类属于com.sun.codemodel包,在下文中一共展示了ClassType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildTemplateConstraint

import com.sun.codemodel.ClassType; //导入依赖的package包/类
private JDefinedClass buildTemplateConstraint(String name) {
    try {
        JDefinedClass tplConstraint = codeModel._class(Config.CFG.getBasePackageName() + ".annot."+name, ClassType.ANNOTATION_TYPE_DECL);
        tplConstraint.annotate(Documented.class);
        tplConstraint.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
        tplConstraint.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE).param(ElementType.FIELD).param(ElementType.METHOD);
        
        // Using direct as I don't know how to build default { } with code model
        tplConstraint.direct("\n" + "    Class<?>[] groups() default {};\n" + "    String message() default \"Invalid value\";\n" + "    Class<? extends Payload>[] payload() default {};\n");
        
        // Hack to force the import of javax.validation.Payload
        tplConstraint.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
        
        return tplConstraint;
    } catch (JClassAlreadyExistsException e) {
        throw new RuntimeException("Tried to create an already existing class: " + name, e);
    }
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:19,代码来源:Jsr303Annotator.java


示例2: MetaJavaBean

import com.sun.codemodel.ClassType; //导入依赖的package包/类
/**
 * Creates a new MetaJavaBean with random fields.
 * 
 * @param fqn
 *            The fully qualified name of the bean's class.
 * @param numFields
 *            Number of simple type fields that will be added.
 */
public MetaJavaBean(JCodeModel cm, String fqn, int numFields) {

    super(cm, fqn, ClassType.CLASS);

    // Empty constructor
    getGeneratedClass().constructor(JMod.PUBLIC);

    // Init the simple fields
    this.fields = Maps.newHashMapWithExpectedSize(numFields);
    for (int i = 0; i < numFields; ++i) {
        String fieldName = "field" + Config.CFG.nextUniqueNum();
        JavaBeanBasicField field = new JavaBeanBasicField(this, fieldName);
        fields.put(fieldName, field);
    }

}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:25,代码来源:MetaJavaBean.java


示例3: define

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@Override
public JType define(AbstractType t) {
	JDefinedClass defineClass = writer.defineClass(t, ClassType.INTERFACE);
	for (AbstractType st:t.superTypes()){
		AbstractType superType = st;
		JType type = writer.getType(superType);
		defineClass._extends((JClass) type);
	}
	t.toPropertiesView().properties().forEach(p -> {
		String name = writer.propNameGenerator.name(p);
		JType propType = writer.getType(p.range(), false, false, p);
		//defineClass.field(JMod.PRIVATE, propType, name);
		defineClass.method(JMod.PUBLIC, propType,
				"get" + Character.toUpperCase(name.charAt(0)) + name.substring(1));
		
		defineClass.method(JMod.PUBLIC, writer.getModel()._ref(void.class),
				(p.range().isBoolean() ? "is" : "set") + Character.toUpperCase(name.charAt(0)) + name.substring(1));
		
	});
	writer.annotate(defineClass, t);
	return defineClass;
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:23,代码来源:InterfaceGenerator.java


示例4: defineClass

import com.sun.codemodel.ClassType; //导入依赖的package包/类
public JDefinedClass defineClass(AbstractType t, ClassType type) {
	String fullyQualifiedName = nameGenerator.fullyQualifiedName(t);
	try {
		JDefinedClass _class = mdl._class(fullyQualifiedName, type);
		if (config.addGenerated) {
			_class.annotate(Generated.class).param("value", JavaWriter.class.getPackage().getName()).param("date",
					new Date().toString());
		}
		if (t.hasDirectMeta(Description.class)) {
			String description = t.oneMeta(Description.class).value();
			_class.javadoc().add(description);
		}
		return _class;
	} catch (JClassAlreadyExistsException e) {
		throw new IllegalStateException(e);
	}
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:18,代码来源:JavaWriter.java


示例5: shouldFindEnumValues

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void shouldFindEnumValues() throws IllegalAccessException {
    klass = modelPackage._getClass("Colour");
    assertThat(klass.getClassType()).isEqualTo(ClassType.ENUM);
    Map<String,JEnumConstant> enums = (Map<String, JEnumConstant>) FieldUtils.readField(klass, "enumConstantsByName", true);
    assertThat(enums.keySet()).contains("LIGHT_BLUE", "RED");

    JEnumConstant lightBlue = enums.get("LIGHT_BLUE");
    assertThat(lightBlue.javadoc().get(0)).isEqualTo("Colour of the sky");

    List<JExpression> args = (List<JExpression>) FieldUtils.readField(lightBlue, "args", true);
    assertThat(args).hasSize(1);

    assertThat(args.get(0)).isInstanceOf(JStringLiteral.class);

    String literal = (String) FieldUtils.readField(args.get(0), "str", true);
    assertThat(literal).isEqualTo("lightBlue");
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:20,代码来源:EnumsTest.java


示例6: generateJava

import com.sun.codemodel.ClassType; //导入依赖的package包/类
private byte[] generateJava() throws Exception {
	
	JDefinedClass classModel = codeModel._class(JMod.PUBLIC | JMod.FINAL, className, ClassType.CLASS);
	Class<?> contractInterface = Class.forName(contractInterfaceName);
	classModel._implements(contractInterface);
          classModel._extends(AbstractDataTransferObject.class);
	
	List<FieldModel> fields = determineFields(contractInterface);
	
	renderConstantsClass(classModel);
	renderElementsClass(classModel, fields);
	renderClassLevelAnnotations(classModel, fields);
	renderFields(classModel, fields);
	renderFutureElementsField(classModel);			
	renderPrivateJaxbConstructor(classModel, fields);
	renderBuilderConstructor(classModel, fields);
	renderGetters(classModel, fields);
	renderBuilderClass(classModel, fields, contractInterface);

	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	codeModel.build(new SingleStreamCodeWriter(outputStream));
	return outputStream.toByteArray();
	
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:25,代码来源:ImmutableJaxbGenerator.java


示例7: caseAPortDeclaration

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@Override
public void caseAPortDeclaration(APortDeclaration node
) {
    TypeModifierAdapter modap = new TypeModifierAdapter(context);
    for (PModifier m : node.getModifier()) {
        m.apply(modap);
    }
    int mods = modap.getMods();
    JDefinedClass c = context.declare(mods, node.getIdentifier(), ClassType.CLASS);

    try {
        c.mods().setPublic(); // ports should be public so Kompics can load them
        c._extends(PortType.class);
        PortBodyAdapter pba = new PortBodyAdapter(c.instanceInit(), context);

        node.getPortBody().apply(pba);
    } finally {
        context.popScope();
    }
}
 
开发者ID:kompics,项目名称:kola,代码行数:21,代码来源:TypeDeclarationAdapter.java


示例8: declare

import com.sun.codemodel.ClassType; //导入依赖的package包/类
JDefinedClass declare(int mods, TIdentifier identifier, ClassType ctype, Optional<String> name) {
    if (current instanceof Scope.Typey) {
        try {
            Scope.Typey typeyScope = (Scope.Typey) current;
            Type t = typeyScope.declare(mods, identifier, ctype, name);
            global.addType(t);
            current = t.scope;
            scopeStack.push(current);
            //System.out.println("Pushing scope " + current);
            return t.definition;
        } catch (JClassAlreadyExistsException ex) {
            throw new RuntimeException(ex);
        }
    } else {
        Logger.error("Cannot add a type (" + identifier.getText() + ") to a Scope (" + current.getClass().getName() + ") that doesn't allow types!");
        throw new RuntimeException("Invalid Scope for operation!");
    }
}
 
开发者ID:kompics,项目名称:kola,代码行数:19,代码来源:ResolutionContext.java


示例9: generete

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@Override
	public void generete(Const definition) throws Exception {
		JDefinedClass jExceptionClass = this.getJavaPackage()._class(JMod.PUBLIC, definition.getName(), ClassType.CLASS);
		jExceptionClass._extends(org.apache.thrift.TException.class);
		
//		this.context.getTypeRegistry().add(jExceptionClass);
		
		
		int[] count = { 0 };
//		for (Const constDef : subprogram.constants) {
		JType fieldType = this.resolvType(definition.getType());
		JExpression exp = this.buildStaticExpression(jConstantsClass, fieldType, definition.getName(), definition.getValue() , count);
		jConstantsClass.field(JMod.PUBLIC | JMod.FINAL | JMod.STATIC, fieldType, definition.getName(), exp);
		
//		}
		
	}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:18,代码来源:ConstantsCodeGenerator.java


示例10: generete

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@Override
public void generete(Service definition) throws Exception {
	JDefinedClass jServiceClass = this.getJavaPackage()._class(JMod.PUBLIC,
			definition.getName(), ClassType.CLASS);

	JDefinedClass _interfaceIface = createServicesInterface(definition,
			jServiceClass);
	createServicesClient(definition, jServiceClass);
	createServicesProcessor(definition, jServiceClass, _interfaceIface);

	JDefinedClass _asyncInterfaceIface = createServicesAsyncInterface(
			definition, jServiceClass);
	createServicesAsyncClient(definition, jServiceClass);
	createServicesAsyncProcessor(definition, jServiceClass,
			_asyncInterfaceIface);
}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:17,代码来源:ServiceCodeGenerator.java


示例11: getThriftType

import com.sun.codemodel.ClassType; //导入依赖的package包/类
public static String getThriftType(JCodeModel cm, JType jType) {

	if (cm.BOOLEAN.equals(jType) || cm.ref(Boolean.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.BOOL";
	} else if (cm.BYTE.equals(jType) || cm.ref(Byte.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.BYTE";
	} else if (cm.CHAR.equals(jType) || cm.ref(Character.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.STRING";
	} else if (cm.DOUBLE.equals(jType) || cm.ref(Double.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.DOUBLE";
	} else if (cm.FLOAT.equals(jType) || cm.ref(Float.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.DOUBLE";
	} else if (cm.INT.equals(jType) || cm.ref(Integer.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.I32";
	} else if (cm.LONG.equals(jType) || cm.ref(Long.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.I64";
	} else if (cm.ref(String.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.STRING";
	} else if (cm.SHORT.equals(jType) || cm.ref(Short.class).equals(jType)) {
		return "org.apache.thrift.protocol.TType.I16";
	} else if (jType instanceof JDefinedClass && ClassType.ENUM.equals(((JDefinedClass) jType).getClassType())) {
		return "org.apache.thrift.protocol.TType.ENUM";
	} else {
		return "org.apache.thrift.protocol.TType.STRUCT";
	}
}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:27,代码来源:JavaGeneratorUtil.java


示例12: NodeGenerator

import com.sun.codemodel.ClassType; //导入依赖的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();
}
 
开发者ID:tbepler,项目名称:LRPaGe,代码行数:17,代码来源:NodeGenerator.java


示例13: defineAbstractNode

import com.sun.codemodel.ClassType; //导入依赖的package包/类
/**
 * @author Jennifer Zou
 * @param s
 * @return
 * @throws JClassAlreadyExistsException
 */
private JDefinedClass defineAbstractNode(String s) throws JClassAlreadyExistsException{
	String name = pckg == null ? s + "AbstractNode" : pckg+"."+NODES+"."+s+"AbstractNode";
	JDefinedClass asn= model._class(JMod.PUBLIC+JMod.ABSTRACT, name, ClassType.CLASS);
	CodeGenerator.appendJDocHeader(asn);
	
	asn._implements(framework.getNodeInterface().narrow(visitorInterface));
	
	//declare the type method
	JMethod type= asn.method(JMod.PUBLIC, framework.getSymbolInterface(), TYPE);
	type.annotate(Override.class);
	type.body()._return(symbolsGen.getSymbolObj(s));
	//define replace method
	JMethod replace= asn.method(JMod.PUBLIC, asn, REPLACE);
	replace.annotate(Override.class);
	replace.body()._return(JExpr._this());
	//define toString()
	JMethod toString= asn.method(JMod.PUBLIC, String.class, "toString");
	toString.annotate(Override.class);
	toString.body()._return(JExpr.invoke(JExpr.invoke(type), "toString"));
	return asn;
}
 
开发者ID:tbepler,项目名称:LRPaGe,代码行数:28,代码来源:NodeGenerator.java


示例14: defineClass

import com.sun.codemodel.ClassType; //导入依赖的package包/类
private JDefinedClass defineClass(String pckg, JCodeModel model, Framework f)
		throws JClassAlreadyExistsException{
	String name = pckg == null ? NAME : pckg + "." + NAME;
	JDefinedClass c = CodeGenerator.appendJDocHeader(
			model._class(JMod.PUBLIC, name, ClassType.ENUM));
	
	JVar str = c.field(JMod.PRIVATE+JMod.FINAL, String.class, "name");
	JMethod cons = c.constructor(JMod.PRIVATE);
	cons.body().assign(JExpr._this().ref(str), cons.param(String.class, "name"));
	JMethod defCons = c.constructor(JMod.PRIVATE);
	defCons.body().assign(JExpr._this().ref(str), JExpr._null());
	
	JMethod toString = c.method(JMod.PUBLIC, String.class, "toString");
	toString.annotate(Override.class);
	toString.body()._if(str.eq(JExpr._null()))._then()._return(JExpr.invoke(JExpr._super(), "toString"));
	toString.body()._return(str);
	
	c._implements(f.getSymbolInterface());
	JMethod type = c.method(JMod.PUBLIC, int.class, "type");
	type.annotate(Override.class);
	type.body()._return(JExpr.invoke(JExpr._this(), "ordinal"));
	
	return c;
}
 
开发者ID:tbepler,项目名称:LRPaGe,代码行数:25,代码来源:SymbolsGenerator.java


示例15: buildJavaClass

import com.sun.codemodel.ClassType; //导入依赖的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);
	}
}
 
开发者ID:aureliano,项目名称:cgraml-maven-plugin,代码行数:17,代码来源:ServiceFetchInterfaceBuilder.java


示例16: createReportingValueClass

import com.sun.codemodel.ClassType; //导入依赖的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);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:17,代码来源:OperationProcessor.java


示例17: AbstractBaseMetaClass

import com.sun.codemodel.ClassType; //导入依赖的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);
    }
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:8,代码来源:AbstractBaseMetaClass.java


示例18: define

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@Override
public JType define(AbstractType t) {
	JDefinedClass defineClass = owner.defineClass(t, ClassType.ENUM);
	Enum oneMeta = t.oneMeta(Enum.class);
	oneMeta.value().forEach(x -> {
		defineClass.enumConstant(owner.escape(x));
	});
	return defineClass;		
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:10,代码来源:EnumTypeGenerator.java


示例19: shouldFindEnumValues

import com.sun.codemodel.ClassType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void shouldFindEnumValues() throws IllegalAccessException {
    klass = modelPackage._getClass("Colour");
    assertThat(klass.getClassType()).isEqualTo(ClassType.ENUM);
    Map<String,JEnumConstant> enums = (Map<String, JEnumConstant>) FieldUtils.readField(klass, "enumConstantsByName", true);
    assertThat(enums.keySet()).containsExactly("LIGHT_BLUE", "RED", "YELLOW", "GREEN");
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:9,代码来源:SimpleObjectTest.java


示例20: withName

import com.sun.codemodel.ClassType; //导入依赖的package包/类
/**
 * Sets this Pojo's name
 * 
 * @param pojoPackage The Package used to create POJO
 * @param className Class to be created
 * @return This instance
 */
public EnumBuilder withName(String pojoPackage, String className) {
	className = NamingHelper.convertToClassName(className);
	
	final String fullyQualifiedClassName = pojoPackage + "." + className;
	// Initiate package if necessary
	if (this.pojoPackage == null) {
		withPackage(pojoPackage);
	}
	// Builders should only have 1 active pojo under their responsibility
	if (this.pojo != null) {
		throw new IllegalStateException("Enum already created");
	}

	try {
		// create the class
		logger.debug("Creating Enum " + fullyQualifiedClassName);
		this.pojo = this.pojoModel._class(fullyQualifiedClassName, ClassType.ENUM);
		
		// Handle Serialization
		// Do enums need to be serializable?
		//implementsSerializable(); 
	} catch (JClassAlreadyExistsException e) {
		// class already exists - reuse it!
		logger.debug("Enum {} already exists. Reusing it!", fullyQualifiedClassName);
		this.pojo = this.pojoModel._getClass(fullyQualifiedClassName);
	}

	// Add to shortcuts
	this.codeModels.put(fullyQualifiedClassName, this.pojo);
	return this;
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:39,代码来源:EnumBuilder.java



注:本文中的com.sun.codemodel.ClassType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ErrorCorrection类代码示例发布时间:2022-05-21
下一篇:
Java TextDirection类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap